https://www.mediawiki.org/wiki/Special:Code/MediaWiki/112448

Revision: 112448
Author:   jeroendedauw
Date:     2012-02-26 20:37:15 +0000 (Sun, 26 Feb 2012)
Log Message:
-----------
initial work on undo and restore actions and some refactoring

Modified Paths:
--------------
    trunk/extensions/EducationProgram/EducationProgram.hooks.php
    trunk/extensions/EducationProgram/EducationProgram.i18n.php
    trunk/extensions/EducationProgram/EducationProgram.php
    trunk/extensions/EducationProgram/actions/EPDeleteAction.php
    trunk/extensions/EducationProgram/actions/EPEditAction.php
    trunk/extensions/EducationProgram/actions/EPViewAction.php
    trunk/extensions/EducationProgram/includes/EPRevisionPager.php
    trunk/extensions/EducationProgram/pages/CoursePage.php
    trunk/extensions/EducationProgram/pages/EPPage.php
    trunk/extensions/EducationProgram/pages/OrgPage.php

Added Paths:
-----------
    trunk/extensions/EducationProgram/actions/EPRestoreAction.php
    trunk/extensions/EducationProgram/actions/EPUndoAction.php

Removed Paths:
-------------
    trunk/extensions/EducationProgram/actions/DeleteCourseAction.php
    trunk/extensions/EducationProgram/actions/DeleteOrgAction.php

Modified: trunk/extensions/EducationProgram/EducationProgram.hooks.php
===================================================================
--- trunk/extensions/EducationProgram/EducationProgram.hooks.php        
2012-02-26 19:55:37 UTC (rev 112447)
+++ trunk/extensions/EducationProgram/EducationProgram.hooks.php        
2012-02-26 20:37:15 UTC (rev 112448)
@@ -340,5 +340,31 @@
 
                return true;
        }
+       
+       /**
+        * Used to add new query-string actions.
+        * @see https://www.mediawiki.org/wiki/Manual:Hooks/UnknownAction
+        *
+        * @since 0.1
+        *
+        * @param string $action
+        * @param Page $page
+        *
+        * @return true
+        */
+       public static function onUnknownAction( $action, Page $page ) {
+               // Action does not allow us to associate actions that are not 
known to core
+               // with a single page, hence the less ideal handling in this 
hook.
+               if ( method_exists( $page, 'getActions' ) ) {
+                       $actions = $page->getActions();
+                       
+                       if ( array_key_exists( $action, $actions ) ) {
+                               $action = new $actions[$action]( $page, 
$page->getContext() );
+                               $action->show();
+                       }
+               }
+               
+               return true;
+       }
 
 }

Modified: trunk/extensions/EducationProgram/EducationProgram.i18n.php
===================================================================
--- trunk/extensions/EducationProgram/EducationProgram.i18n.php 2012-02-26 
19:55:37 UTC (rev 112447)
+++ trunk/extensions/EducationProgram/EducationProgram.i18n.php 2012-02-26 
20:37:15 UTC (rev 112448)
@@ -468,20 +468,20 @@
        'ep-coursehistory-deleted' => 'This course has been deleted. The 
deletion log for the course is provided below for reference.',
 
        // Course deletion
-       'deletecourseaction-text' => 'You are about to delete course $1. This 
will remove all associated students!',
-       'deletecourseaction-summary' => 'Reason for deletion:',
-       'deletecourseaction-title' => 'Delete course "$1"',
-       'deletecourseaction-cancel-button' => 'Cancel',
-       'deletecourseaction-delete-button' => 'Delete course',
-       'deletecourseaction-none' => 'There is no course titled "$1". Existing 
courses can be found in [[Special:Courses|the courses list]].',
+       'coursepage-delete-text' => 'You are about to delete course $1. This 
will remove all associated students!',
+       'coursepage-delete-summary' => 'Reason for deletion:',
+       'coursepage-delete-title' => 'Delete course "$1"',
+       'coursepage-delete-cancel-button' => 'Cancel',
+       'coursepage-delete-delete-button' => 'Delete course',
+       'coursepage-delete-none' => 'There is no course titled "$1". Existing 
courses can be found in [[Special:Courses|the courses list]].',
 
        // Institution deletion
