Index: trunk/extensions/EducationProgram/EducationProgram.php |
— | — | @@ -62,9 +62,13 @@ |
63 | 63 | $wgAutoloadClasses['CourseHistoryAction'] = dirname( __FILE__ ) . '/actions/CourseHistoryAction.php'; |
64 | 64 | $wgAutoloadClasses['EditCourseAction'] = dirname( __FILE__ ) . '/actions/EditCourseAction.php'; |
65 | 65 | $wgAutoloadClasses['EditOrgAction'] = dirname( __FILE__ ) . '/actions/EditOrgAction.php'; |
| 66 | +$wgAutoloadClasses['EPAddArticleAction'] = dirname( __FILE__ ) . '/actions/EPAddArticleAction.php'; |
| 67 | +$wgAutoloadClasses['EPAddReviewerAction'] = dirname( __FILE__ ) . '/actions/EPAddReviewerAction.php'; |
66 | 68 | $wgAutoloadClasses['EPEditAction'] = dirname( __FILE__ ) . '/actions/EPEditAction.php'; |
67 | 69 | $wgAutoloadClasses['EPHistoryAction'] = dirname( __FILE__ ) . '/actions/EPHistoryAction.php'; |
68 | 70 | $wgAutoloadClasses['EPRemoveArticleAction'] = dirname( __FILE__ ) . '/actions/EPRemoveArticleAction.php'; |
| 71 | +$wgAutoloadClasses['EPRemoveReviewerAction'] = dirname( __FILE__ ) . '/actions/EPRemoveReviewerAction.php'; |
| 72 | +$wgAutoloadClasses['EPRemoveStudentAction'] = dirname( __FILE__ ) . '/actions/EPRemoveStudentAction.php'; |
69 | 73 | $wgAutoloadClasses['EPViewAction'] = dirname( __FILE__ ) . '/actions/EPViewAction.php'; |
70 | 74 | $wgAutoloadClasses['OrgHistoryAction'] = dirname( __FILE__ ) . '/actions/OrgHistoryAction.php'; |
71 | 75 | $wgAutoloadClasses['ViewCourseAction'] = dirname( __FILE__ ) . '/actions/ViewCourseAction.php'; |
— | — | @@ -186,10 +190,13 @@ |
187 | 191 | $wgHooks['ArticleFromTitle'][] = 'EPHooks::onArticleFromTitle'; |
188 | 192 | $wgHooks['CanonicalNamespaces'][] = 'EPHooks::onCanonicalNamespaces'; |
189 | 193 | $wgHooks['TitleIsAlwaysKnown'][] = 'EPHooks::onTitleIsAlwaysKnown'; |
190 | | -$wgHooks['UnknownAction'][] = 'EPHooks::onUnknownAction'; |
191 | 194 | |
192 | 195 | // Actions |
193 | 196 | $wgActions['epremarticle'] = 'EPRemoveArticleAction'; |
| 197 | +$wgActions['epremstudent'] = 'EPRemoveStudentAction'; |
| 198 | +$wgActions['epremreviewer'] = 'EPRemoveReviewerAction'; |
| 199 | +$wgActions['epaddarticle'] = 'EPAddArticleAction'; |
| 200 | +$wgActions['epaddreviewer'] = 'EPAddReviewerAction'; |
194 | 201 | |
195 | 202 | // Logging |
196 | 203 | $wgLogTypes[] = 'institution'; |
Index: trunk/extensions/EducationProgram/actions/EPRemoveReviewerAction.php |
— | — | @@ -0,0 +1,58 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * Remove a reviewer from an article-student association. |
| 6 | + * |
| 7 | + * @since 0.1 |
| 8 | + * |
| 9 | + * @file EPRemoveReviewerAction.php |
| 10 | + * @ingroup EducationProgram |
| 11 | + * @ingroup Action |
| 12 | + * |
| 13 | + * @licence GNU GPL v3+ |
| 14 | + * @author Jeroen De Dauw < jeroendedauw@gmail.com > |
| 15 | + */ |
| 16 | +class EPRemoveReviewerAction extends FormlessAction { |
| 17 | + |
| 18 | + /** |
| 19 | + * (non-PHPdoc) |
| 20 | + * @see Action::getName() |
| 21 | + */ |
| 22 | + public function getName() { |
| 23 | + return 'epremreviewer'; |
| 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 | + $salt = $req->getInt( 'user-id' ) .'remarticle' . $req->getInt( 'article-id' ); |
| 35 | + |
| 36 | + if ( $user->matchEditToken( $req->getText( 'token' ), $salt ) |
| 37 | + && ( $user->getId() === $req->getInt( 'user-id' ) || $user->isAllowed( 'ep-remreviewer' ) ) ) { |
| 38 | + |
| 39 | + $article = EPArticles::singleton()->selectRow( |
| 40 | + array( 'id', 'reviewers' ), |
| 41 | + array( 'id' => $req->getInt( 'article-id' ) ) |
| 42 | + ); |
| 43 | + |
| 44 | + if ( $article !== false ) { |
| 45 | + $removedReviewers = $article->removeReviewers( array( $req->getInt( 'user-id' ) ) ); |
| 46 | + |
| 47 | + if ( !empty( $removedReviewers ) ) { |
| 48 | + if ( $article->save() ) { |
| 49 | + $article->logReviewersRemoval( $removedReviewers ); |
| 50 | + } |
| 51 | + } |
| 52 | + } |
| 53 | + } |
| 54 | + |
| 55 | + Action::factory( 'view', $this->page, $this->context )->show(); |
| 56 | + return ''; |
| 57 | + } |
| 58 | + |
| 59 | +} |
Index: trunk/extensions/EducationProgram/actions/EPAddArticleAction.php |
— | — | @@ -0,0 +1,58 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * Add an article-student association. |
| 6 | + * Currently only allows students to associate articles with themselves. |
| 7 | + * |
| 8 | + * @since 0.1 |
| 9 | + * |
| 10 | + * @file EPAddArticleAction.php |
| 11 | + * @ingroup EducationProgram |
| 12 | + * @ingroup Action |
| 13 | + * |
| 14 | + * @licence GNU GPL v3+ |
| 15 | + * @author Jeroen De Dauw < jeroendedauw@gmail.com > |
| 16 | + */ |
| 17 | +class EPAddArticleAction extends FormlessAction { |
| 18 | + |
| 19 | + /** |
| 20 | + * (non-PHPdoc) |
| 21 | + * @see Action::getName() |
| 22 | + */ |
| 23 | + public function getName() { |
| 24 | + return 'epaddarticle'; |
| 25 | + } |
| 26 | + |
| 27 | + /** |
| 28 | + * (non-PHPdoc) |
| 29 | + * @see FormlessAction::onView() |
| 30 | + */ |
| 31 | + public function onView() { |
| 32 | + $req = $this->getRequest(); |
| 33 | + $user = $this->getUser(); |
| 34 | + |
| 35 | + $salt = 'addarticle' . $req->getInt( 'course-id' ); |
| 36 | + |
| 37 | + if ( $user->matchEditToken( $req->getText( 'token' ), $salt ) |
| 38 | + && $user->isAllowed( 'ep-student' ) ) { |
| 39 | + |
| 40 | + $articleData = array( |
| 41 | + 'user_id' => $user->getId(), |
| 42 | + 'course_id' => $req->getInt( 'course-id' ), |
| 43 | + 'page_id' => '', |
| 44 | + ); |
| 45 | + |
| 46 | + if ( !EPArticles::singleton()->has( $articleData ) ) { |
| 47 | + $article = EPArticles::singleton()->newFromArray( $articleData, true ); |
| 48 | + |
| 49 | + if ( $article->save() ) { |
| 50 | + // TODO: log |
| 51 | + } |
| 52 | + } |
| 53 | + } |
| 54 | + |
| 55 | + Action::factory( 'view', $this->page, $this->context )->show(); |
| 56 | + return ''; |
| 57 | + } |
| 58 | + |
| 59 | +} |
Index: trunk/extensions/EducationProgram/actions/EPAddReviewerAction.php |
— | — | @@ -0,0 +1,59 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * Add a reviewer to an article-student association. |
| 6 | + * Currently only the current user can be added. |
| 7 | + * |
| 8 | + * @since 0.1 |
| 9 | + * |
| 10 | + * @file EPAddReviewerAction.php |
| 11 | + * @ingroup EducationProgram |
| 12 | + * @ingroup Action |
| 13 | + * |
| 14 | + * @licence GNU GPL v3+ |
| 15 | + * @author Jeroen De Dauw < jeroendedauw@gmail.com > |
| 16 | + */ |
| 17 | +class EPAddReviewerAction extends FormlessAction { |
| 18 | + |
| 19 | + /** |
| 20 | + * (non-PHPdoc) |
| 21 | + * @see Action::getName() |
| 22 | + */ |
| 23 | + public function getName() { |
| 24 | + return 'epaddreviewer'; |
| 25 | + } |
| 26 | + |
| 27 | + /** |
| 28 | + * (non-PHPdoc) |
| 29 | + * @see FormlessAction::onView() |
| 30 | + */ |
| 31 | + public function onView() { |
| 32 | + $req = $this->getRequest(); |
| 33 | + $user = $this->getUser(); |
| 34 | + |
| 35 | + $salt = 'addreviewer' . $req->getInt( 'article-id' ); |
| 36 | + |
| 37 | + if ( $user->matchEditToken( $req->getText( 'token' ), $salt ) |
| 38 | + && $user->isAllowed( 'ep-bereviewer' ) ) { |
| 39 | + |
| 40 | + $article = EPArticles::singleton()->selectRow( |
| 41 | + array( 'id', 'reviewers' ), |
| 42 | + array( 'id' => $req->getInt( 'article-id' ) ) |
| 43 | + ); |
| 44 | + |
| 45 | + if ( $article !== false ) { |
| 46 | + $addedReviewers = $article->addReviewers( array( $req->getInt( 'user-id' ) ) ); |
| 47 | + |
| 48 | + if ( !empty( $addedReviewers ) ) { |
| 49 | + if ( $article->save() ) { |
| 50 | + $article->logReviewersAdittion( $addedReviewers ); |
| 51 | + } |
| 52 | + } |
| 53 | + } |
| 54 | + } |
| 55 | + |
| 56 | + Action::factory( 'view', $this->page, $this->context )->show(); |
| 57 | + return ''; |
| 58 | + } |
| 59 | + |
| 60 | +} |
Index: trunk/extensions/EducationProgram/actions/EPRemoveArticleAction.php |
— | — | @@ -1,8 +1,8 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | 4 | /** |
| 5 | + * Remove an article-student association. |
5 | 6 | * |
6 | | - * |
7 | 7 | * @since 0.1 |
8 | 8 | * |
9 | 9 | * @file EPRemoveArticleAction.php |
— | — | @@ -31,15 +31,18 @@ |
32 | 32 | $user = $this->getUser(); |
33 | 33 | |
34 | 34 | if ( $user->matchEditToken( $req->getText( 'token' ), 'remarticle' . $req->getInt( 'article-id' ) ) ) { |
35 | | - EPArticles::singleton()->delete( array( |
| 35 | + $article = EPArticles::singleton()->selectRow( 'id', array( |
36 | 36 | 'id' => $req->getInt( 'article-id' ), |
37 | 37 | 'user_id' => $user->getId(), |
38 | 38 | ) ); |
| 39 | + |
| 40 | + if ( $article !== false && $article->remove() ) { |
| 41 | + // TODO: log |
| 42 | + } |
39 | 43 | } |
40 | 44 | |
41 | 45 | Action::factory( 'view', $this->page, $this->context )->show(); |
42 | 46 | return ''; |
43 | 47 | } |
44 | 48 | |
45 | | - |
46 | | -} |
\ No newline at end of file |
| 49 | +} |
Index: trunk/extensions/EducationProgram/actions/EPRemoveStudentAction.php |
— | — | @@ -0,0 +1,46 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * Remove a student from a course. |
| 6 | + * |
| 7 | + * @since 0.1 |
| 8 | + * |
| 9 | + * @file EPRemoveStudentAction.php |
| 10 | + * @ingroup EducationProgram |
| 11 | + * @ingroup Action |
| 12 | + * |
| 13 | + * @licence GNU GPL v3+ |
| 14 | + * @author Jeroen De Dauw < jeroendedauw@gmail.com > |
| 15 | + */ |
| 16 | +class EPRemoveStudentAction extends FormlessAction { |
| 17 | + |
| 18 | + /** |
| 19 | + * (non-PHPdoc) |
| 20 | + * @see Action::getName() |
| 21 | + */ |
| 22 | + public function getName() { |
| 23 | + return 'epremstudent'; |
| 24 | + } |
| 25 | + |
| 26 | + /** |
| 27 | + * (non-PHPdoc) |
| 28 | + * @see FormlessAction::onView() |
| 29 | + */ |
| 30 | + public function onView() { |
| 31 | + $api = new ApiMain( new FauxRequest( array( |
| 32 | + 'action' => 'enlist', |
| 33 | + 'subaction' => 'remove', |
| 34 | + 'format' => 'json', |
| 35 | + 'courseid' => $this->getRequest()->getInt( 'course-id' ), |
| 36 | + 'userid' => $this->getRequest()->getInt( 'user-id' ), |
| 37 | + 'reason' => '', // TODO |
| 38 | + 'role' => 'student' |
| 39 | + ), true ), true ); |
| 40 | + |
| 41 | + try { $api->execute(); } catch ( Exception $exception ) {} |
| 42 | + |
| 43 | + Action::factory( 'view', $this->page, $this->context )->show(); |
| 44 | + return ''; |
| 45 | + } |
| 46 | + |
| 47 | +} |
Index: trunk/extensions/EducationProgram/includes/EPArticleTable.php |
— | — | @@ -377,33 +377,38 @@ |
378 | 378 | protected function getArticleAdittionControl( $courseId ) { |
379 | 379 | $html = ''; |
380 | 380 | |
381 | | - $html .= Html::openElement( |
382 | | - 'form', |
383 | | - array( |
384 | | - 'method' => 'post', |
385 | | - 'action' => $this->getTitle()->getLocalURL( array( 'action' => 'epaddarticle' ) ), |
386 | | - ) |
387 | | - ); |
| 381 | + if ( $this->getUser()->isAllowed( 'ep-student' ) |
| 382 | + && $this->getUser()->getId() === $this->currentObject->getField( 'user_id' ) ) { |
388 | 383 | |
389 | | - $html .= Xml::inputLabel( |
390 | | - wfMsg( 'ep-artciles-addarticle-text' ), |
391 | | - 'addarticlename', |
392 | | - 'addarticlename' |
393 | | - ); |
| 384 | + $html .= Html::openElement( |
| 385 | + 'form', |
| 386 | + array( |
| 387 | + 'method' => 'post', |
| 388 | + 'action' => $this->getTitle()->getLocalURL( array( 'action' => 'epaddarticle' ) ), |
| 389 | + ) |
| 390 | + ); |
394 | 391 | |
395 | | - $html .= ' ' . Html::input( |
396 | | - 'addarticle', |
397 | | - wfMsg( 'ep-artciles-addarticle-button' ), |
398 | | - 'submit', |
399 | | - array( |
400 | | - 'class' => 'ep-addarticle', |
401 | | - ) |
402 | | - ); |
| 392 | + $html .= Xml::inputLabel( |
| 393 | + wfMsg( 'ep-artciles-addarticle-text' ), |
| 394 | + 'addarticlename', |
| 395 | + 'addarticlename' |
| 396 | + ); |
403 | 397 | |
404 | | - $html .= Html::hidden( 'addArticleToken', $this->getUser()->getEditToken( 'addarticle' . $courseId ) ); |
| 398 | + $html .= ' ' . Html::input( |
| 399 | + 'addarticle', |
| 400 | + wfMsg( 'ep-artciles-addarticle-button' ), |
| 401 | + 'submit', |
| 402 | + array( |
| 403 | + 'class' => 'ep-addarticle', |
| 404 | + ) |
| 405 | + ); |
405 | 406 | |
406 | | - $html .= '</form>'; |
| 407 | + $html .= Html::hidden( 'token', $this->getUser()->getEditToken( 'addarticle' . $courseId ) ); |
407 | 408 | |
| 409 | + $html .= '</form>'; |
| 410 | + } |
| 411 | + |
| 412 | + |
408 | 413 | return '<td colspan="2">' . $html . '</td>'; |
409 | 414 | } |
410 | 415 | |
Index: trunk/extensions/EducationProgram/includes/EPArticle.php |
— | — | @@ -98,4 +98,32 @@ |
99 | 99 | return $this->canBecomeReviwer[$user->getId()]; |
100 | 100 | } |
101 | 101 | |
| 102 | + public function addReviewers( array $userIds ) { |
| 103 | + $addedIds = array_diff( $userIds, $this->getField( 'reviewers' ) ); |
| 104 | + |
| 105 | + if ( !empty( $addedIds ) ) { |
| 106 | + $this->setField( 'reviewers', array_merge( $userIds, $addedIds ) ); |
| 107 | + } |
| 108 | + |
| 109 | + return $addedIds; |
| 110 | + } |
| 111 | + |
| 112 | + public function logReviewersAdittion( array $userIds ) { |
| 113 | + // TODO |
| 114 | + } |
| 115 | + |
| 116 | + public function removeReviewers( array $userIds ) { |
| 117 | + $removedIds = array_intersect( $userIds, $this->getField( 'reviewers' ) ); |
| 118 | + |
| 119 | + if ( !empty( $removedIds ) ) { |
| 120 | + $this->setField( 'reviewers', array_diff( $this->getField( 'reviewers' ), $userIds ) ); |
| 121 | + } |
| 122 | + |
| 123 | + return $removedIds; |
| 124 | + } |
| 125 | + |
| 126 | + public function logReviewersRemoval( array $userIds ) { |
| 127 | + // TODO |
| 128 | + } |
| 129 | + |
102 | 130 | } |
Index: trunk/extensions/EducationProgram/EducationProgram.hooks.php |
— | — | @@ -317,19 +317,4 @@ |
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 | | - |
336 | 321 | } |