These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /** |
||
3 | * Implements Special:Activeusers |
||
4 | * |
||
5 | * Copyright © 2008 Aaron Schulz |
||
6 | * |
||
7 | * This program is free software; you can redistribute it and/or modify |
||
8 | * it under the terms of the GNU General Public License as published by |
||
9 | * the Free Software Foundation; either version 2 of the License, or |
||
10 | * (at your option) any later version. |
||
11 | * |
||
12 | * This program is distributed in the hope that it will be useful, |
||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
15 | * GNU General Public License for more details. |
||
16 | * |
||
17 | * You should have received a copy of the GNU General Public License along |
||
18 | * with this program; if not, write to the Free Software Foundation, Inc., |
||
19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
||
20 | * http://www.gnu.org/copyleft/gpl.html |
||
21 | * |
||
22 | * @file |
||
23 | * @ingroup SpecialPage |
||
24 | */ |
||
25 | |||
26 | /** |
||
27 | * Implements Special:Activeusers |
||
28 | * |
||
29 | * @ingroup SpecialPage |
||
30 | */ |
||
31 | class SpecialActiveUsers extends SpecialPage { |
||
32 | |||
33 | /** |
||
34 | * Constructor |
||
35 | */ |
||
36 | public function __construct() { |
||
37 | parent::__construct( 'Activeusers' ); |
||
38 | } |
||
39 | |||
40 | /** |
||
41 | * Show the special page |
||
42 | * |
||
43 | * @param string $par Parameter passed to the page or null |
||
44 | */ |
||
45 | public function execute( $par ) { |
||
46 | $out = $this->getOutput(); |
||
47 | |||
48 | $this->setHeaders(); |
||
49 | $this->outputHeader(); |
||
50 | |||
51 | $opts = new FormOptions(); |
||
52 | |||
53 | $opts->add( 'username', '' ); |
||
54 | $opts->add( 'hidebots', false, FormOptions::BOOL ); |
||
55 | $opts->add( 'hidesysops', false, FormOptions::BOOL ); |
||
56 | |||
57 | $opts->fetchValuesFromRequest( $this->getRequest() ); |
||
58 | |||
59 | if ( $par !== null ) { |
||
60 | $opts->setValue( 'username', $par ); |
||
61 | } |
||
62 | |||
63 | // Mention the level of cache staleness... |
||
64 | $cacheText = ''; |
||
65 | $dbr = wfGetDB( DB_REPLICA, 'recentchanges' ); |
||
66 | $rcMax = $dbr->selectField( 'recentchanges', 'MAX(rc_timestamp)', '', __METHOD__ ); |
||
67 | if ( $rcMax ) { |
||
68 | $cTime = $dbr->selectField( 'querycache_info', |
||
69 | 'qci_timestamp', |
||
70 | [ 'qci_type' => 'activeusers' ], |
||
71 | __METHOD__ |
||
72 | ); |
||
73 | if ( $cTime ) { |
||
74 | $secondsOld = wfTimestamp( TS_UNIX, $rcMax ) - wfTimestamp( TS_UNIX, $cTime ); |
||
75 | } else { |
||
76 | $rcMin = $dbr->selectField( 'recentchanges', 'MIN(rc_timestamp)' ); |
||
77 | $secondsOld = time() - wfTimestamp( TS_UNIX, $rcMin ); |
||
78 | } |
||
79 | if ( $secondsOld > 0 ) { |
||
80 | $cacheTxt = '<br>' . $this->msg( 'cachedspecial-viewing-cached-ttl' ) |
||
0 ignored issues
–
show
|
|||
81 | ->durationParams( $secondsOld ); |
||
82 | } |
||
83 | } |
||
84 | |||
85 | $pager = new ActiveUsersPager( $this->getContext(), $opts ); |
||
86 | $usersBody = $pager->getBody(); |
||
87 | |||
88 | $days = $this->getConfig()->get( 'ActiveUserDays' ); |
||
89 | |||
90 | $formDescriptor = [ |
||
91 | 'username' => [ |
||
92 | 'type' => 'user', |
||
93 | 'name' => 'username', |
||
94 | 'label-message' => 'activeusers-from', |
||
95 | ], |
||
96 | |||
97 | 'hidebots' => [ |
||
98 | 'type' => 'check', |
||
99 | 'name' => 'hidebots', |
||
100 | 'label-message' => 'activeusers-hidebots', |
||
101 | 'default' => false, |
||
102 | ], |
||
103 | |||
104 | 'hidesysops' => [ |
||
105 | 'type' => 'check', |
||
106 | 'name' => 'hidesysops', |
||
107 | 'label-message' => 'activeusers-hidesysops', |
||
108 | 'default' => false, |
||
109 | ], |
||
110 | ]; |
||
111 | |||
112 | $htmlForm = HTMLForm::factory( 'ooui', $formDescriptor, $this->getContext() ) |
||
0 ignored issues
–
show
Are you sure the assignment to
$htmlForm is correct as \HTMLForm::factory('ooui...m()->displayForm(false) (which targets HTMLForm::displayForm() ) seems to always return null.
This check looks for function or method calls that always return null and whose return value is assigned to a variable. class A
{
function getObject()
{
return null;
}
}
$a = new A();
$object = $a->getObject();
The method The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.
Loading history...
$htmlForm is not used, you could remove the assignment.
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently. $myVar = 'Value';
$higher = false;
if (rand(1, 6) > 3) {
$higher = true;
} else {
$higher = false;
}
Both the
Loading history...
|
|||
113 | ->setIntro( $this->msg( 'activeusers-intro' )->numParams( $days ) . $cacheText ) |
||
114 | ->setWrapperLegendMsg( 'activeusers' ) |
||
115 | ->setSubmitTextMsg( 'activeusers-submit' ) |
||
116 | ->setMethod( 'get' ) |
||
117 | ->prepareForm() |
||
118 | ->displayForm( false ); |
||
119 | |||
120 | if ( $usersBody ) { |
||
121 | $out->addHTML( |
||
122 | $pager->getNavigationBar() . |
||
123 | Html::rawElement( 'ul', [], $usersBody ) . |
||
124 | $pager->getNavigationBar() |
||
125 | ); |
||
126 | } else { |
||
127 | $out->addWikiMsg( 'activeusers-noresult' ); |
||
128 | } |
||
129 | } |
||
130 | |||
131 | protected function getGroupName() { |
||
132 | return 'users'; |
||
133 | } |
||
134 | } |
||
135 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.