r112448 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r112447‎ | r112448 | r112449 >
Date:20:37, 26 February 2012
Author:jeroendedauw
Status:deferred
Tags:
Comment:
initial work on undo and restore actions and some refactoring
Modified paths:
  • /trunk/extensions/EducationProgram/EducationProgram.hooks.php (modified) (history)
  • /trunk/extensions/EducationProgram/EducationProgram.i18n.php (modified) (history)
  • /trunk/extensions/EducationProgram/EducationProgram.php (modified) (history)
  • /trunk/extensions/EducationProgram/actions/DeleteCourseAction.php (deleted) (history)
  • /trunk/extensions/EducationProgram/actions/DeleteOrgAction.php (deleted) (history)
  • /trunk/extensions/EducationProgram/actions/EPDeleteAction.php (modified) (history)
  • /trunk/extensions/EducationProgram/actions/EPEditAction.php (modified) (history)
  • /trunk/extensions/EducationProgram/actions/EPRestoreAction.php (added) (history)
  • /trunk/extensions/EducationProgram/actions/EPUndoAction.php (added) (history)
  • /trunk/extensions/EducationProgram/actions/EPViewAction.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPRevisionPager.php (modified) (history)
  • /trunk/extensions/EducationProgram/pages/CoursePage.php (modified) (history)
  • /trunk/extensions/EducationProgram/pages/EPPage.php (modified) (history)
  • /trunk/extensions/EducationProgram/pages/OrgPage.php (modified) (history)

Diff [purge]

Index: trunk/extensions/EducationProgram/EducationProgram.php
@@ -60,8 +60,8 @@
6161 $wgAutoloadClasses['EPSettings'] = dirname( __FILE__ ) . '/EducationProgram.settings.php';
6262
6363 $wgAutoloadClasses['CourseHistoryAction'] = dirname( __FILE__ ) . '/actions/CourseHistoryAction.php';
64 -$wgAutoloadClasses['DeleteCourseAction'] = dirname( __FILE__ ) . '/actions/DeleteCourseAction.php';
65 -$wgAutoloadClasses['DeleteOrgAction'] = dirname( __FILE__ ) . '/actions/DeleteOrgAction.php';
 64+//$wgAutoloadClasses['DeleteCourseAction'] = dirname( __FILE__ ) . '/actions/DeleteCourseAction.php';
 65+//$wgAutoloadClasses['DeleteOrgAction'] = dirname( __FILE__ ) . '/actions/DeleteOrgAction.php';
6666 $wgAutoloadClasses['EditCourseAction'] = dirname( __FILE__ ) . '/actions/EditCourseAction.php';
6767 $wgAutoloadClasses['EditOrgAction'] = dirname( __FILE__ ) . '/actions/EditOrgAction.php';
6868 $wgAutoloadClasses['EPAddArticleAction'] = dirname( __FILE__ ) . '/actions/EPAddArticleAction.php';
@@ -72,10 +72,16 @@
7373 $wgAutoloadClasses['EPRemoveArticleAction'] = dirname( __FILE__ ) . '/actions/EPRemoveArticleAction.php';
7474 $wgAutoloadClasses['EPRemoveReviewerAction'] = dirname( __FILE__ ) . '/actions/EPRemoveReviewerAction.php';
7575 $wgAutoloadClasses['EPRemoveStudentAction'] = dirname( __FILE__ ) . '/actions/EPRemoveStudentAction.php';
 76+$wgAutoloadClasses['EPRestoreAction'] = dirname( __FILE__ ) . '/actions/EPRestoreAction.php';
 77+$wgAutoloadClasses['EPUndoAction'] = dirname( __FILE__ ) . '/actions/EPUndoAction.php';
