r111850 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r111849‎ | r111850 | r111851 >
Date:01:08, 19 February 2012
Author:jeroendedauw
Status:deferred
Tags:
Comment:
work on article table
Modified paths:
  • /trunk/extensions/EducationProgram/EducationProgram.hooks.php (modified) (history)
  • /trunk/extensions/EducationProgram/EducationProgram.php (modified) (history)
  • /trunk/extensions/EducationProgram/actions/EPAddArticleAction.php (added) (history)
  • /trunk/extensions/EducationProgram/actions/EPAddReviewerAction.php (added) (history)
  • /trunk/extensions/EducationProgram/actions/EPRemoveArticleAction.php (modified) (history)
  • /trunk/extensions/EducationProgram/actions/EPRemoveReviewerAction.php (added) (history)
  • /trunk/extensions/EducationProgram/actions/EPRemoveStudentAction.php (added) (history)
  • /trunk/extensions/EducationProgram/includes/EPArticle.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPArticleTable.php (modified) (history)

Diff [purge]

Index: trunk/extensions/EducationProgram/EducationProgram.php
@@ -62,9 +62,13 @@
6363 $wgAutoloadClasses['CourseHistoryAction'] = dirname( __FILE__ ) . '/actions/CourseHistoryAction.php';
6464 $wgAutoloadClasses['EditCourseAction'] = dirname( __FILE__ ) . '/actions/EditCourseAction.php';
6565 $wgAutoloadClasses['EditOrgAction'] = dirname( __FILE__ ) . '/actions/EditOrgAction.php';
 66+$wgAutoloadClasses['EPAddArticleAction'] = dirname( __FILE__ ) . '/actions/EPAddArticleAction.php';
 67+$wgAutoloadClasses['EPAddReviewerAction'] = dirname( __FILE__ ) . '/actions/EPAddReviewerAction.php';
6668 $wgAutoloadClasses['EPEditAction'] = dirname( __FILE__ ) . '/actions/EPEditAction.php';
6769 $wgAutoloadClasses['EPHistoryAction'] = dirname( __FILE__ ) . '/actions/EPHistoryAction.php';
6870 $wgAutoloadClasses['EPRemoveArticleAction'] = dirname( __FILE__ ) . '/actions/EPRemoveArticleAction.php';
 71+$wgAutoloadClasses['EPRemoveReviewerAction'] = dirname( __FILE__ ) . '/actions/EPRemoveReviewerAction.php';
 72+$wgAutoloadClasses['EPRemoveStudentAction'] = dirname( __FILE__ ) . '/actions/EPRemoveStudentAction.php';
6973 $wgAutoloadClasses['EPViewAction'] = dirname( __FILE__ ) . '/actions/EPViewAction.php';
7074 $wgAutoloadClasses['OrgHistoryAction'] = dirname( __FILE__ ) . '/actions/OrgHistoryAction.php';
7175 $wgAutoloadClasses['ViewCourseAction'] = dirname( __FILE__ ) . '/actions/ViewCourseAction.php';
@@ -186,10 +190,13 @@
187191 $wgHooks['ArticleFromTitle'][] = 'EPHooks::onArticleFromTitle';
188192 $wgHooks['CanonicalNamespaces'][] = 'EPHooks::onCanonicalNamespaces';
189193 $wgHooks['TitleIsAlwaysKnown'][] = 'EPHooks::onTitleIsAlwaysKnown';
190 -$wgHooks['UnknownAction'][] = 'EPHooks::onUnknownAction';
191194
192195 // Actions
193196 $wgActions['epremarticle'] = 'EPRemoveArticleAction';
 197+$wgActions['epremstudent'] = 'EPRemoveStudentAction';
 198+$wgActions['epremreviewer'] = 'EPRemoveReviewerAction';
 199+$wgActions['epaddarticle'] = 'EPAddArticleAction';
 200+$wgActions['epaddreviewer'] = 'EPAddReviewerAction';
194201
195202 // Logging
196203 $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 @@
22 <?php
33
44 /**
 5+ * Remove an article-student association.
56 *
6 - *
77 * @since 0.1
88 *
99 * @file EPRemoveArticleAction.php
@@ -31,15 +31,18 @@
3232 $user = $this->getUser();
3333
3434 if ( $user->matchEditToken( $req->getText( 'token' ), 'remarticle' . $req->getInt( 'article-id' ) ) ) {
35 - EPArticles::singleton()->delete( array(
 35+ $article = EPArticles::singleton()->selectRow( 'id', array(
3636 'id' => $req->getInt( 'article-id' ),
3737 'user_id' => $user->getId(),
3838 ) );
 39+
 40+ if ( $article !== false && $article->remove() ) {
 41+ // TODO: log
 42+ }
3943 }
4044
4145 Action::factory( 'view', $this->page, $this->context )->show();
4246 return '';
4347 }
4448
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 @@
378378 protected function getArticleAdittionControl( $courseId ) {
379379 $html = '';
380380
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' ) ) {
388383
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+ );
394391
395 - $html .= '&#160;' . 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+ );
403397
404 - $html .= Html::hidden( 'addArticleToken', $this->getUser()->getEditToken( 'addarticle' . $courseId ) );
 398+ $html .= '&#160;' . Html::input(
 399+ 'addarticle',
 400+ wfMsg( 'ep-artciles-addarticle-button' ),
 401+ 'submit',
 402+ array(
 403+ 'class' => 'ep-addarticle',
 404+ )
 405+ );
405406
406 - $html .= '</form>';
 407+ $html .= Html::hidden( 'token', $this->getUser()->getEditToken( 'addarticle' . $courseId ) );
407408
 409+ $html .= '</form>';
 410+ }
 411+
 412+
408413 return '<td colspan="2">' . $html . '</td>';
409414 }
410415
Index: trunk/extensions/EducationProgram/includes/EPArticle.php
@@ -98,4 +98,32 @@
9999 return $this->canBecomeReviwer[$user->getId()];
100100 }
101101
 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+
102130 }
Index: trunk/extensions/EducationProgram/EducationProgram.hooks.php
@@ -317,19 +317,4 @@
318318 return true;
319319 }
320320
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 -
336321 }

Status & tagging log