From: Happy-melon Date: Sat, 26 Mar 2011 13:04:40 +0000 (+0000) Subject: Break svn blame on every single line of SpecialWatchlist.php by converting it to... X-Git-Tag: 1.31.0-rc.0~31183 X-Git-Url: https://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/exercices/journal.php?a=commitdiff_plain;h=205f6431bbcd1bc058409ba5d405457ad275856c;p=lhc%2Fweb%2Fwiklou.git Break svn blame on every single line of SpecialWatchlist.php by converting it to subclass SpecialPage and hence changing the indentation :D. SpecialInterwikiWatchlist.php is virtually a clone of this code, so make it subclass in turn and remove duplication; there is probably more that could be removed. Only three more global-function special page implementations left. \o/ --- diff --git a/includes/AutoLoader.php b/includes/AutoLoader.php index f0624a33bc..720703fe7c 100644 --- a/includes/AutoLoader.php +++ b/includes/AutoLoader.php @@ -681,6 +681,7 @@ $wgAutoloadLocalClasses = array( 'SpecialUpload' => 'includes/specials/SpecialUpload.php', 'SpecialUserlogout' => 'includes/specials/SpecialUserlogout.php', 'SpecialVersion' => 'includes/specials/SpecialVersion.php', + 'SpecialWatchlist' => 'includes/specials/SpecialWatchlist.php', 'SpecialWhatlinkshere' => 'includes/specials/SpecialWhatlinkshere.php', 'UncategorizedCategoriesPage' => 'includes/specials/SpecialUncategorizedcategories.php', 'UncategorizedImagesPage' => 'includes/specials/SpecialUncategorizedimages.php', diff --git a/includes/SpecialPage.php b/includes/SpecialPage.php index b3f0200b80..f4d3895f84 100644 --- a/includes/SpecialPage.php +++ b/includes/SpecialPage.php @@ -155,7 +155,7 @@ class SpecialPage { # Recent changes and logs 'Newimages' => array( 'IncludableSpecialPage', 'Newimages' ), 'Log' => 'SpecialLog', - 'Watchlist' => array( 'SpecialPage', 'Watchlist' ), + 'Watchlist' => 'SpecialWatchlist', 'Newpages' => 'SpecialNewpages', 'Recentchanges' => 'SpecialRecentchanges', 'Recentchangeslinked' => 'SpecialRecentchangeslinked', diff --git a/includes/specials/SpecialWatchlist.php b/includes/specials/SpecialWatchlist.php index 771a51124d..d05c4bffb3 100644 --- a/includes/specials/SpecialWatchlist.php +++ b/includes/specials/SpecialWatchlist.php @@ -20,478 +20,485 @@ * @file * @ingroup SpecialPage Watchlist */ +class SpecialWatchlist extends SpecialPage { -/** - * Constructor - * - * @param $par Parameter passed to the page - */ -function wfSpecialWatchlist( $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(); + /** + * Constructor + */ + public function __construct(){ + parent::__construct( 'Watchlist' ); } - global $wgFeedClasses; - $apiParams = array( 'action' => 'feedwatchlist', 'allrev' => 'allrev', - 'wlowner' => $wgUser->getName(), 'wltoken' => $wlToken ); - $feedTemplate = wfScript('api').'?'; - - foreach( $wgFeedClasses as $format => $class ) { - $theseParams = $apiParams + array( 'feedformat' => $format ); - $url = $feedTemplate . wfArrayToCGI( $theseParams ); - $wgOut->addFeedLink( $format, $url ); - } + /** + * Execute + * @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(); + } - $skin = $wgUser->getSkin(); - $specialTitle = SpecialPage::getTitleFor( 'Watchlist' ); - $wgOut->setRobotPolicy( 'noindex,nofollow' ); + global $wgFeedClasses; + $apiParams = array( 'action' => 'feedwatchlist', 'allrev' => 'allrev', + 'wlowner' => $wgUser->getName(), 'wltoken' => $wlToken ); + $feedTemplate = wfScript('api').'?'; - # Anons don't get a watchlist - if( $wgUser->isAnon() ) { - $wgOut->setPageTitle( wfMsg( 'watchnologin' ) ); - $llink = $skin->linkKnown( - SpecialPage::getTitleFor( 'Userlogin' ), - wfMsgHtml( 'loginreqlink' ), - array(), - array( 'returnto' => $specialTitle->getPrefixedText() ) - ); - $wgOut->addWikiMsgArray( 'watchlistanontext', array( $llink ), array( 'replaceafter' ) ); - return; - } + foreach( $wgFeedClasses as $format => $class ) { + $theseParams = $apiParams + array( 'feedformat' => $format ); + $url = $feedTemplate . wfArrayToCGI( $theseParams ); + $wgOut->addFeedLink( $format, $url ); + } - $wgOut->setPageTitle( wfMsg( 'watchlist' ) ); - - $sub = wfMsgExt( - 'watchlistfor2', - array( 'parseinline', 'replaceafter' ), - $wgUser->getName(), - SpecialEditWatchlist::buildTools( $wgUser->getSkin() ) - ); - $wgOut->setSubtitle( $sub ); - - if( ( $mode = SpecialEditWatchlist::getMode( $wgRequest, $par ) ) !== false ) { - # TODO: localise? - switch( $mode ){ - case SpecialEditWatchlist::EDIT_CLEAR: - $mode = 'clear'; - break; - case SpecialEditWatchlist::EDIT_RAW: - $mode = 'raw'; - break; - default: - $mode = null; + $skin = $wgUser->getSkin(); + $wgOut->setRobotPolicy( 'noindex,nofollow' ); + + # Anons don't get a watchlist + if( $wgUser->isAnon() ) { + $wgOut->setPageTitle( wfMsg( 'watchnologin' ) ); + $llink = $skin->linkKnown( + SpecialPage::getTitleFor( 'Userlogin' ), + wfMsgHtml( 'loginreqlink' ), + array(), + array( 'returnto' => $this->getTitle()->getPrefixedText() ) + ); + $wgOut->addWikiMsgArray( 'watchlistanontext', array( $llink ), array( 'replaceafter' ) ); + return; } - $title = SpecialPage::getTitleFor( 'EditWatchlist', $mode ); - $wgOut->redirect( $title->getLocalUrl() ); - return; - } - $uid = $wgUser->getId(); - if( ($wgEnotifWatchlist || $wgShowUpdatedMarker) && $wgRequest->getVal( 'reset' ) && - $wgRequest->wasPosted() ) - { - $wgUser->clearAllNotifications( $uid ); - $wgOut->redirect( $specialTitle->getFullUrl() ); - return; - } + $wgOut->setPageTitle( wfMsg( 'watchlist' ) ); - $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' ), - /* ? */ 'namespace' => 'all', - /* ? */ 'invert' => false, - ); - - # 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' ); - - # Get query variables - $days = $wgRequest->getVal( 'days' , $prefs['days'] ); - $hideMinor = $wgRequest->getBool( 'hideMinor', $prefs['hideminor'] ); - $hideBots = $wgRequest->getBool( 'hideBots' , $prefs['hidebots'] ); - $hideAnons = $wgRequest->getBool( 'hideAnons', $prefs['hideanons'] ); - $hideLiu = $wgRequest->getBool( 'hideLiu' , $prefs['hideliu'] ); - $hideOwn = $wgRequest->getBool( 'hideOwn' , $prefs['hideown'] ); - $hidePatrolled = $wgRequest->getBool( 'hidePatrolled' , $prefs['hidepatrolled'] ); - - # Get namespace value, if supplied, and prepare a WHERE fragment - $nameSpace = $wgRequest->getIntOrNull( 'namespace' ); - $invert = $wgRequest->getIntOrNull( 'invert' ); - if( !is_null( $nameSpace ) ) { - $nameSpace = intval( $nameSpace ); - if( $invert && $nameSpace !== 'all' ) - $nameSpaceClause = "rc_namespace != $nameSpace"; - else - $nameSpaceClause = "rc_namespace = $nameSpace"; - } else { - $nameSpace = ''; - $nameSpaceClause = ''; - } + $sub = wfMsgExt( + 'watchlistfor2', + array( 'parseinline', 'replaceafter' ), + $wgUser->getName(), + SpecialEditWatchlist::buildTools( $wgUser->getSkin() ) + ); + $wgOut->setSubtitle( $sub ); + + if( ( $mode = SpecialEditWatchlist::getMode( $wgRequest, $par ) ) !== false ) { + # TODO: localise? + switch( $mode ){ + case SpecialEditWatchlist::EDIT_CLEAR: + $mode = 'clear'; + break; + case SpecialEditWatchlist::EDIT_RAW: + $mode = 'raw'; + break; + default: + $mode = null; + } + $title = SpecialPage::getTitleFor( 'EditWatchlist', $mode ); + $wgOut->redirect( $title->getLocalUrl() ); + return; + } - $dbr = wfGetDB( DB_SLAVE, 'watchlist' ); - $recentchanges = $dbr->tableName( 'recentchanges' ); + $uid = $wgUser->getId(); + if( ($wgEnotifWatchlist || $wgShowUpdatedMarker) && $wgRequest->getVal( 'reset' ) && + $wgRequest->wasPosted() ) + { + $wgUser->clearAllNotifications( $uid ); + $wgOut->redirect( $this->getTitle()->getFullUrl() ); + return; + } - $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); + $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' ), + /* ? */ 'namespace' => 'all', + /* ? */ 'invert' => false, + ); - if( is_null($days) || !is_numeric($days) ) { - $big = 1000; /* The magical big */ - if($nitems > $big) { - # Set default cutoff shorter - $days = $defaults['days'] = (12.0 / 24.0); # 12 hours... + # 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' ); + + # Get query variables + $days = $wgRequest->getVal( 'days' , $prefs['days'] ); + $hideMinor = $wgRequest->getBool( 'hideMinor', $prefs['hideminor'] ); + $hideBots = $wgRequest->getBool( 'hideBots' , $prefs['hidebots'] ); + $hideAnons = $wgRequest->getBool( 'hideAnons', $prefs['hideanons'] ); + $hideLiu = $wgRequest->getBool( 'hideLiu' , $prefs['hideliu'] ); + $hideOwn = $wgRequest->getBool( 'hideOwn' , $prefs['hideown'] ); + $hidePatrolled = $wgRequest->getBool( 'hidePatrolled' , $prefs['hidepatrolled'] ); + + # Get namespace value, if supplied, and prepare a WHERE fragment + $nameSpace = $wgRequest->getIntOrNull( 'namespace' ); + $invert = $wgRequest->getIntOrNull( 'invert' ); + if( !is_null( $nameSpace ) ) { + $nameSpace = intval( $nameSpace ); + if( $invert && $nameSpace !== 'all' ) + $nameSpaceClause = "rc_namespace != $nameSpace"; + else + $nameSpaceClause = "rc_namespace = $nameSpace"; } else { - $days = $defaults['days']; # default cutoff for shortlisters + $nameSpace = ''; + $nameSpaceClause = ''; } - } else { - $days = floatval($days); - } - // Dump everything here - $nondefaults = array(); - - wfAppendToArrayIfNotDefault( 'days' , $days , $defaults, $nondefaults); - wfAppendToArrayIfNotDefault( 'hideMinor', (int)$hideMinor, $defaults, $nondefaults ); - wfAppendToArrayIfNotDefault( 'hideBots' , (int)$hideBots , $defaults, $nondefaults); - wfAppendToArrayIfNotDefault( 'hideAnons', (int)$hideAnons, $defaults, $nondefaults ); - wfAppendToArrayIfNotDefault( 'hideLiu' , (int)$hideLiu , $defaults, $nondefaults ); - wfAppendToArrayIfNotDefault( 'hideOwn' , (int)$hideOwn , $defaults, $nondefaults); - wfAppendToArrayIfNotDefault( 'namespace', $nameSpace , $defaults, $nondefaults); - wfAppendToArrayIfNotDefault( 'hidePatrolled', (int)$hidePatrolled, $defaults, $nondefaults ); - - if( $nitems == 0 ) { - $wgOut->addWikiMsg( 'nowatchlist' ); - return; - } + $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); + + if( is_null($days) || !is_numeric($days) ) { + $big = 1000; /* The magical big */ + if($nitems > $big) { + # Set default cutoff shorter + $days = $defaults['days'] = (12.0 / 24.0); # 12 hours... + } else { + $days = $defaults['days']; # default cutoff for shortlisters + } + } else { + $days = floatval($days); + } - # Possible where conditions - $conds = array(); + // Dump everything here + $nondefaults = array(); + + wfAppendToArrayIfNotDefault( 'days' , $days , $defaults, $nondefaults); + wfAppendToArrayIfNotDefault( 'hideMinor', (int)$hideMinor, $defaults, $nondefaults ); + wfAppendToArrayIfNotDefault( 'hideBots' , (int)$hideBots , $defaults, $nondefaults); + wfAppendToArrayIfNotDefault( 'hideAnons', (int)$hideAnons, $defaults, $nondefaults ); + wfAppendToArrayIfNotDefault( 'hideLiu' , (int)$hideLiu , $defaults, $nondefaults ); + wfAppendToArrayIfNotDefault( 'hideOwn' , (int)$hideOwn , $defaults, $nondefaults); + wfAppendToArrayIfNotDefault( 'namespace', $nameSpace , $defaults, $nondefaults); + wfAppendToArrayIfNotDefault( 'hidePatrolled', (int)$hidePatrolled, $defaults, $nondefaults ); + + if( $nitems == 0 ) { + $wgOut->addWikiMsg( 'nowatchlist' ); + return; + } - if( $days > 0 ) { - $conds[] = "rc_timestamp > '".$dbr->timestamp( time() - intval( $days * 86400 ) )."'"; - } + # Possible where conditions + $conds = array(); - # If the watchlist is relatively short, it's simplest to zip - # down its entirety and then sort the results. + if( $days > 0 ) { + $conds[] = "rc_timestamp > '".$dbr->timestamp( time() - intval( $days * 86400 ) )."'"; + } - # If it's relatively long, it may be worth our while to zip - # through the time-sorted page list checking for watched items. + # If the watchlist is relatively short, it's simplest to zip + # down its entirety and then sort the results. - # Up estimate of watched items by 15% to compensate for talk pages... + # If it's relatively long, it may be worth our while to zip + # through the time-sorted page list checking for watched items. - # Toggles - if( $hideOwn ) { - $conds[] = "rc_user != $uid"; - } - if( $hideBots ) { - $conds[] = 'rc_bot = 0'; - } - if( $hideMinor ) { - $conds[] = 'rc_minor = 0'; - } - if( $hideLiu ) { - $conds[] = 'rc_user = 0'; - } - if( $hideAnons ) { - $conds[] = 'rc_user != 0'; - } - if ( $wgUser->useRCPatrol() && $hidePatrolled ) { - $conds[] = 'rc_patrolled != 1'; - } - if( $nameSpaceClause ) { - $conds[] = $nameSpaceClause; - } + # Up estimate of watched items by 15% to compensate for talk pages... - # Toggle watchlist content (all recent edits or just the latest) - if( $wgUser->getOption( 'extendwatchlist' )) { - $limitWatchlist = intval( $wgUser->getOption( 'wllimit' ) ); - $usePage = false; - } else { - # Top log Ids for a page are not stored - $conds[] = 'rc_this_oldid=page_latest OR rc_type=' . RC_LOG; - $limitWatchlist = 0; - $usePage = true; - } + # Toggles + if( $hideOwn ) { + $conds[] = "rc_user != $uid"; + } + if( $hideBots ) { + $conds[] = 'rc_bot = 0'; + } + if( $hideMinor ) { + $conds[] = 'rc_minor = 0'; + } + if( $hideLiu ) { + $conds[] = 'rc_user = 0'; + } + if( $hideAnons ) { + $conds[] = 'rc_user != 0'; + } + if ( $wgUser->useRCPatrol() && $hidePatrolled ) { + $conds[] = 'rc_patrolled != 1'; + } + if( $nameSpaceClause ) { + $conds[] = $nameSpaceClause; + } - # Show a message about slave lag, if applicable - if( ( $lag = $dbr->getLag() ) > 0 ) - $wgOut->showLagWarning( $lag ); + # Toggle watchlist content (all recent edits or just the latest) + if( $wgUser->getOption( 'extendwatchlist' )) { + $limitWatchlist = intval( $wgUser->getOption( 'wllimit' ) ); + $usePage = false; + } else { + # Top log Ids for a page are not stored + $conds[] = 'rc_this_oldid=page_latest OR rc_type=' . RC_LOG; + $limitWatchlist = 0; + $usePage = true; + } - # Create output form - $form = Xml::fieldset( wfMsg( 'watchlist-options' ), false, array( 'id' => 'mw-watchlist-options' ) ); + # Show a message about slave lag, if applicable + if( ( $lag = $dbr->getLag() ) > 0 ) + $wgOut->showLagWarning( $lag ); - # Show watchlist header - $form .= wfMsgExt( 'watchlist-details', array( 'parseinline' ), $wgLang->formatNum( $nitems ) ); + # Create output form + $form = Xml::fieldset( wfMsg( 'watchlist-options' ), false, array( 'id' => 'mw-watchlist-options' ) ); - if( $wgUser->getOption( 'enotifwatchlistpages' ) && $wgEnotifWatchlist) { - $form .= wfMsgExt( 'wlheader-enotif', 'parse' ) . "\n"; - } - if( $wgShowUpdatedMarker ) { - $form .= Xml::openElement( 'form', array( 'method' => 'post', - 'action' => $specialTitle->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' ); - } - $form .= '
'; - - $tables = array( 'recentchanges', 'watchlist' ); - $fields = array( "{$recentchanges}.*" ); - $join_conds = array( - 'watchlist' => array('INNER JOIN',"wl_user='{$uid}' AND wl_namespace=rc_namespace AND wl_title=rc_title"), - ); - $options = array( 'ORDER BY' => 'rc_timestamp DESC' ); - if( $wgShowUpdatedMarker ) { - $fields[] = 'wl_notificationtimestamp'; - } - if( $limitWatchlist ) { - $options['LIMIT'] = $limitWatchlist; - } - - $rollbacker = $wgUser->isAllowed('rollback'); - if ( $usePage || $rollbacker ) { - $tables[] = 'page'; - $join_conds['page'] = array('LEFT JOIN','rc_cur_id=page_id'); - if ($rollbacker) - $fields[] = 'page_latest'; - } + # Show watchlist header + $form .= wfMsgExt( 'watchlist-details', array( 'parseinline' ), $wgLang->formatNum( $nitems ) ); - ChangeTags::modifyDisplayQuery( $tables, $fields, $conds, $join_conds, $options, '' ); - wfRunHooks('SpecialWatchlistQuery', array(&$conds,&$tables,&$join_conds,&$fields) ); - - $res = $dbr->select( $tables, $fields, $conds, __METHOD__, $options, $join_conds ); - $numRows = $dbr->numRows( $res ); - - /* Start bottom header */ - - $wlInfo = ''; - if( $days >= 1 ) { - $wlInfo = wfMsgExt( 'rcnote', 'parseinline', - $wgLang->formatNum( $numRows ), - $wgLang->formatNum( $days ), - $wgLang->timeAndDate( wfTimestampNow(), true ), - $wgLang->date( wfTimestampNow(), true ), - $wgLang->time( wfTimestampNow(), true ) - ) . '
'; - } elseif( $days > 0 ) { - $wlInfo = wfMsgExt( 'wlnote', 'parseinline', - $wgLang->formatNum( $numRows ), - $wgLang->formatNum( round($days*24) ) - ) . '
'; - } + if( $wgUser->getOption( 'enotifwatchlistpages' ) && $wgEnotifWatchlist) { + $form .= wfMsgExt( 'wlheader-enotif', 'parse' ) . "\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' ); + } + $form .= '
'; - $cutofflinks = "\n" . wlCutoffLinks( $days, 'Watchlist', $nondefaults ) . "
\n"; + $tables = array( 'recentchanges', 'watchlist' ); + $fields = array( "{$recentchanges}.*" ); + $join_conds = array( + 'watchlist' => array('INNER JOIN',"wl_user='{$uid}' AND wl_namespace=rc_namespace AND wl_title=rc_title"), + ); + $options = array( 'ORDER BY' => 'rc_timestamp DESC' ); + if( $wgShowUpdatedMarker ) { + $fields[] = 'wl_notificationtimestamp'; + } + if( $limitWatchlist ) { + $options['LIMIT'] = $limitWatchlist; + } - $thisTitle = SpecialPage::getTitleFor( 'Watchlist' ); + $rollbacker = $wgUser->isAllowed('rollback'); + if ( $usePage || $rollbacker ) { + $tables[] = 'page'; + $join_conds['page'] = array('LEFT JOIN','rc_cur_id=page_id'); + if ($rollbacker) + $fields[] = 'page_latest'; + } - # Spit out some control panel links - $links[] = wlShowHideLink( $nondefaults, 'rcshowhideminor', 'hideMinor', $hideMinor ); - $links[] = wlShowHideLink( $nondefaults, 'rcshowhidebots', 'hideBots', $hideBots ); - $links[] = wlShowHideLink( $nondefaults, 'rcshowhideanons', 'hideAnons', $hideAnons ); - $links[] = wlShowHideLink( $nondefaults, 'rcshowhideliu', 'hideLiu', $hideLiu ); - $links[] = wlShowHideLink( $nondefaults, 'rcshowhidemine', 'hideOwn', $hideOwn ); + ChangeTags::modifyDisplayQuery( $tables, $fields, $conds, $join_conds, $options, '' ); + wfRunHooks('SpecialWatchlistQuery', array(&$conds,&$tables,&$join_conds,&$fields) ); + + $res = $dbr->select( $tables, $fields, $conds, __METHOD__, $options, $join_conds ); + $numRows = $dbr->numRows( $res ); + + /* Start bottom header */ + + $wlInfo = ''; + if( $days >= 1 ) { + $wlInfo = wfMsgExt( 'rcnote', 'parseinline', + $wgLang->formatNum( $numRows ), + $wgLang->formatNum( $days ), + $wgLang->timeAndDate( wfTimestampNow(), true ), + $wgLang->date( wfTimestampNow(), true ), + $wgLang->time( wfTimestampNow(), true ) + ) . '
'; + } elseif( $days > 0 ) { + $wlInfo = wfMsgExt( 'wlnote', 'parseinline', + $wgLang->formatNum( $numRows ), + $wgLang->formatNum( round($days*24) ) + ) . '
'; + } - if( $wgUser->useRCPatrol() ) { - $links[] = wlShowHideLink( $nondefaults, 'rcshowhidepatr', 'hidePatrolled', $hidePatrolled ); - } + $cutofflinks = "\n" . self::cutoffLinks( $days, 'Watchlist', $nondefaults ) . "
\n"; - # 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 .= '

