r90776 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r90775‎ | r90776 | r90777 >
Date:17:59, 25 June 2011
Author:aaron
Status:ok
Tags:
Comment:
* 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()
Modified paths:
  • /trunk/phase3/includes/Autopromote.php (modified) (history)
  • /trunk/phase3/includes/User.php (modified) (history)
  • /trunk/phase3/includes/Wiki.php (modified) (history)
  • /trunk/phase3/includes/cache/HTMLFileCache.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/User.php
@@ -1110,11 +1110,11 @@
11111111 * will not be re-added automatically. The user will also not lose the
11121112 * group if they no longer meet the criteria.
11131113 *
1114 - * @param $event String 'onEdit' or 'onView' (each one has groups/criteria)
 1114+ * @param $event String key in $wgAutopromoteOnce (each one has groups/criteria)
11151115 *
11161116 * @return array Array of groups the user has been promoted to.
11171117 *
1118 - * @see $wgAutopromote
 1118+ * @see $wgAutopromoteOnce
11191119 */
11201120 public function addAutopromoteOnceGroups( $event ) {
11211121 if ( $this->getId() ) {
@@ -2346,7 +2346,7 @@
23472347 'ug_user' => $this->getID(),
23482348 'ug_group' => $group,
23492349 ), __METHOD__ );
2350 - //remember that the user has had this group
 2350+ // Remember that the user was in this group
23512351 $dbw->insert( 'user_former_groups',
23522352 array(
23532353 'ufg_user' => $this->getID(),
Index: trunk/phase3/includes/Wiki.php
@@ -101,7 +101,7 @@
102102 * - special pages
103103 * - normal pages
104104 *
105 - * @return Article object
 105+ * @return void
106106 */
107107 public function performRequest() {
108108 global $wgServer, $wgUsePathInfo;
@@ -113,22 +113,15 @@
114114 $output = $this->context->getOutput();
115115 $user = $this->context->getUser();
116116
117 - # Promote user to any groups they meet the criteria for
118 - $user->addAutopromoteOnceGroups( 'onView' );
119 -
120117 if ( $request->getVal( 'printable' ) === 'yes' ) {
121118 $output->setPrintable();
122119 }
123120
124 - wfRunHooks( 'BeforeInitialize', array(
125 - &$title,
126 - null,
127 - &$output,
128 - &$user,
129 - $request,
130 - $this
131 - ) );
132 -
 121+ $pageView = false; // was an article or special page viewed?
 122+
 123+ wfRunHooks( 'BeforeInitialize',
 124+ array( &$title, null, &$output, &$user, $request, $this ) );
 125+
133126 // Invalid titles. Bug 21776: The interwikis must redirect even if the page name is empty.
134127 if ( $title instanceof BadTitle ) {
135128 throw new ErrorPageError( 'badtitle', 'badtitletext' );
@@ -196,13 +189,15 @@
197190 }
198191 // Special pages
199192 } elseif ( NS_SPECIAL == $title->getNamespace() ) {
200 - // actions that need to be made when we have a special pages
 193+ $pageView = true;
 194+ // Actions that need to be made when we have a special pages
201195 SpecialPageFactory::executePath( $title, $this->context );
202196 } else {
203197 // ...otherwise treat it as an article view. The article
204198 // may be a redirect to another article or URL.
205199 $article = $this->initializeArticle();
206200 if ( is_object( $article ) ) {
 201+ $pageView = true;
207202 /**
208203 * $wgArticle is deprecated, do not use it. This will possibly be removed
209204 * entirely in 1.20 or 1.21
@@ -212,8 +207,6 @@
213208 $wgArticle = $article;
214209
215210 $this->performAction( $article );
216 - wfProfileOut( __METHOD__ );
217 - return $article;
218211 } elseif ( is_string( $article ) ) {
219212 $output->redirect( $article );
220213 } else {
@@ -221,6 +214,12 @@
222215 throw new MWException( "Shouldn't happen: MediaWiki::initializeArticle() returned neither an object nor a URL" );
223216 }
224217 }
 218+
 219+ if ( $pageView ) {
 220+ // Promote user to any groups they meet the criteria for
 221+ $user->addAutopromoteOnceGroups( 'onView' );
 222+ }
 223+
225224 wfProfileOut( __METHOD__ );
226225 }
227226
@@ -406,7 +405,7 @@
407406 *
408407 * @param $article Article
409408 */
410 - private function performAction( $article ) {
 409+ private function performAction( Article $article ) {
411410 global $wgSquidMaxage, $wgUseExternalEditor;
412411
413412 wfProfileIn( __METHOD__ );
@@ -416,9 +415,8 @@
417416 $title = $this->context->getTitle();
418417 $user = $this->context->getUser();
419418
420 - if ( !wfRunHooks( 'MediaWikiPerformAction', array(
421 - $output, $article, $title,
422 - $user, $request, $this ) ) )
 419+ if ( !wfRunHooks( 'MediaWikiPerformAction',
 420+ array( $output, $article, $title, $user, $request, $this ) ) )
423421 {
424422 wfProfileOut( __METHOD__ );
425423 return;
@@ -561,11 +559,11 @@
562560 return;
563561 }
564562
565 - if ( $wgUseFileCache && $wgTitle !== null ) {
 563+ if ( $wgUseFileCache && $wgTitle->getNamespace() != NS_SPECIAL ) {
566564 wfProfileIn( 'main-try-filecache' );
567565 // Raw pages should handle cache control on their own,
568566 // even when using file cache. This reduces hits from clients.
569 - if ( $action != 'raw' && HTMLFileCache::useFileCache() ) {
 567+ if ( HTMLFileCache::useFileCache() ) {
570568 /* Try low-level file cache hit */
571569 $cache = new HTMLFileCache( $wgTitle, $action );
572570 if ( $cache->isFileCacheGood( /* Assume up to date */ ) ) {
Index: trunk/phase3/includes/cache/HTMLFileCache.php
@@ -93,16 +93,14 @@
9494 foreach( $queryVals as $query => $val ) {
9595 if( $query == 'title' || $query == 'curid' ) {
9696 continue;
97 - }
9897 // Normal page view in query form can have action=view.
9998 // Raw hits for pages also stored, like .css pages for example.
100 - elseif( $query == 'action' && ($val == 'view' || $val == 'raw') ) {
 99+ } elseif( $query == 'action' && $val == 'view' ) {
101100 continue;
102101 } elseif( $query == 'usemsgcache' && $val == 'yes' ) {
103102 continue;
104 - }
105103 // Below are header setting params
106 - elseif( $query == 'maxage' || $query == 'smaxage' || $query == 'ctype' || $query == 'gen' ) {
 104+ } elseif( $query == 'maxage' || $query == 'smaxage' || $query == 'ctype' || $query == 'gen' ) {
107105 continue;
108106 } else {
109107 return false;
Index: trunk/phase3/includes/Autopromote.php
@@ -33,9 +33,11 @@
3434 * Does not return groups the user already belongs to or has once belonged.
3535 *
3636 * @param $user The user to get the groups for
37 - * @param $event String 'onEdit' or 'onView' (each one has groups/criteria)
38 - *
 37+ * @param $event String key in $wgAutopromoteOnce (each one has groups/criteria)
 38+ *
3939 * @return array Groups the user should be promoted to.
 40+ *
 41+ * @see $wgAutopromoteOnce
4042 */
4143 public static function getAutopromoteOnceGroups( User $user, $event ) {
4244 global $wgAutopromoteOnce;

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r90749Added one-time promote support via Autopromote::autopromoteOnceHook function....aaron02:52, 25 June 2011

Status & tagging log