r109195 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r109194‎ | r109195 | r109196 >
Date:19:56, 17 January 2012
Author:krinkle
Status:ok (Comments)
Tags:bug27930 
Comment:
[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)
Modified paths:
  • /trunk/phase3/includes/AutoLoader.php (modified) (history)
  • /trunk/phase3/includes/DefaultSettings.php (modified) (history)
  • /trunk/phase3/includes/Wiki.php (modified) (history)
  • /trunk/phase3/includes/actions/DeleteAction.php (added) (history)
  • /trunk/phase3/includes/actions/EditAction.php (added) (history)
  • /trunk/phase3/includes/actions/ProtectAction.php (added) (history)
  • /trunk/phase3/includes/actions/RenderAction.php (added) (history)
  • /trunk/phase3/includes/actions/ViewAction.php (added) (history)

Diff [purge]

Index: trunk/phase3/includes/actions/DeleteAction.php
@@ -0,0 +1,42 @@
 2+<?php
 3+/**
 4+ * Handle page deletion
 5+ *
 6+ * Copyright © 2012 Timo Tijhof
 7+ *
 8+ * This program is free software; you can redistribute it and/or modify
 9+ * it under the terms of the GNU General Public License as published by
 10+ * the Free Software Foundation; either version 2 of the License, or
 11+ * (at your option) any later version.
 12+ *
 13+ * This program is distributed in the hope that it will be useful,
 14+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
 15+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 16+ * GNU General Public License for more details.
 17+ *
 18+ * You should have received a copy of the GNU General Public License
 19+ * along with this program; if not, write to the Free Software
 20+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
 21+ *
 22+ * @file
 23+ * @ingroup Actions
 24+ * @author Timo Tijhof
 25+ */
 26+
 27+class DeleteAction extends FormlessAction {
 28+
 29+ public function getName() {
 30+ return 'delete';
 31+ }
 32+
 33+ public function onView(){
 34+ return null;
 35+ }
 36+
 37+ public function show(){
 38+
 39+ $this->page->delete();
 40+
 41+ }
 42+
 43+}
Property changes on: trunk/phase3/includes/actions/DeleteAction.php
___________________________________________________________________
Added: svn:eol-style
144 + native
Index: trunk/phase3/includes/actions/EditAction.php
@@ -0,0 +1,74 @@
 2+<?php
 3+/**
 4+ * action=edit / action=submit handler
 5+ *
 6+ * Copyright © 2012 Timo Tijhof
 7+ *
 8+ * This program is free software; you can redistribute it and/or modify
 9+ * it under the terms of the GNU General Public License as published by
 10+ * the Free Software Foundation; either version 2 of the License, or
 11+ * (at your option) any later version.
 12+ *
 13+ * This program is distributed in the hope that it will be useful,
 14+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
 15+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 16+ * GNU General Public License for more details.
 17+ *
 18+ * You should have received a copy of the GNU General Public License
 19+ * along with this program; if not, write to the Free Software
 20+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
 21+ *
 22+ * @file
 23+ * @ingroup Actions
 24+ * @author Timo Tijhof
 25+ */
 26+
 27+class EditAction extends FormlessAction {
 28+
 29+ public function getName() {
 30+ return 'edit';
 31+ }
 32+
 33+ public function onView(){
 34+ return null;
 35+ }
 36+
 37+ public function show(){
 38+ $page = $this->page;
 39+ $request = $this->getRequest();
 40+ $user = $this->getUser();
 41+ $context = $this->getContext();
 42+
 43+ if ( wfRunHooks( 'CustomEditor', array( $page, $user ) ) ) {
 44+ if ( ExternalEdit::useExternalEngine( $context, 'edit' )
 45+ && $this->getName() == 'edit' && !$request->getVal( 'section' )
 46+ && !$request->getVal( 'oldid' ) )
 47+ {
 48+ $extedit = new ExternalEdit( $context );
 49+ $extedit->execute();
 50+ } else {
 51+ $editor = new EditPage( $page );
 52+ $editor->edit();
 53+ }
 54+ }
 55+
 56+ }
 57+
 58+}
 59+
 60+class SubmitAction extends EditAction {
 61+
 62+ public function getName() {
 63+ return 'submit';
 64+ }
 65+
 66+ public function show(){
 67+ if ( session_id() == '' ) {
 68+ // Send a cookie so anons get talk message notifications
 69+ wfSetupSession();
 70+ }
 71+
 72+ parent::show();
 73+ }
 74+
 75+}
