Index: trunk/extensions/EducationProgram/EducationProgram.php |
— | — | @@ -64,6 +64,7 @@ |
65 | 65 | $wgAutoloadClasses['EditOrgAction'] = dirname( __FILE__ ) . '/actions/EditOrgAction.php'; |
66 | 66 | $wgAutoloadClasses['EPEditAction'] = dirname( __FILE__ ) . '/actions/EPEditAction.php'; |
67 | 67 | $wgAutoloadClasses['EPHistoryAction'] = dirname( __FILE__ ) . '/actions/EPHistoryAction.php'; |
| 68 | +$wgAutoloadClasses['EPRemoveArticleAction'] = dirname( __FILE__ ) . '/actions/EPRemoveArticleAction.php'; |
68 | 69 | $wgAutoloadClasses['EPViewAction'] = dirname( __FILE__ ) . '/actions/EPViewAction.php'; |
69 | 70 | $wgAutoloadClasses['OrgHistoryAction'] = dirname( __FILE__ ) . '/actions/OrgHistoryAction.php'; |
70 | 71 | $wgAutoloadClasses['ViewCourseAction'] = dirname( __FILE__ ) . '/actions/ViewCourseAction.php'; |
— | — | @@ -185,7 +186,11 @@ |
186 | 187 | $wgHooks['ArticleFromTitle'][] = 'EPHooks::onArticleFromTitle'; |
187 | 188 | $wgHooks['CanonicalNamespaces'][] = 'EPHooks::onCanonicalNamespaces'; |
188 | 189 | $wgHooks['TitleIsAlwaysKnown'][] = 'EPHooks::onTitleIsAlwaysKnown'; |
| 190 | +$wgHooks['UnknownAction'][] = 'EPHooks::onUnknownAction'; |
189 | 191 | |
| 192 | +// Actions |
| 193 | +$wgActions['epremarticle'] = 'EPRemoveArticleAction'; |
| 194 | + |
190 | 195 | // Logging |
191 | 196 | $wgLogTypes[] = 'institution'; |
192 | 197 | $wgLogTypes[] = 'course'; |
Index: trunk/extensions/EducationProgram/actions/EPRemoveArticleAction.php |
— | — | @@ -0,0 +1,45 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * |
| 6 | + * |
| 7 | + * @since 0.1 |
| 8 | + * |
| 9 | + * @file EPRemoveArticleAction.php |
| 10 | + * @ingroup EducationProgram |
| 11 | + * @ingroup Action |
| 12 | + * |
| 13 | + * @licence GNU GPL v3+ |
| 14 | + * @author Jeroen De Dauw < jeroendedauw@gmail.com > |
| 15 | + */ |
| 16 | +class EPRemoveArticleAction extends FormlessAction { |
| 17 | + |
| 18 | + /** |
| 19 | + * (non-PHPdoc) |
| 20 | + * @see Action::getName() |
| 21 | + */ |
| 22 | + public function getName() { |
| 23 | + return 'epremarticle'; |
| 24 | + } |
| 25 | + |
| 26 | + /** |
| 27 | + * (non-PHPdoc) |
| 28 | + * @see FormlessAction::onView() |
| 29 | + */ |
| 30 | + public function onView() { |
| 31 | + $req = $this->getRequest(); |
| 32 | + $user = $this->getUser(); |
| 33 | + |
| 34 | + if ( $user->matchEditToken( $req->getText( 'token' ), 'remarticle' . $req->getInt( 'article-id' ) ) ) { |
| 35 | + EPArticles::singleton()->delete( array( |
| 36 | + 'id' => $req->getInt( 'article-id' ), |
| 37 | + 'user_id' => $user->getId(), |
| 38 | + ) ); |
| 39 | + } |
| 40 | + |
| 41 | + Action::factory( 'view', $this->page, $this->context )->show(); |
| 42 | + return ''; |
| 43 | + } |
| 44 | + |
| 45 | + |
| 46 | +} |
\ No newline at end of file |
Index: trunk/extensions/EducationProgram/includes/EPArticleTable.php |
— | — | @@ -217,6 +217,7 @@ |
218 | 218 | 'data-course-id' => $this->articleConds['course_id'], |
219 | 219 | 'data-user-name' => $name, |
220 | 220 | 'data-course-name' => $this->getCourseName(), |
| 221 | + 'data-token' => $this->getUser()->getEditToken( $this->articleConds['course_id'] . 'remstudent' . $userId ), |
221 | 222 | 'class' => 'ep-rem-student', |
222 | 223 | ), |
223 | 224 | wfMsg( 'ep-artciles-remstudent' ) |
— | — | @@ -262,7 +263,7 @@ |
263 | 264 | * @param integer $rowSpan |
264 | 265 | * |
265 | 266 | * @return string |
266 | | - */- |
| 267 | + */ |
267 | 268 | protected function getArticleCell( EPArticle $article, $rowSpan ) { |
268 | 269 | $html = Linker::link( |
269 | 270 | $article->getTitle(), |
— | — | @@ -273,6 +274,7 @@ |
274 | 275 | 'href' => '#', |
275 | 276 | 'data-article-id' => $article->getId(), |
276 | 277 | 'data-article-name' => $article->getTitle()->getFullText(), |
| 278 | + 'data-token' => $this->getUser()->getEditToken( 'remarticle' . $article->getId() ), |
277 | 279 | 'class' => 'ep-rem-article', |
278 | 280 | ); |
279 | 281 | |
— | — | @@ -329,6 +331,7 @@ |
330 | 332 | 'data-student-name' => $article->getUser()->getName(), |
331 | 333 | 'data-reviewer-name' => $user->getName(), |
332 | 334 | 'data-reviewer-id' => $user->getId(), |
| 335 | + 'data-token' => $this->getUser()->getEditToken( $userId . 'remreviewer' . $article->getId() ), |
333 | 336 | 'class' => 'ep-rem-reviewer', |
334 | 337 | ), |
335 | 338 | wfMsg( 'ep-artciles-remreviewer' ) |
— | — | @@ -346,6 +349,7 @@ |
347 | 350 | 'data-article-id' => $article->getId(), |
348 | 351 | 'data-article-name' => $article->getField( 'name' ), |
349 | 352 | 'data-student-name' => $article->getUser()->getName(), |
| 353 | + 'data-token' => $this->getUser()->getEditToken( $userId . 'remreviewer' . $article->getId() ), |
350 | 354 | ), |
351 | 355 | wfMsg( 'ep-artciles-remreviewer-self' ) |
352 | 356 | ); |
— | — | @@ -421,6 +425,7 @@ |
422 | 426 | 'data-article-id' => $article->getId(), |
423 | 427 | 'data-article-name' => $article->getTitle()->getFullText(), |
424 | 428 | 'data-user-name' => $article->getUser()->getName(), |
| 429 | + 'data-token' => $this->getUser()->getEditToken( 'addreviewer' . $article->getId() ), |
425 | 430 | ), |
426 | 431 | wfMsg( 'ep-artciles-becomereviewer' ) |
427 | 432 | ); |
Index: trunk/extensions/EducationProgram/resources/ep.articletable.js |
— | — | @@ -29,6 +29,12 @@ |
30 | 30 | |
31 | 31 | $form.append( $( '<input>' ).attr( { |
32 | 32 | 'type': 'hidden', |
| 33 | + 'name': 'token', |
| 34 | + 'value': $this.attr( 'data-token' ) |
| 35 | + } ) ); |
| 36 | + |
| 37 | + $form.append( $( '<input>' ).attr( { |
| 38 | + 'type': 'hidden', |
33 | 39 | 'name': 'article-id', |
34 | 40 | 'value': $this.attr( 'data-article-id' ) |
35 | 41 | } ) ); |
— | — | @@ -78,6 +84,12 @@ |
79 | 85 | |
80 | 86 | $form.append( $( '<input>' ).attr( { |
81 | 87 | 'type': 'hidden', |
| 88 | + 'name': 'token', |
| 89 | + 'value': $this.attr( 'data-token' ) |
| 90 | + } ) ); |
| 91 | + |
| 92 | + $form.append( $( '<input>' ).attr( { |
| 93 | + 'type': 'hidden', |
82 | 94 | 'name': 'user-id', |
83 | 95 | 'value': $this.attr( 'data-user-id' ) |
84 | 96 | } ) ); |
— | — | @@ -133,6 +145,12 @@ |
134 | 146 | |
135 | 147 | $form.append( $( '<input>' ).attr( { |
136 | 148 | 'type': 'hidden', |
| 149 | + 'name': 'token', |
| 150 | + 'value': $this.attr( 'data-token' ) |
| 151 | + } ) ); |
| 152 | + |
| 153 | + $form.append( $( '<input>' ).attr( { |
| 154 | + 'type': 'hidden', |
137 | 155 | 'name': 'article-id', |
138 | 156 | 'value': $this.attr( 'data-article-id' ) |
139 | 157 | } ) ); |
— | — | @@ -186,6 +204,12 @@ |
187 | 205 | |
188 | 206 | $form.append( $( '<input>' ).attr( { |
189 | 207 | 'type': 'hidden', |
| 208 | + 'name': 'token', |
| 209 | + 'value': $this.attr( 'data-token' ) |
| 210 | + } ) ); |
| 211 | + |
| 212 | + $form.append( $( '<input>' ).attr( { |
| 213 | + 'type': 'hidden', |
190 | 214 | 'name': 'article-id', |
191 | 215 | 'value': $this.attr( 'data-article-id' ) |
192 | 216 | } ) ); |
Index: trunk/extensions/EducationProgram/EducationProgram.hooks.php |
— | — | @@ -316,5 +316,20 @@ |
317 | 317 | |
318 | 318 | return true; |
319 | 319 | } |
320 | | - |
| 320 | + |
| 321 | + /** |
| 322 | + * Used to add new query-string actions. |
| 323 | + * @see https://www.mediawiki.org/wiki/Manual:Hooks/UnknownAction |
| 324 | + * |
| 325 | + * @since 0.1 |
| 326 | + * |
| 327 | + * @param string $action |
| 328 | + * @param Page $page |
| 329 | + * |
| 330 | + * @return true |
| 331 | + */ |
| 332 | + public static function onUnknownAction( $action, Page $page ) { |
| 333 | + return true; |
| 334 | + } |
| 335 | + |
321 | 336 | } |