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

Revision: 113187
Author:   jeroendedauw
Date:     2012-03-06 22:21:38 +0000 (Tue, 06 Mar 2012)
Log Message:
-----------
work on default summary messages for undo and restore actions

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

Modified: trunk/extensions/EducationProgram/EducationProgram.i18n.php
===================================================================
--- trunk/extensions/EducationProgram/EducationProgram.i18n.php 2012-03-06 
22:17:34 UTC (rev 113186)
+++ trunk/extensions/EducationProgram/EducationProgram.i18n.php 2012-03-06 
22:21:38 UTC (rev 113187)
@@ -500,6 +500,7 @@
        'orgpage-eprestore-summary' => 'Reason for restoration:',
        'orgpage-eprestore-restore-button' => 'Restore revision',
        'orgpage-eprestore-cancel-button' => 'Cancel',
+       'orgpage-eprestore-summary-value' => 'Restore institution to the 
revision made on $1 by $2',
 
        // Course restoration
        'coursepage-eprestore-title' => 'Restore course "$1"',
@@ -507,6 +508,7 @@
        'coursepage-eprestore-summary' => 'Reason for restoration:',
        'coursepage-eprestore-restore-button' => 'Restore revision',
        'coursepage-eprestore-cancel-button' => 'Cancel',
+       'coursepage-eprestore-summary-value' => 'Restore course to the revision 
made on $1 by $2',
 
        // Institution undo revision
        'orgpage-epundo-title' => 'Undo revision of institution "$1"',
@@ -514,6 +516,7 @@
        'orgpage-epundo-summary' => 'Reason for revert:',
        'orgpage-epundo-undo-button' => 'Undo revision',
        'orgpage-epundo-cancel-button' => 'Cancel',
+       'orgpage-epundo-summary-value' => 'Undo revision made on $1 by $2',
 
        // Course undo revision
        'coursepage-epundo-title' => 'Undo revision of  course "$1"',
@@ -521,6 +524,7 @@
        'coursepage-epundo-summary' => 'Reason for revert:',
        'coursepage-epundo-undo-button' => 'Undo revision',
        'coursepage-epundo-cancel-button' => 'Cancel',
+       'coursepage-epundo-summary-value' => 'Undo revision made on $1 by $2',
 
        // Course undeletion
        'coursepage-epundelete-title' => 'Undelete course "$1"',

