r108342 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r108341‎ | r108342 | r108343 >
Date:01:31, 8 January 2012
Author:krinkle
Status:reverted (Comments)
Tags:bug27930 
Comment:
Implement MediaWiki::getPerformedAction()
* Fixes:
-- Bug 27930 - Ablity to get current action (The Right Way)
Modified paths:
  • /trunk/phase3/includes/Wiki.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/Wiki.php
@@ -33,6 +33,11 @@
3434 */
3535 private $context;
3636
 37+ /**
 38+ * @var string
 39+ */
 40+ private $peformedAction = 'nosuchaction';
 41+
3742 public function request( WebRequest $x = null ){
3843 $old = $this->context->getRequest();
3944 $this->context->setRequest( $x );
@@ -296,9 +301,14 @@
297302 /**
298303 * Returns the action that will be executed, not necessarily the one passed
299304 * passed through the "action" parameter. Actions disabled in
300 - * $wgDisabledActions will be replaced by "nosuchaction"
 305+ * $wgDisabledActions will be replaced by "nosuchaction".
301306 *
302 - * @return String: action
 307+ * The return value is merely a suggestion, not the actually performed action,
 308+ * which may be different. The actually performed action is determined by performAction().
 309+ * Requests like action=nonsense will make this function return "nonsense".
 310+ * Use getPerformedAction() to get the performed action.
 311+ *
 312+ * @return string: action
303313 */
304314 public function getAction() {
305315 global $wgDisabledActions;
@@ -489,6 +499,7 @@
490500
491501 $action = Action::factory( $act, $article );
492502 if ( $action instanceof Action ) {
 503+ $this->performedAction = $act;
493504 $action->show();
494505 wfProfileOut( __METHOD__ );
495506 return;
@@ -497,12 +508,14 @@
498509 switch( $act ) {
499510 case 'view':
500511 $output->setSquidMaxage( $wgSquidMaxage );
 512+ $this->performedAction = $act;
501513 $article->view();
502514 break;
503515 case 'delete':
504516 case 'protect':
505517 case 'unprotect':
506518 case 'render':
 519+ $this->performedAction = $act;
507520 $article->$act();
508521 break;
509522 case 'submit':
@@ -513,6 +526,7 @@
514527 // Continue...
515528 case 'edit':
516529 if ( wfRunHooks( 'CustomEditor', array( $article, $user ) ) ) {
 530+ $this->performedAction = 'edit';
517531 if ( ExternalEdit::useExternalEngine( $this->context, 'edit' )
518532 && $act == 'edit' && !$request->getVal( 'section' )
519533 && !$request->getVal( 'oldid' ) )
@@ -527,6 +541,7 @@
528542 break;
529543 default:
530544 if ( wfRunHooks( 'UnknownAction', array( $act, $article ) ) ) {
 545+ $this->performedAction = 'nosuchaction';
531546 $output->showErrorPage( 'nosuchaction', 'nosuchactiontext' );
532547 }
533548 }
@@ -534,6 +549,16 @@
535550 }
536551
537552 /**
 553+ * Returns the real action as determined by performAction.
 554+ * Do not use internally in this class as it depends on the actions by this class.
 555+ *
 556+ * @return string: action
 557+ */
 558+ public function getPerformedAction(){
 559+ return $this->performedAction;
 560+ }
 561+
 562+ /**
538563 * Run the current MediaWiki instance
539564 * index.php just calls this
540565 */

Follow-up revisions

RevisionCommit summaryAuthorDate
r108343[mw.config] wgAction shouldn't use direct URL values...krinkle01:34, 8 January 2012
r108345[Skin] Add CSS hook for action ("action-.." class on body)...krinkle01:49, 8 January 2012
r108346Fix typo from r108342.krinkle02:49, 8 January 2012
r108632Add @since to getPerformedAction, added in r108342...reedy15:51, 11 January 2012
r109195[Actions] Move the remaining actions out of MediaWiki::performAction into sin...krinkle19:56, 17 January 2012
r109223[Actions] Move action logic out of MediaWiki::getAction/MediaWiki::performAct...krinkle21:49, 17 January 2012

Comments

#Comment by IAlex (talk | contribs)   10:12, 8 January 2012

(This concerns this revision and its follow-ups)

You need to be very careful when using $mediaWiki because it's only defined when executing index.php and not other scripts or in CLI; this breaks DumpHTML if you specify another skin than SkinOffline. If you just want to use $peformedAction, why not store it directly in OutputPage so that you don't need to use $mediaWiki?

#Comment by Krinkle (talk | contribs)   18:38, 8 January 2012

I indeed didn't feel good about using that global, but couldn't find a better place for it as I wasn't quite sure on what context it depends

If you know a better place, fine by me. I was thinking about adding it as a field in the ContextSource object, or indeed OutputPage. Not sure what the best place is. Anyone have a better idea, place go ahead :)
#Comment by Krinkle (talk | contribs)   14:48, 13 January 2012

In r108343 CR it is suggested to store this in the RequestContext instead. However, I don't think it has suffecient information to determine the currently performed action. (OutputPage, WebRequest, User, etc.. all these are part of context but neither has suffient information right now due to some action-stuff still being decided in MediaWiki::performAction, which is terrible).

So one could add a public field to the Context class and let MediaWiki::performAction assign a value in it, but that only moves the problem.

I think there is an underlaying problem, namely that this @!#$)! action stuff doesn't belong here in the first place. How about we move the remaining pieces (view, edit, submit, ..) into Action as well (either a couple few-line classes like ViewAction, EditAction, ProtectAction, etc. or move the switch statement from here to Action::factory). Either way, so that calling Action::factory with the query-string value of "action" will be a completely reliable return value that is without a doubt the currently performed action.

Then it suddenly becomes very simply to determine the currently performed action from anywhere (could be something like public static function Action::getPerformedAction( $context )).

#Comment by Krinkle (talk | contribs)   21:50, 17 January 2012

Went ahead and do in r109195. Usage fixed in r109223.

Status & tagging log