-       'deleteorgaction-text' => "You are about to delete institution $1. This 
will remove all it's courses and their associated students!",
-       'deleteorgaction-summary' => 'Reason for deletion:',
-       'deleteorgaction-title' => 'Delete institution "$1"',
-       'deleteorgaction-cancel-button' => 'Cancel',
-       'deleteorgaction-delete-button' => 'Delete institution',
-       'deleteorgaction-none' => 'There is no institution titled "$1". 
Existing institutions can be found in [[Special:Courses|the institution 
list]].',
+       'orgpage-delete-text' => "You are about to delete institution $1. This 
will remove all it's courses and their associated students!",
+       'orgpage-delete-summary' => 'Reason for deletion:',
+       'orgpage-delete-title' => 'Delete institution "$1"',
+       'orgpage-delete-cancel-button' => 'Cancel',
+       'orgpage-delete-delete-button' => 'Delete institution',
+       'orgpage-delete-none' => 'There is no institution titled "$1". Existing 
institutions can be found in [[Special:Courses|the institution list]].',
 
        // Special:Ambassador
        'ep-ambassador-does-not-exist' => 'There is no ambassador with name 
"$1". See [[Special:Ambassadors|here]] for a list of ambassadors.',

Modified: trunk/extensions/EducationProgram/EducationProgram.php
===================================================================
--- trunk/extensions/EducationProgram/EducationProgram.php      2012-02-26 
19:55:37 UTC (rev 112447)
+++ trunk/extensions/EducationProgram/EducationProgram.php      2012-02-26 
20:37:15 UTC (rev 112448)
@@ -60,8 +60,8 @@
 $wgAutoloadClasses['EPSettings']                                       = 
dirname( __FILE__ ) . '/EducationProgram.settings.php';
 
 $wgAutoloadClasses['CourseHistoryAction']                      = dirname( 
__FILE__ ) . '/actions/CourseHistoryAction.php';
-$wgAutoloadClasses['DeleteCourseAction']                       = dirname( 
__FILE__ ) . '/actions/DeleteCourseAction.php';
-$wgAutoloadClasses['DeleteOrgAction']                          = dirname( 
__FILE__ ) . '/actions/DeleteOrgAction.php';
+//$wgAutoloadClasses['DeleteCourseAction']                     = dirname( 
__FILE__ ) . '/actions/DeleteCourseAction.php';
+//$wgAutoloadClasses['DeleteOrgAction']                                = 
dirname( __FILE__ ) . '/actions/DeleteOrgAction.php';
 $wgAutoloadClasses['EditCourseAction']                                 = 
dirname( __FILE__ ) . '/actions/EditCourseAction.php';
 $wgAutoloadClasses['EditOrgAction']                            = dirname( 
__FILE__ ) . '/actions/EditOrgAction.php';
 $wgAutoloadClasses['EPAddArticleAction']                       = dirname( 
__FILE__ ) . '/actions/EPAddArticleAction.php';
@@ -72,10 +72,16 @@
 $wgAutoloadClasses['EPRemoveArticleAction']            = dirname( __FILE__ ) . 
'/actions/EPRemoveArticleAction.php';
 $wgAutoloadClasses['EPRemoveReviewerAction']           = dirname( __FILE__ ) . 
'/actions/EPRemoveReviewerAction.php';
 $wgAutoloadClasses['EPRemoveStudentAction']            = dirname( __FILE__ ) . 
'/actions/EPRemoveStudentAction.php';
+$wgAutoloadClasses['EPRestoreAction']                          = dirname( 
__FILE__ ) . '/actions/EPRestoreAction.php';
+$wgAutoloadClasses['EPUndoAction']                                     = 
dirname( __FILE__ ) . '/actions/EPUndoAction.php';
 $wgAutoloadClasses['EPViewAction']                                     = 
dirname( __FILE__ ) . '/actions/EPViewAction.php';
 $wgAutoloadClasses['OrgHistoryAction']                                 = 
dirname( __FILE__ ) . '/actions/OrgHistoryAction.php';
 $wgAutoloadClasses['ViewCourseAction']                                 = 