Modified: trunk/extensions/EducationProgram/actions/EPRestoreAction.php
===================================================================
--- trunk/extensions/EducationProgram/actions/EPRestoreAction.php       
2012-03-06 22:17:34 UTC (rev 113186)
+++ trunk/extensions/EducationProgram/actions/EPRestoreAction.php       
2012-03-06 22:21:38 UTC (rev 113187)
@@ -53,27 +53,33 @@
                }
                else {
                        $req = $this->getRequest();
-                       
-                       if ( $req->wasPosted() && 
$this->getUser()->matchEditToken( $req->getText( 'restoreToken' ), 
$this->getSalt() ) ) {
-                               if ( $req->getCheck( 'revid' ) ) {
-                                       $success = $this->doRestore( $object, 
$req->getInt( 'revid' ) );
+
+                       $success = false;
+
+                       if ( $req->getCheck( 'revid' ) ) {
+                               $revision = 
EPRevisions::singleton()->selectRow( null, array( 'id' => $req->getInt( 'revid' 
) ) );
+
+                               if ( $revision !== false ) {
+                                       if ( $req->wasPosted() && 
$this->getUser()->matchEditToken( $req->getText( 'restoreToken' ), 
$this->getSalt() ) ) {
+                                               $success = $this->doRestore( 
$object, $revision );
+                                       }
+                                       else {
+                                               $this->displayForm( $object, 
$revision );
+                                               $success = null;
+                                       }
                                }
-                               else {
-                                       $success = false;
-                               }
-                               
+                       }
+
+                       if ( !is_null( $success ) ) {
                                if ( $success ) {
                                        $query = array( 'restored' => '1' ); // 
TODO: handle
                                }
                                else {
                                        $query = array( 'restorefailed' => '1' 
); // TODO: handle
                                }
-                               
+
                                $this->getOutput()->redirect( 
$object->getTitle()->getLocalURL( $query ) );
                        }
-                       else {
-                               $this->displayForm( $object );
-                       }
                }
 
                return '';
@@ -85,12 +91,12 @@
         * @since 0.1
         *
         * @param EPPageObject $object
-        * @param integer $revId
+        * @param EPRevision $revision
         * 
         * @return boolean Success indicator
         */
-       protected function doRestore( EPPageObject $object, $revId ) {
-               $success = $object->restoreToRevisionId( $revId, 
$object->getTable()->getRevertableFields() );
+       protected function doRestore( EPPageObject $object, EPRevision 
$revision ) {
+               $success = $object->restoreToRevision( $revision, 
$object->getTable()->getRevertableFields() );
                
                if ( $success ) {
                        $revAction = new EPRevisionAction();
@@ -99,11 +105,6 @@
                        $revAction->setComment( $this->getRequest()->getText( 
'summary', '' ) );
                        
                        $success = $object->revisionedSave( $revAction );
-                       
-                       if ( $success ) {
-                               // TODO: log
-                               // Already logged - just alter message?
-                       }
                }
                
                return $success;
@@ -115,8 +116,9 @@
         * @since 0.1
         * 
         * @param EPPageObject $object
+        * @param EPRevision $revision
         */
-       protected function displayForm( EPPageObject $object ) {
+       protected function displayForm( EPPageObject $object, EPRevision 
$revision ) {
                $out = $this->getOutput();
 
                $out->addModules( 'ep.formpage' );
@@ -136,7 +138,12 @@
                        'summary',
                        'summary',
                        65,
-                       false,
+                       wfMsgExt(
+                               $this->prefixMsg( 'summary-value' ),
+                               'parsemag',
+                               $this->getLanguage()->timeanddate( 
$revision->getField( 'time' ) ),
+                               $revision->getUser()->getName()
+                       ),
                        array(
                                'maxlength' => 250,
                                'spellcheck' => true,

Modified: trunk/extensions/EducationProgram/actions/EPUndoAction.php
===================================================================
--- trunk/extensions/EducationProgram/actions/EPUndoAction.php  2012-03-06 
22:17:34 UTC (rev 113186)
+++ trunk/extensions/EducationProgram/actions/EPUndoAction.php  2012-03-06 
22:21:38 UTC (rev 113187)
@@ -53,27 +53,33 @@
                }
                else {
                        $req = $this->getRequest();
-                       
-                       if ( $req->wasPosted() && 
$this->getUser()->matchEditToken( $req->getText( 'undoToken' ), 
$this->getSalt() ) ) {
-                               if ( $req->getCheck( 'revid' ) ) {
-                                       $success = $this->doUndo( $object, 
$req->getInt( 'revid' ) );
+
+                       $success = false;
+
+                       if ( $req->getCheck( 'revid' ) ) {
+                               $revision = 
EPRevisions::singleton()->selectRow( null, array( 'id' => $req->getInt( 'revid' 
) ) );
+
+                               if ( $revision !== false ) {
+                                       if ( $req->wasPosted() && 
$this->getUser()->matchEditToken( $req->getText( 'undoToken' ), 
$this->getSalt() ) ) {
+                                               $success = $this->doUndo( 
$object, $revision );
+                                       }
+                                       else {
+                                               $this->displayForm( $object, 
$revision );
+                                               $success = null;
+                                       }
                                }
-                               else {
-                                       $success = false;
-                               }
+                       }
 
+                       if ( !is_null( $success ) ) {
                                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 '';
@@ -85,12 +91,12 @@
         * @since 0.1
         * 
         * @param EPPageObject $object
-        * @param integer $revId
+        * @param EPRevision $revision
         * 
         * @return boolean Success indicator
         */
-       protected function doUndo( EPPageObject $object, $revId ) {
-               $success = $object->undoRevisionId( $revId, 
$object->getTable()->getRevertableFields() );
+       protected function doUndo( EPPageObject $object, EPRevision $revision ) 
{
+               $success = $object->undoRevision( $revision, 
$object->getTable()->getRevertableFields() );
 
                if ( $success ) {
                        $revAction = new EPRevisionAction();
@@ -99,14 +105,9 @@
                        $revAction->setComment( $this->getRequest()->getText( 
'summary', '' ) );
 
                        $success = $object->revisionedSave( $revAction );
+               }
 
-                       if ( $success ) {
-                               // TODO: log
-                               // Already logged - just alter message?
-                       }
-               }
-               
-               return false;
+               return $success;
        }
 
        /**
@@ -115,8 +116,9 @@
         * @since 0.1
         * 
         * @param EPPageObject $object
+        * @param EPRevision $revision
         */
-       protected function displayForm( EPPageObject $object ) {
+       protected function displayForm( EPPageObject $object, EPRevision 
$revision ) {
                $out = $this->getOutput();
 
                $out->addModules( 'ep.formpage' );
@@ -136,7 +138,12 @@
                        'summary',
                        'summary',
                        65,
-                       false,
+                       wfMsgExt(
+                               $this->prefixMsg( 'summary-value' ),
+                               'parsemag',
+                               $this->getLanguage()->timeanddate( 
$revision->getField( 'time' ) ),
+                               $revision->getUser()->getName()
+                       ),
                        array(
                                'maxlength' => 250,
                                'spellcheck' => true,


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

Reply via email to