[Actions] Move the remaining actions out of MediaWiki::performAction into single...
authorKrinkle <krinkle@users.mediawiki.org>
Tue, 17 Jan 2012 19:56:08 +0000 (19:56 +0000)
committerKrinkle <krinkle@users.mediawiki.org>
Tue, 17 Jan 2012 19:56:08 +0000 (19:56 +0000)
- [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
includes/DefaultSettings.php
includes/Wiki.php
includes/actions/DeleteAction.php [new file with mode: 0644]
includes/actions/EditAction.php [new file with mode: 0644]
includes/actions/ProtectAction.php [new file with mode: 0644]
includes/actions/RenderAction.php [new file with mode: 0644]
includes/actions/ViewAction.php [new file with mode: 0644]

index 8c92b6b..c7d4632 100644 (file)
@@ -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
index 3fec4c8..aea3eda 100644 (file)
@@ -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,
 );
 
index 55ff89e..c896f49 100644 (file)
@@ -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 (file)
index 0000000..5a5a382
--- /dev/null
@@ -0,0 +1,42 @@
+<?php
+/**
+ * Handle page deletion
+ *
+ * Copyright © 2012 Timo Tijhof
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ *
+ * @file
+ * @ingroup Actions
+ * @author Timo Tijhof
+ */
+
+class DeleteAction extends FormlessAction {
+
+       public function getName() {
+               return 'delete';
+       }
+
+       public function onView(){
+               return null;
+       }
+
+       public function show(){
+
+               $this->page->delete();
+
+       }
+
+}
diff --git a/includes/actions/EditAction.php b/includes/actions/EditAction.php
new file mode 100644 (file)
index 0000000..08a33f4
--- /dev/null
@@ -0,0 +1,74 @@
+<?php
+/**
+ * action=edit / action=submit handler
+ *
+ * Copyright © 2012 Timo Tijhof
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ *
+ * @file
+ * @ingroup Actions
+ * @author Timo Tijhof
+ */
+
+class EditAction extends FormlessAction {
+
+       public function getName() {
+               return 'edit';
+       }
+
+       public function onView(){
+               return null;
+       }
+
+       public function show(){
+               $page = $this->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 (file)
index 0000000..f053ede
--- /dev/null
@@ -0,0 +1,56 @@
+<?php
+/**
+ * action=protect handler
+ *
+ * Copyright © 2012 Timo Tijhof
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ *
+ * @file
+ * @ingroup Actions
+ * @author Timo Tijhof
+ */
+
+class ProtectAction extends FormlessAction {
+
+       public function getName() {
+               return 'protect';
+       }
+
+       public function onView(){
+               return null;
+       }
+
+       public function show(){
+
+               $this->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 (file)
index 0000000..80af79c
--- /dev/null
@@ -0,0 +1,42 @@
+<?php
+/**
+ * Handle action=render
+ *
+ * Copyright © 2012 Timo Tijhof
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ *
+ * @file
+ * @ingroup Actions
+ * @author Timo Tijhof
+ */
+
+class RenderAction extends FormlessAction {
+
+       public function getName() {
+               return 'render';
+       }
+
+       public function onView(){
+               return null;
+       }
+
+       public function show(){
+
+               $this->page->render();
+
+       }
+
+}
diff --git a/includes/actions/ViewAction.php b/includes/actions/ViewAction.php
new file mode 100644 (file)
index 0000000..4e37381
--- /dev/null
@@ -0,0 +1,43 @@
+<?php
+/**
+ * An action that views article content
+ *
+ * Copyright © 2012 Timo Tijhof
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ *
+ * @file
+ * @ingroup Actions
+ * @author Timo Tijhof
+ */
+
+class ViewAction extends FormlessAction {
+
+       public function getName() {
+               return 'view';
+       }
+
+       public function onView(){
+               return null;
+       }
+
+       public function show(){
+               global $wgSquidMaxage;
+
+               $this->getOutput()->setSquidMaxage( $wgSquidMaxage );
+               $this->page->view();
+       }
+
+}