'; - $form .= Xml::label( wfMsg( 'namespace' ), 'namespace' ) . ' '; - $form .= Xml::namespaceSelector( $nameSpace, '' ) . ' '; - $form .= Xml::checkLabel( wfMsg('invert'), 'invert', 'nsinvert', $invert ) . ' '; - $form .= Xml::submitButton( wfMsg( 'allpagessubmit' ) ) . '

'; - $form .= Html::hidden( 'days', $days ); - if( $hideMinor ) - $form .= Html::hidden( 'hideMinor', 1 ); - if( $hideBots ) - $form .= Html::hidden( 'hideBots', 1 ); - if( $hideAnons ) - $form .= Html::hidden( 'hideAnons', 1 ); - if( $hideLiu ) - $form .= Html::hidden( 'hideLiu', 1 ); - if( $hideOwn ) - $form .= Html::hidden( 'hideOwn', 1 ); - $form .= Xml::closeElement( 'form' ); - $form .= Xml::closeElement( 'fieldset' ); - $wgOut->addHTML( $form ); - - # If there's nothing to show, stop here - if( $numRows == 0 ) { - $wgOut->addWikiMsg( 'watchnochange' ); - return; - } + $thisTitle = SpecialPage::getTitleFor( 'Watchlist' ); - /* End bottom header */ + # Spit out some control panel links + $links[] = self::showHideLink( $nondefaults, 'rcshowhideminor', 'hideMinor', $hideMinor ); + $links[] = self::showHideLink( $nondefaults, 'rcshowhidebots', 'hideBots', $hideBots ); + $links[] = self::showHideLink( $nondefaults, 'rcshowhideanons', 'hideAnons', $hideAnons ); + $links[] = self::showHideLink( $nondefaults, 'rcshowhideliu', 'hideLiu', $hideLiu ); + $links[] = self::showHideLink( $nondefaults, 'rcshowhidemine', 'hideOwn', $hideOwn ); - /* Do link batch query */ - $linkBatch = new LinkBatch; - foreach ( $res as $row ) { - $userNameUnderscored = str_replace( ' ', '_', $row->rc_user_text ); - if ( $row->rc_user != 0 ) { - $linkBatch->add( NS_USER, $userNameUnderscored ); + if( $wgUser->useRCPatrol() ) { + $links[] = self::showHideLink( $nondefaults, 'rcshowhidepatr', 'hidePatrolled', $hidePatrolled ); } - $linkBatch->add( NS_USER_TALK, $userNameUnderscored ); - $linkBatch->add( $row->rc_namespace, $row->rc_title ); - } - $linkBatch->execute(); - $dbr->dataSeek( $res, 0 ); + # 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 .= '

