From d03087df359e4c5bdc2dd0cff0db15ae5f129b48 Mon Sep 17 00:00:00 2001 From: Krinkle Date: Tue, 17 Jan 2012 19:56:08 +0000 Subject: [PATCH] [Actions] Move the remaining actions out of MediaWiki::performAction into single action classes (finally). - [Actions] - * I am aware that eventually these classes should be more than just a few lines re-directing control to WikiPage, but I'm keeping these commits as uncontroversial as possible due to feature freeze. Refactor could be done later. * Contributes to solution of bug 27930 - Ablity to get current action (The Right Way) * Final goal: Get the current action without needing access to Wiki.php internals (i.e. with Action::factory in one hand and an instance of IContextSource in the other) * Required for proper fix of r108342/108343 (currently marked FIXME) --- includes/AutoLoader.php | 7 +++ includes/DefaultSettings.php | 7 +++ includes/Wiki.php | 43 ++--------------- includes/actions/DeleteAction.php | 42 +++++++++++++++++ includes/actions/EditAction.php | 74 ++++++++++++++++++++++++++++++ includes/actions/ProtectAction.php | 56 ++++++++++++++++++++++ includes/actions/RenderAction.php | 42 +++++++++++++++++ includes/actions/ViewAction.php | 43 +++++++++++++++++ 8 files changed, 275 insertions(+), 39 deletions(-) create mode 100644 includes/actions/DeleteAction.php create mode 100644 includes/actions/EditAction.php create mode 100644 includes/actions/ProtectAction.php create mode 100644 includes/actions/RenderAction.php create mode 100644 includes/actions/ViewAction.php diff --git a/includes/AutoLoader.php b/includes/AutoLoader.php index 8c92b6b9cb..c7d4632cbd 100644 --- a/includes/AutoLoader.php +++ b/includes/AutoLoader.php @@ -253,19 +253,26 @@ $wgAutoloadLocalClasses = array( # includes/actions 'CreditsAction' => 'includes/actions/CreditsAction.php', + 'DeleteAction' => 'includes/actions/DeleteAction.php', + 'EditAction' => 'includes/actions/EditAction.php', 'HistoryAction' => 'includes/actions/HistoryAction.php', 'HistoryPage' => 'includes/actions/HistoryAction.php', 'HistoryPager' => 'includes/actions/HistoryAction.php', 'InfoAction' => 'includes/actions/InfoAction.php', 'MarkpatrolledAction' => 'includes/actions/MarkpatrolledAction.php', + 'ProtectAction' => 'includes/actions/ProtectAction.php', 'PurgeAction' => 'includes/actions/PurgeAction.php', 'RawAction' => 'includes/actions/RawAction.php', 'RawPage' => 'includes/actions/RawAction.php', + 'RenderAction' => 'includes/actions/RenderAction.php', 'RevertAction' => 'includes/actions/RevertAction.php', 'RevertFileAction' => 'includes/actions/RevertAction.php', 'RevisiondeleteAction' => 'includes/actions/RevisiondeleteAction.php', 'RollbackAction' => 'includes/actions/RollbackAction.php', + 'SubmitAction' => 'includes/actions/EditAction.php', + 'UnprotectAction' => 'includes/actions/ProtectAction.php', 'UnwatchAction' => 'includes/actions/WatchAction.php', + 'ViewAction' => 'includes/actions/ViewAction.php', 'WatchAction' => 'includes/actions/WatchAction.php', # includes/api diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 3fec4c8643..aea3eda74c 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -5303,15 +5303,22 @@ $wgMaxRedirectLinksRetrieved = 500; */ $wgActions = array( 'credits' => true, + 'delete' => true, + 'edit' => true, 'history' => true, 'info' => true, 'markpatrolled' => true, + 'protect' => true, 'purge' => true, 'raw' => true, + 'render' => true, 'revert' => true, 'revisiondelete' => true, 'rollback' => true, + 'submit' => true, + 'unprotect' => true, 'unwatch' => true, + 'view' => true, 'watch' => true, ); diff --git a/includes/Wiki.php b/includes/Wiki.php index 55ff89ed8c..c896f49660 100644 --- a/includes/Wiki.php +++ b/includes/Wiki.php @@ -516,46 +516,11 @@ class MediaWiki { return; } - switch( $act ) { - case 'view': - $output->setSquidMaxage( $wgSquidMaxage ); - $this->performedAction = $act; - $article->view(); - break; - case 'delete': - case 'protect': - case 'unprotect': - case 'render': - $this->performedAction = $act; - $article->$act(); - break; - case 'submit': - if ( session_id() == '' ) { - // Send a cookie so anons get talk message notifications - wfSetupSession(); - } - // Continue... - case 'edit': - if ( wfRunHooks( 'CustomEditor', array( $article, $user ) ) ) { - $this->performedAction = 'edit'; - if ( ExternalEdit::useExternalEngine( $this->context, 'edit' ) - && $act == 'edit' && !$request->getVal( 'section' ) - && !$request->getVal( 'oldid' ) ) - { - $extedit = new ExternalEdit( $this->context ); - $extedit->execute(); - } else { - $editor = new EditPage( $article ); - $editor->edit(); - } - } - break; - default: - if ( wfRunHooks( 'UnknownAction', array( $act, $article ) ) ) { - $this->performedAction = 'nosuchaction'; - $output->showErrorPage( 'nosuchaction', 'nosuchactiontext' ); - } + if ( wfRunHooks( 'UnknownAction', array( $act, $article ) ) ) { + $this->performedAction = 'nosuchaction'; + $output->showErrorPage( 'nosuchaction', 'nosuchactiontext' ); } + wfProfileOut( __METHOD__ ); } diff --git a/includes/actions/DeleteAction.php b/includes/actions/DeleteAction.php new file mode 100644 index 0000000000..5a5a382b20 --- /dev/null +++ b/includes/actions/DeleteAction.php @@ -0,0 +1,42 @@ +page->delete(); + + } + +} diff --git a/includes/actions/EditAction.php b/includes/actions/EditAction.php new file mode 100644 index 0000000000..08a33f4c0d --- /dev/null +++ b/includes/actions/EditAction.php @@ -0,0 +1,74 @@ +page; + $request = $this->getRequest(); + $user = $this->getUser(); + $context = $this->getContext(); + + if ( wfRunHooks( 'CustomEditor', array( $page, $user ) ) ) { + if ( ExternalEdit::useExternalEngine( $context, 'edit' ) + && $this->getName() == 'edit' && !$request->getVal( 'section' ) + && !$request->getVal( 'oldid' ) ) + { + $extedit = new ExternalEdit( $context ); + $extedit->execute(); + } else { + $editor = new EditPage( $page ); + $editor->edit(); + } + } + + } + +} + +class SubmitAction extends EditAction { + + public function getName() { + return 'submit'; + } + + public function show(){ + if ( session_id() == '' ) { + // Send a cookie so anons get talk message notifications + wfSetupSession(); + } + + parent::show(); + } + +} diff --git a/includes/actions/ProtectAction.php b/includes/actions/ProtectAction.php new file mode 100644 index 0000000000..f053ede779 --- /dev/null +++ b/includes/actions/ProtectAction.php @@ -0,0 +1,56 @@ +page->protect(); + + } + +} + +class UnprotectAction extends ProtectAction { + + public function getName() { + return 'unprotect'; + } + + public function show(){ + + $this->page->unprotect(); + + } + +} diff --git a/includes/actions/RenderAction.php b/includes/actions/RenderAction.php new file mode 100644 index 0000000000..80af79cc64 --- /dev/null +++ b/includes/actions/RenderAction.php @@ -0,0 +1,42 @@ +page->render(); + + } + +} diff --git a/includes/actions/ViewAction.php b/includes/actions/ViewAction.php new file mode 100644 index 0000000000..4e37381b54 --- /dev/null +++ b/includes/actions/ViewAction.php @@ -0,0 +1,43 @@ +getOutput()->setSquidMaxage( $wgSquidMaxage ); + $this->page->view(); + } + +} -- 2.20.1