dirname( __FILE__ ) . '/actions/ViewCourseAction.php';
 $wgAutoloadClasses['ViewOrgAction']                            = dirname( 
__FILE__ ) . '/actions/ViewOrgAction.php';
+//$wgAutoloadClasses['CourseUndoAction']                               = 
dirname( __FILE__ ) . '/actions/CourseUndoAction.php';
+//$wgAutoloadClasses['OrgUndoAction']                          = dirname( 
__FILE__ ) . '/actions/OrgUndoAction.php';
+//$wgAutoloadClasses['CourseRestoreAction']                    = dirname( 
__FILE__ ) . '/actions/CourseRestoreAction.php';
+//$wgAutoloadClasses['OrgRestoreAction']                               = 
dirname( __FILE__ ) . '/actions/OrgRestoreAction.php';
 
 $wgAutoloadClasses['ApiDeleteEducation']                       = dirname( 
__FILE__ ) . '/api/ApiDeleteEducation.php';
 $wgAutoloadClasses['ApiEnlist']                                        = 
dirname( __FILE__ ) . '/api/ApiEnlist.php';
@@ -193,6 +199,7 @@
 $wgHooks['ArticleFromTitle'][]                                                 
= 'EPHooks::onArticleFromTitle';
 $wgHooks['CanonicalNamespaces'][]                                      = 
'EPHooks::onCanonicalNamespaces';
 $wgHooks['TitleIsAlwaysKnown'][]                                       = 
'EPHooks::onTitleIsAlwaysKnown';
+//$wgHooks['UnknownAction'][]                                          = 
'EPHooks::onUnknownAction';
 
 // Actions
 $wgActions['epremarticle'] = 'EPRemoveArticleAction';
@@ -200,6 +207,8 @@
 $wgActions['epremreviewer'] = 'EPRemoveReviewerAction';
 $wgActions['epaddarticle'] = 'EPAddArticleAction';
 $wgActions['epaddreviewer'] = 'EPAddReviewerAction';
+$wgActions['epundo'] = 'EPUndoAction';
+$wgActions['eprestore'] = 'EPRestoreAction';
 
 // Logging
 $wgLogTypes[] = 'institution';

Deleted: trunk/extensions/EducationProgram/actions/DeleteCourseAction.php
===================================================================
--- trunk/extensions/EducationProgram/actions/DeleteCourseAction.php    
2012-02-26 19:55:37 UTC (rev 112447)
+++ trunk/extensions/EducationProgram/actions/DeleteCourseAction.php    
2012-02-26 20:37:15 UTC (rev 112448)
@@ -1,37 +0,0 @@
-<?php
-
-/**
- * Page for deleting a course.
- *
- * @since 0.1
- *
- * @file DeleteCourseAction.php
- * @ingroup EducationProgram
- * @ingroup Action
- *
- * @licence GNU GPL v3+
- * @author Jeroen De Dauw < [email protected] >
- */
-class DeleteCourseAction extends EPDeleteAction {
-
-       /**
-        * Constructor.
-        *
-        * @since 0.1
-        *
-        * @param Page $page
-        * @param IContextSource $context
-        */
-       protected function __construct( Page $page, IContextSource $context = 
null ) {
-               parent::__construct( $page, $context, EPCourses::singleton() );
-       }
-
-       public function getName() {
-               return 'deletecourse';
-       }
-
-       public function getRestriction() {
-               return 'ep-course';
-       }
-
-}
\ No newline at end of file

Deleted: trunk/extensions/EducationProgram/actions/DeleteOrgAction.php
===================================================================
--- trunk/extensions/EducationProgram/actions/DeleteOrgAction.php       
2012-02-26 19:55:37 UTC (rev 112447)
+++ trunk/extensions/EducationProgram/actions/DeleteOrgAction.php       
2012-02-26 20:37:15 UTC (rev 112448)
@@ -1,37 +0,0 @@
-<?php
-
-/**
- * Page for deleting an institution.
- *
- * @since 0.1
- *
- * @file DeleteOrgAction.php
- * @ingroup EducationProgram
- * @ingroup Action
- *
- * @licence GNU GPL v3+
- * @author Jeroen De Dauw < [email protected] >
- */
-class DeleteOrgAction extends EPDeleteAction {
-
-       /**
-        * Constructor.
-        *
-        * @since 0.1
-        *
-        * @param Page $page
-        * @param IContextSource $context
-        */
-       protected function __construct( Page $page, IContextSource $context = 
null ) {
-               parent::__construct( $page, $context, EPOrgs::singleton() );
-       }
-
-       public function getName() {
-               return 'deleteorg';
-       }
-
-       public function getRestriction() {
-               return 'ep-org';
-       }
-
-}
\ No newline at end of file