'; + $form .= Xml::label( wfMsg( 'namespace' ), 'namespace' ) . ' '; + $form .= Xml::namespaceSelector( $nameSpace, '' ) . ' '; + $form .= Xml::checkLabel( wfMsg('invert'), 'invert', 'nsinvert', $invert ) . ' '; + $form .= Xml::submitButton( wfMsg( 'allpagessubmit' ) ) . '

'; + $form .= Html::hidden( 'days', $days ); + if( $hideMinor ) + $form .= Html::hidden( 'hideMinor', 1 ); + if( $hideBots ) + $form .= Html::hidden( 'hideBots', 1 ); + if( $hideAnons ) + $form .= Html::hidden( 'hideAnons', 1 ); + if( $hideLiu ) + $form .= Html::hidden( 'hideLiu', 1 ); + if( $hideOwn ) + $form .= Html::hidden( 'hideOwn', 1 ); + $form .= Xml::closeElement( 'form' ); + $form .= Xml::closeElement( 'fieldset' ); + $wgOut->addHTML( $form ); + + # If there's nothing to show, stop here + if( $numRows == 0 ) { + $wgOut->addWikiMsg( 'watchnochange' ); + return; + } - $list = ChangesList::newFromUser( $wgUser ); - $list->setWatchlistDivs(); + /* End bottom header */ - $s = $list->beginRecentChangesList(); - $counter = 1; - foreach ( $res as $obj ) { - # Make RC entry - $rc = RecentChange::newFromRow( $obj ); - $rc->counter = $counter++; + /* Do link batch query */ + $linkBatch = new LinkBatch; + foreach ( $res as $row ) { + $userNameUnderscored = str_replace( ' ', '_', $row->rc_user_text ); + if ( $row->rc_user != 0 ) { + $linkBatch->add( NS_USER, $userNameUnderscored ); + } + $linkBatch->add( NS_USER_TALK, $userNameUnderscored ); - if ( $wgShowUpdatedMarker ) { - $updated = $obj->wl_notificationtimestamp; - } else { - $updated = false; + $linkBatch->add( $row->rc_namespace, $row->rc_title ); } - - if ($wgRCShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' )) { - $rc->numberofWatchingusers = $dbr->selectField( 'watchlist', - 'COUNT(*)', - array( - 'wl_namespace' => $obj->rc_namespace, - 'wl_title' => $obj->rc_title, - ), - __METHOD__ ); - } else { - $rc->numberofWatchingusers = 0; + $linkBatch->execute(); + $dbr->dataSeek( $res, 0 ); + + $list = ChangesList::newFromUser( $wgUser ); + $list->setWatchlistDivs(); + + $s = $list->beginRecentChangesList(); + $counter = 1; + foreach ( $res as $obj ) { + # Make RC entry + $rc = RecentChange::newFromRow( $obj ); + $rc->counter = $counter++; + + if ( $wgShowUpdatedMarker ) { + $updated = $obj->wl_notificationtimestamp; + } else { + $updated = false; + } + + if ($wgRCShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' )) { + $rc->numberofWatchingusers = $dbr->selectField( 'watchlist', + 'COUNT(*)', + array( + 'wl_namespace' => $obj->rc_namespace, + 'wl_title' => $obj->rc_title, + ), + __METHOD__ ); + } else { + $rc->numberofWatchingusers = 0; + } + + $s .= $list->recentChangesLine( $rc, $updated, $counter ); } + $s .= $list->endRecentChangesList(); - $s .= $list->recentChangesLine( $rc, $updated, $counter ); + $wgOut->addHTML( $s ); } - $s .= $list->endRecentChangesList(); - - $wgOut->addHTML( $s ); -} -function wlShowHideLink( $options, $message, $name, $value ) { - global $wgUser; + public static function showHideLink( $options, $message, $name, $value ) { + global $wgUser; - $showLinktext = wfMsgHtml( 'show' ); - $hideLinktext = wfMsgHtml( 'hide' ); - $title = SpecialPage::getTitleFor( 'Watchlist' ); - $skin = $wgUser->getSkin(); + $showLinktext = wfMsgHtml( 'show' ); + $hideLinktext = wfMsgHtml( 'hide' ); + $title = SpecialPage::getTitleFor( 'Watchlist' ); + $skin = $wgUser->getSkin(); - $label = $value ? $showLinktext : $hideLinktext; - $options[$name] = 1 - (int) $value; - - return wfMsgHtml( $message, $skin->linkKnown( $title, $label, array(), $options ) ); -} + $label = $value ? $showLinktext : $hideLinktext; + $options[$name] = 1 - (int) $value; + return wfMsgHtml( $message, $skin->linkKnown( $title, $label, array(), $options ) ); + } -function wlHoursLink( $h, $page, $options = array() ) { - global $wgUser, $wgLang, $wgContLang; - $sk = $wgUser->getSkin(); - $title = Title::newFromText( $wgContLang->specialPage( $page ) ); - $options['days'] = ($h / 24.0); + public static function hoursLink( $h, $page, $options = array() ) { + global $wgUser, $wgLang, $wgContLang; - $s = $sk->linkKnown( - $title, - $wgLang->formatNum( $h ), - array(), - $options - ); + $sk = $wgUser->getSkin(); + $title = Title::newFromText( $wgContLang->specialPage( $page ) ); + $options['days'] = ($h / 24.0); - return $s; -} + $s = $sk->linkKnown( + $title, + $wgLang->formatNum( $h ), + array(), + $options + ); -function wlDaysLink( $d, $page, $options = array() ) { - global $wgUser, $wgLang, $wgContLang; + return $s; + } - $sk = $wgUser->getSkin(); - $title = Title::newFromText( $wgContLang->specialPage( $page ) ); - $options['days'] = $d; - $message = ($d ? $wgLang->formatNum( $d ) : wfMsgHtml( 'watchlistall2' ) ); + public static function daysLink( $d, $page, $options = array() ) { + global $wgUser, $wgLang, $wgContLang; - $s = $sk->linkKnown( - $title, - $message, - array(), - $options - ); + $sk = $wgUser->getSkin(); + $title = Title::newFromText( $wgContLang->specialPage( $page ) ); + $options['days'] = $d; + $message = ($d ? $wgLang->formatNum( $d ) : wfMsgHtml( 'watchlistall2' ) ); - return $s; -} + $s = $sk->linkKnown( + $title, + $message, + array(), + $options + ); -/** - * Returns html - */ -function wlCutoffLinks( $days, $page = 'Watchlist', $options = array() ) { - global $wgLang; - - $hours = array( 1, 2, 6, 12 ); - $days = array( 1, 3, 7 ); - $i = 0; - foreach( $hours as $h ) { - $hours[$i++] = wlHoursLink( $h, $page, $options ); - } - $i = 0; - foreach( $days as $d ) { - $days[$i++] = wlDaysLink( $d, $page, $options ); + return $s; } - return wfMsgExt('wlshowlast', - array('parseinline', 'replaceafter'), - $wgLang->pipeList( $hours ), - $wgLang->pipeList( $days ), - wlDaysLink( 0, $page, $options ) ); -} - -/** - * Count the number of items on a user's watchlist - * - * @param $user User object - * @param $talk Boolean: include talk pages - * @return Integer - */ -function wlCountItems( &$user, $talk = true ) { - $dbr = wfGetDB( DB_SLAVE, 'watchlist' ); - # Fetch the raw count - $res = $dbr->select( 'watchlist', 'COUNT(*) AS count', - array( 'wl_user' => $user->mId ), 'wlCountItems' ); - $row = $dbr->fetchObject( $res ); - $count = $row->count; - - # Halve to remove talk pages if needed - if( !$talk ) - $count = floor( $count / 2 ); + /** + * Returns html + */ + protected static function cutoffLinks( $days, $page = 'Watchlist', $options = array() ) { + global $wgLang; + + $hours = array( 1, 2, 6, 12 ); + $days = array( 1, 3, 7 ); + $i = 0; + foreach( $hours as $h ) { + $hours[$i++] = self::hoursLink( $h, $page, $options ); + } + $i = 0; + foreach( $days as $d ) { + $days[$i++] = self::daysLink( $d, $page, $options ); + } + return wfMsgExt('wlshowlast', + array('parseinline', 'replaceafter'), + $wgLang->pipeList( $hours ), + $wgLang->pipeList( $days ), + self::daysLink( 0, $page, $options ) ); + } - return( $count ); + /** + * 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 ) { + $dbr = wfGetDB( DB_SLAVE, 'watchlist' ); + + # Fetch the raw count + $res = $dbr->select( 'watchlist', 'COUNT(*) AS count', + array( 'wl_user' => $user->mId ), __METHOD__ ); + $row = $dbr->fetchObject( $res ); + $count = $row->count; + + # Halve to remove talk pages if needed + if( !$talk ) + $count = floor( $count / 2 ); + + return( $count ); + } }