r108772 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r108771‎ | r108772 | r108773 >
Date:22:20, 12 January 2012
Author:jeroendedauw
Status:deferred
Tags:educationprogram 
Comment:
some initial work on logging
Modified paths:
  • /trunk/extensions/EducationProgram/EducationProgram.i18n.php (modified) (history)
  • /trunk/extensions/EducationProgram/EducationProgram.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPDBObject.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPOrg.php (modified) (history)

Diff [purge]

Index: trunk/extensions/EducationProgram/includes/EPOrg.php
@@ -72,6 +72,19 @@
7373
7474 /**
7575 * (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)
7689 * @see EPDBObject::loadSummaryFields()
7790 */
7891 public function loadSummaryFields( $summaryFields = null ) {
@@ -140,6 +153,7 @@
141154 */
142155 public function removeFromDB() {
143156 $id = $this->getId();
 157+ $this->loadFields( array( 'name' ) );
144158
145159 $success = parent::removeFromDB();
146160
@@ -318,6 +332,17 @@
319333 }
320334
321335 /**
 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+ /**
322347 * Get a link to Special:Institution/name.
323348 *
324349 * @since 0.1
@@ -326,7 +351,7 @@
327352 */
328353 public function getLink() {
329354 return Linker::linkKnown(
330 - SpecialPage::getTitleFor( 'Institution', $this->getField( 'name' ) ),
 355+ $this->getTitle(),
331356 htmlspecialchars( $this->getField( 'name' ) )
332357 );
333358 }
Index: trunk/extensions/EducationProgram/includes/EPDBObject.php
@@ -42,6 +42,14 @@
4343 protected $updateSummaries = true;
4444
4545 /**
 46+ * If the object should log changes.
 47+ *
 48+ * @since 0.1
 49+ * @var bool
 50+ */
 51+ protected $log = true;
 52+
 53+ /**
4654 * The database connection to use for read operations.
4755 *
4856 * @since 0.2
@@ -383,12 +391,18 @@
384392 protected function updateInDB() {
385393 $dbw = wfGetDB( DB_MASTER );
386394
387 - return $dbw->update(
 395+ $success = $dbw->update(
388396 $this->getDBTable(),
389397 $this->getWriteValues(),
390398 array( $this->getFieldPrefix() . 'id' => $this->getId() ),
391399 __METHOD__
392400 );
 401+
 402+ if ( $success ) {
 403+ $this->log( 'update' );
 404+ }
 405+
 406+ return $success;
393407 }
394408
395409 /**
@@ -409,7 +423,10 @@
410424 array( 'IGNORE' )
411425 );
412426
413 - $this->setField( 'id', $dbw->insertId() );
 427+ if ( $result ) {
 428+ $this->setField( 'id', $dbw->insertId() );
 429+ $this->log( 'add' );
 430+ }
414431
415432 return $result;
416433 }
@@ -427,12 +444,45 @@
428445
429446 if ( $success ) {
430447 $this->setField( 'id', null );
 448+ $this->log( 'remove' );
431449 }
432450
433451 return $success;
434452 }
435453
436454 /**
 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+ /**
437487 * Return the names and values of the fields.
438488 *
439489 * @since 0.1
@@ -1141,4 +1191,22 @@
11421192 $this->updateSummaries = $update;
11431193 }
11441194
 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+
11451213 }
Index: trunk/extensions/EducationProgram/EducationProgram.i18n.php
@@ -32,6 +32,27 @@
3333 'ep-nav-students' => 'Student list',
3434 'ep-nav-mentors' => 'Ambassador list',
3535
 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+
3657 // Preferences
3758 'prefs-education' => 'Education',
3859 '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 @@
145145 $wgHooks['PersonalUrls'][] = 'EPHooks::onPersonalUrls';
146146 $wgHooks['GetPreferences'][] = 'EPHooks::onGetPreferences';
147147
 148+$wgLogTypes[] = 'institution';
 149+$wgLogTypes[] = 'course';
 150+$wgLogTypes[] = 'term';
 151+
 152+$wgLogActionsHandlers['institution/*'] = 'LogFormatter';
 153+$wgLogActionsHandlers['course/*'] = 'LogFormatter';
 154+$wgLogActionsHandlers['term/*'] = 'LogFormatter';
 155+
148156 // Rights
149157 $wgAvailableRights[] = 'epadmin';
150158 $wgAvailableRights[] = 'epstudent';

Status & tagging log