Modified: trunk/extensions/EducationProgram/actions/EPDeleteAction.php
===================================================================
--- trunk/extensions/EducationProgram/actions/EPDeleteAction.php        
2012-02-26 19:55:37 UTC (rev 112447)
+++ trunk/extensions/EducationProgram/actions/EPDeleteAction.php        
2012-02-26 20:37:15 UTC (rev 112448)
@@ -1,7 +1,7 @@
 <?php
 
 /**
- * Abstract action for deleting EPPageObject items.
+ * Action for deleting EPPageObject items.
  *
  * @since 0.1
  *
@@ -12,29 +12,16 @@
  * @licence GNU GPL v3+
  * @author Jeroen De Dauw < [email protected] >
  */
-abstract class EPDeleteAction extends FormlessAction {
+class EPDeleteAction extends FormlessAction {
 
        /**
-        * @since 0.1
-        * @var DBTable
+        * (non-PHPdoc)
+        * @see Action::getName()
         */
-       protected $table;
-
-       /**
-        * Constructor.
-        *
-        * @since 0.1
-        *
-        * @param Page $page
-        * @param IContextSource $context
-        * @param DBTable $table
-        */
-       protected function __construct( Page $page, IContextSource $context = 
null, DBTable $table ) {
-               $this->table = $table;
-               parent::__construct( $page, $context );
-               $this->getOutput()->addModules( 'ep.formpage' );
+       public function getName() {
+               return 'delete';
        }
-
+       
        /**
         * (non-PHPdoc)
         * @see Action::getDescription()
@@ -42,6 +29,14 @@
        protected function getDescription() {
                return $this->msg( 'backlinksubtitle' )->rawParams( 
Linker::link( $this->getTitle() ) );
        }
+       
+       /**
+        * (non-PHPdoc)
+        * @see Action::getRestriction()
+        */
+       public function getRestriction() {
+               $this->page->getTable()->getEditRight();
+       }
 
        /**
         * (non-PHPdoc)
@@ -50,7 +45,7 @@
        public function onView() {
                $this->getOutput()->setPageTitle( $this->getPageTitle() );
 
-               $object = $this->table->get( $this->getTitle()->getText() );
+               $object = $this->page->getTable()->get( 
$this->getTitle()->getText() );
 
                if ( $object === false ) {
                        $this->getOutput()->addWikiMsg( $this->prefixMsg( 
'none' ), $this->getTitle()->getText() );
@@ -107,6 +102,8 @@
         */
        protected function displayForm( EPPageObject $object ) {
                $out = $this->getOutput();
+               
+               $out->addModules( 'ep.formpage' );
 
                $out->addWikiMsg( $this->prefixMsg( 'text' ), 
$object->getField( 'name' ) );
 
@@ -137,7 +134,7 @@
                        wfMsg( $this->prefixMsg( 'delete-button' ) ),
                        'submit',
                        array(
-                               'class' => 'ep-disenroll',
+                               'class' => 'ep-delete',
                        )
                ) );
 
@@ -145,7 +142,7 @@
                        'button',
                        array(
                                'id' => 'cancelDelete',
-                               'class' => 'ep-delete-cancel',
+                               'class' => 'ep-delete-cancel ep-cancel',
                                'target-url' => 
$this->getTitle()->getLocalURL(),
                        ),
                        wfMsg( $this->prefixMsg( 'cancel-button' ) )
@@ -156,6 +153,13 @@
                $out->addHTML( '</form>' );
        }
        
+       /**
+        * Returns a salt based on the action and the page name.
+        * 
+        * @since 0.1
+        * 
+        * @return string
+        */     
        protected function getSalt() {
                return 'delete' . $this->getTitle()->getLocalURL();
        }
@@ -170,7 +174,7 @@
         * @return string
         */
        protected function prefixMsg( $name ) {
-               return strtolower( get_called_class() ) . '-' . $name;
+               return strtolower( get_class( $this->page ) ) . '-' . 
$this->getName() . '-' . $name;
        }
 
        /**

Modified: trunk/extensions/EducationProgram/actions/EPEditAction.php
===================================================================
--- trunk/extensions/EducationProgram/actions/EPEditAction.php  2012-02-26 
19:55:37 UTC (rev 112447)
+++ trunk/extensions/EducationProgram/actions/EPEditAction.php  2012-02-26 
20:37:15 UTC (rev 112448)
@@ -32,7 +32,7 @@
 
        /**
         * @since 0.1
-        * @var DBTable
+        * @var EPPageTable
         */
        protected $table;
 
@@ -45,7 +45,7 @@
         * @param IContextSource $context
         * @param DBTable $table
         */
-       protected function __construct( Page $page, IContextSource $context = 
null, DBTable $table ) {
+       protected function __construct( Page $page, IContextSource $context = 
null, EPPageTable $table ) {
                $this->table = $table;
                parent::__construct( $page, $context );
        }
@@ -247,6 +247,7 @@
                        'cancelEdit',
                        array(
                                'target-url' => 
$this->getReturnToTitle()->getFullURL(),
+                               'class' => 'ep-cancel',
                        )
                );
 

Added: trunk/extensions/EducationProgram/actions/EPRestoreAction.php
===================================================================
--- trunk/extensions/EducationProgram/actions/EPRestoreAction.php               
                (rev 0)
+++ trunk/extensions/EducationProgram/actions/EPRestoreAction.php       
2012-02-26 20:37:15 UTC (rev 112448)
@@ -0,0 +1,184 @@
+<?php
+
+/**
+ * Abstract action for restoring an EPPageObject to a previous revision.
+ *
+ * @since 0.1
+ *
+ * @file EPRestoreAction.php
+ * @ingroup EducationProgram
+ * @ingroup Action
+ *
+ * @licence GNU GPL v3+
+ * @author Jeroen De Dauw < [email protected] >
+ */
+abstract class EPRestoreAction extends FormlessAction {
+
+       /**
+        * (non-PHPdoc)
+        * @see Action::getName()
+        */
+       public function getName() {
+               return 'eprestore';
+       }
+       
+       /**
+        * (non-PHPdoc)
+        * @see Action::getDescription()
+        */
+       protected function getDescription() {
+               return $this->msg( 'backlinksubtitle' )->rawParams( 
Linker::link( $this->getTitle() ) );
+       }
+
+       /**
+        * (non-PHPdoc)
+        * @see FormlessAction::onView()
+        */
+       public function onView() {
+               $this->getOutput()->setPageTitle( $this->getPageTitle() );
+
+               $object = $this->page->getTable()->get( 
$this->getTitle()->getText() );
+
+               if ( $object === false ) {
+                       $this->getOutput()->addWikiMsg( $this->prefixMsg( 
'none' ), $this->getTitle()->getText() );
+                       $this->getOutput()->setSubtitle( '' );
+               }
+               else {
+                       $req = $this->getRequest();
+                       
+                       if ( $req->wasPosted() && 
$this->getUser()->matchEditToken( $req->getText( 'restoreToken' ), 
$this->getSalt() ) ) {
+                               $success = $this->doRestore( $object );
+                               
+                               if ( $success ) {
+                                       $query = array( 'restored' => '1' ); // 
TODO: handle
+                               }
+                               else {
+                                       $query = array( 'delfailed' => '1' ); 
// TODO: handle
+                               }
+                               
+                               $this->getOutput()->redirect( 
$object->getTitle()->getLocalURL( $query ) );
+                       }
+                       else {
+                               $this->displayForm( $object );
+                       }
+               }
+
+               return '';
+       }
+       
+       /**
+        * Does the actual restore action.
+        * 
+        * @since 0.1
+        * 
+        * @return boolean Success indicator
+        */
+       protected function doRestore( EPPageObject $object ) {
+               $revAction = new EPRevisionAction();
+               
+               $revAction->setUser( $this->getUser() );
+               $revAction->setComment( $this->getRequest()->getText( 
'summary', '' ) );
+               
+               // TODO
+               
+               return false;
+       }
+
+       /**
+        * Display the restoration form for the provided EPPageObject.
+        * 
+        * @since 0.1
+        * 
+        * @param EPPageObject $object
+        */
+       protected function displayForm( EPPageObject $object ) {
+               $out = $this->getOutput();
+
+               $out->addWikiMsg( $this->prefixMsg( 'text' ), 
$object->getField( 'name' ) );
+
+               $out->addHTML( Html::openElement(
+                       'form',
+                       array(
+                               'method' => 'post',
+                               'action' => $this->getTitle()->getLocalURL( 
array( 'action' => 'restore' ) ),
+                       )
+               ) );
+
+               $out->addHTML( '&#160;' . Xml::inputLabel(
+                       wfMsg( $this->prefixMsg( 'summary' ) ),
+                       'summary',
+                       'summary',
+                       65,
+                       false,
+                       array(
+                               'maxlength' => 250,
+                               'spellcheck' => true,
+                       )
+               ) );
+
+               $out->addHTML( '<br />' );
+
+               $out->addHTML( Html::input(
+                       'restore',
+                       wfMsg( $this->prefixMsg( 'restore-button' ) ),
+                       'submit',
+                       array(
+                               'class' => 'ep-restore',
+                       )
+               ) );
+
+               $out->addElement(
+                       'button',
+                       array(
+                               'id' => 'cancelRestore',
+                               'class' => 'ep-restore-cancel ep-cancel',
+                               'target-url' => 
$this->getTitle()->getLocalURL(),
+                       ),
+                       wfMsg( $this->prefixMsg( 'cancel-button' ) )
+               );
+
+               $out->addHTML( Html::hidden( 'restoreToken', 
$this->getUser()->getEditToken( $this->getSalt() ) ) );
+
+               $out->addHTML( '</form>' );
+       }
+       
+       /**
+        * Returns a salt based on the action and the page name.
+        * 
+        * @since 0.1
+        * 
+        * @return string
+        */
+       protected function getSalt() {
+               return 'restore' . $this->getTitle()->getLocalURL();
+       }
+
+       /**
+        * Returns a prefixed message name.
+        * 
+        * @since 0.1
+        * 
+        * @param string $name
+        * 
+        * @return string
+        */
+       protected function prefixMsg( $name ) {
+               return strtolower( get_class( $this->page ) ) . '-' . 
$this->getName() . '-' . $name;
+       }
+
+       /**
+        * Returns the page title.
+        *
+        * @since 0.1
+        *
+        * @return string
+        */
+       protected function getPageTitle() {
+               return wfMsgExt(
+                       $this->prefixMsg( 'title' ),
+                       'parsemag',
+                       $this->getTitle()->getText()
+               );
+       }
+
+}
\ No newline at end of file


Property changes on: 
trunk/extensions/EducationProgram/actions/EPRestoreAction.php
___________________________________________________________________
Added: svn:eol-style
   + native

Added: trunk/extensions/EducationProgram/actions/EPUndoAction.php
===================================================================
--- trunk/extensions/EducationProgram/actions/EPUndoAction.php                  
        (rev 0)
+++ trunk/extensions/EducationProgram/actions/EPUndoAction.php  2012-02-26 
20:37:15 UTC (rev 112448)
@@ -0,0 +1,184 @@
+<?php
+
+/**
+ * Abstract action for undoing a change to an EPPageObject.
+ *
+ * @since 0.1
+ *
+ * @file EPUndoAction.php
+ * @ingroup EducationProgram
+ * @ingroup Action
+ *
+ * @licence GNU GPL v3+
+ * @author Jeroen De Dauw < [email protected] >
+ */
+class EPUndoAction extends FormlessAction {
+
+       /**
+        * (non-PHPdoc)
+        * @see Action::getName()
+        */
+       public function getName() {
+               return 'epundo';
+       }
+       
+       /**
+        * (non-PHPdoc)
+        * @see Action::getDescription()
+        */
+       protected function getDescription() {
+               return $this->msg( 'backlinksubtitle' )->rawParams( 
Linker::link( $this->getTitle() ) );
+       }
+
+       /**
+        * (non-PHPdoc)
+        * @see FormlessAction::onView()
+        */
+       public function onView() {
+               $this->getOutput()->setPageTitle( $this->getPageTitle() );
+
+               $object = $this->page->getTable()->get( 
$this->getTitle()->getText() );
+
+               if ( $object === false ) {
+                       $this->getOutput()->addWikiMsg( $this->prefixMsg( 
'none' ), $this->getTitle()->getText() );
+                       $this->getOutput()->setSubtitle( '' );
+               }
+               else {
+                       $req = $this->getRequest();
+                       
+                       if ( $req->wasPosted() && 
$this->getUser()->matchEditToken( $req->getText( 'undoToken' ), 
$this->getSalt() ) ) {
+                               $success = $this->doUndo( $object );
+                               
+                               if ( $success ) {
+                                       $query = array( 'undid' => '1' ); // 
TODO: handle
+                               }
+                               else {
+                                       $query = array( 'undofailed' => '1' ); 
// TODO: handle
+                               }
+                               
+                               $this->getOutput()->redirect( 
$object->getTitle()->getLocalURL( $query ) );
+                       }
+                       else {
+                               $this->displayForm( $object );
+                       }
+               }
+
+               return '';
+       }
+       
+       /**
+        * Does the actual undo action.
+        * 
+        * @since 0.1
+        * 
+        * @return boolean Success indicator
+        */
+       protected function doUndo( EPPageObject $object ) {
+               $revAction = new EPRevisionAction();
+               
+               $revAction->setUser( $this->getUser() );
+               $revAction->setComment( $this->getRequest()->getText( 
'summary', '' ) );
+               
+               // TODO
+               
+               return false;
+       }
+
+       /**
+        * Display the restoration form for the provided EPPageObject.
+        * 
+        * @since 0.1
+        * 
+        * @param EPPageObject $object
+        */
+       protected function displayForm( EPPageObject $object ) {
+               $out = $this->getOutput();
+
+               $out->addWikiMsg( $this->prefixMsg( 'text' ), 
$object->getField( 'name' ) );
+
+               $out->addHTML( Html::openElement(
+                       'form',
+                       array(
+                               'method' => 'post',
+                               'action' => $this->getTitle()->getLocalURL( 
array( 'action' => 'undo' ) ),
+                       )
+               ) );
+
+               $out->addHTML( '&#160;' . Xml::inputLabel(
+                       wfMsg( $this->prefixMsg( 'summary' ) ),
+                       'summary',
+                       'summary',
+                       65,
+                       false,
+                       array(
+                               'maxlength' => 250,
+                               'spellcheck' => true,
+                       )
+               ) );
+
+               $out->addHTML( '<br />' );
+
+               $out->addHTML( Html::input(
+                       'restore',
+                       wfMsg( $this->prefixMsg( 'undo-button' ) ),
+                       'submit',
+                       array(
+                               'class' => 'ep-undo',
+                       )
+               ) );
+
+               $out->addElement(
+                       'button',
+                       array(
+                               'id' => 'cancelRestore',
+                               'class' => 'ep-undo-cancel ep-cancel',
+                               'target-url' => 
$this->getTitle()->getLocalURL(),
+                       ),
+                       wfMsg( $this->prefixMsg( 'cancel-button' ) )
+               );
+
+               $out->addHTML( Html::hidden( 'undoToken', 
$this->getUser()->getEditToken( $this->getSalt() ) ) );
+
+               $out->addHTML( '</form>' );
+       }
+       
+       /**
+        * Returns a salt based on the action and the page name.
+        * 
+        * @since 0.1
+        * 
+        * @return string
+        */
+       protected function getSalt() {
+               return 'undo' . $this->getTitle()->getLocalURL();
+       }
+
+       /**
+        * Returns a prefixed message name.
+        * 
+        * @since 0.1
+        * 
+        * @param string $name
+        * 
+        * @return string
+        */
+       protected function prefixMsg( $name ) {
+               return strtolower( get_class( $this->page ) ) . '-' . 
$this->getName() . '-' . $name;
+       }
+
+       /**
+        * Returns the page title.
+        *
+        * @since 0.1
+        *
+        * @return string
+        */
+       protected function getPageTitle() {
+               return wfMsgExt(
+                       $this->prefixMsg( 'title' ),
+                       'parsemag',
+                       $this->getTitle()->getText()
+               );
+       }
+
+}
\ No newline at end of file


Property changes on: trunk/extensions/EducationProgram/actions/EPUndoAction.php
___________________________________________________________________
Added: svn:eol-style
   + native

Modified: trunk/extensions/EducationProgram/actions/EPViewAction.php
===================================================================
--- trunk/extensions/EducationProgram/actions/EPViewAction.php  2012-02-26 
19:55:37 UTC (rev 112447)
+++ trunk/extensions/EducationProgram/actions/EPViewAction.php  2012-02-26 
20:37:15 UTC (rev 112448)
@@ -16,7 +16,7 @@
 
        /**
         * @since 0.1
-        * @var DBTable
+        * @var EPPageTable
         */
        protected $table;
 
@@ -29,7 +29,7 @@
         * @param IContextSource $context
         * @param DBTable $table
         */
-       protected function __construct( Page $page, IContextSource $context = 
null, DBTable $table ) {
+       protected function __construct( Page $page, IContextSource $context = 
null, EPPageTable $table ) {
                $this->table = $table;
                parent::__construct( $page, $context );
        }

Modified: trunk/extensions/EducationProgram/includes/EPRevisionPager.php
===================================================================
--- trunk/extensions/EducationProgram/includes/EPRevisionPager.php      
2012-02-26 19:55:37 UTC (rev 112447)
+++ trunk/extensions/EducationProgram/includes/EPRevisionPager.php      
2012-02-26 20:37:15 UTC (rev 112448)
@@ -112,7 +112,7 @@
                        
                        if ( $this->mOffset !== '' || $this->rowNr < 
$this->mResult->numRows() - 1 ) {
                                $actionLinks[] = $object->getLink(
-                                       'undo',
+                                       'epundo',
                                        wfMsgHtml( 'ep-revision-undo' ),
                                        array(),
                                        array( 'revid' => $revision->getId() )
@@ -120,7 +120,7 @@
                        }
                        
                        $actionLinks[] = $object->getLink(
-                               'restore',
+                               'eprestore',
                                wfMsgHtml( 'ep-revision-restore' ),
                                array(),
                                array( 'revid' => $revision->getId() )

Modified: trunk/extensions/EducationProgram/pages/CoursePage.php
===================================================================
--- trunk/extensions/EducationProgram/pages/CoursePage.php      2012-02-26 
19:55:37 UTC (rev 112447)
+++ trunk/extensions/EducationProgram/pages/CoursePage.php      2012-02-26 
20:37:15 UTC (rev 112448)
@@ -14,14 +14,27 @@
  */
 class CoursePage extends EPPage {
        
-       protected function getActions() {
+       /**
+        * (non-PHPdoc)
+        * @see EPPage::getActions()
+        */
+       public function getActions() {
                return array(
                        'view' => 'ViewCourseAction',
                        'edit' => 'EditCourseAction',
                        'history' => 'CourseHistoryAction',
-                       'delete' => 'DeleteCourseAction',
+                       'delete' => 'EPDeleteAction',
                );
        }
        
+       /**
+        * (non-PHPdoc)
+        * @see EPPage::getActions()
+        * @return EPPageTable
+        */
+       public function getTable() {
+               return EPCourses::singleton();
+       }
+       
 }
 

Modified: trunk/extensions/EducationProgram/pages/EPPage.php
===================================================================
--- trunk/extensions/EducationProgram/pages/EPPage.php  2012-02-26 19:55:37 UTC 
(rev 112447)
+++ trunk/extensions/EducationProgram/pages/EPPage.php  2012-02-26 20:37:15 UTC 
(rev 112448)
@@ -1,7 +1,7 @@
 <?php
 
 /**
- * Abstract Page for interacting with a DBDataObject.
+ * Abstract Page for interacting with a EPPageObject.
  *
  * @since 0.1
  *
@@ -22,7 +22,16 @@
         *
         * @return array
         */
-       protected abstract function getActions();
+       public abstract function getActions();
+       
+       /**
+        * Returns an instance of the EPPageTable class for the EPPageObject 
being handled.
+        *
+        * @since 0.1
+        *
+        * @return EPPageTable
+        */
+       public abstract function getTable();
 
        /**
         * @since 0.1

Modified: trunk/extensions/EducationProgram/pages/OrgPage.php
===================================================================
--- trunk/extensions/EducationProgram/pages/OrgPage.php 2012-02-26 19:55:37 UTC 
(rev 112447)
+++ trunk/extensions/EducationProgram/pages/OrgPage.php 2012-02-26 20:37:15 UTC 
(rev 112448)
@@ -14,13 +14,26 @@
  */
 class OrgPage extends EPPage {
        
-       protected function getActions() {
+       /**
+        * (non-PHPdoc)
+        * @see EPPage::getActions()
+        */
+       public function getActions() {
                return array(
                        'view' => 'ViewOrgAction',
                        'edit' => 'EditOrgAction',
                        'history' => 'OrgHistoryAction',
-                       'delete' => 'DeleteOrgAction',
+                       'delete' => 'EPDeleteAction',
                );
        }
        
+       /**
+        * (non-PHPdoc)
+        * @see EPPage::getActions()
+        * @return EPPageTable
+        */
+       public function getTable() {
+               return EPOrgs::singleton();
+       }
+       
 }
\ No newline at end of file


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to