From 16eb5f6e416d6c7a616269e2cb3f3562bc56e0d3 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Sat, 25 Jun 2011 17:59:42 +0000 Subject: [PATCH] * Follow-up r90749 ** Tweaked addAutopromoteOnceGroups() calls for performance ** Some doc tweaks and fixes * Added NS_SPECIAL short-circuit on $wgTitle for file cache and removed unnecessary "is null" check * Pushed "$action != 'raw'" check into HTMLFileCache * Removed useless return value from performRequest() * Added type hint to performAction() --- includes/Autopromote.php | 6 +++-- includes/User.php | 6 ++--- includes/Wiki.php | 42 +++++++++++++++----------------- includes/cache/HTMLFileCache.php | 6 ++--- 4 files changed, 29 insertions(+), 31 deletions(-) diff --git a/includes/Autopromote.php b/includes/Autopromote.php index 85b2f47458..9e8c049a1b 100644 --- a/includes/Autopromote.php +++ b/includes/Autopromote.php @@ -33,9 +33,11 @@ class Autopromote { * Does not return groups the user already belongs to or has once belonged. * * @param $user The user to get the groups for - * @param $event String 'onEdit' or 'onView' (each one has groups/criteria) - * + * @param $event String key in $wgAutopromoteOnce (each one has groups/criteria) + * * @return array Groups the user should be promoted to. + * + * @see $wgAutopromoteOnce */ public static function getAutopromoteOnceGroups( User $user, $event ) { global $wgAutopromoteOnce; diff --git a/includes/User.php b/includes/User.php index 5bae670e79..9e648122dd 100644 --- a/includes/User.php +++ b/includes/User.php @@ -1110,11 +1110,11 @@ class User { * will not be re-added automatically. The user will also not lose the * group if they no longer meet the criteria. * - * @param $event String 'onEdit' or 'onView' (each one has groups/criteria) + * @param $event String key in $wgAutopromoteOnce (each one has groups/criteria) * * @return array Array of groups the user has been promoted to. * - * @see $wgAutopromote + * @see $wgAutopromoteOnce */ public function addAutopromoteOnceGroups( $event ) { if ( $this->getId() ) { @@ -2346,7 +2346,7 @@ class User { 'ug_user' => $this->getID(), 'ug_group' => $group, ), __METHOD__ ); - //remember that the user has had this group + // Remember that the user was in this group $dbw->insert( 'user_former_groups', array( 'ufg_user' => $this->getID(), diff --git a/includes/Wiki.php b/includes/Wiki.php index 1ab94c23b6..8fda0b33c9 100644 --- a/includes/Wiki.php +++ b/includes/Wiki.php @@ -101,7 +101,7 @@ class MediaWiki { * - special pages * - normal pages * - * @return Article object + * @return void */ public function performRequest() { global $wgServer, $wgUsePathInfo; @@ -113,22 +113,15 @@ class MediaWiki { $output = $this->context->getOutput(); $user = $this->context->getUser(); - # Promote user to any groups they meet the criteria for - $user->addAutopromoteOnceGroups( 'onView' ); - if ( $request->getVal( 'printable' ) === 'yes' ) { $output->setPrintable(); } - wfRunHooks( 'BeforeInitialize', array( - &$title, - null, - &$output, - &$user, - $request, - $this - ) ); - + $pageView = false; // was an article or special page viewed? + + wfRunHooks( 'BeforeInitialize', + array( &$title, null, &$output, &$user, $request, $this ) ); + // Invalid titles. Bug 21776: The interwikis must redirect even if the page name is empty. if ( $title instanceof BadTitle ) { throw new ErrorPageError( 'badtitle', 'badtitletext' ); @@ -196,13 +189,15 @@ class MediaWiki { } // Special pages } elseif ( NS_SPECIAL == $title->getNamespace() ) { - // actions that need to be made when we have a special pages + $pageView = true; + // Actions that need to be made when we have a special pages SpecialPageFactory::executePath( $title, $this->context ); } else { // ...otherwise treat it as an article view. The article // may be a redirect to another article or URL. $article = $this->initializeArticle(); if ( is_object( $article ) ) { + $pageView = true; /** * $wgArticle is deprecated, do not use it. This will possibly be removed * entirely in 1.20 or 1.21 @@ -212,8 +207,6 @@ class MediaWiki { $wgArticle = $article; $this->performAction( $article ); - wfProfileOut( __METHOD__ ); - return $article; } elseif ( is_string( $article ) ) { $output->redirect( $article ); } else { @@ -221,6 +214,12 @@ class MediaWiki { throw new MWException( "Shouldn't happen: MediaWiki::initializeArticle() returned neither an object nor a URL" ); } } + + if ( $pageView ) { + // Promote user to any groups they meet the criteria for + $user->addAutopromoteOnceGroups( 'onView' ); + } + wfProfileOut( __METHOD__ ); } @@ -406,7 +405,7 @@ class MediaWiki { * * @param $article Article */ - private function performAction( $article ) { + private function performAction( Article $article ) { global $wgSquidMaxage, $wgUseExternalEditor; wfProfileIn( __METHOD__ ); @@ -416,9 +415,8 @@ class MediaWiki { $title = $this->context->getTitle(); $user = $this->context->getUser(); - if ( !wfRunHooks( 'MediaWikiPerformAction', array( - $output, $article, $title, - $user, $request, $this ) ) ) + if ( !wfRunHooks( 'MediaWikiPerformAction', + array( $output, $article, $title, $user, $request, $this ) ) ) { wfProfileOut( __METHOD__ ); return; @@ -561,11 +559,11 @@ class MediaWiki { return; } - if ( $wgUseFileCache && $wgTitle !== null ) { + if ( $wgUseFileCache && $wgTitle->getNamespace() != NS_SPECIAL ) { wfProfileIn( 'main-try-filecache' ); // Raw pages should handle cache control on their own, // even when using file cache. This reduces hits from clients. - if ( $action != 'raw' && HTMLFileCache::useFileCache() ) { + if ( HTMLFileCache::useFileCache() ) { /* Try low-level file cache hit */ $cache = new HTMLFileCache( $wgTitle, $action ); if ( $cache->isFileCacheGood( /* Assume up to date */ ) ) { diff --git a/includes/cache/HTMLFileCache.php b/includes/cache/HTMLFileCache.php index 5c2763296a..0a01bb7ab5 100644 --- a/includes/cache/HTMLFileCache.php +++ b/includes/cache/HTMLFileCache.php @@ -93,16 +93,14 @@ class HTMLFileCache { foreach( $queryVals as $query => $val ) { if( $query == 'title' || $query == 'curid' ) { continue; - } // Normal page view in query form can have action=view. // Raw hits for pages also stored, like .css pages for example. - elseif( $query == 'action' && ($val == 'view' || $val == 'raw') ) { + } elseif( $query == 'action' && $val == 'view' ) { continue; } elseif( $query == 'usemsgcache' && $val == 'yes' ) { continue; - } // Below are header setting params - elseif( $query == 'maxage' || $query == 'smaxage' || $query == 'ctype' || $query == 'gen' ) { + } elseif( $query == 'maxage' || $query == 'smaxage' || $query == 'ctype' || $query == 'gen' ) { continue; } else { return false; -- 2.20.1