7678 $wgAutoloadClasses['EPViewAction'] = dirname( __FILE__ ) . '/actions/EPViewAction.php';
7779 $wgAutoloadClasses['OrgHistoryAction'] = dirname( __FILE__ ) . '/actions/OrgHistoryAction.php';
7880 $wgAutoloadClasses['ViewCourseAction'] = dirname( __FILE__ ) . '/actions/ViewCourseAction.php';
7981 $wgAutoloadClasses['ViewOrgAction'] = dirname( __FILE__ ) . '/actions/ViewOrgAction.php';
 82+//$wgAutoloadClasses['CourseUndoAction'] = dirname( __FILE__ ) . '/actions/CourseUndoAction.php';
 83+//$wgAutoloadClasses['OrgUndoAction'] = dirname( __FILE__ ) . '/actions/OrgUndoAction.php';
 84+//$wgAutoloadClasses['CourseRestoreAction'] = dirname( __FILE__ ) . '/actions/CourseRestoreAction.php';
 85+//$wgAutoloadClasses['OrgRestoreAction'] = dirname( __FILE__ ) . '/actions/OrgRestoreAction.php';
8086
8187 $wgAutoloadClasses['ApiDeleteEducation'] = dirname( __FILE__ ) . '/api/ApiDeleteEducation.php';
8288 $wgAutoloadClasses['ApiEnlist'] = dirname( __FILE__ ) . '/api/ApiEnlist.php';
@@ -193,6 +199,7 @@
194200 $wgHooks['ArticleFromTitle'][] = 'EPHooks::onArticleFromTitle';
195201 $wgHooks['CanonicalNamespaces'][] = 'EPHooks::onCanonicalNamespaces';
196202 $wgHooks['TitleIsAlwaysKnown'][] = 'EPHooks::onTitleIsAlwaysKnown';
 203+//$wgHooks['UnknownAction'][] = 'EPHooks::onUnknownAction';
197204
198205 // Actions
199206 $wgActions['epremarticle'] = 'EPRemoveArticleAction';
@@ -200,6 +207,8 @@
201208 $wgActions['epremreviewer'] = 'EPRemoveReviewerAction';
202209 $wgActions['epaddarticle'] = 'EPAddArticleAction';
203210 $wgActions['epaddreviewer'] = 'EPAddReviewerAction';
 211+$wgActions['epundo'] = 'EPUndoAction';
 212+$wgActions['eprestore'] = 'EPRestoreAction';
