r91074 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r91073‎ | r91074 | r91075 >
Date:15:16, 29 June 2011
Author:ialex
Status:resolved
Tags:
Comment:
* Modified some methods of SpecialWatchlist to be non-static so that they can use $this->getTitle() instead of having to pass the special page's name
* Use context variable instead of global ones
* Really use countItems()
* Updated InterwikiIntegration for these changes; I'm not keeping b/c since anyway that extension was broken until now because SpecialWatchlist::countItems() was static and SpecialInterwikiWatchlist::countItems() not (was throwing fatal error)
Modified paths:
  • /trunk/extensions/InterwikiIntegration/SpecialInterwikiWatchlist.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialWatchlist.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/specials/SpecialWatchlist.php
@@ -26,8 +26,8 @@
2727 /**
2828 * Constructor
2929 */
30 - public function __construct(){
31 - parent::__construct( 'Watchlist' );
 30+ public function __construct( $page = 'Watchlist' ){
 31+ parent::__construct( $page );
3232 }
3333
3434 /**
@@ -35,47 +35,51 @@
3636 * @param $par Parameter passed to the page
3737 */
3838 function execute( $par ) {
39 - global $wgUser, $wgOut, $wgLang, $wgRequest;
4039 global $wgRCShowWatchingUsers, $wgEnotifWatchlist, $wgShowUpdatedMarker;
4140
 41+ $user = $this->getUser();
 42+ $output = $this->getOutput();
 43+
4244 // Add feed links
43 - $wlToken = $wgUser->getOption( 'watchlisttoken' );
 45+ $wlToken = $user->getOption( 'watchlisttoken' );
4446 if ( !$wlToken ) {
4547 $wlToken = sha1( mt_rand() . microtime( true ) );
46 - $wgUser->setOption( 'watchlisttoken', $wlToken );
47 - $wgUser->saveSettings();
 48+ $user->setOption( 'watchlisttoken', $wlToken );
 49+ $user->saveSettings();
4850 }
4951
5052 $this->addFeedLinks( array( 'action' => 'feedwatchlist', 'allrev' => 'allrev',
51 - 'wlowner' => $wgUser->getName(), 'wltoken' => $wlToken ) );
 53+ 'wlowner' => $user->getName(), 'wltoken' => $wlToken ) );
5254
53 - $skin = $this->getSkin();
54 - $wgOut->setRobotPolicy( 'noindex,nofollow' );
 55+ $output->setRobotPolicy( 'noindex,nofollow' );
