Index: trunk/extensions/EducationProgram/EducationProgram.php |
— | — | @@ -60,8 +60,8 @@ |
61 | 61 | $wgAutoloadClasses['EPSettings'] = dirname( __FILE__ ) . '/EducationProgram.settings.php'; |
62 | 62 | |
63 | 63 | $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'; |
66 | 66 | $wgAutoloadClasses['EditCourseAction'] = dirname( __FILE__ ) . '/actions/EditCourseAction.php'; |
67 | 67 | $wgAutoloadClasses['EditOrgAction'] = dirname( __FILE__ ) . '/actions/EditOrgAction.php'; |
68 | 68 | $wgAutoloadClasses['EPAddArticleAction'] = dirname( __FILE__ ) . '/actions/EPAddArticleAction.php'; |
— | — | @@ -72,10 +72,16 @@ |
73 | 73 | $wgAutoloadClasses['EPRemoveArticleAction'] = dirname( __FILE__ ) . '/actions/EPRemoveArticleAction.php'; |
74 | 74 | $wgAutoloadClasses['EPRemoveReviewerAction'] = dirname( __FILE__ ) . '/actions/EPRemoveReviewerAction.php'; |
75 | 75 | $wgAutoloadClasses['EPRemoveStudentAction'] = dirname( __FILE__ ) . '/actions/EPRemoveStudentAction.php'; |
| 76 | +$wgAutoloadClasses['EPRestoreAction'] = dirname( __FILE__ ) . '/actions/EPRestoreAction.php'; |
| 77 | +$wgAutoloadClasses['EPUndoAction'] = dirname( __FILE__ ) . '/actions/EPUndoAction.php'; |
76 | 78 | $wgAutoloadClasses['EPViewAction'] = dirname( __FILE__ ) . '/actions/EPViewAction.php'; |
77 | 79 | $wgAutoloadClasses['OrgHistoryAction'] = dirname( __FILE__ ) . '/actions/OrgHistoryAction.php'; |
78 | 80 | $wgAutoloadClasses['ViewCourseAction'] = dirname( __FILE__ ) . '/actions/ViewCourseAction.php'; |
79 | 81 | $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'; |
80 | 86 | |
81 | 87 | $wgAutoloadClasses['ApiDeleteEducation'] = dirname( __FILE__ ) . '/api/ApiDeleteEducation.php'; |
82 | 88 | $wgAutoloadClasses['ApiEnlist'] = dirname( __FILE__ ) . '/api/ApiEnlist.php'; |
— | — | @@ -193,6 +199,7 @@ |
194 | 200 | $wgHooks['ArticleFromTitle'][] = 'EPHooks::onArticleFromTitle'; |
195 | 201 | $wgHooks['CanonicalNamespaces'][] = 'EPHooks::onCanonicalNamespaces'; |
196 | 202 | $wgHooks['TitleIsAlwaysKnown'][] = 'EPHooks::onTitleIsAlwaysKnown'; |
| 203 | +//$wgHooks['UnknownAction'][] = 'EPHooks::onUnknownAction'; |
197 | 204 | |
198 | 205 | // Actions |
199 | 206 | $wgActions['epremarticle'] = 'EPRemoveArticleAction'; |
— | — | @@ -200,6 +207,8 @@ |
201 | 208 | $wgActions['epremreviewer'] = 'EPRemoveReviewerAction'; |
202 | 209 | $wgActions['epaddarticle'] = 'EPAddArticleAction'; |
203 | 210 | $wgActions['epaddreviewer'] = 'EPAddReviewerAction'; |
| 211 | +$wgActions['epundo'] = 'EPUndoAction'; |
| 212 | +$wgActions['eprestore'] = 'EPRestoreAction'; |
204 | 213 | |
205 | 214 | // Logging |
206 | 215 | $wgLogTypes[] = 'institution'; |
Index: trunk/extensions/EducationProgram/pages/CoursePage.php |
— | — | @@ -14,14 +14,27 @@ |
15 | 15 | */ |
16 | 16 | class CoursePage extends EPPage { |
17 | 17 | |
18 | | - protected function getActions() { |
| 18 | + /** |
| 19 | + * (non-PHPdoc) |
| 20 | + * @see EPPage::getActions() |
| 21 | + */ |
| 22 | + public function getActions() { |
19 | 23 | return array( |
20 | 24 | 'view' => 'ViewCourseAction', |
21 | 25 | 'edit' => 'EditCourseAction', |
22 | 26 | 'history' => 'CourseHistoryAction', |
23 | | - 'delete' => 'DeleteCourseAction', |
| 27 | + 'delete' => 'EPDeleteAction', |
24 | 28 | ); |
25 | 29 | } |
26 | 30 | |
| 31 | + /** |
| 32 | + * (non-PHPdoc) |
| 33 | + * @see EPPage::getActions() |
| 34 | + * @return EPPageTable |
| 35 | + */ |
| 36 | + public function getTable() { |
| 37 | + return EPCourses::singleton(); |
| 38 | + } |
| 39 | + |
27 | 40 | } |
28 | 41 | |
Index: trunk/extensions/EducationProgram/pages/EPPage.php |
— | — | @@ -1,7 +1,7 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | 4 | /** |
5 | | - * Abstract Page for interacting with a DBDataObject. |
| 5 | + * Abstract Page for interacting with a EPPageObject. |
6 | 6 | * |
7 | 7 | * @since 0.1 |
8 | 8 | * |
— | — | @@ -22,7 +22,16 @@ |
23 | 23 | * |
24 | 24 | * @return array |
25 | 25 | */ |
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(); |
27 | 36 | |
28 | 37 | /** |
29 | 38 | * @since 0.1 |
Index: trunk/extensions/EducationProgram/pages/OrgPage.php |
— | — | @@ -14,13 +14,26 @@ |
15 | 15 | */ |
16 | 16 | class OrgPage extends EPPage { |
17 | 17 | |
18 | | - protected function getActions() { |
| 18 | + /** |
| 19 | + * (non-PHPdoc) |
| 20 | + * @see EPPage::getActions() |
| 21 | + */ |
| 22 | + public function getActions() { |
19 | 23 | return array( |
20 | 24 | 'view' => 'ViewOrgAction', |
21 | 25 | 'edit' => 'EditOrgAction', |
22 | 26 | 'history' => 'OrgHistoryAction', |
23 | | - 'delete' => 'DeleteOrgAction', |
| 27 | + 'delete' => 'EPDeleteAction', |
24 | 28 | ); |
25 | 29 | } |
26 | 30 | |
| 31 | + /** |
| 32 | + * (non-PHPdoc) |
| 33 | + * @see EPPage::getActions() |
| 34 | + * @return EPPageTable |
| 35 | + */ |
| 36 | + public function getTable() { |
| 37 | + return EPOrgs::singleton(); |
| 38 | + } |
| 39 | + |
27 | 40 | } |
\ 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 @@ |
17 | 17 | |
18 | 18 | /** |
19 | 19 | * @since 0.1 |
20 | | - * @var DBTable |
| 20 | + * @var EPPageTable |
21 | 21 | */ |
22 | 22 | protected $table; |
23 | 23 | |
— | — | @@ -29,7 +29,7 @@ |
30 | 30 | * @param IContextSource $context |
31 | 31 | * @param DBTable $table |
32 | 32 | */ |
33 | | - protected function __construct( Page $page, IContextSource $context = null, DBTable $table ) { |
| 33 | + protected function __construct( Page $page, IContextSource $context = null, EPPageTable $table ) { |
34 | 34 | $this->table = $table; |
35 | 35 | parent::__construct( $page, $context ); |
36 | 36 | } |
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( ' ' . 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 |
1 | 186 | + native |
Index: trunk/extensions/EducationProgram/actions/EPEditAction.php |
— | — | @@ -32,7 +32,7 @@ |
33 | 33 | |
34 | 34 | /** |
35 | 35 | * @since 0.1 |
36 | | - * @var DBTable |
| 36 | + * @var EPPageTable |
37 | 37 | */ |
38 | 38 | protected $table; |
39 | 39 | |
— | — | @@ -45,7 +45,7 @@ |
46 | 46 | * @param IContextSource $context |
47 | 47 | * @param DBTable $table |
48 | 48 | */ |
49 | | - protected function __construct( Page $page, IContextSource $context = null, DBTable $table ) { |
| 49 | + protected function __construct( Page $page, IContextSource $context = null, EPPageTable $table ) { |
50 | 50 | $this->table = $table; |
51 | 51 | parent::__construct( $page, $context ); |
52 | 52 | } |
— | — | @@ -247,6 +247,7 @@ |
248 | 248 | 'cancelEdit', |
249 | 249 | array( |
250 | 250 | 'target-url' => $this->getReturnToTitle()->getFullURL(), |
| 251 | + 'class' => 'ep-cancel', |
251 | 252 | ) |
252 | 253 | ); |
253 | 254 | |
Index: trunk/extensions/EducationProgram/actions/EPDeleteAction.php |
— | — | @@ -1,7 +1,7 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | 4 | /** |
5 | | - * Abstract action for deleting EPPageObject items. |
| 5 | + * Action for deleting EPPageObject items. |
6 | 6 | * |
7 | 7 | * @since 0.1 |
8 | 8 | * |
— | — | @@ -12,29 +12,16 @@ |
13 | 13 | * @licence GNU GPL v3+ |
14 | 14 | * @author Jeroen De Dauw < jeroendedauw@gmail.com > |
15 | 15 | */ |
16 | | -abstract class EPDeleteAction extends FormlessAction { |
| 16 | +class EPDeleteAction extends FormlessAction { |
17 | 17 | |
18 | 18 | /** |
19 | | - * @since 0.1 |
20 | | - * @var DBTable |
| 19 | + * (non-PHPdoc) |
| 20 | + * @see Action::getName() |
21 | 21 | */ |
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'; |
37 | 24 | } |
38 | | - |
| 25 | + |
39 | 26 | /** |
40 | 27 | * (non-PHPdoc) |
41 | 28 | * @see Action::getDescription() |
— | — | @@ -42,6 +29,14 @@ |
43 | 30 | protected function getDescription() { |
44 | 31 | return $this->msg( 'backlinksubtitle' )->rawParams( Linker::link( $this->getTitle() ) ); |
45 | 32 | } |
| 33 | + |
| 34 | + /** |
| 35 | + * (non-PHPdoc) |
| 36 | + * @see Action::getRestriction() |
| 37 | + */ |
| 38 | + public function getRestriction() { |
| 39 | + $this->page->getTable()->getEditRight(); |
| 40 | + } |
46 | 41 | |
47 | 42 | /** |
48 | 43 | * (non-PHPdoc) |
— | — | @@ -50,7 +45,7 @@ |
51 | 46 | public function onView() { |
52 | 47 | $this->getOutput()->setPageTitle( $this->getPageTitle() ); |
53 | 48 | |
54 | | - $object = $this->table->get( $this->getTitle()->getText() ); |
| 49 | + $object = $this->page->getTable()->get( $this->getTitle()->getText() ); |
55 | 50 | |
56 | 51 | if ( $object === false ) { |
57 | 52 | $this->getOutput()->addWikiMsg( $this->prefixMsg( 'none' ), $this->getTitle()->getText() ); |
— | — | @@ -107,6 +102,8 @@ |
108 | 103 | */ |
109 | 104 | protected function displayForm( EPPageObject $object ) { |
110 | 105 | $out = $this->getOutput(); |
| 106 | + |
| 107 | + $out->addModules( 'ep.formpage' ); |
111 | 108 | |
112 | 109 | $out->addWikiMsg( $this->prefixMsg( 'text' ), $object->getField( 'name' ) ); |
113 | 110 | |
— | — | @@ -137,7 +134,7 @@ |
138 | 135 | wfMsg( $this->prefixMsg( 'delete-button' ) ), |
139 | 136 | 'submit', |
140 | 137 | array( |
141 | | - 'class' => 'ep-disenroll', |
| 138 | + 'class' => 'ep-delete', |
142 | 139 | ) |
143 | 140 | ) ); |
144 | 141 | |
— | — | @@ -145,7 +142,7 @@ |
146 | 143 | 'button', |
147 | 144 | array( |
148 | 145 | 'id' => 'cancelDelete', |
149 | | - 'class' => 'ep-delete-cancel', |
| 146 | + 'class' => 'ep-delete-cancel ep-cancel', |
150 | 147 | 'target-url' => $this->getTitle()->getLocalURL(), |
151 | 148 | ), |
152 | 149 | wfMsg( $this->prefixMsg( 'cancel-button' ) ) |
— | — | @@ -156,6 +153,13 @@ |
157 | 154 | $out->addHTML( '</form>' ); |
158 | 155 | } |
159 | 156 | |
| 157 | + /** |
| 158 | + * Returns a salt based on the action and the page name. |
| 159 | + * |
| 160 | + * @since 0.1 |
| 161 | + * |
| 162 | + * @return string |
| 163 | + */ |
160 | 164 | protected function getSalt() { |
161 | 165 | return 'delete' . $this->getTitle()->getLocalURL(); |
162 | 166 | } |
— | — | @@ -170,7 +174,7 @@ |
171 | 175 | * @return string |
172 | 176 | */ |
173 | 177 | protected function prefixMsg( $name ) { |
174 | | - return strtolower( get_called_class() ) . '-' . $name; |
| 178 | + return strtolower( get_class( $this->page ) ) . '-' . $this->getName() . '-' . $name; |
175 | 179 | } |
176 | 180 | |
177 | 181 | /** |
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( ' ' . 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 |
1 | 186 | + native |
Index: trunk/extensions/EducationProgram/includes/EPRevisionPager.php |
— | — | @@ -112,7 +112,7 @@ |
113 | 113 | |
114 | 114 | if ( $this->mOffset !== '' || $this->rowNr < $this->mResult->numRows() - 1 ) { |
115 | 115 | $actionLinks[] = $object->getLink( |
116 | | - 'undo', |
| 116 | + 'epundo', |
117 | 117 | wfMsgHtml( 'ep-revision-undo' ), |
118 | 118 | array(), |
119 | 119 | array( 'revid' => $revision->getId() ) |
— | — | @@ -120,7 +120,7 @@ |
121 | 121 | } |
122 | 122 | |
123 | 123 | $actionLinks[] = $object->getLink( |
124 | | - 'restore', |
| 124 | + 'eprestore', |
125 | 125 | wfMsgHtml( 'ep-revision-restore' ), |
126 | 126 | array(), |
127 | 127 | array( 'revid' => $revision->getId() ) |
Index: trunk/extensions/EducationProgram/EducationProgram.i18n.php |
— | — | @@ -468,20 +468,20 @@ |
469 | 469 | 'ep-coursehistory-deleted' => 'This course has been deleted. The deletion log for the course is provided below for reference.', |
470 | 470 | |
471 | 471 | // 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]].', |
478 | 478 | |
479 | 479 | // 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]].', |
486 | 486 | |
487 | 487 | // Special:Ambassador |
488 | 488 | '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 @@ |
341 | 341 | |
342 | 342 | return true; |
343 | 343 | } |
| 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 | + } |
344 | 370 | |
345 | 371 | } |