r78512 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r78511‎ | r78512 | r78513 >
Date:20:11, 16 December 2010
Author:ialex
Status:deferred (Comments)
Tags:
Comment:
Per ^demon, follow-up r78260: introduced MediaWiki::getAction() to get the action that will be executed
Modified paths:
  • /trunk/extensions/InlineEditor/InlineEditor.class.php (modified) (history)
  • /trunk/extensions/InputBox/InputBox.hooks.php (modified) (history)
  • /trunk/extensions/Lockdown/Lockdown.php (modified) (history)
  • /trunk/phase3/includes/Wiki.php (modified) (history)
  • /trunk/phase3/index.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/Wiki.php
@@ -97,17 +97,17 @@
9898
9999 /**
100100 * Checks some initial queries
101 - * Note that $title here is *not* a Title object, but a string!
102101 *
103 - * @param $title String
104 - * @param $action String
 102+ * @param $request WebRequest
105103 * @return Title object to be $wgTitle
106104 */
107 - function checkInitialQueries( $title, $action ) {
108 - global $wgRequest, $wgContLang;
 105+ function checkInitialQueries( WebRequest $request ) {
 106+ global $wgContLang;
109107
110 - $curid = $wgRequest->getInt( 'curid' );
111 - if( $wgRequest->getCheck( 'search' ) ) {
 108+ $curid = $request->getInt( 'curid' );
 109+ $title = $request->getVal( 'title' );
 110+
 111+ if( $request->getCheck( 'search' ) ) {
112112 // Compatibility with old search URLs which didn't use Special:Search
113113 // Just check for presence here, so blank requests still
114114 // show the search page when using ugly URLs (bug 8054).
@@ -115,7 +115,7 @@
116116 } elseif( $curid ) {
117117 // URLs like this are generated by RC, because rc_title isn't always accurate
118118 $ret = Title::newFromID( $curid );
119 - } elseif( $title == '' && $action != 'delete' ) {
 119+ } elseif( $title == '' && $this->getAction( $request ) != 'delete' ) {
120120 $ret = Title::newMainPage();
121121 } else {
122122 $ret = Title::newFromURL( $title );
@@ -127,8 +127,8 @@
128128 // For non-special titles, check for implicit titles
129129 if( is_null( $ret ) || $ret->getNamespace() != NS_SPECIAL ) {
130130 // We can have urls with just ?diff=,?oldid= or even just ?diff=
131 - $oldid = $wgRequest->getInt( 'oldid' );
132 - $oldid = $oldid ? $oldid : $wgRequest->getInt( 'diff' );
 131+ $oldid = $request->getInt( 'oldid' );
 132+ $oldid = $oldid ? $oldid : $request->getInt( 'diff' );
133133 // Allow oldid to override a changed or missing title
134134 if( $oldid ) {
135135 $rev = Revision::newFromId( $oldid );
@@ -173,8 +173,6 @@
174174 function handleSpecialCases( &$title, &$output, $request ) {
175175 wfProfileIn( __METHOD__ );
176176
177 - $action = $this->getVal( 'Action' );
178 -
179177 // Invalid titles. Bug 21776: The interwikis must redirect even if the page name is empty.
180178 if( is_null($title) || ( ( $title->getDBkey() == '' ) && ( $title->getInterwiki() == '' ) ) ) {
181179 $title = SpecialPage::getTitleFor( 'Badtitle' );
@@ -202,7 +200,7 @@
203201 throw new ErrorPageError( 'badtitle', 'badtitletext' );
204202 }
205203 // Redirect loops, no title in URL, $wgUsePathInfo URLs, and URLs with a variant
206 - } else if ( $action == 'view' && !$request->wasPosted()
 204+ } else if ( $request->getVal( 'action', 'view' ) == 'view' && !$request->wasPosted()
207205 && ( $request->getVal( 'title' ) === null || $title->getPrefixedDBKey() != $request->getText( 'title' ) )
208206 && !count( array_diff( array_keys( $request->getValues() ), array( 'action', 'title' ) ) ) )
209207 {
@@ -284,6 +282,41 @@
285283 }
286284
287285 /**
 286+ * Returns the action that will be executed, not necesserly the one passed
 287+ * passed through the "action" parameter. Actions disabled in
 288+ * $wgDisabledActions will be replaced by "nosuchaction"
 289+ *
 290+ * @param $request WebRequest
 291+ * @return String: action
 292+ */
 293+ public function getAction( WebRequest $request ) {
 294+ global $wgDisabledActions;
 295+
 296+ $action = $request->getVal( 'action', 'view' );
 297+
 298+ // Check for disabled actions
 299+ if( in_array( $action, $wgDisabledActions ) ) {
 300+ return 'nosuchaction';
 301+ }
 302+
 303+ // Workaround for bug #20966: inability of IE to provide an action dependent
 304+ // on which submit button is clicked.
 305+ if ( $action === 'historysubmit' ) {
 306+ if ( $request->getBool( 'revisiondelete' ) ) {
 307+ return 'revisiondelete';
 308+ } elseif ( $request->getBool( 'revisionmove' ) ) {
 309+ return 'revisionmove';
 310+ } else {
 311+ return 'view';
 312+ }
 313+ } elseif ( $action == 'editredlink' ) {
 314+ return 'edit';
 315+ }
 316+
 317+ return $action;
 318+ }
 319+
 320+ /**
288321 * Initialize the object to be known as $wgArticle for "standard" actions
289322 * Create an Article object for the page, following redirects if needed.
290323 *
@@ -295,7 +328,7 @@
296329 function initializeArticle( &$title, &$output, $request ) {
297330 wfProfileIn( __METHOD__ );
298331
299 - $action = $this->getVal( 'action', 'view' );
 332+ $action = $request->getVal( 'action', 'view' );
300333 $article = self::articleFromTitle( $title );
301334 // NS_MEDIAWIKI has no redirects.
302335 // It is also used for CSS/JS, so performance matters here...
@@ -439,24 +472,8 @@
440473 return;
441474 }
442475
443 - $action = $this->getVal( 'Action' );
444 - if( in_array( $action, $this->getVal( 'DisabledActions', array() ) ) ) {
445 - /* No such action; this will switch to the default case */
446 - $action = 'nosuchaction';
447 - }
 476+ $action = $this->getAction( $request );
448477
449 - // Workaround for bug #20966: inability of IE to provide an action dependent
450 - // on which submit button is clicked.
451 - if ( $action === 'historysubmit' ) {
452 - if ( $request->getBool( 'revisiondelete' ) ) {
453 - $action = 'revisiondelete';
454 - } elseif ( $request->getBool( 'revisionmove' ) ) {
455 - $action = 'revisionmove';
456 - } else {
457 - $action = 'view';
458 - }
459 - }
460 -
461478 switch( $action ) {
462479 case 'view':
463480 $output->setSquidMaxage( $this->getVal( 'SquidMaxage' ) );
@@ -511,7 +528,6 @@
512529 }
513530 /* Continue... */
514531 case 'edit':
515 - case 'editredlink':
516532 if( wfRunHooks( 'CustomEditor', array( $article, $user ) ) ) {
517533 $internal = $request->getVal( 'internaledit' );
518534 $external = $request->getVal( 'externaledit' );
Index: trunk/phase3/index.php
@@ -50,15 +50,13 @@
5151 exit;
5252 }
5353
54 -# Query string fields
55 -$action = $wgRequest->getVal( 'action', 'view' );
56 -$title = $wgRequest->getVal( 'title' );
57 -
5854 # Set title from request parameters
59 -$wgTitle = $mediaWiki->checkInitialQueries( $title, $action );
 55+$wgTitle = $mediaWiki->checkInitialQueries( $wgRequest );
6056
6157 wfProfileOut( 'main-misc-setup' );
6258
 59+$action = $wgRequest->getVal( 'action' );
 60+
6361 # Send Ajax requests to the Ajax dispatcher.
6462 if( $wgUseAjax && $action == 'ajax' ) {
6563 $dispatcher = new AjaxDispatcher();
@@ -94,8 +92,6 @@
9593 }
9694
9795 # Setting global variables in mediaWiki
98 -$mediaWiki->setVal( 'action', $action );
99 -$mediaWiki->setVal( 'DisabledActions', $wgDisabledActions );
10096 $mediaWiki->setVal( 'DisableHardRedirects', $wgDisableHardRedirects );
10197 $mediaWiki->setVal( 'EnableCreativeCommonsRdf', $wgEnableCreativeCommonsRdf );
10298 $mediaWiki->setVal( 'EnableDublinCoreRdf', $wgEnableDublinCoreRdf );
Index: trunk/extensions/Lockdown/Lockdown.php
@@ -119,7 +119,7 @@
120120 function lockdownMediawikiPerformAction ( $output, $article, $title, $user, $request, $wiki ) {
121121 global $wgActionLockdown;
122122
123 - $action = $request->getVal( 'action', 'view' );
 123+ $action = $wiki->getAction( $request );
124124
125125 if ( !isset( $wgActionLockdown[$action] ) ) return true;
126126
Index: trunk/extensions/InlineEditor/InlineEditor.class.php
@@ -19,19 +19,15 @@
2020 * Checks whether or not to spawn the editor, and does so if nessicary.
2121 */
2222 public static function mediaWikiPerformAction( $output, $article, $title, $user, $request, $wiki ) {
23 - global $wgHooks, $wgDisabledActions;
 23+ global $wgHooks;
2424
25 - // the action of the page, i.e. 'view' or 'edit'
26 - $action = $request->getVal( 'action', 'view' );
27 -
2825 // check if the editor could be used on this page, and if so, hide the [edit] links
2926 if ( self::isValidBrowser() && !self::isAdvancedPage( $article, $title ) ) {
3027 self::hideEditSection( $output );
3128 }
3229
3330 // return if the action is not 'edit' or if it's disabled
34 - if ( $action != 'edit' || in_array( $action, $wgDisabledActions ) )
35 - {
 31+ if ( $wiki->getAction( $request ) != 'edit' ) {
3632 return true;
3733 }
3834
Index: trunk/extensions/InputBox/InputBox.hooks.php
@@ -52,8 +52,7 @@
5353 $request,
5454 $wiki )
5555 {
56 - $action = $request->getVal( 'action', 'view' );
57 - if( $action !== 'edit' ){
 56+ if( $wiki->getAction( $request ) !== 'edit' ){
5857 # not our problem
5958 return true;
6059 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r79542Remove nasty ancient global $title (at least $wgTitle is easier to grep for),...demon00:42, 4 January 2011
r83381Fix bug where Commentbox was only displayed on purged pages, not on normal pa...tbleher11:29, 6 March 2011
r83388Fix for r78512: set the default value to "view" for the action parameterialex16:51, 6 March 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r78260Use the "normal" way to get settings and request parameters instead of the ho...ialex17:33, 12 December 2010

Comments

#Comment by Tbleher (talk | contribs)   22:06, 5 March 2011

-$action = $wgRequest->getVal( 'action', 'view' );

+$action = $wgRequest->getVal( 'action' );

Is this change in index.php intentional? It broke the Commentbox extension, which used the $action global and assumed that $action=='view' holds on normal page views.

I'll check in a fix for the Commentbox extension myself, but wanted to alert you of this issue, because it may affect other code.

Status & tagging log