Index: trunk/extensions/EducationProgram/EducationProgram.php |
— | — | @@ -11,6 +11,7 @@ |
12 | 12 | * * Org instead of Institution |
13 | 13 | * * CA for campus ambassador |
14 | 14 | * * OA for online ambassador |
| 15 | + * * Article is often used to refer to "article student associations" rather then the Article class. |
15 | 16 | * |
16 | 17 | * @file EducationProgram.php |
17 | 18 | * @ingroup EducationProgram |
— | — | @@ -241,7 +242,9 @@ |
242 | 243 | $wgAvailableRights[] = 'ep-remreviewer'; // Remove reviewers from articles |
243 | 244 | $wgAvailableRights[] = 'ep-bulkdelorgs'; // Bulk delete institutions |
244 | 245 | $wgAvailableRights[] = 'ep-bulkdelcourses'; // Bulk delete courses |
| 246 | +$wgAvailableRights[] = 'ep-remarticle'; // Remove artiles (from being student associated) |
245 | 247 | |
| 248 | + |
246 | 249 | // User group rights |
247 | 250 | $wgGroupPermissions['*']['ep-enroll'] = true; |
248 | 251 | $wgGroupPermissions['*']['ep-org'] = false; |
— | — | @@ -254,10 +257,11 @@ |
255 | 258 | $wgGroupPermissions['*']['ep-beonline'] = false; |
256 | 259 | $wgGroupPermissions['*']['ep-becampus'] = false; |
257 | 260 | $wgGroupPermissions['*']['ep-beinstructor'] = false; |
258 | | -$wgGroupPermissions['*']['ep-bereviewer'] = true; // TODO: do we want this? |
| 261 | +$wgGroupPermissions['*']['ep-bereviewer'] = true; |
259 | 262 | $wgGroupPermissions['*']['ep-remreviewer'] = false; |
260 | 263 | $wgGroupPermissions['*']['ep-bulkdelorgs'] = false; |
261 | 264 | $wgGroupPermissions['*']['ep-bulkdelcourses'] = false; |
| 265 | +$wgGroupPermissions['*']['ep-remarticle'] = false; |
262 | 266 | |
263 | 267 | $wgGroupPermissions['epstaff']['ep-org'] = true; |
264 | 268 | $wgGroupPermissions['epstaff']['ep-course'] = true; |
— | — | @@ -274,6 +278,7 @@ |
275 | 279 | $wgGroupPermissions['epstaff']['ep-remreviewer'] = true; |
276 | 280 | $wgGroupPermissions['epstaff']['ep-bulkdelorgs'] = true; |
277 | 281 | $wgGroupPermissions['epstaff']['ep-bulkdelcourses'] = true; |
| 282 | +$wgGroupPermissions['epstaff']['ep-remarticle'] = true; |
278 | 283 | |
279 | 284 | $wgGroupPermissions['epadmin']['ep-org'] = true; |
280 | 285 | $wgGroupPermissions['epadmin']['ep-course'] = true; |
— | — | @@ -289,22 +294,26 @@ |
290 | 295 | $wgGroupPermissions['epadmin']['ep-bereviewer'] = true; |
291 | 296 | $wgGroupPermissions['epadmin']['ep-remreviewer'] = true; |
292 | 297 | $wgGroupPermissions['epadmin']['ep-bulkdelcourses'] = true; |
| 298 | +$wgGroupPermissions['epadmin']['ep-remarticle'] = true; |
293 | 299 | |
294 | 300 | $wgGroupPermissions['eponlineamb']['ep-org'] = true; |
295 | 301 | $wgGroupPermissions['eponlineamb']['ep-course'] = true; |
296 | 302 | $wgGroupPermissions['eponlineamb']['ep-token'] = true; |
297 | 303 | $wgGroupPermissions['eponlineamb']['ep-beonline'] = true; |
| 304 | +$wgGroupPermissions['eponlineamb']['ep-remarticle'] = true; |
298 | 305 | |
299 | 306 | $wgGroupPermissions['epcampamb']['ep-org'] = true; |
300 | 307 | $wgGroupPermissions['epcampamb']['ep-course'] = true; |
301 | 308 | $wgGroupPermissions['epcampamb']['ep-token'] = true; |
302 | 309 | $wgGroupPermissions['epcampamb']['ep-becampus'] = true; |
| 310 | +$wgGroupPermissions['epcampamb']['ep-remarticle'] = true; |
303 | 311 | |
304 | 312 | $wgGroupPermissions['epinstructor']['ep-org'] = true; |
305 | 313 | $wgGroupPermissions['epinstructor']['ep-course'] = true; |
306 | 314 | $wgGroupPermissions['epinstructor']['ep-token'] = true; |
307 | 315 | $wgGroupPermissions['epinstructor']['ep-beinstructor'] = true; |
308 | 316 | $wgGroupPermissions['epinstructor']['ep-remstudent'] = true; |
| 317 | +$wgGroupPermissions['epinstructor']['ep-remarticle'] = true; |
309 | 318 | |
310 | 319 | $wgGroupPermissions['epstaff']['userrights'] = false; |
311 | 320 | $wgAddGroups['epstaff'] = array( 'epstaff', 'epadmin', 'eponlineamb', 'epcampamb', 'epinstructor' ); |
Index: trunk/extensions/EducationProgram/actions/EPRemoveReviewerAction.php |
— | — | @@ -37,7 +37,7 @@ |
38 | 38 | && ( $user->getId() === $userIdToRemove || $user->isAllowed( 'ep-remreviewer' ) ) ) { |
39 | 39 | |
40 | 40 | $article = EPArticles::singleton()->selectRow( |
41 | | - array( 'id', 'reviewers' ), |
| 41 | + null, |
42 | 42 | array( 'id' => $req->getInt( 'article-id' ) ) |
43 | 43 | ); |
44 | 44 | |
Index: trunk/extensions/EducationProgram/actions/EPAddArticleAction.php |
— | — | @@ -53,15 +53,7 @@ |
54 | 54 | $article = EPArticles::singleton()->newFromArray( $articleData, true ); |
55 | 55 | |
56 | 56 | if ( $article->save() ) { |
57 | | - EPUtils::log( array( |
58 | | - 'type' => 'eparticle', |
59 | | - 'subtype' => 'add', |
60 | | - 'user' => $this->getUser(), |
61 | | - 'title' => $course->getTitle(), |
62 | | - 'parameters' => array( |
63 | | - '4::articlename' => $title->getFullText(), |
64 | | - ), |
65 | | - ) ); |
| 57 | + $article->logAdittion( $this->getUser() ); |
66 | 58 | } |
67 | 59 | } |
68 | 60 | } |
Index: trunk/extensions/EducationProgram/actions/EPAddReviewerAction.php |
— | — | @@ -36,7 +36,7 @@ |
37 | 37 | if ( $user->matchEditToken( $req->getText( 'token' ), $salt ) ) { |
38 | 38 | |
39 | 39 | $article = EPArticles::singleton()->selectRow( |
40 | | - array( 'id', 'reviewers', 'page_id', 'page_title' ), |
| 40 | + null, |
41 | 41 | array( 'id' => $req->getInt( 'article-id' ) ) |
42 | 42 | ); |
43 | 43 | |
Index: trunk/extensions/EducationProgram/actions/EPRemoveArticleAction.php |
— | — | @@ -32,28 +32,14 @@ |
33 | 33 | |
34 | 34 | if ( $user->matchEditToken( $req->getText( 'token' ), 'remarticle' . $req->getInt( 'article-id' ) ) ) { |
35 | 35 | $article = EPArticles::singleton()->selectRow( |
| 36 | + null, |
36 | 37 | array( |
37 | | - 'id', |
38 | | - 'course_id', |
39 | | - 'page_id', |
40 | | - 'page_title', |
41 | | - ), |
42 | | - array( |
43 | 38 | 'id' => $req->getInt( 'article-id' ), |
44 | | - 'user_id' => $user->getId(), |
45 | 39 | ) |
46 | 40 | ); |
47 | 41 | |
48 | | - if ( $article !== false && $article->remove() ) { |
49 | | - EPUtils::log( array( |
50 | | - 'type' => 'eparticle', |
51 | | - 'subtype' => 'remove', |
52 | | - 'user' => $this->getUser(), |
53 | | - 'title' => $article->getCourse()->getTitle(), |
54 | | - 'parameters' => array( |
55 | | - '4::articlename' => $article->getTitle()->getFullText(), |
56 | | - ), |
57 | | - ) ); |
| 42 | + if ( $article !== false && $article->userCanRemove( $this->getUser() ) && $article->remove() ) { |
| 43 | + $article->logRemoval( $this->getUser() ); |
58 | 44 | } |
59 | 45 | } |
60 | 46 | |
Index: trunk/extensions/EducationProgram/includes/EPLogFormatter.php |
— | — | @@ -21,6 +21,11 @@ |
22 | 22 | * |
23 | 23 | * This is overridden to change the link text to only include the name of the object, |
24 | 24 | * rather then the full name of it's page. |
| 25 | + * |
| 26 | + * @param Title $title |
| 27 | + * @param $parameters |
| 28 | + * |
| 29 | + * @return string |
25 | 30 | */ |
26 | 31 | protected function makePageLink( Title $title = null, $parameters = array() ) { |
27 | 32 | if ( !$title instanceof Title ) { |
— | — | @@ -41,6 +46,17 @@ |
42 | 47 | |
43 | 48 | } |
44 | 49 | |
| 50 | +/** |
| 51 | + * Class for logging role changes. ie people gaining or losing a role. |
| 52 | + * |
| 53 | + * @since 0.1 |
| 54 | + * |
| 55 | + * @file EPLogFormatter.php |
| 56 | + * @ingroup EducationProgram |
| 57 | + * |
| 58 | + * @licence GNU GPL v3 or later |
| 59 | + * @author Jeroen De Dauw < jeroendedauw@gmail.com > |
| 60 | + */ |
45 | 61 | class EPRoleChangeFormatter extends EPLogFormatter { |
46 | 62 | |
47 | 63 | /** |
— | — | @@ -62,6 +78,17 @@ |
63 | 79 | |
64 | 80 | } |
65 | 81 | |
| 82 | +/** |
| 83 | + * Class for logging role changes to student article associations. |
| 84 | + * |
| 85 | + * @since 0.1 |
| 86 | + * |
| 87 | + * @file EPLogFormatter.php |
| 88 | + * @ingroup EducationProgram |
| 89 | + * |
| 90 | + * @licence GNU GPL v3 or later |
| 91 | + * @author Jeroen De Dauw < jeroendedauw@gmail.com > |
| 92 | + */ |
66 | 93 | class EPArticleFormatter extends EPLogFormatter { |
67 | 94 | |
68 | 95 | /** |
— | — | @@ -73,6 +100,12 @@ |
74 | 101 | |
75 | 102 | if ( !empty( $params ) ) { |
76 | 103 | $params[3] = Message::rawParam( Linker::link( Title::newFromText( $params[3] ) ) ); |
| 104 | + |
| 105 | + if ( isset( $params[4] ) ) { |
| 106 | + list( $id, $name ) = $params[4]; |
| 107 | + $params[4] = Message::rawParam( Linker::userLink( $id, $name ) ); |
| 108 | + $params[5] = $name; |
| 109 | + } |
77 | 110 | } |
78 | 111 | |
79 | 112 | return $params; |
Index: trunk/extensions/EducationProgram/includes/EPArticleTable.php |
— | — | @@ -310,7 +310,7 @@ |
311 | 311 | 'returnto' => $this->getTitle()->getFullText(), |
312 | 312 | ) ); |
313 | 313 | |
314 | | - if ( $this->getUser()->getId() === $article->getField( 'user_id' ) ) { |
| 314 | + if ( $article->userCanRemove( $this->getUser() ) ) { |
315 | 315 | $html .= ' (' . Html::element( |
316 | 316 | 'a', |
317 | 317 | $attr, |
Index: trunk/extensions/EducationProgram/includes/EPArticle.php |
— | — | @@ -177,12 +177,7 @@ |
178 | 178 | */ |
179 | 179 | public function logReviewersAdittion( array $userIds ) { |
180 | 180 | foreach ( $userIds as $userId ) { |
181 | | - EPUtils::log( array( |
182 | | - 'user' => User::newFromId( $userId ), |
183 | | - 'title' => $this->getTitle(), |
184 | | - 'type' => 'eparticle', |
185 | | - 'subtype' => 'review', |
186 | | - ) ); |
| 181 | + $this->log( User::newFromId( $userId ), 'review' ); |
187 | 182 | } |
188 | 183 | } |
189 | 184 | |
— | — | @@ -216,13 +211,68 @@ |
217 | 212 | */ |
218 | 213 | public function logReviewersRemoval( array $userIds ) { |
219 | 214 | foreach ( $userIds as $userId ) { |
220 | | - EPUtils::log( array( |
221 | | - 'user' => User::newFromId( $userId ), |
222 | | - 'title' => $this->getTitle(), |
223 | | - 'type' => 'eparticle', |
224 | | - 'subtype' => 'unreview', |
225 | | - ) ); |
| 215 | + $this->log( User::newFromId( $userId ), 'unreview' ); |
226 | 216 | } |
227 | 217 | } |
228 | 218 | |
| 219 | + /** |
| 220 | + * Log adittion of the article. |
| 221 | + * |
| 222 | + * @param User $actionUser |
| 223 | + */ |
| 224 | + public function logAdittion( User $actionUser ) { |
| 225 | + $this->log( |
| 226 | + $actionUser, |
| 227 | + $actionUser->getId() === $this->getUser()->getId() ? 'selfadd' : 'add' |
| 228 | + ); |
| 229 | + } |
| 230 | + |
| 231 | + /** |
| 232 | + * Log removal of the article. |
| 233 | + * |
| 234 | + * @param User $actionUser |
| 235 | + */ |
| 236 | + public function logRemoval( User $actionUser ) { |
| 237 | + $this->log( |
| 238 | + $actionUser, |
| 239 | + $actionUser->getId() === $this->getUser()->getId() ? 'selfremove' : 'remove' |
| 240 | + ); |
| 241 | + } |
| 242 | + |
| 243 | + /** |
| 244 | + * Logging helper method. |
| 245 | + * |
| 246 | + * @since 0.1 |
| 247 | + * |
| 248 | + * @param User $actionUser |
| 249 | + * @param string $subType |
| 250 | + */ |
| 251 | + protected function log( User $actionUser, $subType ) { |
| 252 | + $articleOwner = $this->getUser(); |
| 253 | + |
| 254 | + EPUtils::log( array( |
| 255 | + 'user' => $actionUser, |
| 256 | + 'title' => $this->getTitle(), |
| 257 | + 'type' => 'eparticle', |
| 258 | + 'subtype' => $subType, |
| 259 | + 'parameters' => array( |
| 260 | + '4::coursename' => $this->getCourse()->getTitle()->getFullText(), |
| 261 | + '5::owner' => array( $articleOwner->getId(), $articleOwner->getName() ), |
| 262 | + ), |
| 263 | + ) ); |
| 264 | + } |
| 265 | + |
| 266 | + /** |
| 267 | + * Returns if the provided user can remove the article. |
| 268 | + * |
| 269 | + * @since 0.1 |
| 270 | + * |
| 271 | + * @param User $user |
| 272 | + * |
| 273 | + * @return boolean |
| 274 | + */ |
| 275 | + public function userCanRemove( User $user ) { |
| 276 | + return $user->isAllowed( 'ep-remarticle' ) || $user->getId() === $this->getField( 'user_id' ); |
| 277 | + } |
| 278 | + |
229 | 279 | } |
Index: trunk/extensions/EducationProgram/EducationProgram.i18n.php |
— | — | @@ -118,8 +118,12 @@ |
119 | 119 | 'logentry-student-selfadd' => '$1 enrolled in course $3', |
120 | 120 | 'logentry-student-selfremove' => '$1 disenrolled from course $3', |
121 | 121 | |
122 | | - 'logentry-eparticle-add' => '$1 added article $4 to {{GENDER:$2|his|her}} list of articles at course $3', |
123 | | - 'logentry-eparticle-remove' => '$1 removed article $4 from {{GENDER:$2|his|her}} list of articles at course $3', |
| 122 | + 'logentry-eparticle-selfadd' => '$1 added article $3 to {{GENDER:$2|his|her}} list of articles at course $4', |
| 123 | + 'logentry-eparticle-selfremove' => '$1 removed article $3 from {{GENDER:$2|his|her}} list of articles at course $4', |
| 124 | + 'logentry-eparticle-add' => '$1 added article $3 to $5 {{GENDER:$6|his|her}} list of articles at course $4', |
| 125 | + 'logentry-eparticle-remove' => '$1 removed article $3 from $5 {{GENDER:$6|his|her}} list of articles at course $4', |
| 126 | + 'logentry-eparticle-review' => '$1 added {{GENDER:$2|himself|herself}} as reviewer to article $3 worked upon by $5 as part of course $4', |
| 127 | + 'logentry-eparticle-unreview' => '$1 removed {{GENDER:$2|himself|herself}} as reviewer to article $3 worked upon by $5 as part of course $4', |
124 | 128 | |
125 | 129 | // Preferences |
126 | 130 | 'prefs-education' => 'Education', |