From ca32f08966f1b51fcb19460f0996bb0c4048e6fe Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Sat, 3 Dec 2011 13:29:22 +0100 Subject: Update to MediaWiki 1.18.0 * also update ArchLinux skin to chagnes in MonoBook * Use only css to hide our menu bar when printing --- includes/specials/SpecialRecentchanges.php | 417 ++++++++++++++++++----------- 1 file changed, 260 insertions(+), 157 deletions(-) (limited to 'includes/specials/SpecialRecentchanges.php') diff --git a/includes/specials/SpecialRecentchanges.php b/includes/specials/SpecialRecentchanges.php index c012beca..6c78ced0 100644 --- a/includes/specials/SpecialRecentchanges.php +++ b/includes/specials/SpecialRecentchanges.php @@ -28,6 +28,7 @@ */ class SpecialRecentChanges extends IncludableSpecialPage { var $rcOptions, $rcSubpage; + protected $customFilters; public function __construct( $name = 'Recentchanges' ) { parent::__construct( $name ); @@ -39,22 +40,22 @@ class SpecialRecentChanges extends IncludableSpecialPage { * @return FormOptions */ public function getDefaultOptions() { - global $wgUser; $opts = new FormOptions(); - $opts->add( 'days', (int)$wgUser->getOption( 'rcdays' ) ); - $opts->add( 'limit', (int)$wgUser->getOption( 'rclimit' ) ); + $opts->add( 'days', (int)$this->getUser()->getOption( 'rcdays' ) ); + $opts->add( 'limit', (int)$this->getUser()->getOption( 'rclimit' ) ); $opts->add( 'from', '' ); - $opts->add( 'hideminor', $wgUser->getBoolOption( 'hideminor' ) ); + $opts->add( 'hideminor', $this->getUser()->getBoolOption( 'hideminor' ) ); $opts->add( 'hidebots', true ); $opts->add( 'hideanons', false ); $opts->add( 'hideliu', false ); - $opts->add( 'hidepatrolled', $wgUser->getBoolOption( 'hidepatrolled' ) ); + $opts->add( 'hidepatrolled', $this->getUser()->getBoolOption( 'hidepatrolled' ) ); $opts->add( 'hidemyself', false ); $opts->add( 'namespace', '', FormOptions::INTNULL ); $opts->add( 'invert', false ); + $opts->add( 'associated', false ); $opts->add( 'categories', '' ); $opts->add( 'categories_any', false ); @@ -65,13 +66,20 @@ class SpecialRecentChanges extends IncludableSpecialPage { /** * Create a FormOptions object with options as specified by the user * + * @param $parameters array + * * @return FormOptions */ public function setup( $parameters ) { - global $wgRequest; - $opts = $this->getDefaultOptions(); - $opts->fetchValuesFromRequest( $wgRequest ); + + $this->customFilters = array(); + wfRunHooks( 'SpecialRecentChangesFilters', array( $this, &$this->customFilters ) ); + foreach( $this->customFilters as $key => $params ) { + $opts->add( $key, $params['default'] ); + } + + $opts->fetchValuesFromRequest( $this->getRequest() ); // Give precedence to subpage syntax if( $parameters !== null ) { @@ -88,10 +96,10 @@ class SpecialRecentChanges extends IncludableSpecialPage { * @return FormOptions */ public function feedSetup() { - global $wgFeedLimit, $wgRequest; + global $wgFeedLimit; $opts = $this->getDefaultOptions(); # Feed is cached on limit,hideminor,namespace; other params would randomly not work - $opts->fetchValuesFromRequest( $wgRequest, array( 'limit', 'hideminor', 'namespace' ) ); + $opts->fetchValuesFromRequest( $this->getRequest(), array( 'limit', 'hideminor', 'namespace' ) ); $opts->validateIntBounds( 'limit', 0, $wgFeedLimit ); return $opts; } @@ -101,9 +109,12 @@ class SpecialRecentChanges extends IncludableSpecialPage { */ public function getOptions() { if ( $this->rcOptions === null ) { - global $wgRequest; - $feedFormat = $wgRequest->getVal( 'feed' ); - $this->rcOptions = $feedFormat ? $this->feedSetup() : $this->setup( $this->rcSubpage ); + if ( $this->including() ) { + $isFeed = false; + } else { + $isFeed = (bool)$this->getRequest()->getVal( 'feed' ); + } + $this->rcOptions = $isFeed ? $this->feedSetup() : $this->setup( $this->rcSubpage ); } return $this->rcOptions; } @@ -115,12 +126,11 @@ class SpecialRecentChanges extends IncludableSpecialPage { * @param $subpage String */ public function execute( $subpage ) { - global $wgRequest, $wgOut; $this->rcSubpage = $subpage; - $feedFormat = $wgRequest->getVal( 'feed' ); + $feedFormat = $this->including() ? null : $this->getRequest()->getVal( 'feed' ); # 10 seconds server-side caching max - $wgOut->setSquidMaxage( 10 ); + $this->getOutput()->setSquidMaxage( 10 ); # Check if the client has a cached version $lastmod = $this->checkLastModified( $feedFormat ); if( $lastmod === false ) { @@ -130,6 +140,7 @@ class SpecialRecentChanges extends IncludableSpecialPage { $opts = $this->getOptions(); $this->setHeaders(); $this->outputHeader(); + $this->addRecentChangesJS(); // Fetch results, prepare a batch link existence check query $conds = $this->buildMainQueryConds( $opts ); @@ -144,8 +155,8 @@ class SpecialRecentChanges extends IncludableSpecialPage { if( !$feedFormat ) { $batch = new LinkBatch; foreach( $rows as $row ) { - $batch->add( NS_USER, $row->rc_user_text ); - $batch->add( NS_USER_TALK, $row->rc_user_text ); + $batch->add( NS_USER, $row->rc_user_text ); + $batch->add( NS_USER_TALK, $row->rc_user_text ); $batch->add( $row->rc_namespace, $row->rc_title ); } $batch->execute(); @@ -169,7 +180,8 @@ class SpecialRecentChanges extends IncludableSpecialPage { $changesFeed = new ChangesFeed( $feedFormat, 'rcfeed' ); $formatter = $changesFeed->getFeedObject( wfMsgForContent( 'recentchanges' ), - wfMsgForContent( 'recentchanges-feed-description' ) + wfMsgForContent( 'recentchanges-feed-description' ), + $this->getTitle()->getFullURL() ); return array( $changesFeed, $formatter ); } @@ -184,20 +196,42 @@ class SpecialRecentChanges extends IncludableSpecialPage { public function parseParameters( $par, FormOptions $opts ) { $bits = preg_split( '/\s*,\s*/', trim( $par ) ); foreach( $bits as $bit ) { - if( 'hidebots' === $bit ) $opts['hidebots'] = true; - if( 'bots' === $bit ) $opts['hidebots'] = false; - if( 'hideminor' === $bit ) $opts['hideminor'] = true; - if( 'minor' === $bit ) $opts['hideminor'] = false; - if( 'hideliu' === $bit ) $opts['hideliu'] = true; - if( 'hidepatrolled' === $bit ) $opts['hidepatrolled'] = true; - if( 'hideanons' === $bit ) $opts['hideanons'] = true; - if( 'hidemyself' === $bit ) $opts['hidemyself'] = true; + if( 'hidebots' === $bit ) { + $opts['hidebots'] = true; + } + if( 'bots' === $bit ) { + $opts['hidebots'] = false; + } + if( 'hideminor' === $bit ) { + $opts['hideminor'] = true; + } + if( 'minor' === $bit ) { + $opts['hideminor'] = false; + } + if( 'hideliu' === $bit ) { + $opts['hideliu'] = true; + } + if( 'hidepatrolled' === $bit ) { + $opts['hidepatrolled'] = true; + } + if( 'hideanons' === $bit ) { + $opts['hideanons'] = true; + } + if( 'hidemyself' === $bit ) { + $opts['hidemyself'] = true; + } - if( is_numeric( $bit ) ) $opts['limit'] = $bit; + if( is_numeric( $bit ) ) { + $opts['limit'] = $bit; + } $m = array(); - if( preg_match( '/^limit=(\d+)$/', $bit, $m ) ) $opts['limit'] = $m[1]; - if( preg_match( '/^days=(\d+)$/', $bit, $m ) ) $opts['days'] = $m[1]; + if( preg_match( '/^limit=(\d+)$/', $bit, $m ) ) { + $opts['limit'] = $m[1]; + } + if( preg_match( '/^days=(\d+)$/', $bit, $m ) ) { + $opts['days'] = $m[1]; + } } } @@ -210,11 +244,10 @@ class SpecialRecentChanges extends IncludableSpecialPage { * @return String or false */ public function checkLastModified( $feedFormat ) { - global $wgUseRCPatrol, $wgOut; $dbr = wfGetDB( DB_SLAVE ); $lastmod = $dbr->selectField( 'recentchanges', 'MAX(rc_timestamp)', false, __METHOD__ ); - if( $feedFormat || !$wgUseRCPatrol ) { - if( $lastmod && $wgOut->checkLastModified( $lastmod ) ) { + if( $feedFormat || !$this->getUser()->useRCPatrol() ) { + if( $lastmod && $this->getOutput()->checkLastModified( $lastmod ) ) { # Client cache fresh and headers sent, nothing more to do. return false; } @@ -229,8 +262,6 @@ class SpecialRecentChanges extends IncludableSpecialPage { * @return array */ public function buildMainQueryConds( FormOptions $opts ) { - global $wgUser; - $dbr = wfGetDB( DB_SLAVE ); $conds = array(); @@ -261,35 +292,58 @@ class SpecialRecentChanges extends IncludableSpecialPage { $conds[] = 'rc_timestamp >= ' . $dbr->addQuotes( $cutoff ); - - $hidePatrol = $wgUser->useRCPatrol() && $opts['hidepatrolled']; + $hidePatrol = $this->getUser()->useRCPatrol() && $opts['hidepatrolled']; $hideLoggedInUsers = $opts['hideliu'] && !$forcebot; $hideAnonymousUsers = $opts['hideanons'] && !$forcebot; - if( $opts['hideminor'] ) $conds['rc_minor'] = 0; - if( $opts['hidebots'] ) $conds['rc_bot'] = 0; - if( $hidePatrol ) $conds['rc_patrolled'] = 0; - if( $forcebot ) $conds['rc_bot'] = 1; - if( $hideLoggedInUsers ) $conds[] = 'rc_user = 0'; - if( $hideAnonymousUsers ) $conds[] = 'rc_user != 0'; + if( $opts['hideminor'] ) { + $conds['rc_minor'] = 0; + } + if( $opts['hidebots'] ) { + $conds['rc_bot'] = 0; + } + if( $hidePatrol ) { + $conds['rc_patrolled'] = 0; + } + if( $forcebot ) { + $conds['rc_bot'] = 1; + } + if( $hideLoggedInUsers ) { + $conds[] = 'rc_user = 0'; + } + if( $hideAnonymousUsers ) { + $conds[] = 'rc_user != 0'; + } if( $opts['hidemyself'] ) { - if( $wgUser->getId() ) { - $conds[] = 'rc_user != ' . $dbr->addQuotes( $wgUser->getId() ); + if( $this->getUser()->getId() ) { + $conds[] = 'rc_user != ' . $dbr->addQuotes( $this->getUser()->getId() ); } else { - $conds[] = 'rc_user_text != ' . $dbr->addQuotes( $wgUser->getName() ); + $conds[] = 'rc_user_text != ' . $dbr->addQuotes( $this->getUser()->getName() ); } } # Namespace filtering if( $opts['namespace'] !== '' ) { - if( !$opts['invert'] ) { - $conds[] = 'rc_namespace = ' . $dbr->addQuotes( $opts['namespace'] ); + $selectedNS = $dbr->addQuotes( $opts['namespace'] ); + $operator = $opts['invert'] ? '!=' : '='; + $boolean = $opts['invert'] ? 'AND' : 'OR'; + + # namespace association (bug 2429) + if( !$opts['associated'] ) { + $condition = "rc_namespace $operator $selectedNS"; } else { - $conds[] = 'rc_namespace != ' . $dbr->addQuotes( $opts['namespace'] ); + # Also add the associated namespace + $associatedNS = $dbr->addQuotes( + MWNamespace::getAssociated( $opts['namespace'] ) + ); + $condition = "(rc_namespace $operator $selectedNS " + . $boolean + . " rc_namespace $operator $associatedNS)"; } - } + $conds[] = $condition; + } return $conds; } @@ -301,75 +355,94 @@ class SpecialRecentChanges extends IncludableSpecialPage { * @return database result or false (for Recentchangeslinked only) */ public function doMainQuery( $conds, $opts ) { - global $wgUser; - $tables = array( 'recentchanges' ); $join_conds = array(); - $query_options = array( 'USE INDEX' => array('recentchanges' => 'rc_timestamp') ); + $query_options = array( + 'USE INDEX' => array( 'recentchanges' => 'rc_timestamp' ) + ); - $uid = $wgUser->getId(); + $uid = $this->getUser()->getId(); $dbr = wfGetDB( DB_SLAVE ); $limit = $opts['limit']; $namespace = $opts['namespace']; - $select = '*'; $invert = $opts['invert']; + $associated = $opts['associated']; + $fields = array( $dbr->tableName( 'recentchanges' ) . '.*' ); // all rc columns // JOIN on watchlist for users - if( $uid ) { + if ( $uid ) { $tables[] = 'watchlist'; + $fields[] = 'wl_user'; + $fields[] = 'wl_notificationtimestamp'; $join_conds['watchlist'] = array('LEFT JOIN', "wl_user={$uid} AND wl_title=rc_title AND wl_namespace=rc_namespace"); } - if ($wgUser->isAllowed("rollback")) { + if ( $this->getUser()->isAllowed( 'rollback' ) ) { $tables[] = 'page'; + $fields[] = 'page_latest'; $join_conds['page'] = array('LEFT JOIN', 'rc_cur_id=page_id'); } if ( !$this->including() ) { // Tag stuff. // Doesn't work when transcluding. See bug 23293 - $fields = array(); - // Fields are * in this case, so let the function modify an empty array to keep it happy. ChangeTags::modifyDisplayQuery( - $tables, $fields, $conds, $join_conds, $query_options, $opts['tagfilter'] + $tables, $fields, $conds, $join_conds, $query_options, + $opts['tagfilter'] ); } - if ( !wfRunHooks( 'SpecialRecentChangesQuery', array( &$conds, &$tables, &$join_conds, $opts, &$query_options, &$select ) ) ) + if ( !wfRunHooks( 'SpecialRecentChangesQuery', + array( &$conds, &$tables, &$join_conds, $opts, &$query_options, &$fields ) ) ) + { return false; + } // Don't use the new_namespace_time timestamp index if: // (a) "All namespaces" selected - // (b) We want all pages NOT in a certain namespaces (inverted) + // (b) We want pages in more than one namespace (inverted/associated) // (c) There is a tag to filter on (use tag index instead) // (d) UNION + sort/limit is not an option for the DBMS - if( is_null( $namespace ) - || ( $invert && !is_null( $namespace ) ) + if( $namespace === '' + || ( $invert || $associated ) || $opts['tagfilter'] != '' || !$dbr->unionSupportsOrderAndLimit() ) { - $res = $dbr->select( $tables, '*', $conds, __METHOD__, + $res = $dbr->select( $tables, $fields, $conds, __METHOD__, array( 'ORDER BY' => 'rc_timestamp DESC', 'LIMIT' => $limit ) + $query_options, $join_conds ); // We have a new_namespace_time index! UNION over new=(0,1) and sort result set! } else { // New pages - $sqlNew = $dbr->selectSQLText( $tables, $select, + $sqlNew = $dbr->selectSQLText( + $tables, + $fields, array( 'rc_new' => 1 ) + $conds, __METHOD__, - array( 'ORDER BY' => 'rc_timestamp DESC', 'LIMIT' => $limit, - 'USE INDEX' => array('recentchanges' => 'rc_timestamp') ), - $join_conds ); + array( + 'ORDER BY' => 'rc_timestamp DESC', + 'LIMIT' => $limit, + 'USE INDEX' => array( 'recentchanges' => 'new_name_timestamp' ) + ), + $join_conds + ); // Old pages - $sqlOld = $dbr->selectSQLText( $tables, '*', + $sqlOld = $dbr->selectSQLText( + $tables, + $fields, array( 'rc_new' => 0 ) + $conds, __METHOD__, - array( 'ORDER BY' => 'rc_timestamp DESC', 'LIMIT' => $limit, - 'USE INDEX' => array('recentchanges' => 'rc_timestamp') ), - $join_conds ); + array( + 'ORDER BY' => 'rc_timestamp DESC', + 'LIMIT' => $limit, + 'USE INDEX' => array( 'recentchanges' => 'new_name_timestamp' ) + ), + $join_conds + ); # Join the two fast queries, and sort the result set - $sql = $dbr->unionQueries(array($sqlNew, $sqlOld), false).' ORDER BY rc_timestamp DESC'; - $sql = $dbr->limitResult($sql, $limit, false); + $sql = $dbr->unionQueries( array( $sqlNew, $sqlOld ), false ) . + ' ORDER BY rc_timestamp DESC'; + $sql = $dbr->limitResult( $sql, $limit, false ); $res = $dbr->query( $sql, __METHOD__ ); } @@ -377,14 +450,13 @@ class SpecialRecentChanges extends IncludableSpecialPage { } /** - * Send output to $wgOut, only called if not used feeds + * Send output to the OutputPage object, only called if not used feeds * * @param $rows Array of database rows * @param $opts FormOptions */ public function webOutput( $rows, $opts ) { - global $wgOut, $wgUser, $wgRCShowWatchingUsers, $wgShowUpdatedMarker; - global $wgAllowCategorizedRecentChanges; + global $wgRCShowWatchingUsers, $wgShowUpdatedMarker, $wgAllowCategorizedRecentChanges; $limit = $opts['limit']; @@ -394,43 +466,47 @@ class SpecialRecentChanges extends IncludableSpecialPage { } // And now for the content - $wgOut->setFeedAppendQuery( $this->getFeedQuery() ); + $this->getOutput()->setFeedAppendQuery( $this->getFeedQuery() ); if( $wgAllowCategorizedRecentChanges ) { $this->filterByCategories( $rows, $opts ); } - $showWatcherCount = $wgRCShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' ); + $showWatcherCount = $wgRCShowWatchingUsers && $this->getUser()->getOption( 'shownumberswatching' ); $watcherCache = array(); $dbr = wfGetDB( DB_SLAVE ); $counter = 1; - $list = ChangesList::newFromUser( $wgUser ); + $list = ChangesList::newFromContext( $this->getContext() ); $s = $list->beginRecentChangesList(); foreach( $rows as $obj ) { - if( $limit == 0 ) break; + if( $limit == 0 ) { + break; + } $rc = RecentChange::newFromRow( $obj ); $rc->counter = $counter++; # Check if the page has been updated since the last visit - if( $wgShowUpdatedMarker && !empty($obj->wl_notificationtimestamp) ) { - $rc->notificationtimestamp = ($obj->rc_timestamp >= $obj->wl_notificationtimestamp); + if( $wgShowUpdatedMarker && !empty( $obj->wl_notificationtimestamp ) ) { + $rc->notificationtimestamp = ( $obj->rc_timestamp >= $obj->wl_notificationtimestamp ); } else { $rc->notificationtimestamp = false; // Default } # Check the number of users watching the page $rc->numberofWatchingusers = 0; // Default if( $showWatcherCount && $obj->rc_namespace >= 0 ) { - if( !isset($watcherCache[$obj->rc_namespace][$obj->rc_title]) ) { + if( !isset( $watcherCache[$obj->rc_namespace][$obj->rc_title] ) ) { $watcherCache[$obj->rc_namespace][$obj->rc_title] = - $dbr->selectField( 'watchlist', + $dbr->selectField( + 'watchlist', 'COUNT(*)', array( 'wl_namespace' => $obj->rc_namespace, 'wl_title' => $obj->rc_title, ), - __METHOD__ . '-watchers' ); + __METHOD__ . '-watchers' + ); } $rc->numberofWatchingusers = $watcherCache[$obj->rc_namespace][$obj->rc_title]; } @@ -438,7 +514,7 @@ class SpecialRecentChanges extends IncludableSpecialPage { --$limit; } $s .= $list->endRecentChangesList(); - $wgOut->addHTML( $s ); + $this->getOutput()->addHTML( $s ); } /** @@ -456,14 +532,16 @@ class SpecialRecentChanges extends IncludableSpecialPage { * @return String: XHTML */ public function doHeader( $opts ) { - global $wgScript, $wgOut; + global $wgScript; - $this->setTopText( $wgOut, $opts ); + $this->setTopText( $opts ); $defaults = $opts->getAllValues(); $nondefaults = $opts->getChangedValues(); - $opts->consumeValues( array( 'namespace', 'invert', 'tagfilter', - 'categories', 'categories_any' ) ); + $opts->consumeValues( array( + 'namespace', 'invert', 'associated', 'tagfilter', + 'categories', 'categories_any' + ) ); $panel = array(); $panel[] = $this->optionsPanel( $defaults, $nondefaults ); @@ -502,11 +580,11 @@ class SpecialRecentChanges extends IncludableSpecialPage { $panel[] = $form; $panelString = implode( "\n", $panel ); - $wgOut->addHTML( + $this->getOutput()->addHTML( Xml::fieldset( wfMsg( 'recentchanges-legend' ), $panelString, array( 'class' => 'rcoptions' ) ) ); - $this->setBottomText( $wgOut, $opts ); + $this->setBottomText( $opts ); } /** @@ -515,7 +593,7 @@ class SpecialRecentChanges extends IncludableSpecialPage { * @param $opts FormOptions * @return Array */ - function getExtraOptions( $opts ){ + function getExtraOptions( $opts ) { $extraOpts = array(); $extraOpts['namespace'] = $this->namespaceFilterForm( $opts ); @@ -525,8 +603,9 @@ class SpecialRecentChanges extends IncludableSpecialPage { } $tagFilter = ChangeTags::buildTagFilterSelector( $opts['tagfilter'] ); - if ( count($tagFilter) ) + if ( count( $tagFilter ) ) { $extraOpts['tagfilter'] = $tagFilter; + } wfRunHooks( 'SpecialRecentChangesPanel', array( &$extraOpts, $opts ) ); return $extraOpts; @@ -535,33 +614,41 @@ class SpecialRecentChanges extends IncludableSpecialPage { /** * Send the text to be displayed above the options * - * @param $out OutputPage * @param $opts FormOptions */ - function setTopText( OutputPage $out, FormOptions $opts ){ - $out->addWikiText( wfMsgForContentNoTrans( 'recentchangestext' ) ); + function setTopText( FormOptions $opts ) { + $this->getOutput()->addWikiText( wfMsgForContentNoTrans( 'recentchangestext' ) ); } /** * Send the text to be displayed after the options, for use in * Recentchangeslinked * - * @param $out OutputPage * @param $opts FormOptions */ - function setBottomText( OutputPage $out, FormOptions $opts ){} + function setBottomText( FormOptions $opts ) {} /** * Creates the choose namespace selection * + * @todo Uses radio buttons (HASHAR) * @param $opts FormOptions * @return String */ protected function namespaceFilterForm( FormOptions $opts ) { $nsSelect = Xml::namespaceSelector( $opts['namespace'], '' ); - $nsLabel = Xml::label( wfMsg('namespace'), 'namespace' ); - $invert = Xml::checkLabel( wfMsg('invert'), 'invert', 'nsinvert', $opts['invert'] ); - return array( $nsLabel, "$nsSelect $invert" ); + $nsLabel = Xml::label( wfMsg( 'namespace' ), 'namespace' ); + $invert = Xml::checkLabel( + wfMsg( 'invert' ), 'invert', 'nsinvert', + $opts['invert'], + array( 'title' => wfMsg( 'tooltip-invert' ) ) + ); + $associated = Xml::checkLabel( + wfMsg( 'namespace_association' ), 'associated', 'nsassociated', + $opts['associated'], + array( 'title' => wfMsg( 'tooltip-namespace_association' ) ) + ); + return array( $nsLabel, "$nsSelect $invert $associated" ); } /** @@ -571,10 +658,10 @@ class SpecialRecentChanges extends IncludableSpecialPage { * @return Array */ protected function categoryFilterForm( FormOptions $opts ) { - list( $label, $input ) = Xml::inputLabelSep( wfMsg('rc_categories'), + list( $label, $input ) = Xml::inputLabelSep( wfMsg( 'rc_categories' ), 'categories', 'mw-categories', false, $opts['categories'] ); - $input .= ' ' . Xml::checkLabel( wfMsg('rc_categories_any'), + $input .= ' ' . Xml::checkLabel( wfMsg( 'rc_categories_any' ), 'categories_any', 'mw-categories_any', $opts['categories_any'] ); return array( $label, $input ); @@ -597,7 +684,9 @@ class SpecialRecentChanges extends IncludableSpecialPage { $cats = array(); foreach( $categories as $cat ) { $cat = trim( $cat ); - if( $cat == '' ) continue; + if( $cat == '' ) { + continue; + } $cats[] = $cat; } @@ -605,10 +694,12 @@ class SpecialRecentChanges extends IncludableSpecialPage { $articles = array(); $a2r = array(); $rowsarr = array(); - foreach( $rows AS $k => $r ) { + foreach( $rows as $k => $r ) { $nt = Title::makeTitle( $r->rc_namespace, $r->rc_title ); $id = $nt->getArticleID(); - if( $id == 0 ) continue; # Page might have been deleted... + if( $id == 0 ) { + continue; # Page might have been deleted... + } if( !in_array( $id, $articles ) ) { $articles[] = $id; } @@ -620,18 +711,19 @@ class SpecialRecentChanges extends IncludableSpecialPage { } # Shortcut? - if( !count( $articles ) || !count( $cats ) ) - return ; + if( !count( $articles ) || !count( $cats ) ) { + return; + } # Look up $c = new Categoryfinder; - $c->seed( $articles, $cats, $opts['categories_any'] ? "OR" : "AND" ) ; + $c->seed( $articles, $cats, $opts['categories_any'] ? 'OR' : 'AND' ); $match = $c->run(); # Filter $newrows = array(); - foreach( $match AS $id ) { - foreach( $a2r[$id] AS $rev ) { + foreach( $match as $id ) { + foreach( $a2r[$id] as $rev ) { $k = $rev; $newrows[$k] = $rowsarr[$k]; } @@ -648,15 +740,12 @@ class SpecialRecentChanges extends IncludableSpecialPage { * @param $active Boolean: whether to show the link in bold */ function makeOptionsLink( $title, $override, $options, $active = false ) { - global $wgUser; - $sk = $wgUser->getSkin(); $params = $override + $options; + $text = htmlspecialchars( $title ); if ( $active ) { - return $sk->link( $this->getTitle(), '' . htmlspecialchars( $title ) . '', - array(), $params, array( 'known' ) ); - } else { - return $sk->link( $this->getTitle(), htmlspecialchars( $title ), array() , $params, array( 'known' ) ); + $text = '' . $text . ''; } + return Linker::linkKnown( $this->getTitle(), $text, array(), $params ); } /** @@ -666,20 +755,21 @@ class SpecialRecentChanges extends IncludableSpecialPage { * @param $nondefaults Array */ function optionsPanel( $defaults, $nondefaults ) { - global $wgLang, $wgUser, $wgRCLinkLimits, $wgRCLinkDays; + global $wgRCLinkLimits, $wgRCLinkDays; $options = $nondefaults + $defaults; $note = ''; - if( !wfEmptyMsg( 'rclegend', wfMsg('rclegend') ) ) { - $note .= '
' . wfMsgExt( 'rclegend', array('parseinline') ) . "
\n"; + if( !wfEmptyMsg( 'rclegend' ) ) { + $note .= '
' . + wfMsgExt( 'rclegend', array( 'parseinline' ) ) . "
\n"; } if( $options['from'] ) { $note .= wfMsgExt( 'rcnotefrom', array( 'parseinline' ), - $wgLang->formatNum( $options['limit'] ), - $wgLang->timeanddate( $options['from'], true ), - $wgLang->date( $options['from'], true ), - $wgLang->time( $options['from'], true ) ) . '
'; + $this->getLang()->formatNum( $options['limit'] ), + $this->getLang()->timeanddate( $options['from'], true ), + $this->getLang()->date( $options['from'], true ), + $this->getLang()->time( $options['from'], true ) ) . '
'; } # Sort data for display and make sure it's unique after we've added user data. @@ -692,50 +782,63 @@ class SpecialRecentChanges extends IncludableSpecialPage { // limit links foreach( $wgRCLinkLimits as $value ) { - $cl[] = $this->makeOptionsLink( $wgLang->formatNum( $value ), - array( 'limit' => $value ), $nondefaults, $value == $options['limit'] ) ; + $cl[] = $this->makeOptionsLink( $this->getLang()->formatNum( $value ), + array( 'limit' => $value ), $nondefaults, $value == $options['limit'] ); } - $cl = $wgLang->pipeList( $cl ); + $cl = $this->getLang()->pipeList( $cl ); // day links, reset 'from' to none foreach( $wgRCLinkDays as $value ) { - $dl[] = $this->makeOptionsLink( $wgLang->formatNum( $value ), - array( 'days' => $value, 'from' => '' ), $nondefaults, $value == $options['days'] ) ; + $dl[] = $this->makeOptionsLink( $this->getLang()->formatNum( $value ), + array( 'days' => $value, 'from' => '' ), $nondefaults, $value == $options['days'] ); } - $dl = $wgLang->pipeList( $dl ); + $dl = $this->getLang()->pipeList( $dl ); // show/hide links $showhide = array( wfMsg( 'show' ), wfMsg( 'hide' ) ); - $minorLink = $this->makeOptionsLink( $showhide[1-$options['hideminor']], - array( 'hideminor' => 1-$options['hideminor'] ), $nondefaults); - $botLink = $this->makeOptionsLink( $showhide[1-$options['hidebots']], - array( 'hidebots' => 1-$options['hidebots'] ), $nondefaults); - $anonsLink = $this->makeOptionsLink( $showhide[ 1 - $options['hideanons'] ], - array( 'hideanons' => 1 - $options['hideanons'] ), $nondefaults ); - $liuLink = $this->makeOptionsLink( $showhide[1-$options['hideliu']], - array( 'hideliu' => 1-$options['hideliu'] ), $nondefaults); - $patrLink = $this->makeOptionsLink( $showhide[1-$options['hidepatrolled']], - array( 'hidepatrolled' => 1-$options['hidepatrolled'] ), $nondefaults); - $myselfLink = $this->makeOptionsLink( $showhide[1-$options['hidemyself']], - array( 'hidemyself' => 1-$options['hidemyself'] ), $nondefaults); - - $links[] = wfMsgHtml( 'rcshowhideminor', $minorLink ); - $links[] = wfMsgHtml( 'rcshowhidebots', $botLink ); - $links[] = wfMsgHtml( 'rcshowhideanons', $anonsLink ); - $links[] = wfMsgHtml( 'rcshowhideliu', $liuLink ); - if( $wgUser->useRCPatrol() ) - $links[] = wfMsgHtml( 'rcshowhidepatr', $patrLink ); - $links[] = wfMsgHtml( 'rcshowhidemine', $myselfLink ); - $hl = $wgLang->pipeList( $links ); + $filters = array( + 'hideminor' => 'rcshowhideminor', + 'hidebots' => 'rcshowhidebots', + 'hideanons' => 'rcshowhideanons', + 'hideliu' => 'rcshowhideliu', + 'hidepatrolled' => 'rcshowhidepatr', + 'hidemyself' => 'rcshowhidemine' + ); + foreach ( $this->customFilters as $key => $params ) { + $filters[$key] = $params['msg']; + } + // Disable some if needed + if ( !$this->getUser()->useRCPatrol() ) { + unset( $filters['hidepatrolled'] ); + } + + $links = array(); + foreach ( $filters as $key => $msg ) { + $link = $this->makeOptionsLink( $showhide[1 - $options[$key]], + array( $key => 1-$options[$key] ), $nondefaults ); + $links[] = wfMsgHtml( $msg, $link ); + } // show from this onward link - $now = $wgLang->timeanddate( wfTimestampNow(), true ); - $tl = $this->makeOptionsLink( $now, array( 'from' => wfTimestampNow() ), $nondefaults ); + $timestamp = wfTimestampNow(); + $now = $this->getLang()->timeanddate( $timestamp, true ); + $tl = $this->makeOptionsLink( + $now, array( 'from' => $timestamp ), $nondefaults + ); $rclinks = wfMsgExt( 'rclinks', array( 'parseinline', 'replaceafter' ), - $cl, $dl, $hl ); + $cl, $dl, $this->getLang()->pipeList( $links ) ); $rclistfrom = wfMsgExt( 'rclistfrom', array( 'parseinline', 'replaceafter' ), $tl ); return "{$note}$rclinks
$rclistfrom"; } + + /** + * add javascript specific to the [[Special:RecentChanges]] page + */ + function addRecentChangesJS() { + $this->getOutput()->addModules( array( + 'mediawiki.special.recentchanges', + ) ); + } } -- cgit v1.2.2