Merge "Notice: Undefined property: stdClass::$hitcount in list=tags"
[lhc/web/wiklou.git] / includes / specials / SpecialWatchlist.php
index 9179a50..a81eb5b 100644 (file)
@@ -26,8 +26,8 @@ class SpecialWatchlist extends SpecialPage {
        /**
         * Constructor
         */
-       public function __construct(){
-               parent::__construct( 'Watchlist' );
+       public function __construct( $page = 'Watchlist' ){
+               parent::__construct( $page );
        }
 
        /**
@@ -35,47 +35,45 @@ class SpecialWatchlist extends SpecialPage {
         * @param $par Parameter passed to the page
         */
        function execute( $par ) {
-               global $wgUser, $wgOut, $wgLang, $wgRequest;
                global $wgRCShowWatchingUsers, $wgEnotifWatchlist, $wgShowUpdatedMarker;
 
-               // Add feed links
-               $wlToken = $wgUser->getOption( 'watchlisttoken' );
-               if ( !$wlToken ) {
-                       $wlToken = sha1( mt_rand() . microtime( true ) );
-                       $wgUser->setOption( 'watchlisttoken', $wlToken );
-                       $wgUser->saveSettings();
-               }
-
-               $this->addFeedLinks( array( 'action' => 'feedwatchlist', 'allrev' => 'allrev',
-                                                       'wlowner' => $wgUser->getName(), 'wltoken' => $wlToken ) );
-
-               $skin = $this->getSkin();
-               $wgOut->setRobotPolicy( 'noindex,nofollow' );
+               $user = $this->getUser();
+               $output = $this->getOutput();
 
                # Anons don't get a watchlist
-               if( $wgUser->isAnon() ) {
-                       $wgOut->setPageTitle( wfMsg( 'watchnologin' ) );
-                       $llink = $skin->linkKnown(
+               if( $user->isAnon() ) {
+                       $output->setPageTitle( $this->msg( 'watchnologin' ) );
+                       $output->setRobotPolicy( 'noindex,nofollow' );
+                       $llink = Linker::linkKnown(
                                SpecialPage::getTitleFor( 'Userlogin' ),
-                               wfMsgHtml( 'loginreqlink' ),
+                               $this->msg( 'loginreqlink' )->escaped(),
                                array(),
                                array( 'returnto' => $this->getTitle()->getPrefixedText() )
                        );
-                       $wgOut->addWikiMsgArray( 'watchlistanontext', array( $llink ), array( 'replaceafter' ) );
+                       $output->addHTML( $this->msg( 'watchlistanontext' )->rawParams( $llink )->parse() );
                        return;
                }
 
-               $wgOut->setPageTitle( wfMsg( 'watchlist' ) );
+               // Add feed links
+               $wlToken = $user->getOption( 'watchlisttoken' );
+               if ( !$wlToken ) {
+                       $wlToken = MWCryptRand::generateHex( 40 );
+                       $user->setOption( 'watchlisttoken', $wlToken );
+                       $user->saveSettings();
+               }
+
+               $this->addFeedLinks( array( 'action' => 'feedwatchlist', 'allrev' => 'allrev',
+                                                       'wlowner' => $user->getName(), 'wltoken' => $wlToken ) );
 
-               $sub = wfMsgExt(
-                       'watchlistfor2',
-                       array( 'parseinline', 'replaceafter' ),
-                       $wgUser->getName(),
-                       SpecialEditWatchlist::buildTools( $skin )
-               );
-               $wgOut->setSubtitle( $sub );
+               $this->setHeaders();
+               $this->outputHeader();
 
-               $mode = SpecialEditWatchlist::getMode( $wgRequest, $par );
+               $output->addSubtitle( $this->msg( 'watchlistfor2', $user->getName()
+                       )->rawParams( SpecialEditWatchlist::buildTools( null ) ) );
+
+               $request = $this->getRequest();
+
+               $mode = SpecialEditWatchlist::getMode( $request, $par );
                if( $mode !== false ) {
                        # TODO: localise?
                        switch( $mode ){
@@ -89,30 +87,28 @@ class SpecialWatchlist extends SpecialPage {
                                        $mode = null;
                        }
                        $title = SpecialPage::getTitleFor( 'EditWatchlist', $mode );
-                       $wgOut->redirect( $title->getLocalUrl() );
+                       $output->redirect( $title->getLocalUrl() );
                        return;
                }
 
-               $uid = $wgUser->getId();
-               if( ( $wgEnotifWatchlist || $wgShowUpdatedMarker ) && $wgRequest->getVal( 'reset' ) &&
-                       $wgRequest->wasPosted() )
-               {
-                       $wgUser->clearAllNotifications( $uid );
-                       $wgOut->redirect( $this->getTitle()->getFullUrl() );
+               $nitems = $this->countItems();
+               if ( $nitems == 0 ) {
+                       $output->addWikiMsg( 'nowatchlist' );
                        return;
                }
 
                // @TODO: use FormOptions!
                $defaults = array(
-               /* float */ 'days'      => floatval( $wgUser->getOption( 'watchlistdays' ) ), /* 3.0 or 0.5, watch further below */
-               /* bool  */ 'hideMinor' => (int)$wgUser->getBoolOption( 'watchlisthideminor' ),
-               /* bool  */ 'hideBots'  => (int)$wgUser->getBoolOption( 'watchlisthidebots' ),
-               /* bool  */ 'hideAnons' => (int)$wgUser->getBoolOption( 'watchlisthideanons' ),
-               /* bool  */ 'hideLiu'   => (int)$wgUser->getBoolOption( 'watchlisthideliu' ),
-               /* bool  */ 'hidePatrolled' => (int)$wgUser->getBoolOption( 'watchlisthidepatrolled' ),
-               /* bool  */ 'hideOwn'   => (int)$wgUser->getBoolOption( 'watchlisthideown' ),
+               /* float */ 'days'      => floatval( $user->getOption( 'watchlistdays' ) ), /* 3.0 or 0.5, watch further below */
+               /* bool  */ 'hideMinor' => (int)$user->getBoolOption( 'watchlisthideminor' ),
+               /* bool  */ 'hideBots'  => (int)$user->getBoolOption( 'watchlisthidebots' ),
+               /* bool  */ 'hideAnons' => (int)$user->getBoolOption( 'watchlisthideanons' ),
+               /* bool  */ 'hideLiu'   => (int)$user->getBoolOption( 'watchlisthideliu' ),
+               /* bool  */ 'hidePatrolled' => (int)$user->getBoolOption( 'watchlisthidepatrolled' ),
+               /* bool  */ 'hideOwn'   => (int)$user->getBoolOption( 'watchlisthideown' ),
                /* ?     */ 'namespace' => 'all',
                /* ?     */ 'invert'    => false,
+               /* bool  */ 'associated' => false,
                );
                $this->customFilters = array();
                wfRunHooks( 'SpecialWatchlistFilters', array( $this, &$this->customFilters ) );
@@ -122,36 +118,43 @@ class SpecialWatchlist extends SpecialPage {
 
                # Extract variables from the request, falling back to user preferences or
                # other default values if these don't exist
-               $prefs['days']      = floatval( $wgUser->getOption( 'watchlistdays' ) );
-               $prefs['hideminor'] = $wgUser->getBoolOption( 'watchlisthideminor' );
-               $prefs['hidebots']  = $wgUser->getBoolOption( 'watchlisthidebots' );
-               $prefs['hideanons'] = $wgUser->getBoolOption( 'watchlisthideanons' );
-               $prefs['hideliu']   = $wgUser->getBoolOption( 'watchlisthideliu' );
-               $prefs['hideown' ]  = $wgUser->getBoolOption( 'watchlisthideown' );
-               $prefs['hidepatrolled' ] = $wgUser->getBoolOption( 'watchlisthidepatrolled' );
+               $prefs['days']      = floatval( $user->getOption( 'watchlistdays' ) );
+               $prefs['hideminor'] = $user->getBoolOption( 'watchlisthideminor' );
+               $prefs['hidebots']  = $user->getBoolOption( 'watchlisthidebots' );
+               $prefs['hideanons'] = $user->getBoolOption( 'watchlisthideanons' );
+               $prefs['hideliu']   = $user->getBoolOption( 'watchlisthideliu' );
+               $prefs['hideown' ]  = $user->getBoolOption( 'watchlisthideown' );
+               $prefs['hidepatrolled' ] = $user->getBoolOption( 'watchlisthidepatrolled' );
 
                # Get query variables
                $values = array();
-               $values['days']          = $wgRequest->getVal( 'days', $prefs['days'] );
-               $values['hideMinor']     = (int)$wgRequest->getBool( 'hideMinor', $prefs['hideminor'] );
-               $values['hideBots']      = (int)$wgRequest->getBool( 'hideBots' , $prefs['hidebots'] );
-               $values['hideAnons']     = (int)$wgRequest->getBool( 'hideAnons', $prefs['hideanons'] );
-               $values['hideLiu']       = (int)$wgRequest->getBool( 'hideLiu'  , $prefs['hideliu'] );
-               $values['hideOwn']       = (int)$wgRequest->getBool( 'hideOwn'  , $prefs['hideown'] );
-               $values['hidePatrolled'] = (int)$wgRequest->getBool( 'hidePatrolled', $prefs['hidepatrolled'] );
+               $values['days']          = $request->getVal( 'days', $prefs['days'] );
+               $values['hideMinor']     = (int)$request->getBool( 'hideMinor', $prefs['hideminor'] );
+               $values['hideBots']      = (int)$request->getBool( 'hideBots' , $prefs['hidebots'] );
+               $values['hideAnons']     = (int)$request->getBool( 'hideAnons', $prefs['hideanons'] );
+               $values['hideLiu']       = (int)$request->getBool( 'hideLiu'  , $prefs['hideliu'] );
+               $values['hideOwn']       = (int)$request->getBool( 'hideOwn'  , $prefs['hideown'] );
+               $values['hidePatrolled'] = (int)$request->getBool( 'hidePatrolled', $prefs['hidepatrolled'] );
                foreach( $this->customFilters as $key => $params ) {
-                       $values[$key] = (int)$wgRequest->getBool( $key );
+                       $values[$key] = (int)$request->getBool( $key );
                }
 
                # Get namespace value, if supplied, and prepare a WHERE fragment
-               $nameSpace = $wgRequest->getIntOrNull( 'namespace' );
-               $invert = $wgRequest->getIntOrNull( 'invert' );
+               $nameSpace = $request->getIntOrNull( 'namespace' );
+               $invert = $request->getBool( 'invert' );
+               $associated = $request->getBool( 'associated' );
                if ( !is_null( $nameSpace ) ) {
+                       $eq_op = $invert ? '!=' : '=';
+                       $bool_op = $invert ? 'AND' : 'OR';
                        $nameSpace = intval( $nameSpace ); // paranioa
-                       if ( $invert ) {
-                               $nameSpaceClause = "rc_namespace != $nameSpace";
+                       if ( !$associated ) {
+                               $nameSpaceClause = "rc_namespace $eq_op $nameSpace";
                        } else {
-                               $nameSpaceClause = "rc_namespace = $nameSpace";
+                               $associatedNS = MWNamespace::getAssociated( $nameSpace );
+                               $nameSpaceClause =
+                                       "rc_namespace $eq_op $nameSpace " .
+                                       $bool_op .
+                                       " rc_namespace $eq_op $associatedNS";
                        }
                } else {
                        $nameSpace = '';
@@ -159,15 +162,7 @@ class SpecialWatchlist extends SpecialPage {
                }
                $values['namespace'] = $nameSpace;
                $values['invert'] = $invert;
-
-               $dbr = wfGetDB( DB_SLAVE, 'watchlist' );
-               $recentchanges = $dbr->tableName( 'recentchanges' );
-
-               $watchlistCount = $dbr->selectField( 'watchlist', 'COUNT(*)',
-                       array( 'wl_user' => $uid ), __METHOD__ );
-               // Adjust for page X, talk:page X, which are both stored separately,
-               // but treated together
-               $nitems = floor( $watchlistCount / 2 );
+               $values['associated'] = $associated;
 
                if( is_null( $values['days'] ) || !is_numeric( $values['days'] ) ) {
                        $big = 1000; /* The magical big */
@@ -187,11 +182,16 @@ class SpecialWatchlist extends SpecialPage {
                        wfAppendToArrayIfNotDefault( $name, $values[$name], $defaults, $nondefaults );
                }
 
-               if( $nitems == 0 ) {
-                       $wgOut->addWikiMsg( 'nowatchlist' );
+               if( ( $wgEnotifWatchlist || $wgShowUpdatedMarker ) && $request->getVal( 'reset' ) &&
+                       $request->wasPosted() )
+               {
+                       $user->clearAllNotifications();
+                       $output->redirect( $this->getTitle()->getFullUrl( $nondefaults ) );
                        return;
                }
 
+               $dbr = wfGetDB( DB_SLAVE, 'watchlist' );
+
                # Possible where conditions
                $conds = array();
 
@@ -207,9 +207,10 @@ class SpecialWatchlist extends SpecialPage {
 
                # Up estimate of watched items by 15% to compensate for talk pages...
 
+
                # Toggles
                if( $values['hideOwn'] ) {
-                       $conds[] = "rc_user != $uid";
+                       $conds[] = 'rc_user != ' . $user->getId();
                }
                if( $values['hideBots'] ) {
                        $conds[] = 'rc_bot = 0';
@@ -223,7 +224,7 @@ class SpecialWatchlist extends SpecialPage {
                if( $values['hideAnons'] ) {
                        $conds[] = 'rc_user != 0';
                }
-               if ( $wgUser->useRCPatrol() && $values['hidePatrolled'] ) {
+               if ( $user->useRCPatrol() && $values['hidePatrolled'] ) {
                        $conds[] = 'rc_patrolled != 1';
                }
                if ( $nameSpaceClause ) {
@@ -231,8 +232,8 @@ class SpecialWatchlist extends SpecialPage {
                }
 
                # Toggle watchlist content (all recent edits or just the latest)
-               if( $wgUser->getOption( 'extendwatchlist' ) ) {
-                       $limitWatchlist = intval( $wgUser->getOption( 'wllimit' ) );
+               if( $user->getOption( 'extendwatchlist' ) ) {
+                       $limitWatchlist = intval( $user->getOption( 'wllimit' ) );
                        $usePage = false;
                } else {
                        # Top log Ids for a page are not stored
@@ -242,35 +243,45 @@ class SpecialWatchlist extends SpecialPage {
                }
 
                # Show a message about slave lag, if applicable
-               $lag = $dbr->getLag();
+               $lag = wfGetLB()->safeGetLag( $dbr );
                if( $lag > 0 ) {
-                       $wgOut->showLagWarning( $lag );
+                       $output->showLagWarning( $lag );
                }
 
                # Create output form
-               $form  = Xml::fieldset( wfMsg( 'watchlist-options' ), false, array( 'id' => 'mw-watchlist-options' ) );
+               $form  = Xml::fieldset( $this->msg( 'watchlist-options' )->text(), false, array( 'id' => 'mw-watchlist-options' ) );
 
                # Show watchlist header
-               $form .= wfMsgExt( 'watchlist-details', array( 'parseinline' ), $wgLang->formatNum( $nitems ) );
+               $form .= $this->msg( 'watchlist-details' )->numParams( $nitems )->parse();
 
-               if( $wgUser->getOption( 'enotifwatchlistpages' ) && $wgEnotifWatchlist) {
-                       $form .= wfMsgExt( 'wlheader-enotif', 'parse' ) . "\n";
+               if( $user->getOption( 'enotifwatchlistpages' ) && $wgEnotifWatchlist) {
+                       $form .= $this->msg( 'wlheader-enotif' )->parseAsBlock() . "\n";
                }
                if( $wgShowUpdatedMarker ) {
                        $form .= Xml::openElement( 'form', array( 'method' => 'post',
                                                'action' => $this->getTitle()->getLocalUrl(),
                                                'id' => 'mw-watchlist-resetbutton' ) ) .
-                                       wfMsgExt( 'wlheader-showupdated', array( 'parseinline' ) ) . ' ' .
-                                       Xml::submitButton( wfMsg( 'enotif_reset' ), array( 'name' => 'dummy' ) ) .
-                                       Html::hidden( 'reset', 'all' ) .
-                                       Xml::closeElement( 'form' );
+                                       $this->msg( 'wlheader-showupdated' )->parse() . ' ' .
+                                       Xml::submitButton( $this->msg( 'enotif_reset' )->text(), array( 'name' => 'dummy' ) ) .
+                                       Html::hidden( 'reset', 'all' );
+                                       foreach ( $nondefaults as $key => $value ) {
+                                               $form .= Html::hidden( $key, $value );
+                                       }
+                                       $form .= Xml::closeElement( 'form' );
                }
                $form .= '<hr />';
 
                $tables = array( 'recentchanges', 'watchlist' );
-               $fields = array( "{$recentchanges}.*" );
+               $fields = array( $dbr->tableName( 'recentchanges' ) . '.*' );
                $join_conds = array(
-                       'watchlist' => array('INNER JOIN',"wl_user='{$uid}' AND wl_namespace=rc_namespace AND wl_title=rc_title"),
+                       'watchlist' => array(
+                               'INNER JOIN',
+                               array(
+                                       'wl_user' => $user->getId(),
+                                       'wl_namespace=rc_namespace',
+                                       'wl_title=rc_title'
+                               ),
+                       ),
                );
                $options = array( 'ORDER BY' => 'rc_timestamp DESC' );
                if( $wgShowUpdatedMarker ) {
@@ -280,7 +291,7 @@ class SpecialWatchlist extends SpecialPage {
                        $options['LIMIT'] = $limitWatchlist;
                }
 
-               $rollbacker = $wgUser->isAllowed('rollback');
+               $rollbacker = $user->isAllowed('rollback');
                if ( $usePage || $rollbacker ) {
                        $tables[] = 'page';
                        $join_conds['page'] = array('LEFT JOIN','rc_cur_id=page_id');
@@ -293,30 +304,19 @@ class SpecialWatchlist extends SpecialPage {
                wfRunHooks('SpecialWatchlistQuery', array(&$conds,&$tables,&$join_conds,&$fields) );
 
                $res = $dbr->select( $tables, $fields, $conds, __METHOD__, $options, $join_conds );
-               $numRows = $dbr->numRows( $res );
+               $numRows = $res->numRows();
 
                /* Start bottom header */
 
+               $lang = $this->getLanguage();
                $wlInfo = '';
-               if( $values['days'] >= 1 ) {
+               if( $values['days'] > 0 ) {
                        $timestamp = wfTimestampNow();
-                       $wlInfo = wfMsgExt( 'rcnote', 'parseinline',
-                                       $wgLang->formatNum( $numRows ),
-                                       $wgLang->formatNum( $values['days'] ),
-                                       $wgLang->timeAndDate( $timestamp, true ),
-                                       $wgLang->date( $timestamp, true ),
-                                       $wgLang->time( $timestamp, true )
-                               ) . '<br />';
-               } elseif( $values['days'] > 0 ) {
-                       $wlInfo = wfMsgExt( 'wlnote', 'parseinline',
-                                       $wgLang->formatNum( $numRows ),
-                                       $wgLang->formatNum( round( $values['days'] * 24 ) )
-                               ) . '<br />';
+                       $wlInfo = $this->msg( 'wlnote' )->numParams( $numRows, round( $values['days'] * 24 ) )->params(
+                               $lang->userDate( $timestamp, $user ), $lang->userTime( $timestamp, $user ) )->parse() . '<br />';
                }
 
-               $cutofflinks = "\n" . self::cutoffLinks( $values['days'], 'Watchlist', $nondefaults ) . "<br />\n";
-
-               $thisTitle = SpecialPage::getTitleFor( 'Watchlist' );
+               $cutofflinks = "\n" . $this->cutoffLinks( $values['days'], $nondefaults ) . "<br />\n";
 
                # Spit out some control panel links
                $filters = array(
@@ -331,25 +331,47 @@ class SpecialWatchlist extends SpecialPage {
                        $filters[$key] = $params['msg'];
                }
                // Disable some if needed
-               if ( !$wgUser->useNPPatrol() ) {
+               if ( !$user->useNPPatrol() ) {
                        unset( $filters['hidePatrolled'] );
                }
 
                $links = array();
                foreach( $filters as $name => $msg ) {
-                       $links[] = self::showHideLink( $nondefaults, $msg, $name, $values[$name] );
+                       $links[] = $this->showHideLink( $nondefaults, $msg, $name, $values[$name] );
                }
 
                # Namespace filter and put the whole form together.
                $form .= $wlInfo;
                $form .= $cutofflinks;
-               $form .= $wgLang->pipeList( $links );
-               $form .= Xml::openElement( 'form', array( 'method' => 'post', 'action' => $thisTitle->getLocalUrl(), 'id' => 'mw-watchlist-form-namespaceselector' ) );
+               $form .= $lang->pipeList( $links );
+               $form .= Xml::openElement( 'form', array( 'method' => 'post', 'action' => $this->getTitle()->getLocalUrl(), 'id' => 'mw-watchlist-form-namespaceselector' ) );
                $form .= '<hr /><p>';
-               $form .= Xml::label( wfMsg( 'namespace' ), 'namespace' ) . '&#160;';
-               $form .= Xml::namespaceSelector( $nameSpace, '' ) . '&#160;';
-               $form .= Xml::checkLabel( wfMsg('invert'), 'invert', 'nsinvert', $invert ) . '&#160;';
-               $form .= Xml::submitButton( wfMsg( 'allpagessubmit' ) ) . '</p>';
+               $form .= Html::namespaceSelector(
+                       array(
+                               'selected' => $nameSpace,
+                               'all' => '',
+                               'label' => $this->msg( 'namespace' )->text()
+                       ), array(
+                               'name'  => 'namespace',
+                               'id'    => 'namespace',
+                               'class' => 'namespaceselector',
+                       )
+               ) . '&#160;';
+               $form .= Xml::checkLabel(
+                       $this->msg( 'invert' )->text(),
+                       'invert',
+                       'nsinvert',
+                       $invert,
+                       array( 'title' => $this->msg( 'tooltip-invert' )->text() )
+               ) . '&#160;';
+               $form .= Xml::checkLabel(
+                       $this->msg( 'namespace_association' )->text(),
+                       'associated',
+                       'associated',
+                       $associated,
+                       array( 'title' => $this->msg( 'tooltip-namespace_association' )->text() )
+               ) . '&#160;';
+               $form .= Xml::submitButton( $this->msg( 'allpagessubmit' )->text() ) . '</p>';
                $form .= Html::hidden( 'days', $values['days'] );
                foreach ( $filters as $key => $msg ) {
                        if ( $values[$key] ) {
@@ -358,11 +380,11 @@ class SpecialWatchlist extends SpecialPage {
                }
                $form .= Xml::closeElement( 'form' );
                $form .= Xml::closeElement( 'fieldset' );
-               $wgOut->addHTML( $form );
+               $output->addHTML( $form );
 
                # If there's nothing to show, stop here
                if( $numRows == 0 ) {
-                       $wgOut->addWikiMsg( 'watchnochange' );
+                       $output->addWikiMsg( 'watchnochange' );
                        return;
                }
 
@@ -382,7 +404,7 @@ class SpecialWatchlist extends SpecialPage {
                $linkBatch->execute();
                $dbr->dataSeek( $res, 0 );
 
-               $list = ChangesList::newFromUser( $wgUser );
+               $list = ChangesList::newFromContext( $this->getContext() );
                $list->setWatchlistDivs();
 
                $s = $list->beginRecentChangesList();
@@ -398,7 +420,7 @@ class SpecialWatchlist extends SpecialPage {
                                $updated = false;
                        }
 
-                       if ( $wgRCShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' ) ) {
+                       if ( $wgRCShowWatchingUsers && $user->getOption( 'shownumberswatching' ) ) {
                                $rc->numberofWatchingusers = $dbr->selectField( 'watchlist',
                                        'COUNT(*)',
                                        array(
@@ -414,48 +436,33 @@ class SpecialWatchlist extends SpecialPage {
                }
                $s .= $list->endRecentChangesList();
 
-               $wgOut->addHTML( $s );
+               $output->addHTML( $s );
        }
 
-       public static function showHideLink( $options, $message, $name, $value ) {
-               global $wgUser;
-
-               $showLinktext = wfMsgHtml( 'show' );
-               $hideLinktext = wfMsgHtml( 'hide' );
-               $title = SpecialPage::getTitleFor( 'Watchlist' );
-               $skin = $wgUser->getSkin();
-
-               $label = $value ? $showLinktext : $hideLinktext;
+       protected function showHideLink( $options, $message, $name, $value ) {
+               $label = $this->msg( $value ? 'show' : 'hide' )->escaped();
                $options[$name] = 1 - (int) $value;
 
-               return wfMsgHtml( $message, $skin->linkKnown( $title, $label, array(), $options ) );
+               return $this->msg( $message )->rawParams( Linker::linkKnown( $this->getTitle(), $label, array(), $options ) )->escaped();
        }
 
-       public static function hoursLink( $h, $page, $options = array() ) {
-               global $wgUser, $wgLang, $wgContLang;
-
-               $sk = $wgUser->getSkin();
-               $title = Title::newFromText( $wgContLang->specialPage( $page ) );
+       protected function hoursLink( $h, $options = array() ) {
                $options['days'] = ( $h / 24.0 );
 
-               return $sk->linkKnown(
-                       $title,
-                       $wgLang->formatNum( $h ),
+               return Linker::linkKnown(
+                       $this->getTitle(),
+                       $this->getLanguage()->formatNum( $h ),
                        array(),
                        $options
                );
        }
 
-       public static function daysLink( $d, $page, $options = array() ) {
-               global $wgUser, $wgLang, $wgContLang;
-
-               $sk = $wgUser->getSkin();
-               $title = Title::newFromText( $wgContLang->specialPage( $page ) );
+       protected function daysLink( $d, $options = array() ) {
                $options['days'] = $d;
-               $message = ( $d ? $wgLang->formatNum( $d ) : wfMsgHtml( 'watchlistall2' ) );
+               $message = ( $d ? $this->getLanguage()->formatNum( $d ) : $this->msg( 'watchlistall2' )->escaped() );
 
-               return $sk->linkKnown(
-                       $title,
+               return Linker::linkKnown(
+                       $this->getTitle(),
                        $message,
                        array(),
                        $options
@@ -467,47 +474,37 @@ class SpecialWatchlist extends SpecialPage {
         *
         * @return string
         */
-       protected static function cutoffLinks( $days, $page = 'Watchlist', $options = array() ) {
-               global $wgLang;
-
+       protected function cutoffLinks( $days, $options = array() ) {
                $hours = array( 1, 2, 6, 12 );
                $days = array( 1, 3, 7 );
                $i = 0;
                foreach( $hours as $h ) {
-                       $hours[$i++] = self::hoursLink( $h, $page, $options );
+                       $hours[$i++] = $this->hoursLink( $h, $options );
                }
                $i = 0;
                foreach( $days as $d ) {
-                       $days[$i++] = self::daysLink( $d, $page, $options );
+                       $days[$i++] = $this->daysLink( $d, $options );
                }
-               return wfMsgExt('wlshowlast',
-                       array('parseinline', 'replaceafter'),
-                       $wgLang->pipeList( $hours ),
-                       $wgLang->pipeList( $days ),
-                       self::daysLink( 0, $page, $options ) );
+               return $this->msg( 'wlshowlast' )->rawParams(
+                       $this->getLanguage()->pipeList( $hours ),
+                       $this->getLanguage()->pipeList( $days ),
+                       $this->daysLink( 0, $options ) )->parse();
        }
 
        /**
         * Count the number of items on a user's watchlist
         *
-        * @param $user User object
-        * @param $talk Boolean: include talk pages
         * @return Integer
         */
-       protected static function countItems( &$user, $talk = true ) {
+       protected function countItems() {
                $dbr = wfGetDB( DB_SLAVE, 'watchlist' );
 
                # Fetch the raw count
                $res = $dbr->select( 'watchlist', 'COUNT(*) AS count',
-                       array( 'wl_user' => $user->mId ), __METHOD__ );
+                       array( 'wl_user' => $this->getUser()->getId() ), __METHOD__ );
                $row = $dbr->fetchObject( $res );
                $count = $row->count;
 
-               # Halve to remove talk pages if needed
-               if( !$talk ) {
-                       $count = floor( $count / 2 );
-               }
-
-               return( $count );
+               return floor( $count / 2 );
        }
 }