https://www.mediawiki.org/wiki/Special:Code/MediaWiki/113687

Revision: 113687
Author:   jeroendedauw
Date:     2012-03-12 23:58:35 +0000 (Mon, 12 Mar 2012)
Log Message:
-----------
allow certain people to delete article associations from students

Modified Paths:
--------------
    trunk/extensions/EducationProgram/EducationProgram.i18n.php
    trunk/extensions/EducationProgram/EducationProgram.php
    trunk/extensions/EducationProgram/actions/EPAddArticleAction.php
    trunk/extensions/EducationProgram/actions/EPAddReviewerAction.php
    trunk/extensions/EducationProgram/actions/EPRemoveArticleAction.php
    trunk/extensions/EducationProgram/actions/EPRemoveReviewerAction.php
    trunk/extensions/EducationProgram/includes/EPArticle.php
    trunk/extensions/EducationProgram/includes/EPArticleTable.php
    trunk/extensions/EducationProgram/includes/EPLogFormatter.php

Modified: trunk/extensions/EducationProgram/EducationProgram.i18n.php
===================================================================
--- trunk/extensions/EducationProgram/EducationProgram.i18n.php 2012-03-12 
23:56:59 UTC (rev 113686)
+++ trunk/extensions/EducationProgram/EducationProgram.i18n.php 2012-03-12 
23:58:35 UTC (rev 113687)
@@ -118,8 +118,12 @@
        'logentry-student-selfadd' => '$1 enrolled in course $3',
        'logentry-student-selfremove' => '$1 disenrolled from course $3',
 
-       'logentry-eparticle-add' => '$1 added article $4 to 
{{GENDER:$2|his|her}} list of articles at course $3',
-       'logentry-eparticle-remove' => '$1 removed article $4 from 
{{GENDER:$2|his|her}} list of articles at course $3',
+       'logentry-eparticle-selfadd' => '$1 added article $3 to 
{{GENDER:$2|his|her}} list of articles at course $4',
+       'logentry-eparticle-selfremove' => '$1 removed article $3 from 
{{GENDER:$2|his|her}} list of articles at course $4',
+       'logentry-eparticle-add' => '$1 added article $3 to $5 
{{GENDER:$6|his|her}} list of articles at course $4',
+       'logentry-eparticle-remove' => '$1 removed article $3 from $5 
{{GENDER:$6|his|her}} list of articles at course $4',
+       'logentry-eparticle-review' => '$1 added {{GENDER:$2|himself|herself}} 
as reviewer to article $3 worked upon by $5 as part of course $4',
+       'logentry-eparticle-unreview' => '$1 removed 
{{GENDER:$2|himself|herself}} as reviewer to article $3 worked upon by $5 as 
part of course $4',
 
        // Preferences
        'prefs-education' => 'Education',

Modified: trunk/extensions/EducationProgram/EducationProgram.php
===================================================================
--- trunk/extensions/EducationProgram/EducationProgram.php      2012-03-12 
23:56:59 UTC (rev 113686)
+++ trunk/extensions/EducationProgram/EducationProgram.php      2012-03-12 
23:58:35 UTC (rev 113687)
@@ -11,6 +11,7 @@
  * * Org instead of Institution
  * * CA for campus ambassador
  * * OA for online ambassador
+ * * Article is often used to refer to "article student associations" rather 
then the Article class.
  *
  * @file EducationProgram.php
  * @ingroup EducationProgram
@@ -241,7 +242,9 @@
 $wgAvailableRights[] = 'ep-remreviewer';       // Remove reviewers from 
articles
 $wgAvailableRights[] = 'ep-bulkdelorgs';       // Bulk delete institutions
 $wgAvailableRights[] = 'ep-bulkdelcourses';    // Bulk delete courses
+$wgAvailableRights[] = 'ep-remarticle';                // Remove artiles (from 
being student associated)
 
+
 // User group rights
 $wgGroupPermissions['*']['ep-enroll'] = true;
 $wgGroupPermissions['*']['ep-org'] = false;
@@ -254,10 +257,11 @@
 $wgGroupPermissions['*']['ep-beonline'] = false;
 $wgGroupPermissions['*']['ep-becampus'] = false;
 $wgGroupPermissions['*']['ep-beinstructor'] = false;