Property changes on: trunk/phase3/includes/actions/EditAction.php
___________________________________________________________________
Added: svn:eol-style
176 + native
Index: trunk/phase3/includes/actions/ViewAction.php
@@ -0,0 +1,43 @@
 2+<?php
 3+/**
 4+ * An action that views article content
 5+ *
 6+ * Copyright © 2012 Timo Tijhof
 7+ *
 8+ * This program is free software; you can redistribute it and/or modify
 9+ * it under the terms of the GNU General Public License as published by
 10+ * the Free Software Foundation; either version 2 of the License, or
 11+ * (at your option) any later version.
 12+ *
 13+ * This program is distributed in the hope that it will be useful,
 14+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
 15+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 16+ * GNU General Public License for more details.
 17+ *
 18+ * You should have received a copy of the GNU General Public License
 19+ * along with this program; if not, write to the Free Software
 20+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
 21+ *
 22+ * @file
 23+ * @ingroup Actions
 24+ * @author Timo Tijhof
 25+ */
 26+
 27+class ViewAction extends FormlessAction {
 28+
 29+ public function getName() {
 30+ return 'view';
 31+ }
 32+
 33+ public function onView(){
 34+ return null;
 35+ }
 36+
 37+ public function show(){
 38+ global $wgSquidMaxage;
 39+
 40+ $this->getOutput()->setSquidMaxage( $wgSquidMaxage );
 41+ $this->page->view();
 42+ }
 43+
 44+}
Property changes on: trunk/phase3/includes/actions/ViewAction.php
___________________________________________________________________
Added: svn:eol-style
145 + native
Index: trunk/phase3/includes/actions/RenderAction.php
@@ -0,0 +1,42 @@
 2+<?php
 3+/**
 4+ * Handle action=render
 5+ *
 6+ * Copyright © 2012 Timo Tijhof
 7+ *
 8+ * This program is free software; you can redistribute it and/or modify
 9+ * it under the terms of the GNU General Public License as published by
 10+ * the Free Software Foundation; either version 2 of the License, or
 11+ * (at your option) any later version.
 12+ *
 13+ * This program is distributed in the hope that it will be useful,
 14+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
 15+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 16+ * GNU General Public License for more details.
 17+ *
 18+ * You should have received a copy of the GNU General Public License
 19+ * along with this program; if not, write to the Free Software
 20+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
 21+ *
 22+ * @file
 23+ * @ingroup Actions
 24+ * @author Timo Tijhof
 25+ */
 26+
 27+class RenderAction extends FormlessAction {
 28+
 29+ public function getName() {
 30+ return 'render';
 31+ }
 32+
 33+ public function onView(){
 34+ return null;
 35+ }
 36+
 37+ public function show(){
 38+
 39+ $this->page->render();
 40+
 41+ }
 42+
 43+}
Property changes on: trunk/phase3/includes/actions/RenderAction.php
___________________________________________________________________
Added: svn:eol-style
144 + native
Index: trunk/phase3/includes/actions/ProtectAction.php
@@ -0,0 +1,56 @@
 2+<?php
 3+/**
 4+ * action=protect handler
 5+ *
 6+ * Copyright © 2012 Timo Tijhof
 7+ *
 8+ * This program is free software; you can redistribute it and/or modify
 9+ * it under the terms of the GNU General Public License as published by
 10+ * the Free Software Foundation; either version 2 of the License, or
 11+ * (at your option) any later version.
 12+ *
 13+ * This program is distributed in the hope that it will be useful,
 14+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
 15+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 16+ * GNU General Public License for more details.
 17+ *
 18+ * You should have received a copy of the GNU General Public License
 19+ * along with this program; if not, write to the Free Software
 20+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
 21+ *
 22+ * @file
 23+ * @ingroup Actions
 24+ * @author Timo Tijhof
 25+ */
 26+
 27+class ProtectAction extends FormlessAction {
 28+
 29+ public function getName() {
 30+ return 'protect';
 31+ }
 32+
 33+ public function onView(){
 34+ return null;
 35+ }
 36+
 37+ public function show(){
 38+
 39+ $this->page->protect();
 40+
 41+ }
 42+
 43+}
 44+
 45+class UnprotectAction extends ProtectAction {
 46+
 47+ public function getName() {
 48+ return 'unprotect';
 49+ }
 50+
 51+ public function show(){
 52+
 53+ $this->page->unprotect();
 54+
 55+ }
 56+
 57+}
