r113187 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r113186‎ | r113187 | r113188 >
Date:22:21, 6 March 2012
Author:jeroendedauw
Status:deferred
Tags:
Comment:
work on default summary messages for undo and restore actions
Modified paths:
  • /trunk/extensions/EducationProgram/EducationProgram.i18n.php (modified) (history)
  • /trunk/extensions/EducationProgram/actions/EPRestoreAction.php (modified) (history)
  • /trunk/extensions/EducationProgram/actions/EPUndoAction.php (modified) (history)

Diff [purge]

Index: trunk/extensions/EducationProgram/actions/EPRestoreAction.php
@@ -53,27 +53,33 @@
5454 }
5555 else {
5656 $req = $this->getRequest();
57 -
58 - if ( $req->wasPosted() && $this->getUser()->matchEditToken( $req->getText( 'restoreToken' ), $this->getSalt() ) ) {
59 - if ( $req->getCheck( 'revid' ) ) {
60 - $success = $this->doRestore( $object, $req->getInt( 'revid' ) );
 57+
 58+ $success = false;
 59+
 60+ if ( $req->getCheck( 'revid' ) ) {
 61+ $revision = EPRevisions::singleton()->selectRow( null, array( 'id' => $req->getInt( 'revid' ) ) );
 62+
 63+ if ( $revision !== false ) {
 64+ if ( $req->wasPosted() && $this->getUser()->matchEditToken( $req->getText( 'restoreToken' ), $this->getSalt() ) ) {
 65+ $success = $this->doRestore( $object, $revision );
 66+ }
 67+ else {
 68+ $this->displayForm( $object, $revision );
 69+ $success = null;
 70+ }
6171 }
62 - else {
63 - $success = false;
64 - }
65 -
 72+ }
 73+
 74+ if ( !is_null( $success ) ) {
6675 if ( $success ) {
6776 $query = array( 'restored' => '1' ); // TODO: handle
6877 }
6978 else {
7079 $query = array( 'restorefailed' => '1' ); // TODO: handle
7180 }
72 -
 81+
7382 $this->getOutput()->redirect( $object->getTitle()->getLocalURL( $query ) );
7483 }
75 - else {
76 - $this->displayForm( $object );
77 - }
7884 }
7985
8086 return '';
@@ -85,12 +91,12 @@
8692 * @since 0.1
8793 *
8894 * @param EPPageObject $object
89 - * @param integer $revId
 95+ * @param EPRevision $revision
9096 *
9197 * @return boolean Success indicator
9298 */
93 - protected function doRestore( EPPageObject $object, $revId ) {
94 - $success = $object->restoreToRevisionId( $revId, $object->getTable()->getRevertableFields() );
 99+ protected function doRestore( EPPageObject $object, EPRevision $revision ) {
 100+ $success = $object->restoreToRevision( $revision, $object->getTable()->getRevertableFields() );
95101
96102 if ( $success ) {
97103 $revAction = new EPRevisionAction();
@@ -99,11 +105,6 @@
100106 $revAction->setComment( $this->getRequest()->getText( 'summary', '' ) );
101107
102108 $success = $object->revisionedSave( $revAction );
103 -
104 - if ( $success ) {
105 - // TODO: log
106 - // Already logged - just alter message?
107 - }
108109 }
109110
110111 return $success;
@@ -115,8 +116,9 @@
116117 * @since 0.1
117118 *
118119 * @param EPPageObject $object
 120+ * @param EPRevision $revision
119121 */
120 - protected function displayForm( EPPageObject $object ) {
 122+ protected function displayForm( EPPageObject $object, EPRevision $revision ) {
121123 $out = $this->getOutput();
122124
123125 $out->addModules( 'ep.formpage' );
@@ -136,7 +138,12 @@
137139 'summary',
138140 'summary',
139141 65,
140 - false,
 142+ wfMsgExt(
 143+ $this->prefixMsg( 'summary-value' ),
 144+ 'parsemag',
 145+ $this->getLanguage()->timeanddate( $revision->getField( 'time' ) ),
 146+ $revision->getUser()->getName()
 147+ ),
141148 array(
142149 'maxlength' => 250,
143150 'spellcheck' => true,
Index: trunk/extensions/EducationProgram/actions/EPUndoAction.php
@@ -53,27 +53,33 @@
5454 }
5555 else {
5656 $req = $this->getRequest();
57 -
58 - if ( $req->wasPosted() && $this->getUser()->matchEditToken( $req->getText( 'undoToken' ), $this->getSalt() ) ) {
59 - if ( $req->getCheck( 'revid' ) ) {
60 - $success = $this->doUndo( $object, $req->getInt( 'revid' ) );
 57+
 58+ $success = false;
 59+
 60+ if ( $req->getCheck( 'revid' ) ) {
 61+ $revision = EPRevisions::singleton()->selectRow( null, array( 'id' => $req->getInt( 'revid' ) ) );
 62+
 63+ if ( $revision !== false ) {
 64+ if ( $req->wasPosted() && $this->getUser()->matchEditToken( $req->getText( 'undoToken' ), $this->getSalt() ) ) {
 65+ $success = $this->doUndo( $object, $revision );
 66+ }
 67+ else {
 68+ $this->displayForm( $object, $revision );
 69+ $success = null;
 70+ }
6171 }
62 - else {
63 - $success = false;
64 - }
 72+ }
6573
 74+ if ( !is_null( $success ) ) {
6675 if ( $success ) {
6776 $query = array( 'undid' => '1' ); // TODO: handle
6877 }
6978 else {
7079 $query = array( 'undofailed' => '1' ); // TODO: handle
7180 }
72 -
 81+
7382 $this->getOutput()->redirect( $object->getTitle()->getLocalURL( $query ) );
7483 }
75 - else {
76 - $this->displayForm( $object );
77 - }
7884 }
7985
8086 return '';
@@ -85,12 +91,12 @@
8692 * @since 0.1
8793 *
8894 * @param EPPageObject $object
89 - * @param integer $revId
 95+ * @param EPRevision $revision
9096 *
9197 * @return boolean Success indicator
9298 */
93 - protected function doUndo( EPPageObject $object, $revId ) {
94 - $success = $object->undoRevisionId( $revId, $object->getTable()->getRevertableFields() );
 99+ protected function doUndo( EPPageObject $object, EPRevision $revision ) {
 100+ $success = $object->undoRevision( $revision, $object->getTable()->getRevertableFields() );
95101
96102 if ( $success ) {
97103 $revAction = new EPRevisionAction();
@@ -99,14 +105,9 @@
100106 $revAction->setComment( $this->getRequest()->getText( 'summary', '' ) );
101107
102108 $success = $object->revisionedSave( $revAction );
 109+ }
103110
104 - if ( $success ) {
105 - // TODO: log
106 - // Already logged - just alter message?
107 - }
108 - }
109 -
110 - return false;
 111+ return $success;
111112 }
112113
113114 /**
@@ -115,8 +116,9 @@
116117 * @since 0.1
117118 *
118119 * @param EPPageObject $object
 120+ * @param EPRevision $revision
119121 */
120 - protected function displayForm( EPPageObject $object ) {
 122+ protected function displayForm( EPPageObject $object, EPRevision $revision ) {
121123 $out = $this->getOutput();
122124
123125 $out->addModules( 'ep.formpage' );
@@ -136,7 +138,12 @@
137139 'summary',
138140 'summary',
139141 65,
140 - false,
 142+ wfMsgExt(
 143+ $this->prefixMsg( 'summary-value' ),
 144+ 'parsemag',
 145+ $this->getLanguage()->timeanddate( $revision->getField( 'time' ) ),
 146+ $revision->getUser()->getName()
 147+ ),
141148 array(
142149 'maxlength' => 250,
143150 'spellcheck' => true,
Index: trunk/extensions/EducationProgram/EducationProgram.i18n.php
@@ -500,6 +500,7 @@
501501 'orgpage-eprestore-summary' => 'Reason for restoration:',
502502 'orgpage-eprestore-restore-button' => 'Restore revision',
503503 'orgpage-eprestore-cancel-button' => 'Cancel',
 504+ 'orgpage-eprestore-summary-value' => 'Restore institution to the revision made on $1 by $2',
504505
505506 // Course restoration
506507 'coursepage-eprestore-title' => 'Restore course "$1"',
@@ -507,6 +508,7 @@
508509 'coursepage-eprestore-summary' => 'Reason for restoration:',
509510 'coursepage-eprestore-restore-button' => 'Restore revision',
510511 'coursepage-eprestore-cancel-button' => 'Cancel',
 512+ 'coursepage-eprestore-summary-value' => 'Restore course to the revision made on $1 by $2',
511513
512514 // Institution undo revision
513515 'orgpage-epundo-title' => 'Undo revision of institution "$1"',
@@ -514,6 +516,7 @@
515517 'orgpage-epundo-summary' => 'Reason for revert:',
516518 'orgpage-epundo-undo-button' => 'Undo revision',
517519 'orgpage-epundo-cancel-button' => 'Cancel',
 520+ 'orgpage-epundo-summary-value' => 'Undo revision made on $1 by $2',
518521
519522 // Course undo revision
520523 'coursepage-epundo-title' => 'Undo revision of course "$1"',
@@ -521,6 +524,7 @@
522525 'coursepage-epundo-summary' => 'Reason for revert:',
523526 'coursepage-epundo-undo-button' => 'Undo revision',
524527 'coursepage-epundo-cancel-button' => 'Cancel',
 528+ 'coursepage-epundo-summary-value' => 'Undo revision made on $1 by $2',
525529
526530 // Course undeletion
527531 'coursepage-epundelete-title' => 'Undelete course "$1"',

Status & tagging log