-$wgGroupPermissions['*']['ep-bereviewer'] = true; // TODO: do we want this?
+$wgGroupPermissions['*']['ep-bereviewer'] = true;
 $wgGroupPermissions['*']['ep-remreviewer'] = false;
 $wgGroupPermissions['*']['ep-bulkdelorgs'] = false;
 $wgGroupPermissions['*']['ep-bulkdelcourses'] = false;
+$wgGroupPermissions['*']['ep-remarticle'] = false;
 
 $wgGroupPermissions['epstaff']['ep-org'] = true;
 $wgGroupPermissions['epstaff']['ep-course'] = true;
@@ -274,6 +278,7 @@
 $wgGroupPermissions['epstaff']['ep-remreviewer'] = true;
 $wgGroupPermissions['epstaff']['ep-bulkdelorgs'] = true;
 $wgGroupPermissions['epstaff']['ep-bulkdelcourses'] = true;
+$wgGroupPermissions['epstaff']['ep-remarticle'] = true;
 
 $wgGroupPermissions['epadmin']['ep-org'] = true;
 $wgGroupPermissions['epadmin']['ep-course'] = true;
@@ -289,22 +294,26 @@
 $wgGroupPermissions['epadmin']['ep-bereviewer'] = true;
 $wgGroupPermissions['epadmin']['ep-remreviewer'] = true;
 $wgGroupPermissions['epadmin']['ep-bulkdelcourses'] = true;
+$wgGroupPermissions['epadmin']['ep-remarticle'] = true;
 
 $wgGroupPermissions['eponlineamb']['ep-org'] = true;
 $wgGroupPermissions['eponlineamb']['ep-course'] = true;
 $wgGroupPermissions['eponlineamb']['ep-token'] = true;
 $wgGroupPermissions['eponlineamb']['ep-beonline'] = true;
+$wgGroupPermissions['eponlineamb']['ep-remarticle'] = true;
 
 $wgGroupPermissions['epcampamb']['ep-org'] = true;
 $wgGroupPermissions['epcampamb']['ep-course'] = true;
 $wgGroupPermissions['epcampamb']['ep-token'] = true;
 $wgGroupPermissions['epcampamb']['ep-becampus'] = true;
+$wgGroupPermissions['epcampamb']['ep-remarticle'] = true;
 
 $wgGroupPermissions['epinstructor']['ep-org'] = true;
 $wgGroupPermissions['epinstructor']['ep-course'] = true;
 $wgGroupPermissions['epinstructor']['ep-token'] = true;
 $wgGroupPermissions['epinstructor']['ep-beinstructor'] = true;
 $wgGroupPermissions['epinstructor']['ep-remstudent'] = true;
+$wgGroupPermissions['epinstructor']['ep-remarticle'] = true;
 
 $wgGroupPermissions['epstaff']['userrights'] = false;
 $wgAddGroups['epstaff'] = array( 'epstaff', 'epadmin', 'eponlineamb', 
'epcampamb', 'epinstructor' );

Modified: trunk/extensions/EducationProgram/actions/EPAddArticleAction.php
===================================================================
--- trunk/extensions/EducationProgram/actions/EPAddArticleAction.php    
2012-03-12 23:56:59 UTC (rev 113686)
+++ trunk/extensions/EducationProgram/actions/EPAddArticleAction.php    
2012-03-12 23:58:35 UTC (rev 113687)
@@ -53,15 +53,7 @@
                                        $article = 
EPArticles::singleton()->newFromArray( $articleData, true );
 
                                        if ( $article->save() ) {
-                                               EPUtils::log( array(
-                                                       'type' => 'eparticle',
-                                                       'subtype' => 'add',
-                                                       'user' => 
$this->getUser(),
-                                                       'title' => 
$course->getTitle(),
-                                                       'parameters' => array(
-                                                               
'4::articlename' => $title->getFullText(),
-                                                       ),
-                                               ) );
+                                               $article->logAdittion( 
$this->getUser() );
                                        }
                                }
                        }

