r91720 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r91719‎ | r91720 | r91721 >
Date:13:07, 8 July 2011
Author:yuvipanda
Status:deferred
Tags:
Comment:
Added logging
Modified paths:
  • /trunk/extensions/GPoC/GPoC.hooks.php (modified) (history)
  • /trunk/extensions/GPoC/GPoC.php (modified) (history)
  • /trunk/extensions/GPoC/models/Log.php (added) (history)
  • /trunk/extensions/GPoC/models/Rating.php (modified) (history)
  • /trunk/extensions/GPoC/schema/log.sql (modified) (history)

Diff [purge]

Index: trunk/extensions/GPoC/GPoC.hooks.php
@@ -53,6 +53,7 @@
5454 $base = dirname( __FILE__ ) . '/schema';
5555 $du->addExtensionTable( "ratings", "$base/ratings.sql");
5656 $du->addExtensionTable( "project_stats", "$base/project_stats.sql" );
 57+ $du->addExtensionTable( "assessment_changelog", "$base/log.sql" );
5758 return true;
5859 }
5960 }
Index: trunk/extensions/GPoC/schema/log.sql
@@ -1,7 +1,7 @@
22 -- Replace /*_*/ with the proper prefix
33 -- Replace /*$wgDBTableOptions*/ with the correct options
44
5 -CREATE TABLE IF NOT EXISTS /*_*/log (
 5+CREATE TABLE IF NOT EXISTS /*_*/assessment_changelog (
66 l_project varchar(63) not null,
77 -- project name
88
@@ -14,11 +14,7 @@
1515 l_action varchar(20) character set ascii not null,
1616 -- type of log entry (e.g. 'quality')
1717
18 - -- NOTE: this is ASCII because of maximum index key
19 - -- length constraints interacting with utf-8 fields in
20 - -- mysql. The primary key for this table is just under the limit.
21 -
22 - l_timestamp binary(14) not null,
 18+ l_timestamp binary(14) not null,
2319 -- timestamp when log entry was added
2420
2521 l_old varchar(63),
@@ -35,4 +31,4 @@
3632 key (l_article, l_namespace)
3733 ) /*$wgDBTableOptions*/;
3834
39 -CREATE INDEX /*i*/l_project ON /*_*/log (l_project);
 35+CREATE INDEX /*i*/l_project ON /*_*/assessment_changelog (l_project);
Index: trunk/extensions/GPoC/models/Log.php
@@ -0,0 +1,24 @@
 2+<?php
 3+
 4+/**
 5+ * Represents an convenience methods for logging
 6+ **/
 7+class AssessmentChangeLog {
 8+ public static function makeEntry( $project, $namespace, $article, $timestamp, $action, $old, $new ) {
 9+ $dbw = wfGetDB( DB_MASTER );
 10+ $dbw->insert(
 11+ 'assessment_changelog',
 12+ array(
 13+ 'l_project' => $project,
 14+ 'l_namespace' => $namespace,
 15+ 'l_article' => $article,
 16+ 'l_action' => $action,
 17+ 'l_timestamp' => $timestamp,
 18+ 'l_old' => $old,
 19+ 'l_new' => $new,
 20+ 'l_revision_timestamp' => 0
 21+ ),
 22+ __METHOD__
 23+ );
 24+ }
 25+}
Property changes on: trunk/extensions/GPoC/models/Log.php
___________________________________________________________________
Added: svn:eol-style
126 + native
Index: trunk/extensions/GPoC/models/Rating.php
@@ -27,17 +27,46 @@
2828 }
2929
3030 public function update( $importance, $quality, $timestamp ) {
 31+ $logAction = ""; // q for quality change, i for importance change, qi for both
3132 if( $quality != $this->quality ) {
3233 $this->old_quality = $this->quality;
3334 $this->quality = $quality;
3435 $this->quality_timestamp = $timestamp;
 36+ $logAction .= "q";
3537 }
3638 if( $importance != $this->importance ) {
3739 $this->old_importance = $this->importance;
3840 $this->importance = $importance;
3941 $this->importance_timestamp = $timestamp;
 42+ $logAction .= "i";
4043 }
41 - $this->saveAll();
 44+ if( $logAction != "") {
 45+ $timestamp = wfTimestamp( TS_MW );
 46+ if( strpos( $logAction, 'q' ) !== false ) {
 47+ AssessmentChangeLog::makeEntry(
 48+ $this->project,
 49+ $this->namespace,
 50+ $this->title,
 51+ $timestamp,
 52+ "quality",
 53+ $this->old_quality,
 54+ $this->quality
 55+ );
 56+ }
 57+ if( strpos( $logAction, 'i' ) !== false ) {
 58+ AssessmentChangeLog::makeEntry(
 59+ $this->project,
 60+ $this->namespace,
 61+ $this->title,
 62+ $timestamp,
 63+ "importance",
 64+ $this->old_importance,
 65+ $this->importance
 66+ );
 67+ }
 68+
 69+ $this->saveAll();
 70+ }
4271 }
4372
4473 private function updateAggregateStats( $is_new_rating ) {
@@ -123,7 +152,7 @@
124153
125154 $this->updateAggregateStats( true );
126155 $this->inDB = true;
127 - }
 156+ }
128157 }
129158
130159 public static function forTitle( $title ) {
Index: trunk/extensions/GPoC/GPoC.php
@@ -22,6 +22,7 @@
2323 $wgAutoloadClasses['GPoCHooks'] = $dir . 'GPoC.hooks.php';
2424 $wgAutoloadClasses['Statistics'] = $dir . 'models/Statistics.php';
2525 $wgAutoloadClasses['Rating'] = $dir . 'models/Rating.php';
 26+$wgAutoloadClasses['AssessmentChangeLog'] = $dir . 'models/Log.php';
2627 $wgAutoloadClasses['TableDisplay'] = $dir . 'TableDisplay.php';
2728 $wgAutoloadClasses['AssessmentsExtractor'] = $dir . 'AssessmentsExtractor.php';
2829

Status & tagging log