204213
205214 // Logging
206215 $wgLogTypes[] = 'institution';
Index: trunk/extensions/EducationProgram/pages/CoursePage.php
@@ -14,14 +14,27 @@
1515 */
1616 class CoursePage extends EPPage {
1717
18 - protected function getActions() {
 18+ /**
 19+ * (non-PHPdoc)
 20+ * @see EPPage::getActions()
 21+ */
 22+ public function getActions() {
1923 return array(
2024 'view' => 'ViewCourseAction',
2125 'edit' => 'EditCourseAction',
2226 'history' => 'CourseHistoryAction',
23 - 'delete' => 'DeleteCourseAction',
 27+ 'delete' => 'EPDeleteAction',
2428 );
2529 }
2630
 31+ /**
 32+ * (non-PHPdoc)
 33+ * @see EPPage::getActions()
 34+ * @return EPPageTable
 35+ */
 36+ public function getTable() {
 37+ return EPCourses::singleton();
 38+ }
 39+
2740 }
2841
Index: trunk/extensions/EducationProgram/pages/EPPage.php
@@ -1,7 +1,7 @@
22 <?php
33
44 /**
5 - * Abstract Page for interacting with a DBDataObject.
 5+ * Abstract Page for interacting with a EPPageObject.
66 *
77 * @since 0.1
88 *
@@ -22,7 +22,16 @@
2323 *
2424 * @return array
2525 */
26 - protected abstract function getActions();
 26+ public abstract function getActions();
 27+
 28+ /**
 29+ * Returns an instance of the EPPageTable class for the EPPageObject being handled.
 30+ *
 31+ * @since 0.1
 32+ *
 33+ * @return EPPageTable
 34+ */
 35+ public abstract function getTable();
2736
2837 /**
2938 * @since 0.1
Index: trunk/extensions/EducationProgram/pages/OrgPage.php
@@ -14,13 +14,26 @@
1515 */
1616 class OrgPage extends EPPage {
1717
18 - protected function getActions() {
 18+ /**
 19+ * (non-PHPdoc)
 20+ * @see EPPage::getActions()
 21+ */
 22+ public function getActions() {
1923 return array(
2024 'view' => 'ViewOrgAction',
2125 'edit' => 'EditOrgAction',
2226 'history' => 'OrgHistoryAction',
23 - 'delete' => 'DeleteOrgAction',
 27+ 'delete' => 'EPDeleteAction',
2428 );
2529 }
2630
 31+ /**
 32+ * (non-PHPdoc)
 33+ * @see EPPage::getActions()
 34+ * @return EPPageTable
 35+ */
 36+ public function getTable() {
 37+ return EPOrgs::singleton();
 38+ }
 39+
2740 }
\ No newline at end of file
Index: trunk/extensions/EducationProgram/actions/DeleteOrgAction.php
@@ -1,37 +0,0 @@
2 -<?php
3 -
4 -/**
5 - * Page for deleting an institution.
6 - *
7 - * @since 0.1
8 - *
9 - * @file DeleteOrgAction.php
10 - * @ingroup EducationProgram
11 - * @ingroup Action
12 - *
13 - * @licence GNU GPL v3+
14 - * @author Jeroen De Dauw < jeroendedauw@gmail.com >
15 - */
16 -class DeleteOrgAction extends EPDeleteAction {
17 -
18 - /**
19 - * Constructor.
20 - *
21 - * @since 0.1
22 - *
23 - * @param Page $page
24 - * @param IContextSource $context
25 - */
26 - protected function __construct( Page $page, IContextSource $context = null ) {
27 - parent::__construct( $page, $context, EPOrgs::singleton() );
28 - }
29 -
30 - public function getName() {
31 - return 'deleteorg';
32 - }
33 -
34 - public function getRestriction() {
35 - return 'ep-org';
36 - }
37 -
38 -}
\ No newline at end of file
Index: trunk/extensions/EducationProgram/actions/DeleteCourseAction.php
@@ -1,37 +0,0 @@
2 -<?php
3 -
4 -/**
5 - * Page for deleting a course.
6 - *
7 - * @since 0.1
8 - *
9 - * @file DeleteCourseAction.php
10 - * @ingroup EducationProgram
11 - * @ingroup Action
12 - *
13 - * @licence GNU GPL v3+
14 - * @author Jeroen De Dauw < jeroendedauw@gmail.com >
15 - */
16 -class DeleteCourseAction extends EPDeleteAction {
17 -
18 - /**
19 - * Constructor.
20 - *
21 - * @since 0.1
22 - *
23 - * @param Page $page
24 - * @param IContextSource $context
25 - */
26 - protected function __construct( Page $page, IContextSource $context = null ) {
27 - parent::__construct( $page, $context, EPCourses::singleton() );
28 - }
29 -
30 - public function getName() {
31 - return 'deletecourse';
32 - }
33 -
34 - public function getRestriction() {
35 - return 'ep-course';
36 - }
37 -
38 -}
\ No newline at end of file
Index: trunk/extensions/EducationProgram/actions/EPViewAction.php
@@ -16,7 +16,7 @@
1717
1818 /**
1919 * @since 0.1
20 - * @var DBTable
 20+ * @var EPPageTable
2121 */
2222 protected $table;
2323
@@ -29,7 +29,7 @@
3030 * @param IContextSource $context
3131 * @param DBTable $table
3232 */
33 - protected function __construct( Page $page, IContextSource $context = null, DBTable $table ) {
 33+ protected function __construct( Page $page, IContextSource $context = null, EPPageTable $table ) {
3434 $this->table = $table;
3535 parent::__construct( $page, $context );
3636 }
Index: trunk/extensions/EducationProgram/actions/EPRestoreAction.php
@@ -0,0 +1,184 @@
 2+<?php
 3+
 4+/**
 5+ * Abstract action for restoring an EPPageObject to a previous revision.
 6+ *
 7+ * @since 0.1
 8+ *
 9+ * @file EPRestoreAction.php
 10+ * @ingroup EducationProgram
 11+ * @ingroup Action
 12+ *
 13+ * @licence GNU GPL v3+
 14+ * @author Jeroen De Dauw < jeroendedauw@gmail.com >
 15+ */
 16+abstract class EPRestoreAction extends FormlessAction {
 17+
 18+ /**
 19+ * (non-PHPdoc)
 20+ * @see Action::getName()
 21+ */
 22+ public function getName() {
 23+ return 'eprestore';
 24+ }
 25+
 26+ /**
 27+ * (non-PHPdoc)
 28+ * @see Action::getDescription()
 29+ */
 30+ protected function getDescription() {
 31+ return $this->msg( 'backlinksubtitle' )->rawParams( Linker::link( $this->getTitle() ) );
 32+ }
 33+
 34+ /**
 35+ * (non-PHPdoc)
 36+ * @see FormlessAction::onView()
 37+ */
 38+ public function onView() {
 39+ $this->getOutput()->setPageTitle( $this->getPageTitle() );
 40+
 41+ $object = $this->page->getTable()->get( $this->getTitle()->getText() );
 42+
 43+ if ( $object === false ) {
 44+ $this->getOutput()->addWikiMsg( $this->prefixMsg( 'none' ), $this->getTitle()->getText() );
 45+ $this->getOutput()->setSubtitle( '' );
 46+ }
 47+ else {
 48+ $req = $this->getRequest();
 49+
 50+ if ( $req->wasPosted() && $this->getUser()->matchEditToken( $req->getText( 'restoreToken' ), $this->getSalt() ) ) {
 51+ $success = $this->doRestore( $object );
 52+
 53+ if ( $success ) {
 54+ $query = array( 'restored' => '1' ); // TODO: handle
 55+ }
 56+ else {
 57+ $query = array( 'delfailed' => '1' ); // TODO: handle
 58+ }
 59+
 60+ $this->getOutput()->redirect( $object->getTitle()->getLocalURL( $query ) );
 61+ }
 62+ else {
 63+ $this->displayForm( $object );
 64+ }
 65+ }
 66+
 67+ return '';
 68+ }
 69+
 70+ /**
 71+ * Does the actual restore action.
 72+ *
 73+ * @since 0.1
 74+ *
 75+ * @return boolean Success indicator
 76+ */
 77+ protected function doRestore( EPPageObject $object ) {
 78+ $revAction = new EPRevisionAction();
 79+
 80+ $revAction->setUser( $this->getUser() );
 81+ $revAction->setComment( $this->getRequest()->getText( 'summary', '' ) );
 82+
 83+ // TODO
 84+
 85+ return false;
 86+ }
 87+
 88+ /**
 89+ * Display the restoration form for the provided EPPageObject.
 90+ *
 91+ * @since 0.1
 92+ *
 93+ * @param EPPageObject $object
 94+ */
 95+ protected function displayForm( EPPageObject $object ) {
 96+ $out = $this->getOutput();
 97+
 98+ $out->addWikiMsg( $this->prefixMsg( 'text' ), $object->getField( 'name' ) );
 99+
 100+ $out->addHTML( Html::openElement(
 101+ 'form',
 102+ array(
 103+ 'method' => 'post',
 104+ 'action' => $this->getTitle()->getLocalURL( array( 'action' => 'restore' ) ),
 105+ )
 106+ ) );
 107+
 108+ $out->addHTML( '&#160;' . Xml::inputLabel(
 109+ wfMsg( $this->prefixMsg( 'summary' ) ),
 110+ 'summary',
 111+ 'summary',
 112+ 65,
 113+ false,
 114+ array(
 115+ 'maxlength' => 250,
 116+ 'spellcheck' => true,
 117+ )
 118+ ) );
 119+
 120+ $out->addHTML( '<br />' );
 121+
 122+ $out->addHTML( Html::input(
 123+ 'restore',
 124+ wfMsg( $this->prefixMsg( 'restore-button' ) ),
 125+ 'submit',
 126+ array(
 127+ 'class' => 'ep-restore',
 128+ )
 129+ ) );
 130+
 131+ $out->addElement(
 132+ 'button',
 133+ array(
 134+ 'id' => 'cancelRestore',
 135+ 'class' => 'ep-restore-cancel ep-cancel',
 136+ 'target-url' => $this->getTitle()->getLocalURL(),
 137+ ),
 138+ wfMsg( $this->prefixMsg( 'cancel-button' ) )
 139+ );
 140+
 141+ $out->addHTML( Html::hidden( 'restoreToken', $this->getUser()->getEditToken( $this->getSalt() ) ) );
 142+
 143+ $out->addHTML( '</form>' );
 144+ }
 145+
 146+ /**
 147+ * Returns a salt based on the action and the page name.
 148+ *
 149+ * @since 0.1
 150+ *
 151+ * @return string
 152+ */
 153+ protected function getSalt() {
 154+ return 'restore' . $this->getTitle()->getLocalURL();
 155+ }
 156+
 157+ /**
 158+ * Returns a prefixed message name.
 159+ *
 160+ * @since 0.1
 161+ *
 162+ * @param string $name
 163+ *
 164+ * @return string
 165+ */
 166+ protected function prefixMsg( $name ) {
 167+ return strtolower( get_class( $this->page ) ) . '-' . $this->getName() . '-' . $name;
 168+ }
 169+
 170+ /**
 171+ * Returns the page title.
 172+ *
 173+ * @since 0.1
 174+ *
 175+ * @return string
 176+ */
 177+ protected function getPageTitle() {
 178+ return wfMsgExt(
 179+ $this->prefixMsg( 'title' ),
 180+ 'parsemag',
 181+ $this->getTitle()->getText()
 182+ );
 183+ }
 184+
 185+}
\ No newline at end of file
Property changes on: trunk/extensions/EducationProgram/actions/EPRestoreAction.php
___________________________________________________________________
Added: svn:eol-style
1186 + native
Index: trunk/extensions/EducationProgram/actions/EPEditAction.php
@@ -32,7 +32,7 @@
3333
3434 /**
3535 * @since 0.1
36 - * @var DBTable
 36+ * @var EPPageTable
3737 */
3838 protected $table;
3939
@@ -45,7 +45,7 @@
4646 * @param IContextSource $context
4747 * @param DBTable $table
4848 */
49 - protected function __construct( Page $page, IContextSource $context = null, DBTable $table ) {
 49+ protected function __construct( Page $page, IContextSource $context = null, EPPageTable $table ) {
5050 $this->table = $table;
5151 parent::__construct( $page, $context );
5252 }
@@ -247,6 +247,7 @@
248248 'cancelEdit',
249249 array(
250250 'target-url' => $this->getReturnToTitle()->getFullURL(),
 251+ 'class' => 'ep-cancel',
251252 )
252253 );
253254
Index: trunk/extensions/EducationProgram/actions/EPDeleteAction.php
@@ -1,7 +1,7 @@
22 <?php
33
44 /**
5 - * Abstract action for deleting EPPageObject items.
 5+ * Action for deleting EPPageObject items.
66 *
77 * @since 0.1
88 *
@@ -12,29 +12,16 @@
1313 * @licence GNU GPL v3+
1414 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
1515 */
16 -abstract class EPDeleteAction extends FormlessAction {
 16+class EPDeleteAction extends FormlessAction {
1717
1818 /**
19 - * @since 0.1
20 - * @var DBTable
 19+ * (non-PHPdoc)
 20+ * @see Action::getName()
2121 */
22 - protected $table;
23 -
24 - /**
25 - * Constructor.
26 - *
27 - * @since 0.1
28 - *
29 - * @param Page $page
30 - * @param IContextSource $context
31 - * @param DBTable $table
32 - */
33 - protected function __construct( Page $page, IContextSource $context = null, DBTable $table ) {
34 - $this->table = $table;
35 - parent::__construct( $page, $context );
36 - $this->getOutput()->addModules( 'ep.formpage' );
 22+ public function getName() {
 23+ return 'delete';
3724 }
38 -
 25+
3926 /**
4027 * (non-PHPdoc)
4128 * @see Action::getDescription()
@@ -42,6 +29,14 @@
4330 protected function getDescription() {
4431 return $this->msg( 'backlinksubtitle' )->rawParams( Linker::link( $this->getTitle() ) );
4532 }
 33+
 34+ /**
 35+ * (non-PHPdoc)
 36+ * @see Action::getRestriction()
 37+ */
 38+ public function getRestriction() {
 39+ $this->page->getTable()->getEditRight();
 40+ }
4641
4742 /**
4843 * (non-PHPdoc)
@@ -50,7 +45,7 @@
5146 public function onView() {
5247 $this->getOutput()->setPageTitle( $this->getPageTitle() );
5348
54 - $object = $this->table->get( $this->getTitle()->getText() );
 49+ $object = $this->page->getTable()->get( $this->getTitle()->getText() );
5550
5651 if ( $object === false ) {
5752 $this->getOutput()->addWikiMsg( $this->prefixMsg( 'none' ), $this->getTitle()->getText() );
@@ -107,6 +102,8 @@
108103 */
109104 protected function displayForm( EPPageObject $object ) {
110105 $out = $this->getOutput();
 106+
 107+ $out->addModules( 'ep.formpage' );
111108
112109 $out->addWikiMsg( $this->prefixMsg( 'text' ), $object->getField( 'name' ) );
113110
@@ -137,7 +134,7 @@
138135 wfMsg( $this->prefixMsg( 'delete-button' ) ),
139136 'submit',
140137 array(
141 - 'class' => 'ep-disenroll',
 138+ 'class' => 'ep-delete',
142139 )
143140 ) );
144141
@@ -145,7 +142,7 @@
146143 'button',
147144 array(
148145 'id' => 'cancelDelete',
149 - 'class' => 'ep-delete-cancel',
 146+ 'class' => 'ep-delete-cancel ep-cancel',
150147 'target-url' => $this->getTitle()->getLocalURL(),
151148 ),
152149 wfMsg( $this->prefixMsg( 'cancel-button' ) )
@@ -156,6 +153,13 @@
157154 $out->addHTML( '</form>' );
158155 }
159156
 157+ /**
 158+ * Returns a salt based on the action and the page name.
 159+ *
 160+ * @since 0.1
 161+ *
 162+ * @return string
 163+ */
160164 protected function getSalt() {
161165 return 'delete' . $this->getTitle()->getLocalURL();
162166 }
@@ -170,7 +174,7 @@
171175 * @return string
172176 */
173177 protected function prefixMsg( $name ) {
174 - return strtolower( get_called_class() ) . '-' . $name;
 178+ return strtolower( get_class( $this->page ) ) . '-' . $this->getName() . '-' . $name;
175179 }
176180
177181 /**
Index: trunk/extensions/EducationProgram/actions/EPUndoAction.php
@@ -0,0 +1,184 @@
 2+<?php
 3+
 4+/**
 5+ * Abstract action for undoing a change to an EPPageObject.
 6+ *
 7+ * @since 0.1
 8+ *
 9+ * @file EPUndoAction.php
 10+ * @ingroup EducationProgram
 11+ * @ingroup Action
 12+ *
 13+ * @licence GNU GPL v3+
 14+ * @author Jeroen De Dauw < jeroendedauw@gmail.com >
 15+ */
 16+class EPUndoAction extends FormlessAction {
 17+
 18+ /**
 19+ * (non-PHPdoc)
 20+ * @see Action::getName()
 21+ */
 22+ public function getName() {
 23+ return 'epundo';
 24+ }
 25+
 26+ /**
 27+ * (non-PHPdoc)
 28+ * @see Action::getDescription()
 29+ */
 30+ protected function getDescription() {
 31+ return $this->msg( 'backlinksubtitle' )->rawParams( Linker::link( $this->getTitle() ) );
 32+ }
 33+
 34+ /**
 35+ * (non-PHPdoc)
 36+ * @see FormlessAction::onView()
 37+ */
 38+ public function onView() {
 39+ $this->getOutput()->setPageTitle( $this->getPageTitle() );
 40+
 41+ $object = $this->page->getTable()->get( $this->getTitle()->getText() );
 42+
 43+ if ( $object === false ) {
 44+ $this->getOutput()->addWikiMsg( $this->prefixMsg( 'none' ), $this->getTitle()->getText() );
 45+ $this->getOutput()->setSubtitle( '' );
 46+ }
 47+ else {
 48+ $req = $this->getRequest();
 49+
 50+ if ( $req->wasPosted() && $this->getUser()->matchEditToken( $req->getText( 'undoToken' ), $this->getSalt() ) ) {
 51+ $success = $this->doUndo( $object );
 52+
 53+ if ( $success ) {
 54+ $query = array( 'undid' => '1' ); // TODO: handle
 55+ }
 56+ else {
 57+ $query = array( 'undofailed' => '1' ); // TODO: handle
 58+ }
 59+
 60+ $this->getOutput()->redirect( $object->getTitle()->getLocalURL( $query ) );
 61+ }
 62+ else {
 63+ $this->displayForm( $object );
 64+ }
 65+ }
 66+
 67+ return '';
 68+ }
 69+
 70+ /**
 71+ * Does the actual undo action.
 72+ *
 73+ * @since 0.1
 74+ *
 75+ * @return boolean Success indicator
 76+ */
 77+ protected function doUndo( EPPageObject $object ) {
 78+ $revAction = new EPRevisionAction();
 79+
 80+ $revAction->setUser( $this->getUser() );
 81+ $revAction->setComment( $this->getRequest()->getText( 'summary', '' ) );
 82+
 83+ // TODO
 84+
 85+ return false;
 86+ }
 87+
 88+ /**
 89+ * Display the restoration form for the provided EPPageObject.
 90+ *
 91+ * @since 0.1
 92+ *
 93+ * @param EPPageObject $object
 94+ */
 95+ protected function displayForm( EPPageObject $object ) {
 96+ $out = $this->getOutput();
 97+
 98+ $out->addWikiMsg( $this->prefixMsg( 'text' ), $object->getField( 'name' ) );
 99+
 100+ $out->addHTML( Html::openElement(
 101+ 'form',
 102+ array(
 103+ 'method' => 'post',
 104+ 'action' => $this->getTitle()->getLocalURL( array( 'action' => 'undo' ) ),
 105+ )
 106+ ) );
 107+
 108+ $out->addHTML( '&#160;' . Xml::inputLabel(
 109+ wfMsg( $this->prefixMsg( 'summary' ) ),
 110+ 'summary',
 111+ 'summary',
 112+ 65,
 113+ false,
 114+ array(
 115+ 'maxlength' => 250,
 116+ 'spellcheck' => true,
 117+ )
 118+ ) );
 119+
 120+ $out->addHTML( '<br />' );
 121+
 122+ $out->addHTML( Html::input(
 123+ 'restore',
 124+ wfMsg( $this->prefixMsg( 'undo-button' ) ),
 125+ 'submit',
 126+ array(
 127+ 'class' => 'ep-undo',
 128+ )
 129+ ) );
 130+
 131+ $out->addElement(
 132+ 'button',
 133+ array(
 134+ 'id' => 'cancelRestore',
 135+ 'class' => 'ep-undo-cancel ep-cancel',
 136+ 'target-url' => $this->getTitle()->getLocalURL(),
 137+ ),
 138+ wfMsg( $this->prefixMsg( 'cancel-button' ) )
 139+ );
 140+
 141+ $out->addHTML( Html::hidden( 'undoToken', $this->getUser()->getEditToken( $this->getSalt() ) ) );
 142+
 143+ $out->addHTML( '</form>' );
 144+ }
 145+
 146+ /**
 147+ * Returns a salt based on the action and the page name.
 148+ *
 149+ * @since 0.1
 150+ *
 151+ * @return string
 152+ */
 153+ protected function getSalt() {
 154+ return 'undo' . $this->getTitle()->getLocalURL();
 155+ }
 156+
 157+ /**
 158+ * Returns a prefixed message name.
 159+ *
 160+ * @since 0.1
 161+ *
 162+ * @param string $name
 163+ *
 164+ * @return string
 165+ */
 166+ protected function prefixMsg( $name ) {
 167+ return strtolower( get_class( $this->page ) ) . '-' . $this->getName() . '-' . $name;
 168+ }
 169+
 170+ /**
 171+ * Returns the page title.
 172+ *
 173+ * @since 0.1
 174+ *
 175+ * @return string
 176+ */
 177+ protected function getPageTitle() {
 178+ return wfMsgExt(
 179+ $this->prefixMsg( 'title' ),
 180+ 'parsemag',
 181+ $this->getTitle()->getText()
 182+ );
 183+ }
 184+
 185+}
\ No newline at end of file
Property changes on: trunk/extensions/EducationProgram/actions/EPUndoAction.php
___________________________________________________________________
Added: svn:eol-style
1186 + native
Index: trunk/extensions/EducationProgram/includes/EPRevisionPager.php
@@ -112,7 +112,7 @@
113113
114114 if ( $this->mOffset !== '' || $this->rowNr < $this->mResult->numRows() - 1 ) {
115115 $actionLinks[] = $object->getLink(
116 - 'undo',
 116+ 'epundo',
117117 wfMsgHtml( 'ep-revision-undo' ),
118118 array(),
119119 array( 'revid' => $revision->getId() )
@@ -120,7 +120,7 @@
121121 }
122122
123123 $actionLinks[] = $object->getLink(
124 - 'restore',
 124+ 'eprestore',
125125 wfMsgHtml( 'ep-revision-restore' ),
126126 array(),
127127 array( 'revid' => $revision->getId() )
Index: trunk/extensions/EducationProgram/EducationProgram.i18n.php
@@ -468,20 +468,20 @@
469469 'ep-coursehistory-deleted' => 'This course has been deleted. The deletion log for the course is provided below for reference.',
470470
471471 // Course deletion
472 - 'deletecourseaction-text' => 'You are about to delete course $1. This will remove all associated students!',
473 - 'deletecourseaction-summary' => 'Reason for deletion:',
474 - 'deletecourseaction-title' => 'Delete course "$1"',
475 - 'deletecourseaction-cancel-button' => 'Cancel',
476 - 'deletecourseaction-delete-button' => 'Delete course',
477 - 'deletecourseaction-none' => 'There is no course titled "$1". Existing courses can be found in [[Special:Courses|the courses list]].',
 472+ 'coursepage-delete-text' => 'You are about to delete course $1. This will remove all associated students!',
 473+ 'coursepage-delete-summary' => 'Reason for deletion:',
 474+ 'coursepage-delete-title' => 'Delete course "$1"',
 475+ 'coursepage-delete-cancel-button' => 'Cancel',
 476+ 'coursepage-delete-delete-button' => 'Delete course',
 477+ 'coursepage-delete-none' => 'There is no course titled "$1". Existing courses can be found in [[Special:Courses|the courses list]].',
478478
479479 // Institution deletion
480 - 'deleteorgaction-text' => "You are about to delete institution $1. This will remove all it's courses and their associated students!",
481 - 'deleteorgaction-summary' => 'Reason for deletion:',
482 - 'deleteorgaction-title' => 'Delete institution "$1"',
483 - 'deleteorgaction-cancel-button' => 'Cancel',
484 - 'deleteorgaction-delete-button' => 'Delete institution',
485 - 'deleteorgaction-none' => 'There is no institution titled "$1". Existing institutions can be found in [[Special:Courses|the institution list]].',
 480+ 'orgpage-delete-text' => "You are about to delete institution $1. This will remove all it's courses and their associated students!",
 481+ 'orgpage-delete-summary' => 'Reason for deletion:',
 482+ 'orgpage-delete-title' => 'Delete institution "$1"',
 483+ 'orgpage-delete-cancel-button' => 'Cancel',
 484+ 'orgpage-delete-delete-button' => 'Delete institution',
 485+ 'orgpage-delete-none' => 'There is no institution titled "$1". Existing institutions can be found in [[Special:Courses|the institution list]].',
486486
487487 // Special:Ambassador
488488 'ep-ambassador-does-not-exist' => 'There is no ambassador with name "$1". See [[Special:Ambassadors|here]] for a list of ambassadors.',
Index: trunk/extensions/EducationProgram/EducationProgram.hooks.php
@@ -340,5 +340,31 @@
341341
342342 return true;
343343 }
 344+
 345+ /**
 346+ * Used to add new query-string actions.
 347+ * @see https://www.mediawiki.org/wiki/Manual:Hooks/UnknownAction
 348+ *
 349+ * @since 0.1
 350+ *
 351+ * @param string $action
 352+ * @param Page $page
 353+ *
 354+ * @return true
 355+ */
 356+ public static function onUnknownAction( $action, Page $page ) {
 357+ // Action does not allow us to associate actions that are not known to core
 358+ // with a single page, hence the less ideal handling in this hook.
 359+ if ( method_exists( $page, 'getActions' ) ) {
 360+ $actions = $page->getActions();
 361+
 362+ if ( array_key_exists( $action, $actions ) ) {
 363+ $action = new $actions[$action]( $page, $page->getContext() );
 364+ $action->show();
 365+ }
 366+ }
 367+
 368+ return true;
 369+ }
344370
345371 }

Status & tagging log