Modified: trunk/extensions/EducationProgram/actions/EPAddReviewerAction.php
===================================================================
--- trunk/extensions/EducationProgram/actions/EPAddReviewerAction.php   
2012-03-12 23:56:59 UTC (rev 113686)
+++ trunk/extensions/EducationProgram/actions/EPAddReviewerAction.php   
2012-03-12 23:58:35 UTC (rev 113687)
@@ -36,7 +36,7 @@
                if ( $user->matchEditToken( $req->getText( 'token' ), $salt ) ) 
{
 
                        $article = EPArticles::singleton()->selectRow(
-                               array( 'id', 'reviewers', 'page_id', 
'page_title' ),
+                               null,
                                array( 'id' => $req->getInt( 'article-id' ) )
                        );
 

Modified: trunk/extensions/EducationProgram/actions/EPRemoveArticleAction.php
===================================================================
--- trunk/extensions/EducationProgram/actions/EPRemoveArticleAction.php 
2012-03-12 23:56:59 UTC (rev 113686)
+++ trunk/extensions/EducationProgram/actions/EPRemoveArticleAction.php 
2012-03-12 23:58:35 UTC (rev 113687)
@@ -32,28 +32,14 @@
 
                if ( $user->matchEditToken( $req->getText( 'token' ), 
'remarticle' . $req->getInt( 'article-id' ) ) ) {
                        $article = EPArticles::singleton()->selectRow(
+                               null,
                                array(
-                                       'id',
-                                       'course_id',
-                                       'page_id',
-                                       'page_title',
-                               ),
-                               array(
                                        'id' => $req->getInt( 'article-id' ),
-                                       'user_id' => $user->getId(),
                                )
                        );
 
-                       if ( $article !== false && $article->remove() ) {
-                               EPUtils::log( array(
-                                       'type' => 'eparticle',
-                                       'subtype' => 'remove',
-                                       'user' => $this->getUser(),
-                                       'title' => 
$article->getCourse()->getTitle(),
-                                       'parameters' => array(
-                                               '4::articlename' => 
$article->getTitle()->getFullText(),
-                                       ),
-                               ) );
+                       if ( $article !== false && $article->userCanRemove( 
$this->getUser() ) && $article->remove() ) {
+                               $article->logRemoval( $this->getUser() );
                        }
                }
 

Modified: trunk/extensions/EducationProgram/actions/EPRemoveReviewerAction.php
===================================================================
--- trunk/extensions/EducationProgram/actions/EPRemoveReviewerAction.php        
2012-03-12 23:56:59 UTC (rev 113686)
+++ trunk/extensions/EducationProgram/actions/EPRemoveReviewerAction.php        
2012-03-12 23:58:35 UTC (rev 113687)
@@ -37,7 +37,7 @@
                        && ( $user->getId() === $userIdToRemove || 
$user->isAllowed( 'ep-remreviewer' ) ) ) {
 
                        $article = EPArticles::singleton()->selectRow(
-                               array( 'id', 'reviewers' ),
+                               null,
                                array( 'id' => $req->getInt( 'article-id' ) )
                        );
 

Modified: trunk/extensions/EducationProgram/includes/EPArticle.php
===================================================================
--- trunk/extensions/EducationProgram/includes/EPArticle.php    2012-03-12 
23:56:59 UTC (rev 113686)
+++ trunk/extensions/EducationProgram/includes/EPArticle.php    2012-03-12 
23:58:35 UTC (rev 113687)
@@ -177,12 +177,7 @@
         */
        public function logReviewersAdittion( array $userIds ) {
                foreach ( $userIds as $userId ) {
-                       EPUtils::log( array(
-                               'user' => User::newFromId( $userId ),
-                               'title' => $this->getTitle(),
-                               'type' => 'eparticle',
-                               'subtype' => 'review',
-                       ) );
+                       $this->log( User::newFromId( $userId ), 'review' );
                }
        }
 
@@ -216,13 +211,68 @@
         */
        public function logReviewersRemoval( array $userIds ) {
                foreach ( $userIds as $userId ) {
-                       EPUtils::log( array(
-                               'user' => User::newFromId( $userId ),
-                               'title' => $this->getTitle(),
-                               'type' => 'eparticle',
-                               'subtype' => 'unreview',
-                       ) );
+                       $this->log( User::newFromId( $userId ), 'unreview' );
                }
        }
 
+       /**
+        * Log adittion of the article.
+        *
+        * @param User $actionUser
+        */
+       public function logAdittion( User $actionUser ) {
+               $this->log(
+                       $actionUser,
+                       $actionUser->getId() === $this->getUser()->getId() ? 
'selfadd' : 'add'
+               );
+       }
+
+       /**
+        * Log removal of the article.
+        *
+        * @param User $actionUser
+        */
+       public function logRemoval( User $actionUser ) {
+               $this->log(
+                       $actionUser,
+                       $actionUser->getId() === $this->getUser()->getId() ? 
'selfremove' : 'remove'
+               );
+       }
+
+       /**
+        * Logging helper method.
+        *
+        * @since 0.1
+        *
+        * @param User $actionUser
+        * @param string $subType
+        */
+       protected function log( User $actionUser, $subType ) {
+               $articleOwner = $this->getUser();
+
+               EPUtils::log( array(
+                       'user' => $actionUser,
+                       'title' => $this->getTitle(),
+                       'type' => 'eparticle',
+                       'subtype' => $subType,
+                       'parameters' => array(
+                               '4::coursename' => 
$this->getCourse()->getTitle()->getFullText(),
+                               '5::owner' => array( $articleOwner->getId(), 
$articleOwner->getName() ),
+                       ),
+               ) );
+       }
+
+       /**
+        * Returns if the provided user can remove the article.
+        *
+        * @since 0.1
+        *
+        * @param User $user
+        *
+        * @return boolean
+        */
+       public function userCanRemove( User $user ) {
+               return $user->isAllowed( 'ep-remarticle' ) || $user->getId() 
=== $this->getField( 'user_id' );
+       }
+
 }

Modified: trunk/extensions/EducationProgram/includes/EPArticleTable.php
===================================================================
--- trunk/extensions/EducationProgram/includes/EPArticleTable.php       
2012-03-12 23:56:59 UTC (rev 113686)
+++ trunk/extensions/EducationProgram/includes/EPArticleTable.php       
2012-03-12 23:58:35 UTC (rev 113687)
@@ -310,7 +310,7 @@
                                'returnto' => $this->getTitle()->getFullText(),
                        ) );
 