Property changes on: trunk/phase3/includes/actions/ProtectAction.php
___________________________________________________________________
Added: svn:eol-style
158 + native
Index: trunk/phase3/includes/Wiki.php
@@ -516,46 +516,11 @@
517517 return;
518518 }
519519
520 - switch( $act ) {
521 - case 'view':
522 - $output->setSquidMaxage( $wgSquidMaxage );
523 - $this->performedAction = $act;
524 - $article->view();
525 - break;
526 - case 'delete':
527 - case 'protect':
528 - case 'unprotect':
529 - case 'render':
530 - $this->performedAction = $act;
531 - $article->$act();
532 - break;
533 - case 'submit':
534 - if ( session_id() == '' ) {
535 - // Send a cookie so anons get talk message notifications
536 - wfSetupSession();
537 - }
538 - // Continue...
539 - case 'edit':
540 - if ( wfRunHooks( 'CustomEditor', array( $article, $user ) ) ) {
541 - $this->performedAction = 'edit';
542 - if ( ExternalEdit::useExternalEngine( $this->context, 'edit' )
543 - && $act == 'edit' && !$request->getVal( 'section' )
544 - && !$request->getVal( 'oldid' ) )
545 - {
546 - $extedit = new ExternalEdit( $this->context );
547 - $extedit->execute();
548 - } else {
549 - $editor = new EditPage( $article );
550 - $editor->edit();
551 - }
552 - }
553 - break;
554 - default:
555 - if ( wfRunHooks( 'UnknownAction', array( $act, $article ) ) ) {
556 - $this->performedAction = 'nosuchaction';
557 - $output->showErrorPage( 'nosuchaction', 'nosuchactiontext' );
558 - }
 520+ if ( wfRunHooks( 'UnknownAction', array( $act, $article ) ) ) {
 521+ $this->performedAction = 'nosuchaction';
 522+ $output->showErrorPage( 'nosuchaction', 'nosuchactiontext' );
559523 }
 524+
560525 wfProfileOut( __METHOD__ );
561526 }
562527
Index: trunk/phase3/includes/AutoLoader.php
@@ -253,19 +253,26 @@
254254
255255 # includes/actions
256256 'CreditsAction' => 'includes/actions/CreditsAction.php',
 257+ 'DeleteAction' => 'includes/actions/DeleteAction.php',
 258+ 'EditAction' => 'includes/actions/EditAction.php',
257259 'HistoryAction' => 'includes/actions/HistoryAction.php',
258260 'HistoryPage' => 'includes/actions/HistoryAction.php',
259261 'HistoryPager' => 'includes/actions/HistoryAction.php',
260262 'InfoAction' => 'includes/actions/InfoAction.php',
261263 'MarkpatrolledAction' => 'includes/actions/MarkpatrolledAction.php',
 264+ 'ProtectAction' => 'includes/actions/ProtectAction.php',
262265 'PurgeAction' => 'includes/actions/PurgeAction.php',
263266 'RawAction' => 'includes/actions/RawAction.php',
264267 'RawPage' => 'includes/actions/RawAction.php',
 268+ 'RenderAction' => 'includes/actions/RenderAction.php',
265269 'RevertAction' => 'includes/actions/RevertAction.php',
266270 'RevertFileAction' => 'includes/actions/RevertAction.php',
267271 'RevisiondeleteAction' => 'includes/actions/RevisiondeleteAction.php',
268272 'RollbackAction' => 'includes/actions/RollbackAction.php',
 273+ 'SubmitAction' => 'includes/actions/EditAction.php',
 274+ 'UnprotectAction' => 'includes/actions/ProtectAction.php',
269275 'UnwatchAction' => 'includes/actions/WatchAction.php',
 276+ 'ViewAction' => 'includes/actions/ViewAction.php',
270277 'WatchAction' => 'includes/actions/WatchAction.php',
271278
272279 # includes/api
Index: trunk/phase3/includes/DefaultSettings.php
@@ -5303,15 +5303,22 @@
53045304 */
53055305 $wgActions = array(
53065306 'credits' => true,
 5307+ 'delete' => true,
 5308+ 'edit' => true,
53075309 'history' => true,
53085310 'info' => true,
53095311 'markpatrolled' => true,
 5312+ 'protect' => true,
53105313 'purge' => true,
53115314 'raw' => true,
 5315+ 'render' => true,
53125316 'revert' => true,
53135317 'revisiondelete' => true,
53145318 'rollback' => true,
 5319+ 'submit' => true,
 5320+ 'unprotect' => true,
53155321 'unwatch' => true,
 5322+ 'view' => true,
53165323 'watch' => true,
53175324 );
53185325

Follow-up revisions

RevisionCommit summaryAuthorDate
r109223[Actions] Move action logic out of MediaWiki::getAction/MediaWiki::performAct...krinkle21:49, 17 January 2012
r110302align $wgActions array values...hashar16:33, 30 January 2012

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r108342Implement MediaWiki::getPerformedAction()...krinkle01:31, 8 January 2012

Comments

#Comment by Nikerabbit (talk | contribs)   21:12, 17 January 2012

Whitespace

#Comment by Hashar (talk | contribs)   16:42, 30 January 2012

Now we just need a nice UnknownAction action class to get ride of the remaining code:

	if ( wfRunHooks( 'UnknownAction', array( $act, $article ) ) ) {

$this->performedAction = 'nosuchaction'; $output->showErrorPage( 'nosuchaction', 'nosuchactiontext' ); }

Status & tagging log