Test Failed
Push — newinternal ( 8c4587...b2f220 )
by Michael
15:41 queued 06:17
created

PageLog::setupPageData()   A

Complexity

Conditions 6
Paths 4

Size

Total Lines 41
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 42

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 19
c 1
b 0
f 0
dl 0
loc 41
ccs 0
cts 25
cp 0
rs 9.0111
cc 6
nc 4
nop 3
crap 42
1
<?php
2
/******************************************************************************
3
 * Wikipedia Account Creation Assistance tool                                 *
4
 *                                                                            *
5
 * All code in this file is released into the public domain by the ACC        *
6
 * Development Team. Please see team.json for a list of contributors.         *
7
 ******************************************************************************/
8
9
namespace Waca\Pages;
10
11
use Waca\DataObjects\Log;
12
use Waca\DataObjects\User;
13
use Waca\Helpers\LogHelper;
14
use Waca\Helpers\SearchHelpers\LogSearchHelper;
15
use Waca\Tasks\PagedInternalPageBase;
16
use Waca\WebRequest;
17
18
class PageLog extends PagedInternalPageBase
19
{
20
    /**
21
     * Main function for this page, when no specific actions are called.
22
     */
23
    protected function main()
24
    {
25
        $this->setHtmlTitle('Logs');
26
27
        $filterUser = WebRequest::getString('filterUser');
28
        $filterAction = WebRequest::getString('filterAction');
29
        $filterObjectType = WebRequest::getString('filterObjectType');
30
        $filterObjectId = WebRequest::getInt('filterObjectId');
31
32
        $database = $this->getDatabase();
33
34
        if (!array_key_exists($filterObjectType, LogHelper::getObjectTypes())) {
35
            $filterObjectType = null;
36
        }
37
38
        $this->addJs("/api.php?action=users&all=true&targetVariable=typeaheaddata");
39
40
        $logSearch = LogSearchHelper::get($database);
41
42
        if ($filterUser !== null) {
43
            $userObj = User::getByUsername($filterUser, $database);
44
            if ($userObj !== false) {
45
                $logSearch->byUser($userObj->getId());
46
            } else {
47
                $logSearch->byUser(-1);
48
            }
49
        }
50
        if ($filterAction !== null) {
51
            $logSearch->byAction($filterAction);
52
        }
53
        if ($filterObjectType !== null) {
54
            $logSearch->byObjectType($filterObjectType);
55
        }
56
        if ($filterObjectId !== null) {
57
            $logSearch->byObjectId($filterObjectId);
58
        }
59
60
        $this->setSearchHelper($logSearch);
61
        $this->setupLimits();
62
63
        /** @var Log[] $logs */
64
        $logs = $logSearch->getRecordCount($count)->fetch();
65
66
        list($users, $logData) = LogHelper::prepareLogsForTemplate($logs, $database, $this->getSiteConfiguration());
67
68
        $this->setupPageData($count, array('filterUser' => $filterUser, 'filterAction' => $filterAction, 'filterObjectType' => $filterObjectType, 'filterObjectId' => $filterObjectId));
69
70
        $this->assign("logs", $logData);
71
        $this->assign("users", $users);
72
73
        $this->assign('allLogActions', LogHelper::getLogActions($this->getDatabase()));
74
        $this->assign('allObjectTypes', LogHelper::getObjectTypes());
75
76
        $this->setTemplate("logs/main.tpl");
77
    }
78
}
79