Index: trunk/extensions/EducationProgram/includes/EPOrg.php |
— | — | @@ -72,6 +72,19 @@ |
73 | 73 | |
74 | 74 | /** |
75 | 75 | * (non-PHPdoc) |
| 76 | + * @see EPDBObject::createLogEntry() |
| 77 | + */ |
| 78 | + protected function createLogEntry( $subType ) { |
| 79 | + $logEntry = new ManualLogEntry( 'institution', $subType ); |
| 80 | + |
| 81 | + $logEntry->setPerformer( $GLOBALS['wgUser'] ); |
| 82 | + $logEntry->setTarget( $this->getTitle() ); |
| 83 | + |
| 84 | + return $logEntry; |
| 85 | + } |
| 86 | + |
| 87 | + /** |
| 88 | + * (non-PHPdoc) |
76 | 89 | * @see EPDBObject::loadSummaryFields() |
77 | 90 | */ |
78 | 91 | public function loadSummaryFields( $summaryFields = null ) { |
— | — | @@ -140,6 +153,7 @@ |
141 | 154 | */ |
142 | 155 | public function removeFromDB() { |
143 | 156 | $id = $this->getId(); |
| 157 | + $this->loadFields( array( 'name' ) ); |
144 | 158 | |
145 | 159 | $success = parent::removeFromDB(); |
146 | 160 | |
— | — | @@ -318,6 +332,17 @@ |
319 | 333 | } |
320 | 334 | |
321 | 335 | /** |
| 336 | + * Get the title of Special:Institution/name. |
| 337 | + * |
| 338 | + * @since 0.1 |
| 339 | + * |
| 340 | + * @return Title |
| 341 | + */ |
| 342 | + public function getTitle() { |
| 343 | + return SpecialPage::getTitleFor( 'Institution', $this->getField( 'name' ) ); |
| 344 | + } |
| 345 | + |
| 346 | + /** |
322 | 347 | * Get a link to Special:Institution/name. |
323 | 348 | * |
324 | 349 | * @since 0.1 |
— | — | @@ -326,7 +351,7 @@ |
327 | 352 | */ |
328 | 353 | public function getLink() { |
329 | 354 | return Linker::linkKnown( |
330 | | - SpecialPage::getTitleFor( 'Institution', $this->getField( 'name' ) ), |
| 355 | + $this->getTitle(), |
331 | 356 | htmlspecialchars( $this->getField( 'name' ) ) |
332 | 357 | ); |
333 | 358 | } |
Index: trunk/extensions/EducationProgram/includes/EPDBObject.php |
— | — | @@ -42,6 +42,14 @@ |
43 | 43 | protected $updateSummaries = true; |
44 | 44 | |
45 | 45 | /** |
| 46 | + * If the object should log changes. |
| 47 | + * |
| 48 | + * @since 0.1 |
| 49 | + * @var bool |
| 50 | + */ |
| 51 | + protected $log = true; |
| 52 | + |
| 53 | + /** |
46 | 54 | * The database connection to use for read operations. |
47 | 55 | * |
48 | 56 | * @since 0.2 |
— | — | @@ -383,12 +391,18 @@ |
384 | 392 | protected function updateInDB() { |
385 | 393 | $dbw = wfGetDB( DB_MASTER ); |
386 | 394 | |
387 | | - return $dbw->update( |
| 395 | + $success = $dbw->update( |
388 | 396 | $this->getDBTable(), |
389 | 397 | $this->getWriteValues(), |
390 | 398 | array( $this->getFieldPrefix() . 'id' => $this->getId() ), |
391 | 399 | __METHOD__ |
392 | 400 | ); |
| 401 | + |
| 402 | + if ( $success ) { |
| 403 | + $this->log( 'update' ); |
| 404 | + } |
| 405 | + |
| 406 | + return $success; |
393 | 407 | } |
394 | 408 | |
395 | 409 | /** |
— | — | @@ -409,7 +423,10 @@ |
410 | 424 | array( 'IGNORE' ) |
411 | 425 | ); |
412 | 426 | |
413 | | - $this->setField( 'id', $dbw->insertId() ); |
| 427 | + if ( $result ) { |
| 428 | + $this->setField( 'id', $dbw->insertId() ); |
| 429 | + $this->log( 'add' ); |
| 430 | + } |
414 | 431 | |
415 | 432 | return $result; |
416 | 433 | } |
— | — | @@ -427,12 +444,45 @@ |
428 | 445 | |
429 | 446 | if ( $success ) { |
430 | 447 | $this->setField( 'id', null ); |
| 448 | + $this->log( 'remove' ); |
431 | 449 | } |
432 | 450 | |
433 | 451 | return $success; |
434 | 452 | } |
435 | 453 | |
436 | 454 | /** |
| 455 | + * Log an action. |
| 456 | + * |
| 457 | + * @since 0.1 |
| 458 | + * |
| 459 | + * @param string $subType |
| 460 | + */ |
| 461 | + protected function log( $subType ) { |
| 462 | + if ( $this->log ) { |
| 463 | + $logEntry = $this->createLogEntry( $subType ); |
| 464 | + |
| 465 | + if ( createLogEntry !== false ) { |
| 466 | + $logid = $logEntry->insert(); |
| 467 | + $logEntry->publish( $logid ); |
| 468 | + } |
| 469 | + } |
| 470 | + } |
| 471 | + |
| 472 | + /** |
| 473 | + * Override and create and return a log entry to |
| 474 | + * make the log method have an actual effect. |
| 475 | + * |
| 476 | + * @since 0.1 |
| 477 | + * |
| 478 | + * @param string $subType |
| 479 | + * |
| 480 | + * @return false|ManualLogEntry |
| 481 | + */ |
| 482 | + protected function createLogEntry( $subType ) { |
| 483 | + return false; |
| 484 | + } |
| 485 | + |
| 486 | + /** |
437 | 487 | * Return the names and values of the fields. |
438 | 488 | * |
439 | 489 | * @since 0.1 |
— | — | @@ -1141,4 +1191,22 @@ |
1142 | 1192 | $this->updateSummaries = $update; |
1143 | 1193 | } |
1144 | 1194 | |
| 1195 | + /** |
| 1196 | + * Sets the value for the @see $log field. |
| 1197 | + * |
| 1198 | + * @since 0.1 |
| 1199 | + */ |
| 1200 | + public function enableLogging() { |
| 1201 | + $this->log = true; |
| 1202 | + } |
| 1203 | + |
| 1204 | + /** |
| 1205 | + * Sets the value for the @see $log field. |
| 1206 | + * |
| 1207 | + * @since 0.1 |
| 1208 | + */ |
| 1209 | + public function disableLogging() { |
| 1210 | + $this->log = false; |
| 1211 | + } |
| 1212 | + |
1145 | 1213 | } |
Index: trunk/extensions/EducationProgram/EducationProgram.i18n.php |
— | — | @@ -32,6 +32,27 @@ |
33 | 33 | 'ep-nav-students' => 'Student list', |
34 | 34 | 'ep-nav-mentors' => 'Ambassador list', |
35 | 35 | |
| 36 | + // Logging |
| 37 | + 'log-name-institution' => 'Institution log', |
| 38 | + 'log-name-course' => 'Course log', |
| 39 | + 'log-name-term' => 'Term log', |
| 40 | + |
| 41 | + 'log-header-institution' => 'These events track when changes are made to institutions.', |
| 42 | + 'log-header-course' => 'These events track when changes are made to courses.', |
| 43 | + 'log-header-term' => 'These events track when changes are made to terms.', |
| 44 | + |
| 45 | + 'logentry-institution-add' => '$1 {{GENDER:$2|created institution}} $3', |
| 46 | + 'logentry-institution-remove' => '$1 {{GENDER:$2|removed institution}} $3', |
| 47 | + 'logentry-institution-update' => '$1 {{GENDER:$2|updated institution}} $3', |
| 48 | + |
| 49 | + 'logentry-course-add' => '$1 {{GENDER:$2|created course}} $3', |
| 50 | + 'logentry-course-remove' => '$1 {{GENDER:$2|removed course}} $3', |
| 51 | + 'logentry-course-update' => '$1 {{GENDER:$2|updated course}} $3', |
| 52 | + |
| 53 | + 'logentry-term-add' => '$1 {{GENDER:$2|created term}} $3', |
| 54 | + 'logentry-term-remove' => '$1 {{GENDER:$2|removed term}} $3', |
| 55 | + 'logentry-term-update' => '$1 {{GENDER:$2|updated term}} $3', |
| 56 | + |
36 | 57 | // Preferences |
37 | 58 | 'prefs-education' => 'Education', |
38 | 59 | 'ep-prefs-showtoplink' => 'Show a link to [[Special:MyCourses|your courses]] at the top of every page.', |
Index: trunk/extensions/EducationProgram/EducationProgram.php |
— | — | @@ -144,6 +144,14 @@ |
145 | 145 | $wgHooks['PersonalUrls'][] = 'EPHooks::onPersonalUrls'; |
146 | 146 | $wgHooks['GetPreferences'][] = 'EPHooks::onGetPreferences'; |
147 | 147 | |
| 148 | +$wgLogTypes[] = 'institution'; |
| 149 | +$wgLogTypes[] = 'course'; |
| 150 | +$wgLogTypes[] = 'term'; |
| 151 | + |
| 152 | +$wgLogActionsHandlers['institution/*'] = 'LogFormatter'; |
| 153 | +$wgLogActionsHandlers['course/*'] = 'LogFormatter'; |
| 154 | +$wgLogActionsHandlers['term/*'] = 'LogFormatter'; |
| 155 | + |
148 | 156 | // Rights |
149 | 157 | $wgAvailableRights[] = 'epadmin'; |
150 | 158 | $wgAvailableRights[] = 'epstudent'; |