r34633 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r34632‎ | r34633 | r34634 >
Date:21:43, 11 May 2008
Author:nikerabbit
Status:old
Tags:
Comment:
* Code cleanup
Modified paths:
  • /trunk/phase3/includes/SpecialNewpages.php (modified) (history)
  • /trunk/phase3/includes/SpecialWhatlinkshere.php (modified) (history)
  • /trunk/phase3/includes/Xml.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/Xml.php
@@ -397,6 +397,26 @@
398398 }
399399
400400 /**
 401+ * Shortcut for creating fieldsets.
 402+ *
 403+ * @param mixed $legend Legend of the fieldset. If evaluates to false, legend is not added.
 404+ * @param mixed $content Pre-escaped content for the fieldset. If null, only open fieldset is returned.
 405+ * @param mixed $attribs Any attributes to fieldset-element.
 406+ */
 407+ public static function fieldset( $legend = false, $content = false, $attribs = array() ) {
 408+ $s = Xml::openElement( 'fieldset', $attribs ) . "\n";
 409+ if ( $legend ) {
 410+ $s .= Xml::element( 'legend', null, $legend ) . "\n";
 411+ }
 412+ if ( $content !== false ) {
 413+ $s .= $content . "\n";
 414+ $s .= Xml::closeElement( 'fieldset' ) . "\n";
 415+ }
 416+
 417+ return $s;
 418+ }
 419+
 420+ /**
401421 * Returns an escaped string suitable for inclusion in a string literal
402422 * for JavaScript source code.
403423 * Illegal control characters are assumed not to be present.
Index: trunk/phase3/includes/SpecialWhatlinkshere.php
@@ -55,6 +55,8 @@
5656
5757 $opts->fetchValuesFromRequest( $this->request );
5858 $opts->validateIntBounds( 'limit', 0, 5000 );
 59+
 60+ // Give precedence to subpage syntax
5961 if ( isset($this->par) ) {
6062 $opts->setValue( 'target', $this->par );
6163 }
@@ -67,12 +69,12 @@
6870 $wgOut->addHTML( $this->whatlinkshereForm() );
6971 return;
7072 }
71 - $this->selfTitle = Title::makeTitleSafe( NS_SPECIAL,
72 - 'Whatlinkshere/' . $this->target->getPrefixedDBkey() );
7373
74 - $wgOut->setPageTitle( wfMsg( 'whatlinkshere-title', $this->target->getPrefixedText() ) );
75 - $wgOut->setSubtitle( wfMsg( 'linklistsub' ) );
 74+ $this->selfTitle = SpecialPage::getTitleFor( 'Whatlinkshere', $this->target->getPrefixedDBkey() );
7675
 76+ $wgOut->setPageTitle( wfMsgExt( 'whatlinkshere-title', 'escape', $this->target->getPrefixedText() ) );
 77+ $wgOut->setSubtitle( wfMsgHtml( 'linklistsub' ) );
 78+
7779 $wgOut->addHTML( wfMsgExt( 'whatlinkshere-barrow', array( 'escapenoentities') ) . ' ' .$this->skin->makeLinkObj($this->target, '', 'redirect=no' )."<br />\n");
7880
7981 $this->showIndirectLinks( 0, $this->target, $opts->getValue( 'limit' ),
@@ -222,7 +224,7 @@
223225 $prevId = $from;
224226
225227 if ( $level == 0 ) {
226 - $wgOut->addHTML( $this->whatlinkshereForm( ) );
 228+ $wgOut->addHTML( $this->whatlinkshereForm() );
227229 $wgOut->addHTML( $this->getFilterPanel() );
228230 $wgOut->addWikiMsg( 'linkshere', $this->target->getPrefixedText() );
229231
@@ -352,7 +354,7 @@
353355 $namespace = $this->opts->consumeValue( 'namespace' );
354356
355357 # Build up the form
356 - $f = Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) );
 358+ $f = Xml::openElement( 'form', array( 'action' => $wgScript ) );
357359
358360 # Values that should not be forgotten
359361 $f .= Xml::hidden( 'title', $wgTitle->getPrefixedText() );
@@ -360,8 +362,7 @@
361363 $f .= Xml::hidden( $name, $value );
362364 }
363365
364 - $f .= Xml::openElement( 'fieldset' );
365 - $f .= Xml::element( 'legend', null, wfMsg( 'whatlinkshere' ) );
 366+ $f .= Xml::fieldset( wfMsg( 'whatlinkshere' ) );
366367
367368 # Target input
368369 $f .= Xml::inputLabel( wfMsg( 'whatlinkshere-page' ), 'target',
@@ -399,9 +400,6 @@
400401 $overrides = array( $type => !$chosen );
401402 $links[] = $this->makeSelfLink( $msg, wfArrayToCGI( $overrides, $changed ) );
402403 }
403 - return Xml::tags( 'fieldset', null,
404 - Xml::element( 'legend', null, wfMsg( 'whatlinkshere-filters' ) ) .
405 - implode( '&nbsp;|&nbsp;', $links )
406 - );
 404+ return Xml::fieldset( wfMsg( 'whatlinkshere-filters' ), implode( '&nbsp;|&nbsp;', $links ) );
407405 }
408406 }
Index: trunk/phase3/includes/SpecialNewpages.php
@@ -10,8 +10,7 @@
1111 */
1212 function wfSpecialNewPages( $par, $sp ) {
1313 $page = new NewPagesForm();
14 -
15 - $page->showList( $par, $sp->including() );
 14+ $page->execute( $par, $sp->including() );
1615 }
1716
1817 /**
@@ -19,6 +18,71 @@
2019 * @addtogroup SpecialPage
2120 */
2221 class NewPagesForm {
 22+
 23+ // Stored objects
 24+ protected $opts, $title, $skin;
 25+
 26+ // Some internal settings
 27+ protected $showNavigation = false;
 28+
 29+ protected function setup( $par ) {
 30+ global $wgRequest, $wgUser, $wgEnableNewpagesUserFilter;
 31+
 32+ // Options
 33+ $opts = new FormOptions();
 34+ $opts->add( 'hideliu', false );
 35+ $opts->add( 'hidepatrolled', false );
 36+ $opts->add( 'hidebots', false );
 37+ $opts->add( 'limit', 50 );
 38+ $opts->add( 'offset', 0 );
 39+ $opts->add( 'namespace', '0' );
 40+ $opts->add( 'username', '' );
 41+ $opts->add( 'feed', '' );
 42+
 43+ // Set values
 44+ $opts->fetchValuesFromRequest( $wgRequest );
 45+ if ( $par ) $this->parseParams( $par );
 46+
 47+ // Validate
 48+ $opts->validateIntBounds( 'limit', 0, 5000 );
 49+ if( !$wgEnableNewpagesUserFilter ) {
 50+ $opts->setValue( 'username', '' );
 51+ }
 52+
 53+ // Store some objects
 54+ $this->opts = $opts;
 55+ $this->skin = $wgUser->getSkin();
 56+ $this->title = SpecialPage::getTitleFor( 'NewPages' );
 57+ }
 58+
 59+ protected function parseParams( $par ) {
 60+ $bits = preg_split( '/\s*,\s*/', trim( $par ) );
 61+ foreach ( $bits as $bit ) {
 62+ if ( 'shownav' == $bit )
 63+ $this->showNavigation = true;
 64+ if ( 'hideliu' === $bit )
 65+ $this->opts->setValue( 'hideliu', true );
 66+ if ( 'hidepatrolled' == $bit )
 67+ $this->opts->setValue( 'hidepatrolled', true );
 68+ if ( 'hidebots' == $bit )
 69+ $this->opts->setValue( 'hidebots', true );
 70+ if ( is_numeric( $bit ) )
 71+ $this->opts->setValue( 'limit', intval( $bit ) );
 72+
 73+ $m = array();
 74+ if ( preg_match( '/^limit=(\d+)$/', $bit, $m ) )
 75+ $this->opts->setValue( 'limit', intval($m[1]) );
 76+ if ( preg_match( '/^offset=(\d+)$/', $bit, $m ) )
 77+ $this->opts->setValue( 'offset', intval($m[1]) );
 78+ if ( preg_match( '/^namespace=(.*)$/', $bit, $m ) ) {
 79+ $ns = $wgLang->getNsIndex( $m[1] );
 80+ if( $ns !== false ) {
 81+ $this->opts->setValue( 'namespace', $ns );
 82+ }
 83+ }
 84+ }
 85+ }
 86+
2387 /**
2488 * Show a form for filtering namespace and username
2589 *
@@ -26,177 +90,139 @@
2791 * @param bool $including true if the page is being included with {{Special:Newpages}}
2892 * @return string
2993 */
30 - public function showList( $par, $including ) {
31 - global $wgScript, $wgLang, $wgGroupPermissions, $wgRequest, $wgUser, $wgOut;
32 - global $wgEnableNewpagesUserFilter;
33 - $sk = $wgUser->getSkin();
34 - $self = SpecialPage::getTitleFor( 'NewPages' );
 94+ public function execute( $par, $including ) {
 95+ global $wgLang, $wgGroupPermissions, $wgUser, $wgOut;
3596
36 - // show/hide links
37 - $showhide = array( wfMsgHtml( 'show' ), wfMsgHtml( 'hide' ) );
 97+ $this->showNavigation = !$including; // Maybe changed in setup
 98+ $this->setup( $par );
3899
39 - $hidelinks = array();
 100+ // Settings
 101+ $this->form();
40102
41 - if ( $wgGroupPermissions['*']['createpage'] === true ) {
42 - $hidelinks['hideliu'] = 'rcshowhideliu';
 103+ if( !$including ){
 104+ $this->setSyndicated();
 105+ $feedType = $this->opts->getValue( 'feed' );
 106+ if( $feedType ) {
 107+ return $this->feed( $feedType, $options );
 108+ }
43109 }
44 - if ( $wgUser->useNPPatrol() ) {
45 - $hidelinks['hidepatrolled'] = 'rcshowhidepatr';
46 - }
47 - $hidelinks['hidebots'] = 'rcshowhidebots';
48110
49 - $defaults = array(
50 - /* bool */ 'hideliu' => false,
51 - /* bool */ 'hidepatrolled' => false,
52 - /* bool */ 'hidebots' => false,
53 - /* text */ 'namespace' => "0",
54 - /* text */ 'username' => '',
55 - /* int */ 'offset' => 0,
56 - /* int */ 'limit' => 50,
57 - );
58 - $options = $defaults;
 111+ $pager = new NewPagesPager( $this, $this->opts );
 112+ $pager->mLimit = $this->opts->getValue( 'limit' );
 113+ $pager->mOffset = $this->opts->getValue( 'offset' );
59114
60 - // Override all values from requests, if specified
61 - foreach ( $defaults as $v => $t ) {
62 - if ( is_bool($t) ) {
63 - $options[$v] = $wgRequest->getBool( $v, $options[$v] );
64 - } elseif( is_int($t) ) {
65 - $options[$v] = $wgRequest->getInt( $v, $options[$v] );
66 - } elseif( is_string($t) ) {
67 - $options[$v] = trim( $wgRequest->getVal( $v, $options[$v] ) );
68 - }
 115+ if( $pager->getNumRows() ) {
 116+ $navigation = '';
 117+ if ( $this->showNavigation ) $navigation = $pager->getNavigationBar();
 118+ $wgOut->addHTML( $navigation . $pager->getBody() . $navigation );
 119+ } else {
 120+ $wgOut->addWikiMsg( 'specialpage-empty' );
69121 }
 122+ }
70123
71 - $shownav = !$including;
72 - if ( $par ) {
73 - $bits = preg_split( '/\s*,\s*/', trim( $par ) );
74 - foreach ( $bits as $bit ) {
75 - if ( 'shownav' == $bit )
76 - $shownav = true;
77 - if ( 'hideliu' === $bit )
78 - $options['hideliu'] = true;
79 - if ( 'hidepatrolled' == $bit )
80 - $options['hidepatrolled'] = true;
81 - if ( 'hidebots' == $bit )
82 - $options['hidebots'] = true;
83 - if ( is_numeric( $bit ) )
84 - $options['limit'] = intval( $bit );
 124+ protected function filterLinks() {
 125+ global $wgGroupPermissions, $wgUser;
85126
86 - $m = array();
87 - if ( preg_match( '/^limit=(\d+)$/', $bit, $m ) )
88 - $options['limit'] = intval($m[1]);
89 - if ( preg_match( '/^offset=(\d+)$/', $bit, $m ) )
90 - $options['offset'] = intval($m[1]);
91 - if ( preg_match( '/^namespace=(.*)$/', $bit, $m ) ) {
92 - $ns = $wgLang->getNsIndex( $m[1] );
93 - if( $ns !== false ) {
94 - $options['namespace'] = $ns;
95 - }
96 - }
97 - }
98 - }
 127+ // show/hide links
 128+ $showhide = array( wfMsgHtml( 'show' ), wfMsgHtml( 'hide' ) );
99129
100 - if( !$wgEnableNewpagesUserFilter ) {
101 - // hack disable
102 - $options['username'] = '';
103 - }
104 -
105 - if( !$including ){
106 - $wgOut->setSyndicated( true );
107 - $wgOut->setFeedAppendQuery( "namespace={$options['namespace']}&username={$options['username']}" );
 130+ // Option value -> message mapping
 131+ $filters = array(
 132+ 'hideliu' => 'rcshowhideliu',
 133+ 'hidepatrolled' => 'rcshowhidepatr',
 134+ 'hidebots' => 'rcshowhidebots'
 135+ );
108136
109 - $feedType = $wgRequest->getVal( 'feed' );
110 - if( $feedType ) {
111 - wfProfileOut( __METHOD__ );
112 - return $this->feed( $feedType, $options );
113 - }
 137+ // Disable some if needed
 138+ if ( $wgGroupPermissions['*']['createpage'] !== true )
 139+ unset($hidelinks['hideliu']);
114140
115 - $nondefaults = array();
116 - foreach ( $options as $v => $t ) {
117 - if ( $v === 'offset' ) continue; # Reset offset if parameters change
118 - wfAppendToArrayIfNotDefault( $v, $t, $defaults, $nondefaults );
119 - }
 141+ if ( $wgUser->useNPPatrol() )
 142+ unset($hidelinks['hidepatrolled']);
120143
121 - $links = array();
122 - foreach ( $hidelinks as $key => $msg ) {
123 - $reversed = 1 - $options[$key];
124 - $link = $sk->makeKnownLinkObj( $self, $showhide[$reversed],
125 - wfArrayToCGI( array( $key => $reversed ), $nondefaults )
126 - );
127 - $links[$key] = wfMsgHtml( $msg, $link );
128 - }
 144+ $links = array();
 145+ $changed = $this->opts->getChangedValues();
 146+ unset($changed['offset']); // Reset offset if query type changes
129147
130 - $hl = implode( ' | ', $links );
 148+ foreach ( $filters as $key => $msg ) {
 149+ $onoff = 1 - $this->opts->getValue($key);
 150+ $link = $this->skin->makeKnownLinkObj( $this->title, $showhide[$onoff],
 151+ wfArrayToCGI( array( $key => $onoff ), $changed )
 152+ );
 153+ $links[$key] = wfMsgHtml( $msg, $link );
 154+ }
131155
132 - // Store query values in hidden fields so that form submission doesn't lose them
133 - $hidden = array();
134 - foreach ( $nondefaults as $key => $value ) {
135 - if ( $key === 'namespace' ) continue;
136 - if ( $key === 'username' ) continue;
137 - $hidden[] = Xml::hidden( $key, $value );
138 - }
139 - $hidden = implode( "\n", $hidden );
140 -
141 - $ut = Title::makeTitleSafe( NS_USER, $options['username'] );
142 - $userText = $ut ? $ut->getText() : '';
 156+ return implode( ' | ', $links );
 157+ }
143158
144 - $form = Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) ) .
145 - Xml::hidden( 'title', $self->getPrefixedDBkey() ) .
146 - Xml::openElement( 'fieldset' ) .
147 - Xml::element( 'legend', null, wfMsg( 'newpages' ) ) .
148 - Xml::openElement( 'table', array( 'id' => 'mw-newpages-table' ) ) .
149 - "<tr>
150 - <td class='mw-label'>" .
151 - Xml::label( wfMsg( 'namespace' ), 'namespace' ) .
152 - "</td>
153 - <td class='mw-input'>" .
154 - Xml::namespaceSelector( $options['namespace'], 'all' ) .
155 - "</td>
156 - </tr>" .
157 - ($wgEnableNewpagesUserFilter ?
158 - "<tr>
159 - <td class='mw-label'>" .
160 - Xml::label( wfMsg( 'newpages-username' ), 'mw-np-username' ) .
161 - "</td>
162 - <td class='mw-input'>" .
163 - Xml::input( 'username', 30, $userText, array( 'id' => 'mw-np-username' ) ) .
164 - "</td>
165 - </tr>" : "" ) .
166 - "<tr> <td></td>
167 - <td class='mw-submit'>" .
168 - Xml::submitButton( wfMsg( 'allpagessubmit' ) ) .
169 - "</td>
170 - </tr>" .
171 - "<tr>
172 - <td></td>
173 - <td class='mw-input'>" .
174 - $hl .
175 - "</td>
176 - </tr>" .
177 - Xml::closeElement( 'table' ) .
178 - Xml::closeElement( 'fieldset' ) .
179 - $hidden .
180 - Xml::closeElement( 'form' );
 159+ protected function form() {
 160+ global $wgOut, $wgEnableNewpagesUserFilter, $wgScript;
181161
182 - $wgOut->addHTML( $form );
 162+ // Consume values
 163+ $namespace = $this->opts->consumeValue( 'namespace' );
 164+ $username = $this->opts->consumeValue( 'username' );
 165+
 166+ // Check username input validity
 167+ $ut = Title::makeTitleSafe( NS_USER, $username );
 168+ $userText = $ut ? $ut->getText() : '';
 169+
 170+ // Store query values in hidden fields so that form submission doesn't lose them
 171+ $hidden = array();
 172+ foreach ( $this->opts->getUnconsumedValues() as $key => $value ) {
 173+ $hidden[] = Xml::hidden( $key, $value );
183174 }
 175+ $hidden = implode( "\n", $hidden );
184176
185 - $pager = new NewPagesPager( $this, array(), $options['namespace'], $options['hideliu'],
186 - $options['hidepatrolled'], $options['hidebots'], $options['username'] );
187 - $pager->mLimit = $options['limit'];
188 - $pager->mOffset = $options['offset'];
 177+ $form = Xml::openElement( 'form', array( 'action' => $wgScript ) ) .
 178+ Xml::hidden( 'title', $this->title->getPrefixedDBkey() ) .
 179+ Xml::fieldset( wfMsg( 'newpages' ) ) .
 180+ Xml::openElement( 'table', array( 'id' => 'mw-newpages-table' ) ) .
 181+ "<tr>
 182+ <td class='mw-label'>" .
 183+ Xml::label( wfMsg( 'namespace' ), 'namespace' ) .
 184+ "</td>
 185+ <td class='mw-input'>" .
 186+ Xml::namespaceSelector( $namespace, 'all' ) .
 187+ "</td>
 188+ </tr>" .
 189+ ($wgEnableNewpagesUserFilter ?
 190+ "<tr>
 191+ <td class='mw-label'>" .
 192+ Xml::label( wfMsg( 'newpages-username' ), 'mw-np-username' ) .
 193+ "</td>
 194+ <td class='mw-input'>" .
 195+ Xml::input( 'username', 30, $userText, array( 'id' => 'mw-np-username' ) ) .
 196+ "</td>
 197+ </tr>" : "" ) .
 198+ "<tr> <td></td>
 199+ <td class='mw-submit'>" .
 200+ Xml::submitButton( wfMsg( 'allpagessubmit' ) ) .
 201+ "</td>
 202+ </tr>" .
 203+ "<tr>
 204+ <td></td>
 205+ <td class='mw-input'>" .
 206+ $this->filterLinks() .
 207+ "</td>
 208+ </tr>" .
 209+ Xml::closeElement( 'table' ) .
 210+ Xml::closeElement( 'fieldset' ) .
 211+ $hidden .
 212+ Xml::closeElement( 'form' );
189213
190 - if( $pager->getNumRows() ) {
191 - $wgOut->addHTML(
192 - ( $shownav ? $pager->getNavigationBar() : '' ) .
193 - $pager->getBody() .
194 - ( $shownav ? $pager->getNavigationBar() : '' )
195 - );
196 - } else {
197 - $wgOut->addHTML( Xml::element( 'p', null, wfMsg( 'specialpage-empty' ) ) );
198 - }
 214+ $wgOut->addHTML( $form );
199215 }
200216
 217+ protected function setSyndicated() {
 218+ global $wgOut;
 219+ $queryParams = array(
 220+ 'namespace' => $this->opts->getValue( 'namespace' ),
 221+ 'username' => $this->opts->getValue( 'username' )
 222+ );
 223+ $wgOut->setSyndicated( true );
 224+ $wgOut->setFeedAppendQuery( wfArrayToCGI( $queryParams ) );
 225+ }
 226+
201227 /**
202228 * Format a row, providing the timestamp, links to the page/history, size, user links, and a comment
203229 *
@@ -208,20 +234,15 @@
209235 global $wgLang, $wgContLang, $wgUser;
210236 $dm = $wgContLang->getDirMark();
211237
212 - static $skin=null;
213 -
214 - if( is_null( $skin ) )
215 - $skin = $wgUser->getSkin();
216 -
217238 $title = Title::makeTitleSafe( $result->rc_namespace, $result->rc_title );
218239 $time = $wgLang->timeAndDate( $result->rc_timestamp, true );
219 - $plink = $skin->makeKnownLinkObj( $title, '', $this->patrollable( $result ) ? 'rcid=' . $result->rc_id : '' );
220 - $hist = $skin->makeKnownLinkObj( $title, wfMsgHtml( 'hist' ), 'action=history' );
 240+ $plink = $this->skin->makeKnownLinkObj( $title, '', $this->patrollable( $result ) ? 'rcid=' . $result->rc_id : '' );
 241+ $hist = $this->skin->makeKnownLinkObj( $title, wfMsgHtml( 'hist' ), 'action=history' );
221242 $length = wfMsgExt( 'nbytes', array( 'parsemag', 'escape' ),
222 - $wgLang->formatNum( htmlspecialchars( $result->length ) ) );
223 - $ulink = $skin->userLink( $result->rc_user, $result->rc_user_text ) . ' ' .
224 - $skin->userToolLinks( $result->rc_user, $result->rc_user_text );
225 - $comment = $skin->commentBlock( $result->rc_comment );
 243+ $wgLang->formatNum( $result->length ) );
 244+ $ulink = $this->skin->userLink( $result->rc_user, $result->rc_user_text ) . ' ' .
 245+ $this->skin->userToolLinks( $result->rc_user, $result->rc_user_text );
 246+ $comment = $this->skin->commentBlock( $result->rc_comment );
226247 $css = $this->patrollable( $result ) ? 'not-patrolled' : '';
227248
228249 return "<li class='$css'>{$time} {$dm}{$plink} ({$hist}) {$dm}[{$length}] {$dm}{$ulink} {$comment}</li>\n";
@@ -259,14 +280,12 @@
260281 return;
261282 }
262283
263 - $self = SpecialPage::getTitleFor( 'NewPages' );
264284 $feed = new $wgFeedClasses[$type](
265285 $this->feedTitle(),
266286 wfMsg( 'tagline' ),
267 - $self->getFullUrl() );
 287+ $this->title->getFullUrl() );
268288
269 - $pager = new NewPagesPager( $this, array(), $options['namespace'], $options['hideliu'],
270 - $options['hidepatrolled'], $options['hidebots'], $options['username'] );
 289+ $pager = new NewPagesPager( $this, $this->opts );
271290
272291 $feed->outHeader();
273292 if( $pager->getNumRows() > 0 ) {
@@ -329,33 +348,37 @@
330349 * @addtogroup Pager
331350 */
332351 class NewPagesPager extends ReverseChronologicalPager {
 352+ // Stored opts
 353+ protected $opts, $mForm;
 354+
333355 private $hideliu, $hidepatrolled, $hidebots, $namespace, $user, $spTitle;
334356
335 - function __construct( $form, $conds=array(), $namespace, $hliu=false, $hpatrolled=false, $hbots=1, $user='' ) {
 357+ function __construct( $form, FormOptions $opts ) {
336358 parent::__construct();
337359 $this->mForm = $form;
338 - $this->mConds = $conds;
339 -
340 - $this->namespace = ($namespace === "all") ? false : intval($namespace);
341 - $this->user = $user;
342 -
343 - $this->hideliu = (bool)$hliu;
344 - $this->hidepatrolled = (bool)$hpatrolled;
345 - $this->hidebots = (bool)$hbots;
 360+ $this->opts = $opts;
346361 }
347362
348363 function getTitle(){
349 - if( !isset( $this->spTitle ) )
350 - $this->spTitle = SpecialPage::getTitleFor( 'Newpages' );
351 - return $this->spTitle;
 364+ static $title = null;
 365+ if ( $title === null )
 366+ $title = SpecialPage::getTitleFor( 'Newpages' );
 367+ return $title;
352368 }
353369
354370 function getQueryInfo() {
355 - global $wgEnableNewpagesUserFilter;
356 - $conds = $this->mConds;
 371+ global $wgEnableNewpagesUserFilter, $wgGroupPermissions, $wgUser;
 372+ $conds = array();
357373 $conds['rc_new'] = 1;
358 - if( $this->namespace !== false ) {
359 - $conds['rc_namespace'] = $this->namespace;
 374+
 375+ $namespace = $this->opts->getValue( 'namespace' );
 376+ $namespace = ( $namespace === 'all' ) ? false : intval( $namespace );
 377+
 378+ $username = $this->opts->getValue( 'username' );
 379+ $user = Title::makeTitleSafe( NS_USER, $username );
 380+
 381+ if( $namespace !== false ) {
 382+ $conds['rc_namespace'] = $namespace;
360383 $rcIndexes = array( 'new_name_timestamp' );
361384 } else {
362385 $rcIndexes = array( 'rc_timestamp' );
@@ -363,26 +386,22 @@
364387 $conds[] = 'page_id = rc_cur_id';
365388 $conds['page_is_redirect'] = 0;
366389
367 - global $wgGroupPermissions, $wgUser;
368390 # If anons cannot make new pages, don't query for it!
369 - if( $wgGroupPermissions['*']['createpage'] && $this->hideliu ) {
 391+ if( $wgGroupPermissions['*']['createpage'] && $this->opts->getValue( 'hideliu' ) ) {
370392 $conds['rc_user'] = 0;
371 - } else {
372 - $title = Title::makeTitleSafe( NS_USER, $this->user );
373 - if( $title ) {
374 - $conds['rc_user_text'] = $title->getText();
375 - }
 393+ } elseif ( $user ) {
 394+ $conds['rc_user_text'] = $user->getText();
376395 }
377396 # If this user cannot see patrolled edits or they are off, don't do dumb queries!
378 - if( $this->hidepatrolled && $wgUser->useNPPatrol() ) {
 397+ if( $this->opts->getValue( 'hidepatrolled' ) && $wgUser->useNPPatrol() ) {
379398 $conds['rc_patrolled'] = 0;
380399 }
381 - if( $this->hidebots ) {
 400+ if( $this->opts->getValue( 'hidebots' ) ) {
382401 $conds['rc_bot'] = 0;
383402 }
384403 # $wgEnableNewpagesUserFilter - temp WMF hack
385 - if( $wgEnableNewpagesUserFilter && $this->user ) {
386 - $conds['rc_user_text'] = $this->user;
 404+ if( $wgEnableNewpagesUserFilter && $user ) {
 405+ $conds['rc_user_text'] = $user->getText();
387406 $rcIndexes = 'rc_user_text';
388407 }
389408

Status & tagging log