5556
5657 # Anons don't get a watchlist
57 - if( $wgUser->isAnon() ) {
58 - $wgOut->setPageTitle( wfMsg( 'watchnologin' ) );
59 - $llink = $skin->linkKnown(
 58+ if( $user->isAnon() ) {
 59+ $output->setPageTitle( wfMsg( 'watchnologin' ) );
 60+ $llink = Linker::linkKnown(
6061 SpecialPage::getTitleFor( 'Userlogin' ),
6162 wfMsgHtml( 'loginreqlink' ),
6263 array(),
6364 array( 'returnto' => $this->getTitle()->getPrefixedText() )
6465 );
65 - $wgOut->addWikiMsgArray( 'watchlistanontext', array( $llink ), array( 'replaceafter' ) );
 66+ $output->addWikiMsgArray( 'watchlistanontext', array( $llink ), array( 'replaceafter' ) );
6667 return;
6768 }
6869
69 - $wgOut->setPageTitle( wfMsg( 'watchlist' ) );
 70+ $this->setHeaders();
 71+ $this->outputHeader();
7072
7173 $sub = wfMsgExt(
7274 'watchlistfor2',
7375 array( 'parseinline', 'replaceafter' ),
74 - $wgUser->getName(),
75 - SpecialEditWatchlist::buildTools( $skin )
 76+ $user->getName(),
 77+ SpecialEditWatchlist::buildTools( $this->getSkin() )
7678 );
77 - $wgOut->setSubtitle( $sub );
 79+ $output->setSubtitle( $sub );
7880
79 - $mode = SpecialEditWatchlist::getMode( $wgRequest, $par );
 81+ $request = $this->getRequest();
 82+
 83+ $mode = SpecialEditWatchlist::getMode( $request, $par );
8084 if( $mode !== false ) {
8185 # TODO: localise?
8286 switch( $mode ){
@@ -89,28 +93,33 @@
9094 $mode = null;
9195 }
9296 $title = SpecialPage::getTitleFor( 'EditWatchlist', $mode );
93 - $wgOut->redirect( $title->getLocalUrl() );
 97+ $output->redirect( $title->getLocalUrl() );
9498 return;
9599 }
96100
97 - $uid = $wgUser->getId();
98 - if( ( $wgEnotifWatchlist || $wgShowUpdatedMarker ) && $wgRequest->getVal( 'reset' ) &&
99 - $wgRequest->wasPosted() )
 101+ if( ( $wgEnotifWatchlist || $wgShowUpdatedMarker ) && $request->getVal( 'reset' ) &&
 102+ $request->wasPosted() )
100103 {
101 - $wgUser->clearAllNotifications( $uid );
102 - $wgOut->redirect( $this->getTitle()->getFullUrl() );
 104+ $user->clearAllNotifications();
 105+ $output->redirect( $this->getTitle()->getFullUrl() );
103106 return;
104107 }
105108
 109+ $nitems = $this->countItems();
 110+ if ( $nitems == 0 ) {
 111+ $output->addWikiMsg( 'nowatchlist' );
 112+ return;
 113+ }
 114+
106115 // @TODO: use FormOptions!
107116 $defaults = array(
108 - /* float */ 'days' => floatval( $wgUser->getOption( 'watchlistdays' ) ), /* 3.0 or 0.5, watch further below */
109 - /* bool */ 'hideMinor' => (int)$wgUser->getBoolOption( 'watchlisthideminor' ),
110 - /* bool */ 'hideBots' => (int)$wgUser->getBoolOption( 'watchlisthidebots' ),
111 - /* bool */ 'hideAnons' => (int)$wgUser->getBoolOption( 'watchlisthideanons' ),
112 - /* bool */ 'hideLiu' => (int)$wgUser->getBoolOption( 'watchlisthideliu' ),
113 - /* bool */ 'hidePatrolled' => (int)$wgUser->getBoolOption( 'watchlisthidepatrolled' ),
114 - /* bool */ 'hideOwn' => (int)$wgUser->getBoolOption( 'watchlisthideown' ),
 117+ /* float */ 'days' => floatval( $user->getOption( 'watchlistdays' ) ), /* 3.0 or 0.5, watch further below */
 118+ /* bool */ 'hideMinor' => (int)$user->getBoolOption( 'watchlisthideminor' ),
 119+ /* bool */ 'hideBots' => (int)$user->getBoolOption( 'watchlisthidebots' ),
 120+ /* bool */ 'hideAnons' => (int)$user->getBoolOption( 'watchlisthideanons' ),
 121+ /* bool */ 'hideLiu' => (int)$user->getBoolOption( 'watchlisthideliu' ),
 122+ /* bool */ 'hidePatrolled' => (int)$user->getBoolOption( 'watchlisthidepatrolled' ),
 123+ /* bool */ 'hideOwn' => (int)$user->getBoolOption( 'watchlisthideown' ),
115124 /* ? */ 'namespace' => 'all',
116125 /* ? */ 'invert' => false,
117126 );
@@ -122,30 +131,30 @@
123132
124133 # Extract variables from the request, falling back to user preferences or
125134 # other default values if these don't exist
126 - $prefs['days'] = floatval( $wgUser->getOption( 'watchlistdays' ) );
127 - $prefs['hideminor'] = $wgUser->getBoolOption( 'watchlisthideminor' );
128 - $prefs['hidebots'] = $wgUser->getBoolOption( 'watchlisthidebots' );
129 - $prefs['hideanons'] = $wgUser->getBoolOption( 'watchlisthideanons' );
130 - $prefs['hideliu'] = $wgUser->getBoolOption( 'watchlisthideliu' );
131 - $prefs['hideown' ] = $wgUser->getBoolOption( 'watchlisthideown' );
132 - $prefs['hidepatrolled' ] = $wgUser->getBoolOption( 'watchlisthidepatrolled' );
 135+ $prefs['days'] = floatval( $user->getOption( 'watchlistdays' ) );
 136+ $prefs['hideminor'] = $user->getBoolOption( 'watchlisthideminor' );
 137+ $prefs['hidebots'] = $user->getBoolOption( 'watchlisthidebots' );
 138+ $prefs['hideanons'] = $user->getBoolOption( 'watchlisthideanons' );
 139+ $prefs['hideliu'] = $user->getBoolOption( 'watchlisthideliu' );
 140+ $prefs['hideown' ] = $user->getBoolOption( 'watchlisthideown' );
 141+ $prefs['hidepatrolled' ] = $user->getBoolOption( 'watchlisthidepatrolled' );
133142
134143 # Get query variables
135144 $values = array();
136 - $values['days'] = $wgRequest->getVal( 'days', $prefs['days'] );
137 - $values['hideMinor'] = (int)$wgRequest->getBool( 'hideMinor', $prefs['hideminor'] );
138 - $values['hideBots'] = (int)$wgRequest->getBool( 'hideBots' , $prefs['hidebots'] );
139 - $values['hideAnons'] = (int)$wgRequest->getBool( 'hideAnons', $prefs['hideanons'] );
140 - $values['hideLiu'] = (int)$wgRequest->getBool( 'hideLiu' , $prefs['hideliu'] );
141 - $values['hideOwn'] = (int)$wgRequest->getBool( 'hideOwn' , $prefs['hideown'] );
142 - $values['hidePatrolled'] = (int)$wgRequest->getBool( 'hidePatrolled', $prefs['hidepatrolled'] );
 145+ $values['days'] = $request->getVal( 'days', $prefs['days'] );
 146+ $values['hideMinor'] = (int)$request->getBool( 'hideMinor', $prefs['hideminor'] );
 147+ $values['hideBots'] = (int)$request->getBool( 'hideBots' , $prefs['hidebots'] );
 148+ $values['hideAnons'] = (int)$request->getBool( 'hideAnons', $prefs['hideanons'] );
 149+ $values['hideLiu'] = (int)$request->getBool( 'hideLiu' , $prefs['hideliu'] );
 150+ $values['hideOwn'] = (int)$request->getBool( 'hideOwn' , $prefs['hideown'] );
 151+ $values['hidePatrolled'] = (int)$request->getBool( 'hidePatrolled', $prefs['hidepatrolled'] );
143152 foreach( $this->customFilters as $key => $params ) {
144 - $values[$key] = (int)$wgRequest->getBool( $key );
 153+ $values[$key] = (int)$request->getBool( $key );
145154 }
146155
147156 # Get namespace value, if supplied, and prepare a WHERE fragment
148 - $nameSpace = $wgRequest->getIntOrNull( 'namespace' );
149 - $invert = $wgRequest->getIntOrNull( 'invert' );
 157+ $nameSpace = $request->getIntOrNull( 'namespace' );
 158+ $invert = $request->getIntOrNull( 'invert' );
150159 if ( !is_null( $nameSpace ) ) {
151160 $nameSpace = intval( $nameSpace ); // paranioa
152161 if ( $invert ) {
@@ -160,15 +169,6 @@
161170 $values['namespace'] = $nameSpace;
162171 $values['invert'] = $invert;
163172
164 - $dbr = wfGetDB( DB_SLAVE, 'watchlist' );
165 - $recentchanges = $dbr->tableName( 'recentchanges' );
166 -
167 - $watchlistCount = $dbr->selectField( 'watchlist', 'COUNT(*)',
168 - array( 'wl_user' => $uid ), __METHOD__ );
169 - // Adjust for page X, talk:page X, which are both stored separately,
170 - // but treated together
171 - $nitems = floor( $watchlistCount / 2 );
172 -
173173 if( is_null( $values['days'] ) || !is_numeric( $values['days'] ) ) {
174174 $big = 1000; /* The magical big */
175175 if( $nitems > $big ) {
@@ -187,10 +187,7 @@
188188 wfAppendToArrayIfNotDefault( $name, $values[$name], $defaults, $nondefaults );
189189 }
190190
191 - if( $nitems == 0 ) {
192 - $wgOut->addWikiMsg( 'nowatchlist' );
193 - return;
194 - }
 191+ $dbr = wfGetDB( DB_SLAVE, 'watchlist' );
195192
196193 # Possible where conditions
197194 $conds = array();
@@ -207,9 +204,10 @@
208205
209206 # Up estimate of watched items by 15% to compensate for talk pages...
210207
 208+
211209 # Toggles
212210 if( $values['hideOwn'] ) {
213 - $conds[] = "rc_user != $uid";
 211+ $conds[] = 'rc_user != ' . $user->getId();
214212 }
215213 if( $values['hideBots'] ) {
216214 $conds[] = 'rc_bot = 0';
@@ -223,7 +221,7 @@
224222 if( $values['hideAnons'] ) {
225223 $conds[] = 'rc_user != 0';
226224 }
227 - if ( $wgUser->useRCPatrol() && $values['hidePatrolled'] ) {
 225+ if ( $user->useRCPatrol() && $values['hidePatrolled'] ) {
228226 $conds[] = 'rc_patrolled != 1';
229227 }
230228 if ( $nameSpaceClause ) {
@@ -231,8 +229,8 @@
232230 }
233231
234232 # Toggle watchlist content (all recent edits or just the latest)
235 - if( $wgUser->getOption( 'extendwatchlist' ) ) {
236 - $limitWatchlist = intval( $wgUser->getOption( 'wllimit' ) );
 233+ if( $user->getOption( 'extendwatchlist' ) ) {
 234+ $limitWatchlist = intval( $user->getOption( 'wllimit' ) );
237235 $usePage = false;
238236 } else {
239237 # Top log Ids for a page are not stored
@@ -244,16 +242,18 @@
245243 # Show a message about slave lag, if applicable
246244 $lag = $dbr->getLag();
247245 if( $lag > 0 ) {
248 - $wgOut->showLagWarning( $lag );
 246+ $output->showLagWarning( $lag );
249247 }
250248
 249+ $lang = $this->getLang();
 250+
251251 # Create output form
252252 $form = Xml::fieldset( wfMsg( 'watchlist-options' ), false, array( 'id' => 'mw-watchlist-options' ) );
253253
254254 # Show watchlist header
255 - $form .= wfMsgExt( 'watchlist-details', array( 'parseinline' ), $wgLang->formatNum( $nitems ) );
 255+ $form .= wfMsgExt( 'watchlist-details', array( 'parseinline' ), $lang->formatNum( $nitems ) );
256256
257 - if( $wgUser->getOption( 'enotifwatchlistpages' ) && $wgEnotifWatchlist) {
 257+ if( $user->getOption( 'enotifwatchlistpages' ) && $wgEnotifWatchlist) {
258258 $form .= wfMsgExt( 'wlheader-enotif', 'parse' ) . "\n";
259259 }
260260 if( $wgShowUpdatedMarker ) {
@@ -268,9 +268,9 @@
269269 $form .= '<hr />';
270270
271271 $tables = array( 'recentchanges', 'watchlist' );
272 - $fields = array( "{$recentchanges}.*" );
 272+ $fields = array( $dbr->tableName( 'recentchanges' ) . '.*' );
273273 $join_conds = array(
274 - 'watchlist' => array('INNER JOIN',"wl_user='{$uid}' AND wl_namespace=rc_namespace AND wl_title=rc_title"),
 274+ 'watchlist' => array('INNER JOIN',"wl_user='{$user->getId()}' AND wl_namespace=rc_namespace AND wl_title=rc_title"),
275275 );
276276 $options = array( 'ORDER BY' => 'rc_timestamp DESC' );
277277 if( $wgShowUpdatedMarker ) {
@@ -280,7 +280,7 @@
281281 $options['LIMIT'] = $limitWatchlist;
282282 }
283283
284 - $rollbacker = $wgUser->isAllowed('rollback');
 284+ $rollbacker = $user->isAllowed('rollback');
285285 if ( $usePage || $rollbacker ) {
286286 $tables[] = 'page';
287287 $join_conds['page'] = array('LEFT JOIN','rc_cur_id=page_id');
@@ -301,23 +301,21 @@
302302 if( $values['days'] >= 1 ) {
303303 $timestamp = wfTimestampNow();
304304 $wlInfo = wfMsgExt( 'rcnote', 'parseinline',
305 - $wgLang->formatNum( $numRows ),
306 - $wgLang->formatNum( $values['days'] ),
307 - $wgLang->timeAndDate( $timestamp, true ),
308 - $wgLang->date( $timestamp, true ),
309 - $wgLang->time( $timestamp, true )
 305+ $lang->formatNum( $numRows ),
 306+ $lang->formatNum( $values['days'] ),
 307+ $lang->timeAndDate( $timestamp, true ),
 308+ $lang->date( $timestamp, true ),
 309+ $lang->time( $timestamp, true )
310310 ) . '<br />';
311311 } elseif( $values['days'] > 0 ) {
312312 $wlInfo = wfMsgExt( 'wlnote', 'parseinline',
313 - $wgLang->formatNum( $numRows ),
314 - $wgLang->formatNum( round( $values['days'] * 24 ) )
 313+ $lang->formatNum( $numRows ),
 314+ $lang->formatNum( round( $values['days'] * 24 ) )
315315 ) . '<br />';
316316 }
317317
318 - $cutofflinks = "\n" . self::cutoffLinks( $values['days'], 'Watchlist', $nondefaults ) . "<br />\n";
 318+ $cutofflinks = "\n" . $this->cutoffLinks( $values['days'], $nondefaults ) . "<br />\n";
319319
320 - $thisTitle = SpecialPage::getTitleFor( 'Watchlist' );
321 -
322320 # Spit out some control panel links
323321 $filters = array(
324322 'hideMinor' => 'rcshowhideminor',
@@ -331,20 +329,20 @@
332330 $filters[$key] = $params['msg'];
333331 }
334332 // Disable some if needed
335 - if ( !$wgUser->useNPPatrol() ) {
 333+ if ( !$user->useNPPatrol() ) {
336334 unset( $filters['hidePatrolled'] );
337335 }
338336
339337 $links = array();
340338 foreach( $filters as $name => $msg ) {
341 - $links[] = self::showHideLink( $nondefaults, $msg, $name, $values[$name] );
 339+ $links[] = $this->showHideLink( $nondefaults, $msg, $name, $values[$name] );
342340 }
343341
344342 # Namespace filter and put the whole form together.
345343 $form .= $wlInfo;
346344 $form .= $cutofflinks;
347 - $form .= $wgLang->pipeList( $links );
348 - $form .= Xml::openElement( 'form', array( 'method' => 'post', 'action' => $thisTitle->getLocalUrl(), 'id' => 'mw-watchlist-form-namespaceselector' ) );
 345+ $form .= $lang->pipeList( $links );
 346+ $form .= Xml::openElement( 'form', array( 'method' => 'post', 'action' => $this->getTitle()->getLocalUrl(), 'id' => 'mw-watchlist-form-namespaceselector' ) );
349347 $form .= '<hr /><p>';
350348 $form .= Xml::label( wfMsg( 'namespace' ), 'namespace' ) . '&#160;';
351349 $form .= Xml::namespaceSelector( $nameSpace, '' ) . '&#160;';
@@ -358,11 +356,11 @@
359357 }
360358 $form .= Xml::closeElement( 'form' );
361359 $form .= Xml::closeElement( 'fieldset' );
362 - $wgOut->addHTML( $form );
 360+ $output->addHTML( $form );
363361
364362 # If there's nothing to show, stop here
365363 if( $numRows == 0 ) {
366 - $wgOut->addWikiMsg( 'watchnochange' );
 364+ $output->addWikiMsg( 'watchnochange' );
367365 return;
368366 }
369367
@@ -382,7 +380,7 @@
383381 $linkBatch->execute();
384382 $dbr->dataSeek( $res, 0 );
385383
386 - $list = ChangesList::newFromUser( $wgUser );
 384+ $list = ChangesList::newFromUser( $this->getUser() );
387385 $list->setWatchlistDivs();
388386
389387 $s = $list->beginRecentChangesList();
@@ -398,7 +396,7 @@
399397 $updated = false;
400398 }
401399
402 - if ( $wgRCShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' ) ) {
 400+ if ( $wgRCShowWatchingUsers && $user->getOption( 'shownumberswatching' ) ) {
403401 $rc->numberofWatchingusers = $dbr->selectField( 'watchlist',
404402 'COUNT(*)',
405403 array(
@@ -414,48 +412,36 @@
415413 }
416414 $s .= $list->endRecentChangesList();
417415
418 - $wgOut->addHTML( $s );
 416+ $output->addHTML( $s );
419417 }
420418
421 - public static function showHideLink( $options, $message, $name, $value ) {
422 - global $wgUser;
423 -
 419+ protected function showHideLink( $options, $message, $name, $value ) {
424420 $showLinktext = wfMsgHtml( 'show' );
425421 $hideLinktext = wfMsgHtml( 'hide' );
426 - $title = SpecialPage::getTitleFor( 'Watchlist' );
427 - $skin = $wgUser->getSkin();
428422
429423 $label = $value ? $showLinktext : $hideLinktext;
430424 $options[$name] = 1 - (int) $value;
431425
432 - return wfMsgHtml( $message, $skin->linkKnown( $title, $label, array(), $options ) );
 426+ return wfMsgHtml( $message, Linker::linkKnown( $this->getTitle(), $label, array(), $options ) );
433427 }
434428
435 - public static function hoursLink( $h, $page, $options = array() ) {
436 - global $wgUser, $wgLang, $wgContLang;
437 -
438 - $sk = $wgUser->getSkin();
439 - $title = Title::newFromText( $wgContLang->specialPage( $page ) );
 429+ protected function hoursLink( $h, $options = array() ) {
440430 $options['days'] = ( $h / 24.0 );
441431
442 - return $sk->linkKnown(
443 - $title,
444 - $wgLang->formatNum( $h ),
 432+ return Linker::linkKnown(
 433+ $this->getTitle(),
 434+ $this->getLang()->formatNum( $h ),
445435 array(),
446436 $options
447437 );
448438 }
449439
450 - public static function daysLink( $d, $page, $options = array() ) {
451 - global $wgUser, $wgLang, $wgContLang;
452 -
453 - $sk = $wgUser->getSkin();
454 - $title = Title::newFromText( $wgContLang->specialPage( $page ) );
 440+ protected function daysLink( $d, $options = array() ) {
455441 $options['days'] = $d;
456 - $message = ( $d ? $wgLang->formatNum( $d ) : wfMsgHtml( 'watchlistall2' ) );
 442+ $message = ( $d ? $this->getLang()->formatNum( $d ) : wfMsgHtml( 'watchlistall2' ) );
457443
458 - return $sk->linkKnown(
459 - $title,
 444+ return Linker::linkKnown(
 445+ $this->getTitle(),
460446 $message,
461447 array(),
462448 $options
@@ -467,47 +453,38 @@
468454 *
469455 * @return string
470456 */
471 - protected static function cutoffLinks( $days, $page = 'Watchlist', $options = array() ) {
472 - global $wgLang;
473 -
 457+ protected function cutoffLinks( $days, $options = array() ) {
474458 $hours = array( 1, 2, 6, 12 );
475459 $days = array( 1, 3, 7 );
476460 $i = 0;
477461 foreach( $hours as $h ) {
478 - $hours[$i++] = self::hoursLink( $h, $page, $options );
 462+ $hours[$i++] = $this->hoursLink( $h, $options );
479463 }
480464 $i = 0;
481465 foreach( $days as $d ) {
482 - $days[$i++] = self::daysLink( $d, $page, $options );
 466+ $days[$i++] = $this->daysLink( $d, $options );
483467 }
484468 return wfMsgExt('wlshowlast',
485469 array('parseinline', 'replaceafter'),
486 - $wgLang->pipeList( $hours ),
487 - $wgLang->pipeList( $days ),
488 - self::daysLink( 0, $page, $options ) );
 470+ $this->getLang()->pipeList( $hours ),
 471+ $this->getLang()->pipeList( $days ),
 472+ $this->daysLink( 0, $options ) );
489473 }
490474
491475 /**
492476 * Count the number of items on a user's watchlist
493477 *
494 - * @param $user User object
495 - * @param $talk Boolean: include talk pages
496478 * @return Integer
497479 */
498 - protected static function countItems( &$user, $talk = true ) {
 480+ protected function countItems() {
499481 $dbr = wfGetDB( DB_SLAVE, 'watchlist' );
500482
501483 # Fetch the raw count
502484 $res = $dbr->select( 'watchlist', 'COUNT(*) AS count',
503 - array( 'wl_user' => $user->mId ), __METHOD__ );
 485+ array( 'wl_user' => $this->getUser()->getId() ), __METHOD__ );
504486 $row = $dbr->fetchObject( $res );
505487 $count = $row->count;
506488
507 - # Halve to remove talk pages if needed
508 - if( !$talk ) {
509 - $count = floor( $count / 2 );
510 - }
511 -
512 - return( $count );
 489+ return floor( $count / 2 );
513490 }
514491 }
Index: trunk/extensions/InterwikiIntegration/SpecialInterwikiWatchlist.php
@@ -62,9 +62,21 @@
6363 $sub .= '<br />' . WatchlistEditor::buildTools( $wgUser->getSkin() );
6464 $wgOut->setSubtitle( $sub );
6565
66 - if( ( $mode = WatchlistEditor::getMode( $wgRequest, $par ) ) !== false ) {
67 - $editor = new WatchlistEditor();
68 - $editor->execute( $wgUser, $wgOut, $wgRequest, $mode );
 66+ $mode = SpecialEditWatchlist::getMode( $this->getRequest(), $par );
 67+ if( $mode !== false ) {
 68+ # TODO: localise?
 69+ switch( $mode ){
 70+ case SpecialEditWatchlist::EDIT_CLEAR:
 71+ $mode = 'clear';
 72+ break;
 73+ case SpecialEditWatchlist::EDIT_RAW:
 74+ $mode = 'raw';
 75+ break;
 76+ default:
 77+ $mode = null;
 78+ }
 79+ $title = SpecialPage::getTitleFor( 'EditWatchlist', $mode );
 80+ $wgOut->redirect( $title->getLocalUrl() );
6981 return;
7082 }
7183
@@ -72,7 +84,7 @@
7385 if( ($wgEnotifWatchlist || $wgShowUpdatedMarker) && $wgRequest->getVal( 'reset' ) &&
7486 $wgRequest->wasPosted() )
7587 {
76 - $wgUser->clearAllNotifications( $uid );
 88+ $wgUser->clearAllNotifications();
7789 $wgOut->redirect( $specialTitle->getFullUrl() );
7890 return;
7991 }
@@ -127,11 +139,7 @@
128140 $dbr = wfGetDB( DB_SLAVE, 'integration_watchlist' );
129141 $recentchanges = $dbr->tableName( 'integration_recentchanges' );
130142
131 - $watchlistCount = $dbr->selectField( 'integration_watchlist', 'COUNT(*)',
132 - array( 'integration_wl_user' => $uid ), __METHOD__ );
133 - // Adjust for page X, talk:page X, which are both stored separately,
134 - // but treated together
135 - $nitems = floor($watchlistCount / 2);
 143+ $nitems = $this->countItems();
136144
137145 if( is_null($days) || !is_numeric($days) ) {
138146 $big = 1000; /* The magical big */
@@ -282,26 +290,24 @@
283291 ) . '<br />';
284292 }
285293
286 - $cutofflinks = "\n" . self::cutoffLinks( $days, 'Watchlist', $nondefaults ) . "<br />\n";
287 -
288 - $thisTitle = SpecialPage::getTitleFor( 'Watchlist' );
289 -
 294+ $cutofflinks = "\n" . $this->cutoffLinks( $days, $nondefaults ) . "<br />\n";
 295+
290296 # Spit out some control panel links
291 - $links[] = self::showHideLink( $nondefaults, 'rcshowhideminor', 'hideMinor', $hideMinor );
292 - $links[] = self::showHideLink( $nondefaults, 'rcshowhidebots', 'hideBots', $hideBots );
293 - $links[] = self::showHideLink( $nondefaults, 'rcshowhideanons', 'hideAnons', $hideAnons );
294 - $links[] = self::showHideLink( $nondefaults, 'rcshowhideliu', 'hideLiu', $hideLiu );
295 - $links[] = self::showHideLink( $nondefaults, 'rcshowhidemine', 'hideOwn', $hideOwn );
 297+ $links[] = $this->showHideLink( $nondefaults, 'rcshowhideminor', 'hideMinor', $hideMinor );
 298+ $links[] = $this->showHideLink( $nondefaults, 'rcshowhidebots', 'hideBots', $hideBots );
 299+ $links[] = $this->showHideLink( $nondefaults, 'rcshowhideanons', 'hideAnons', $hideAnons );
 300+ $links[] = $this->showHideLink( $nondefaults, 'rcshowhideliu', 'hideLiu', $hideLiu );
 301+ $links[] = $this->showHideLink( $nondefaults, 'rcshowhidemine', 'hideOwn', $hideOwn );
296302
297303 if( $wgUser->useRCPatrol() ) {
298 - $links[] = self::showHideLink( $nondefaults, 'rcshowhidepatr', 'hidePatrolled', $hidePatrolled );
 304+ $links[] = $this->showHideLink( $nondefaults, 'rcshowhidepatr', 'hidePatrolled', $hidePatrolled );
299305 }
300306
301307 # Namespace filter and put the whole form together.
302308 $form .= $wlInfo;
303309 $form .= $cutofflinks;
304310 $form .= $wgLang->pipeList( $links );
305 - $form .= Xml::openElement( 'form', array( 'method' => 'post', 'action' => $thisTitle->getLocalUrl(), 'id' => 'mw-watchlist-form-namespaceselector' ) );
 311+ $form .= Xml::openElement( 'form', array( 'method' => 'post', 'action' => $this->getTitle()->getLocalUrl(), 'id' => 'mw-watchlist-form-namespaceselector' ) );
306312 $form .= '<hr /><p>';
307313 $form .= Xml::label( wfMsg( 'namespace' ), 'namespace' ) . '&#160;';
308314 $form .= Xml::namespaceSelector( $nameSpace, '' ) . '&#160;';
@@ -385,23 +391,18 @@
386392 /**
387393 * Count the number of items on a user's watchlist
388394 *
389 - * @param $talk Include talk pages
390395 * @return integer
391396 */
392 - function countItems( &$user, $talk = true ) {
 397+ function countItems() {
393398 $dbr = wfGetDB( DB_SLAVE, 'integration_watchlist' );
394 -
 399+
395400 # Fetch the raw count
396401 $res = $dbr->select( 'integration_watchlist', 'COUNT(*) AS count',
397 - array( 'integration_wl_user' => $user->mId ), __METHOD__ );
 402+ array( 'integration_wl_user' => $this->getUser()->getId() ), __METHOD__ );
398403 $row = $dbr->fetchObject( $res );
399404 $count = $row->count;
400405 $dbr->freeResult( $res );
401 -
402 - # Halve to remove talk pages if needed
403 - if( !$talk )
404 - $count = floor( $count / 2 );
405 -
406 - return( $count );
 406+
 407+ return floor( $count / 2 );
407408 }
408 -}
\ No newline at end of file
 409+}

Follow-up revisions

RevisionCommit summaryAuthorDate
r91168And I forgot to commit this file in r91074ialex13:56, 30 June 2011

Status & tagging log