r91707 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r91706‎ | r91707 | r91708 >
Date:02:01, 8 July 2011
Author:kaldari
Status:ok
Tags:
Comment:
storing campaign name differently in logs, beginning output to Logs tab, fixing issues with campaign deletion
Modified paths:
  • /trunk/extensions/CentralNotice/CentralNotice.db.php (modified) (history)
  • /trunk/extensions/CentralNotice/patches/patch-notice_log.sql (added) (history)
  • /trunk/extensions/CentralNotice/patches/patch-notice_logs.sql (deleted) (history)
  • /trunk/extensions/CentralNotice/special/SpecialCentralNotice.php (modified) (history)
  • /trunk/extensions/CentralNotice/special/SpecialCentralNoticeLogs.php (modified) (history)

Diff [purge]

Index: trunk/extensions/CentralNotice/special/SpecialCentralNotice.php
@@ -1160,7 +1160,6 @@
11611161 // Log the creation of the campaign
11621162 $beginSettings = array();
11631163 $endSettings = array(
1164 - 'name' => $noticeName,
11651164 'projects' => implode( ", ", $projects ),
11661165 'languages' => implode( ", ", $project_languages ),
11671166 'countries' => implode( ", ", $geo_countries ),
@@ -1192,17 +1191,19 @@
11931192 $this->showError( 'centralnotice-notice-is-locked' );
11941193 return;
11951194 } else {
 1195+ // Log the removal of the campaign
 1196+ $noticeId = $this->getNoticeId( $noticeName );
 1197+ $this->logCampaignChange( 'removed', $noticeId );
 1198+
11961199 $dbw = wfGetDB( DB_MASTER );
11971200 $dbw->begin();
1198 - $noticeId = htmlspecialchars( $this->getNoticeId( $noticeName ) );
11991201 $res = $dbw->delete( 'cn_assignments', array ( 'not_id' => $noticeId ) );
12001202 $res = $dbw->delete( 'cn_notices', array ( 'not_name' => $noticeName ) );
12011203 $res = $dbw->delete( 'cn_notice_languages', array ( 'nl_notice_id' => $noticeId ) );
 1204+ $res = $dbw->delete( 'cn_notice_projects', array ( 'np_notice_id' => $noticeId ) );
 1205+ $res = $dbw->delete( 'cn_notice_countries', array ( 'nc_notice_id' => $noticeId ) );
12021206 $dbw->commit();
12031207
1204 - // Log the removal of the campaign
1205 - $this->logCampaignChange( 'removed', $noticeId );
1206 -
12071208 return;
12081209 }
12091210 }
@@ -1678,13 +1679,13 @@
16791680 /**
16801681 * Log any changes related to a campaign
16811682 * @param $action string: 'created', 'modified', or 'removed'
1682 - * @param $campaign integer: id of campaign
 1683+ * @param $campaignId integer: ID of campaign
16831684 * @param $beginSettings array of campaign settings before changes (optional)
16841685 * @param $endSettings array of campaign settings after changes (optional)
16851686 * @param $beginAssignments array of banner assignments before changes (optional)
16861687 * @param $endAssignments array of banner assignments after changes (optional)
16871688 */
1688 - function logCampaignChange( $action, $campaign, $beginSettings = array(),
 1689+ function logCampaignChange( $action, $campaignId, $beginSettings = array(),
16891690 $endSettings = array(), $beginAssignments = array(), $endAssignments = array() )
16901691 {
16911692 global $wgUser;
@@ -1695,7 +1696,8 @@
16961697 'notlog_timestamp' => $dbw->timestamp(),
16971698 'notlog_user_id' => $wgUser->getId(),
16981699 'notlog_action' => $action,
1699 - 'notlog_not_id' => $campaign
 1700+ 'notlog_not_id' => $campaignId,
 1701+ 'notlog_not_name' => $this->getNoticeName( $campaignId )
17001702 );
17011703
17021704 foreach ( $beginSettings as $key => $value ) {
Index: trunk/extensions/CentralNotice/special/SpecialCentralNoticeLogs.php
@@ -68,21 +68,62 @@
6969 * Show a log.
7070 */
7171 function showLog( $logType ) {
72 - global $wgOut;
 72+ global $wgOut, $wgLang;
7373
7474 $htmlOut = '';
7575
7676 // Begin log fieldset
7777 $htmlOut .= Xml::openElement( 'fieldset', array( 'class' => 'prefsection' ) );
7878
79 - $htmlOut .= Xml::tags( 'p', null,
80 - '<i>Coming soon...</i>'
81 - );
 79+ $campaignLogs = $this->getCampaignLogs();
8280
 81+ foreach( $campaignLogs as $campaignLog ) {
 82+ $htmlOut .= Xml::openElement( 'div', array( 'class' => 'cn-log-entry' ) );
 83+
 84+ // Timestamp
 85+ $htmlOut .= Xml::tags( 'span', null,
 86+ $wgLang->date( $campaignLog['timestamp'] ) . ' ' . $wgLang->time( $campaignLog['timestamp'] )
 87+ );
 88+ // User
 89+ $cnUser = User::newFromId( $campaignLog['user_id'] );
 90+ $htmlOut .= Xml::tags( 'span', null, $cnUser->getName() );
 91+ // Action
 92+ $htmlOut .= Xml::tags( 'span', null, $campaignLog['action'] );
 93+ // Campaign
 94+ $htmlOut .= Xml::tags( 'span', null, $campaignLog['campaign_name'] );
 95+
 96+ $htmlOut .= Xml::closeElement( 'div', array( 'class' => 'cn-log-entry' ) );
 97+ }
 98+
8399 // End log fieldset
84100 $htmlOut .= Xml::closeElement( 'fieldset' );
85101
86102 $wgOut->addHTML( $htmlOut );
87103 }
 104+
 105+ function getCampaignLogs() {
 106+ global $wgCentralDBname;
 107+ $dbr = wfGetDB( DB_SLAVE, array(), $wgCentralDBname );
 108+ $logs = array();
88109
 110+ $results = $dbr->select( 'cn_notice_log', array(
 111+ 'notlog_timestamp',
 112+ 'notlog_user_id',
 113+ 'notlog_action',
 114+ 'notlog_not_id',
 115+ 'notlog_not_name',
 116+ )
 117+ );
 118+ foreach ( $results as $row ) {
 119+ $logs[] = array(
 120+ 'timestamp' => $row->notlog_timestamp,
 121+ 'user_id' => $row->notlog_user_id,
 122+ 'action' => $row->notlog_action,
 123+ 'campaign_id' => $row->notlog_not_id,
 124+ 'campaign_name' => $row->notlog_not_name,
 125+ );
 126+ }
 127+ return $logs;
 128+ }
 129+
89130 }
Index: trunk/extensions/CentralNotice/patches/patch-notice_logs.sql
@@ -1,34 +0,0 @@
2 -
3 -CREATE TABLE IF NOT EXISTS /*$wgDBprefix*/cn_notice_log (
4 - `notlog_id` int unsigned NOT NULL PRIMARY KEY auto_increment,
5 - `notlog_timestamp` binary(14) NOT NULL,
6 - `notlog_user_id` int unsigned NOT NULL,
7 - `notlog_action` enum('created','modified','removed') NOT NULL DEFAULT 'modified',
8 - `notlog_not_id` int unsigned NOT NULL,
9 - `notlog_begin_name` varchar(255) DEFAULT NULL,
10 - `notlog_end_name` varchar(255) DEFAULT NULL,
11 - `notlog_begin_projects` varchar(255) DEFAULT NULL,
12 - `notlog_end_projects` varchar(255) DEFAULT NULL,
13 - `notlog_begin_languages` text,
14 - `notlog_end_languages` text,
15 - `notlog_begin_countries` text,
16 - `notlog_end_countries` text,
17 - `notlog_begin_start` char(14) DEFAULT NULL,
18 - `notlog_end_start` char(14) DEFAULT NULL,
19 - `notlog_begin_end` char(14) DEFAULT NULL,
20 - `notlog_end_end` char(14) DEFAULT NULL,
21 - `notlog_begin_enabled` tinyint(1) DEFAULT NULL,
22 - `notlog_end_enabled` tinyint(1) DEFAULT NULL,
23 - `notlog_begin_preferred` tinyint(1) DEFAULT NULL,
24 - `notlog_end_preferred` tinyint(1) DEFAULT NULL,
25 - `notlog_begin_locked` tinyint(1) DEFAULT NULL,
26 - `notlog_end_locked` tinyint(1) DEFAULT NULL,
27 - `notlog_begin_geo` tinyint(1) DEFAULT NULL,
28 - `notlog_end_geo` tinyint(1) DEFAULT NULL,
29 - `notlog_begin_banners` text,
30 - `notlog_end_banners` text
31 -) /*$wgDBTableOptions*/;
32 -CREATE INDEX /*i*/notlog_timestamp ON /*_*/cn_notice_log (notlog_timestamp);
33 -CREATE INDEX /*i*/notlog_user_id ON /*_*/cn_notice_log (notlog_user_id, notlog_timestamp);
34 -CREATE INDEX /*i*/notlog_not_id ON /*_*/cn_notice_log (notlog_not_id, notlog_timestamp);
\ No newline at end of file
Index: trunk/extensions/CentralNotice/patches/patch-notice_log.sql
@@ -0,0 +1,34 @@
 2+-- Update to allow for logging of changes to campaign settings.
 3+
 4+CREATE TABLE IF NOT EXISTS /*$wgDBprefix*/cn_notice_log (
 5+ `notlog_id` int unsigned NOT NULL PRIMARY KEY auto_increment,
 6+ `notlog_timestamp` binary(14) NOT NULL,
 7+ `notlog_user_id` int unsigned NOT NULL,
 8+ `notlog_action` enum('created','modified','removed') NOT NULL DEFAULT 'modified',
 9+ `notlog_not_id` int unsigned NOT NULL,
 10+ `notlog_begin_name` varchar(255) DEFAULT NULL,
 11+ `notlog_end_name` varchar(255) DEFAULT NULL,
 12+ `notlog_begin_projects` varchar(255) DEFAULT NULL,
 13+ `notlog_end_projects` varchar(255) DEFAULT NULL,
 14+ `notlog_begin_languages` text,
 15+ `notlog_end_languages` text,
 16+ `notlog_begin_countries` text,
 17+ `notlog_end_countries` text,
 18+ `notlog_begin_start` char(14) DEFAULT NULL,
 19+ `notlog_end_start` char(14) DEFAULT NULL,
 20+ `notlog_begin_end` char(14) DEFAULT NULL,
 21+ `notlog_end_end` char(14) DEFAULT NULL,
 22+ `notlog_begin_enabled` tinyint(1) DEFAULT NULL,
 23+ `notlog_end_enabled` tinyint(1) DEFAULT NULL,
 24+ `notlog_begin_preferred` tinyint(1) DEFAULT NULL,
 25+ `notlog_end_preferred` tinyint(1) DEFAULT NULL,
 26+ `notlog_begin_locked` tinyint(1) DEFAULT NULL,
 27+ `notlog_end_locked` tinyint(1) DEFAULT NULL,
 28+ `notlog_begin_geo` tinyint(1) DEFAULT NULL,
 29+ `notlog_end_geo` tinyint(1) DEFAULT NULL,
 30+ `notlog_begin_banners` text,
 31+ `notlog_end_banners` text
 32+) /*$wgDBTableOptions*/;
 33+CREATE INDEX /*i*/notlog_timestamp ON /*_*/cn_notice_log (notlog_timestamp);
 34+CREATE INDEX /*i*/notlog_user_id ON /*_*/cn_notice_log (notlog_user_id, notlog_timestamp);
 35+CREATE INDEX /*i*/notlog_not_id ON /*_*/cn_notice_log (notlog_not_id, notlog_timestamp);
\ No newline at end of file
Property changes on: trunk/extensions/CentralNotice/patches/patch-notice_log.sql
___________________________________________________________________
Added: svn:eol-style
136 + native
Index: trunk/extensions/CentralNotice/CentralNotice.db.php
@@ -136,7 +136,6 @@
137137 $row = $dbr->selectRow( 'cn_notices',
138138 array(
139139 'not_id',
140 - 'not_name',
141140 'not_start',
142141 'not_end',
143142 'not_enabled',
@@ -149,7 +148,6 @@
150149 );
151150 if ( $row ) {
152151 $campaign = array(
153 - 'name' => $row->not_name,
154152 'start' => $row->not_start,
155153 'end' => $row->not_end,
156154 'enabled' => $row->not_enabled,

Status & tagging log