-                       if ( $this->getUser()->getId() === $article->getField( 
'user_id' ) ) {
+                       if ( $article->userCanRemove( $this->getUser() ) ) {
                                $html .= ' (' . Html::element(
                                        'a',
                                        $attr,

Modified: trunk/extensions/EducationProgram/includes/EPLogFormatter.php
===================================================================
--- trunk/extensions/EducationProgram/includes/EPLogFormatter.php       
2012-03-12 23:56:59 UTC (rev 113686)
+++ trunk/extensions/EducationProgram/includes/EPLogFormatter.php       
2012-03-12 23:58:35 UTC (rev 113687)
@@ -21,6 +21,11 @@
         * 
         * This is overridden to change the link text to only include the name 
of the object,
         * rather then the full name of it's page.
+        *
+        * @param Title $title
+        * @param $parameters
+        *
+        * @return string
         */
        protected function makePageLink( Title $title = null, $parameters = 
array() ) {
                if ( !$title instanceof Title ) {
@@ -41,6 +46,17 @@
 
 }
 
+/**
+ * Class for logging role changes. ie people gaining or losing a role.
+ *
+ * @since 0.1
+ *
+ * @file EPLogFormatter.php
+ * @ingroup EducationProgram
+ *
+ * @licence GNU GPL v3 or later
+ * @author Jeroen De Dauw < [email protected] >
+ */
 class EPRoleChangeFormatter extends EPLogFormatter {
 
        /**
@@ -62,6 +78,17 @@
 
 }
 
+/**
+ * Class for logging role changes to student article associations.
+ *
+ * @since 0.1
+ *
+ * @file EPLogFormatter.php
+ * @ingroup EducationProgram
+ *
+ * @licence GNU GPL v3 or later
+ * @author Jeroen De Dauw < [email protected] >
+ */
 class EPArticleFormatter extends EPLogFormatter {
 
        /**
@@ -73,6 +100,12 @@
 
                if ( !empty( $params ) ) {
                        $params[3] = Message::rawParam( Linker::link( 
Title::newFromText( $params[3] ) ) );
+
+                       if ( isset( $params[4] ) ) {
+                               list( $id, $name ) = $params[4];
+                               $params[4] = Message::rawParam( 
Linker::userLink( $id, $name ) );
+                               $params[5] = $name;
+                       }
                }
 
                return $params;


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to