https://www.mediawiki.org/wiki/Special:Code/MediaWiki/111850
Revision: 111850
Author: jeroendedauw
Date: 2012-02-19 01:08:32 +0000 (Sun, 19 Feb 2012)
Log Message:
-----------
work on article table
Modified Paths:
--------------
trunk/extensions/EducationProgram/EducationProgram.hooks.php
trunk/extensions/EducationProgram/EducationProgram.php
trunk/extensions/EducationProgram/actions/EPRemoveArticleAction.php
trunk/extensions/EducationProgram/includes/EPArticle.php
trunk/extensions/EducationProgram/includes/EPArticleTable.php
Added Paths:
-----------
trunk/extensions/EducationProgram/actions/EPAddArticleAction.php
trunk/extensions/EducationProgram/actions/EPAddReviewerAction.php
trunk/extensions/EducationProgram/actions/EPRemoveReviewerAction.php
trunk/extensions/EducationProgram/actions/EPRemoveStudentAction.php
Modified: trunk/extensions/EducationProgram/EducationProgram.hooks.php
===================================================================
--- trunk/extensions/EducationProgram/EducationProgram.hooks.php
2012-02-19 01:07:16 UTC (rev 111849)
+++ trunk/extensions/EducationProgram/EducationProgram.hooks.php
2012-02-19 01:08:32 UTC (rev 111850)
@@ -317,19 +317,4 @@
return true;
}
- /**
- * Used to add new query-string actions.
- * @see https://www.mediawiki.org/wiki/Manual:Hooks/UnknownAction
- *
- * @since 0.1
- *
- * @param string $action
- * @param Page $page
- *
- * @return true
- */
- public static function onUnknownAction( $action, Page $page ) {
- return true;
- }
-
}
Modified: trunk/extensions/EducationProgram/EducationProgram.php
===================================================================
--- trunk/extensions/EducationProgram/EducationProgram.php 2012-02-19
01:07:16 UTC (rev 111849)
+++ trunk/extensions/EducationProgram/EducationProgram.php 2012-02-19
01:08:32 UTC (rev 111850)
@@ -62,9 +62,13 @@
$wgAutoloadClasses['CourseHistoryAction'] = dirname(
__FILE__ ) . '/actions/CourseHistoryAction.php';
$wgAutoloadClasses['EditCourseAction'] =
dirname( __FILE__ ) . '/actions/EditCourseAction.php';
$wgAutoloadClasses['EditOrgAction'] = dirname(
__FILE__ ) . '/actions/EditOrgAction.php';
+$wgAutoloadClasses['EPAddArticleAction'] = dirname(
__FILE__ ) . '/actions/EPAddArticleAction.php';
+$wgAutoloadClasses['EPAddReviewerAction'] = dirname(
__FILE__ ) . '/actions/EPAddReviewerAction.php';
$wgAutoloadClasses['EPEditAction'] =
dirname( __FILE__ ) . '/actions/EPEditAction.php';
$wgAutoloadClasses['EPHistoryAction'] = dirname(
__FILE__ ) . '/actions/EPHistoryAction.php';
$wgAutoloadClasses['EPRemoveArticleAction'] = dirname( __FILE__ ) .
'/actions/EPRemoveArticleAction.php';
+$wgAutoloadClasses['EPRemoveReviewerAction'] = dirname( __FILE__ ) .
'/actions/EPRemoveReviewerAction.php';
+$wgAutoloadClasses['EPRemoveStudentAction'] = dirname( __FILE__ ) .
'/actions/EPRemoveStudentAction.php';
$wgAutoloadClasses['EPViewAction'] =
dirname( __FILE__ ) . '/actions/EPViewAction.php';
$wgAutoloadClasses['OrgHistoryAction'] =
dirname( __FILE__ ) . '/actions/OrgHistoryAction.php';
$wgAutoloadClasses['ViewCourseAction'] =
dirname( __FILE__ ) . '/actions/ViewCourseAction.php';
@@ -186,10 +190,13 @@
$wgHooks['ArticleFromTitle'][]
= 'EPHooks::onArticleFromTitle';
$wgHooks['CanonicalNamespaces'][] =
'EPHooks::onCanonicalNamespaces';
$wgHooks['TitleIsAlwaysKnown'][] =
'EPHooks::onTitleIsAlwaysKnown';
-$wgHooks['UnknownAction'][] =
'EPHooks::onUnknownAction';
// Actions
$wgActions['epremarticle'] = 'EPRemoveArticleAction';
+$wgActions['epremstudent'] = 'EPRemoveStudentAction';
+$wgActions['epremreviewer'] = 'EPRemoveReviewerAction';
+$wgActions['epaddarticle'] = 'EPAddArticleAction';
+$wgActions['epaddreviewer'] = 'EPAddReviewerAction';
// Logging
$wgLogTypes[] = 'institution';
Added: trunk/extensions/EducationProgram/actions/EPAddArticleAction.php
===================================================================
--- trunk/extensions/EducationProgram/actions/EPAddArticleAction.php
(rev 0)
+++ trunk/extensions/EducationProgram/actions/EPAddArticleAction.php
2012-02-19 01:08:32 UTC (rev 111850)
@@ -0,0 +1,58 @@
+<?php
+
+/**
+ * Add an article-student association.
+ * Currently only allows students to associate articles with themselves.
+ *
+ * @since 0.1
+ *
+ * @file EPAddArticleAction.php
+ * @ingroup EducationProgram
+ * @ingroup Action
+ *
+ * @licence GNU GPL v3+
+ * @author Jeroen De Dauw < [email protected] >
+ */
+class EPAddArticleAction extends FormlessAction {
+
+ /**
+ * (non-PHPdoc)
+ * @see Action::getName()
+ */
+ public function getName() {
+ return 'epaddarticle';
+ }
+
+ /**
+ * (non-PHPdoc)
+ * @see FormlessAction::onView()
+ */
+ public function onView() {
+ $req = $this->getRequest();
+ $user = $this->getUser();
+
+ $salt = 'addarticle' . $req->getInt( 'course-id' );
+
+ if ( $user->matchEditToken( $req->getText( 'token' ), $salt )
+ && $user->isAllowed( 'ep-student' ) ) {
+
+ $articleData = array(
+ 'user_id' => $user->getId(),
+ 'course_id' => $req->getInt( 'course-id' ),
+ 'page_id' => '',
+ );
+
+ if ( !EPArticles::singleton()->has( $articleData ) ) {
+ $article =
EPArticles::singleton()->newFromArray( $articleData, true );
+
+ if ( $article->save() ) {
+ // TODO: log
+ }
+ }
+ }
+
+ Action::factory( 'view', $this->page, $this->context )->show();
+ return '';
+ }
+
+}
Added: trunk/extensions/EducationProgram/actions/EPAddReviewerAction.php
===================================================================
--- trunk/extensions/EducationProgram/actions/EPAddReviewerAction.php
(rev 0)
+++ trunk/extensions/EducationProgram/actions/EPAddReviewerAction.php
2012-02-19 01:08:32 UTC (rev 111850)
@@ -0,0 +1,59 @@
+<?php
+
+/**
+ * Add a reviewer to an article-student association.
+ * Currently only the current user can be added.
+ *
+ * @since 0.1
+ *
+ * @file EPAddReviewerAction.php
+ * @ingroup EducationProgram
+ * @ingroup Action
+ *
+ * @licence GNU GPL v3+
+ * @author Jeroen De Dauw < [email protected] >
+ */
+class EPAddReviewerAction extends FormlessAction {
+
+ /**
+ * (non-PHPdoc)
+ * @see Action::getName()
+ */
+ public function getName() {
+ return 'epaddreviewer';
+ }
+
+ /**
+ * (non-PHPdoc)
+ * @see FormlessAction::onView()
+ */
+ public function onView() {
+ $req = $this->getRequest();
+ $user = $this->getUser();
+
+ $salt = 'addreviewer' . $req->getInt( 'article-id' );
+
+ if ( $user->matchEditToken( $req->getText( 'token' ), $salt )
+ && $user->isAllowed( 'ep-bereviewer' ) ) {
+
+ $article = EPArticles::singleton()->selectRow(
+ array( 'id', 'reviewers' ),
+ array( 'id' => $req->getInt( 'article-id' ) )
+ );
+
+ if ( $article !== false ) {
+ $addedReviewers = $article->addReviewers(
array( $req->getInt( 'user-id' ) ) );
+
+ if ( !empty( $addedReviewers ) ) {
+ if ( $article->save() ) {
+ $article->logReviewersAdittion(
$addedReviewers );
+ }
+ }
+ }
+ }
+
+ Action::factory( 'view', $this->page, $this->context )->show();
+ return '';
+ }
+
+}
Modified: trunk/extensions/EducationProgram/actions/EPRemoveArticleAction.php
===================================================================
--- trunk/extensions/EducationProgram/actions/EPRemoveArticleAction.php
2012-02-19 01:07:16 UTC (rev 111849)
+++ trunk/extensions/EducationProgram/actions/EPRemoveArticleAction.php
2012-02-19 01:08:32 UTC (rev 111850)
@@ -1,8 +1,8 @@
<?php
/**
+ * Remove an article-student association.
*
- *
* @since 0.1
*
* @file EPRemoveArticleAction.php
@@ -31,15 +31,18 @@
$user = $this->getUser();
if ( $user->matchEditToken( $req->getText( 'token' ),
'remarticle' . $req->getInt( 'article-id' ) ) ) {
- EPArticles::singleton()->delete( array(
+ $article = EPArticles::singleton()->selectRow( 'id',
array(
'id' => $req->getInt( 'article-id' ),
'user_id' => $user->getId(),
) );
+
+ if ( $article !== false && $article->remove() ) {
+ // TODO: log
+ }
}
Action::factory( 'view', $this->page, $this->context )->show();
return '';
}
-
-}
\ No newline at end of file
+}
Added: trunk/extensions/EducationProgram/actions/EPRemoveReviewerAction.php
===================================================================
--- trunk/extensions/EducationProgram/actions/EPRemoveReviewerAction.php
(rev 0)
+++ trunk/extensions/EducationProgram/actions/EPRemoveReviewerAction.php
2012-02-19 01:08:32 UTC (rev 111850)
@@ -0,0 +1,58 @@
+<?php
+
+/**
+ * Remove a reviewer from an article-student association.
+ *
+ * @since 0.1
+ *
+ * @file EPRemoveReviewerAction.php
+ * @ingroup EducationProgram
+ * @ingroup Action
+ *
+ * @licence GNU GPL v3+
+ * @author Jeroen De Dauw < [email protected] >
+ */
+class EPRemoveReviewerAction extends FormlessAction {
+
+ /**
+ * (non-PHPdoc)
+ * @see Action::getName()
+ */
+ public function getName() {
+ return 'epremreviewer';
+ }
+
+ /**
+ * (non-PHPdoc)
+ * @see FormlessAction::onView()
+ */
+ public function onView() {
+ $req = $this->getRequest();
+ $user = $this->getUser();
+
+ $salt = $req->getInt( 'user-id' ) .'remarticle' . $req->getInt(
'article-id' );
+
+ if ( $user->matchEditToken( $req->getText( 'token' ), $salt )
+ && ( $user->getId() === $req->getInt( 'user-id' ) ||
$user->isAllowed( 'ep-remreviewer' ) ) ) {
+
+ $article = EPArticles::singleton()->selectRow(
+ array( 'id', 'reviewers' ),
+ array( 'id' => $req->getInt( 'article-id' ) )
+ );
+
+ if ( $article !== false ) {
+ $removedReviewers = $article->removeReviewers(
array( $req->getInt( 'user-id' ) ) );
+
+ if ( !empty( $removedReviewers ) ) {
+ if ( $article->save() ) {
+ $article->logReviewersRemoval(
$removedReviewers );
+ }
+ }
+ }
+ }
+
+ Action::factory( 'view', $this->page, $this->context )->show();
+ return '';
+ }
+
+}
Added: trunk/extensions/EducationProgram/actions/EPRemoveStudentAction.php
===================================================================
--- trunk/extensions/EducationProgram/actions/EPRemoveStudentAction.php
(rev 0)
+++ trunk/extensions/EducationProgram/actions/EPRemoveStudentAction.php
2012-02-19 01:08:32 UTC (rev 111850)
@@ -0,0 +1,46 @@
+<?php
+
+/**
+ * Remove a student from a course.
+ *
+ * @since 0.1
+ *
+ * @file EPRemoveStudentAction.php
+ * @ingroup EducationProgram
+ * @ingroup Action
+ *
+ * @licence GNU GPL v3+
+ * @author Jeroen De Dauw < [email protected] >
+ */
+class EPRemoveStudentAction extends FormlessAction {
+
+ /**
+ * (non-PHPdoc)
+ * @see Action::getName()
+ */
+ public function getName() {
+ return 'epremstudent';
+ }
+
+ /**
+ * (non-PHPdoc)
+ * @see FormlessAction::onView()
+ */
+ public function onView() {
+ $api = new ApiMain( new FauxRequest( array(
+ 'action' => 'enlist',
+ 'subaction' => 'remove',
+ 'format' => 'json',
+ 'courseid' => $this->getRequest()->getInt( 'course-id'
),
+ 'userid' => $this->getRequest()->getInt( 'user-id' ),
+ 'reason' => '', // TODO
+ 'role' => 'student'
+ ), true ), true );
+
+ try { $api->execute(); } catch ( Exception $exception ) {}
+
+ Action::factory( 'view', $this->page, $this->context )->show();
+ return '';
+ }
+
+}
Modified: trunk/extensions/EducationProgram/includes/EPArticle.php
===================================================================
--- trunk/extensions/EducationProgram/includes/EPArticle.php 2012-02-19
01:07:16 UTC (rev 111849)
+++ trunk/extensions/EducationProgram/includes/EPArticle.php 2012-02-19
01:08:32 UTC (rev 111850)
@@ -98,4 +98,32 @@
return $this->canBecomeReviwer[$user->getId()];
}
+ public function addReviewers( array $userIds ) {
+ $addedIds = array_diff( $userIds, $this->getField( 'reviewers'
) );
+
+ if ( !empty( $addedIds ) ) {
+ $this->setField( 'reviewers', array_merge( $userIds,
$addedIds ) );
+ }
+
+ return $addedIds;
+ }
+
+ public function logReviewersAdittion( array $userIds ) {
+ // TODO
+ }
+
+ public function removeReviewers( array $userIds ) {
+ $removedIds = array_intersect( $userIds, $this->getField(
'reviewers' ) );
+
+ if ( !empty( $removedIds ) ) {
+ $this->setField( 'reviewers', array_diff(
$this->getField( 'reviewers' ), $userIds ) );
+ }
+
+ return $removedIds;
+ }
+
+ public function logReviewersRemoval( array $userIds ) {
+ // TODO
+ }
+
}
Modified: trunk/extensions/EducationProgram/includes/EPArticleTable.php
===================================================================
--- trunk/extensions/EducationProgram/includes/EPArticleTable.php
2012-02-19 01:07:16 UTC (rev 111849)
+++ trunk/extensions/EducationProgram/includes/EPArticleTable.php
2012-02-19 01:08:32 UTC (rev 111850)
@@ -377,33 +377,38 @@
protected function getArticleAdittionControl( $courseId ) {
$html = '';
- $html .= Html::openElement(
- 'form',
- array(
- 'method' => 'post',
- 'action' => $this->getTitle()->getLocalURL(
array( 'action' => 'epaddarticle' ) ),
- )
- );
+ if ( $this->getUser()->isAllowed( 'ep-student' )
+ && $this->getUser()->getId() ===
$this->currentObject->getField( 'user_id' ) ) {
- $html .= Xml::inputLabel(
- wfMsg( 'ep-artciles-addarticle-text' ),
- 'addarticlename',
- 'addarticlename'
- );
+ $html .= Html::openElement(
+ 'form',
+ array(
+ 'method' => 'post',
+ 'action' =>
$this->getTitle()->getLocalURL( array( 'action' => 'epaddarticle' ) ),
+ )
+ );
- $html .= ' ' . Html::input(
- 'addarticle',
- wfMsg( 'ep-artciles-addarticle-button' ),
- 'submit',
- array(
- 'class' => 'ep-addarticle',
- )
- );
+ $html .= Xml::inputLabel(
+ wfMsg( 'ep-artciles-addarticle-text' ),
+ 'addarticlename',
+ 'addarticlename'
+ );
- $html .= Html::hidden( 'addArticleToken',
$this->getUser()->getEditToken( 'addarticle' . $courseId ) );
+ $html .= ' ' . Html::input(
+ 'addarticle',
+ wfMsg( 'ep-artciles-addarticle-button' ),
+ 'submit',
+ array(
+ 'class' => 'ep-addarticle',
+ )
+ );
- $html .= '</form>';
+ $html .= Html::hidden( 'token',
$this->getUser()->getEditToken( 'addarticle' . $courseId ) );
+ $html .= '</form>';
+ }
+
+
return '<td colspan="2">' . $html . '</td>';
}
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs