r92822 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r92821‎ | r92822 | r92823 >
Date:23:08, 21 July 2011
Author:kaldari
Status:ok
Tags:
Comment:
changing field prefix for banner logging so that it is consistant, adding beginnings of banner logging, and log switching
Modified paths:
  • /trunk/extensions/CentralNotice/patches/patch-template_log.sql (modified) (history)
  • /trunk/extensions/CentralNotice/special/SpecialCentralNoticeLogs.php (modified) (history)
  • /trunk/extensions/CentralNotice/special/SpecialNoticeTemplate.php (modified) (history)

Diff [purge]

Index: trunk/extensions/CentralNotice/special/SpecialNoticeTemplate.php
@@ -743,6 +743,17 @@
744744 }
745745 return null;
746746 }
 747+
 748+ public static function getBannerName( $bannerId ) {
 749+ $dbr = wfGetDB( DB_MASTER );
 750+ if ( is_numeric( $bannerId ) ) {
 751+ $row = $dbr->selectRow( 'cn_templates', 'tmp_name', array( 'tmp_id' => $bannerId ) );
 752+ if ( $row ) {
 753+ return $row->tmp_name;
 754+ }
 755+ }
 756+ return null;
 757+ }
747758
748759 private function removeTemplate ( $name ) {
749760 $id = $this->getTemplateId( $name );
@@ -805,12 +816,24 @@
806817 ),
807818 __METHOD__
808819 );
 820+ $bannerId = $dbw->insertId();
809821
810822 // Perhaps these should move into the db as blobs instead of being stored as articles
811823 $article = new Article(
812824 Title::newFromText( "centralnotice-template-{$name}", NS_MEDIAWIKI )
813825 );
814826 $article->doEdit( $body, '', EDIT_FORCE_BOT );
 827+
 828+ // Log the creation of the banner
 829+ $beginSettings = array();
 830+ $endSettings = array(
 831+ 'anon_display' => $displayAnon,
 832+ 'account_display' => $displayAccount,
 833+ 'fundraising' => $fundraising,
 834+ 'landing_pages' => $landingPages
 835+ );
 836+ $this->logBannerChange( 'created', $bannerId, $beginSettings, $endSettings );
 837+
815838 return true;
816839 }
817840 }
@@ -960,5 +983,41 @@
961984 $wgOut->wrapWikiMsg( "<div class='cn-error'>\n$1\n</div>", $message );
962985 $this->centralNoticeError = true;
963986 }
 987+
 988+ /**
 989+ * Log setting changes related to a banner
 990+ * @param $action string: 'created', 'modified', or 'removed'
 991+ * @param $bannerId integer: ID of banner
 992+ * @param $beginSettings array of banner settings before changes (optional)
 993+ * @param $endSettings array of banner settings after changes (optional)
 994+ * @param $beginContent banner content before changes (optional)
 995+ * @param $endContent banner content after changes (optional)
 996+ */
 997+ function logBannerChange( $action, $bannerId, $beginSettings = array(),
 998+ $endSettings = array(), $beginContent = null, $endContent = null )
 999+ {
 1000+ global $wgUser;
 1001+
 1002+ $dbw = wfGetDB( DB_MASTER );
 1003+
 1004+ $log = array(
 1005+ 'tmplog_timestamp' => $dbw->timestamp(),
 1006+ 'tmplog_user_id' => $wgUser->getId(),
 1007+ 'tmplog_action' => $action,
 1008+ 'tmplog_template_id' => $bannerId,
 1009+ 'tmplog_template_name' => SpecialNoticeTemplate::getBannerName( $bannerId )
 1010+ );
 1011+
 1012+ foreach ( $beginSettings as $key => $value ) {
 1013+ $log['tmplog_begin_'.$key] = $value;
 1014+ }
 1015+ foreach ( $endSettings as $key => $value ) {
 1016+ $log['tmplog_end_'.$key] = $value;
 1017+ }
 1018+
 1019+ $res = $dbw->insert( 'cn_template_log', $log );
 1020+ $log_id = $dbw->insertId();
 1021+ return $log_id;
 1022+ }
9641023
9651024 }
Index: trunk/extensions/CentralNotice/special/SpecialCentralNoticeLogs.php
@@ -19,9 +19,7 @@
2020 function execute( $sub ) {
2121 global $wgOut, $wgRequest, $wgExtensionAssetsPath;
2222
23 - if ( $wgRequest->wasPosted() ) {
24 - $this->logType = $wgRequest->getText( 'log', 'campaignsettings' );
25 - }
 23+ $this->logType = $wgRequest->getText( 'log', 'campaignsettings' );
2624
2725 // Begin output
2826 $this->setHeaders();
@@ -68,20 +66,25 @@
6967
7068 $wgOut->addHTML( $htmlOut );
7169
72 - $this->showCampaignLog( $this->logType );
 70+ $this->showLog( $this->logType );
7371
7472 // End Banners tab content
7573 $wgOut->addHTML( Xml::closeElement( 'div' ) );
7674 }
7775
7876 /**
79 - * Show a log of campaign changes.
 77+ * Show a log of changes.
 78+ * @param $logType string: which type of log to show
8079 */
81 - function showCampaignLog( $logType ) {
 80+ function showLog( $logType ) {
8281 global $wgOut;
8382
84 - //$pager = new CentralNoticeLogPager( $this );
85 - $pager = new CentralNoticeBannerLogPager( $this );
 83+ if ( $logType == 'bannersettings' ) {
 84+ $pager = new CentralNoticeBannerLogPager( $this );
 85+ } else {
 86+ $pager = new CentralNoticeLogPager( $this );
 87+ }
 88+
8689 $htmlOut = '';
8790
8891 // Begin log fieldset
@@ -423,7 +426,7 @@
424427 * Sort the log list by timestamp
425428 */
426429 function getIndexField() {
427 - return 'templog_timestamp';
 430+ return 'tmplog_timestamp';
428431 }
429432
430433 /**
@@ -443,7 +446,7 @@
444447 global $wgLang, $wgExtensionAssetsPath;
445448
446449 // Create a user object so we can pull the name, user page, etc.
447 - $loggedUser = User::newFromId( $row->templog_user_id );
 450+ $loggedUser = User::newFromId( $row->tmplog_user_id );
448451 // Create the user page link
449452 $userLink = $this->getSkin()->makeLinkObj( $loggedUser->getUserPage(),
450453 $loggedUser->getName() );
@@ -452,28 +455,28 @@
453456
454457 // Create the banner link
455458 $bannerLink = $this->getSkin()->makeLinkObj( $this->viewPage,
456 - htmlspecialchars( $row->templog_template_name ),
457 - 'template=' . urlencode( $row->templog_template_name ) );
 459+ htmlspecialchars( $row->tmplog_template_name ),
 460+ 'template=' . urlencode( $row->tmplog_template_name ) );
458461
459462 // Begin log entry primary row
460463 $htmlOut = Xml::openElement( 'tr' );
461464
462465 $htmlOut .= Xml::openElement( 'td', array( 'valign' => 'top' ) );
463 - if ( $row->templog_action !== 'removed' ) {
464 - $htmlOut .= '<a href="javascript:toggleDisplay(\''.$row->templog_id.'\')">'.
465 - '<img src="'.$wgExtensionAssetsPath.'/CentralNotice/collapsed.png" id="cn-collapsed-'.$row->templog_id.'" style="display:block;vertical-align:baseline;"/>'.
466 - '<img src="'.$wgExtensionAssetsPath.'/CentralNotice/uncollapsed.png" id="cn-uncollapsed-'.$row->templog_id.'" style="display:none;vertical-align:baseline;"/>'.
 466+ if ( $row->tmplog_action !== 'removed' ) {
 467+ $htmlOut .= '<a href="javascript:toggleDisplay(\''.$row->tmplog_id.'\')">'.
 468+ '<img src="'.$wgExtensionAssetsPath.'/CentralNotice/collapsed.png" id="cn-collapsed-'.$row->tmplog_id.'" style="display:block;vertical-align:baseline;"/>'.
 469+ '<img src="'.$wgExtensionAssetsPath.'/CentralNotice/uncollapsed.png" id="cn-uncollapsed-'.$row->tmplog_id.'" style="display:none;vertical-align:baseline;"/>'.
467470 '</a>';
468471 }
469472 $htmlOut .= Xml::closeElement( 'td' );
470473 $htmlOut .= Xml::tags( 'td', array( 'valign' => 'top', 'class' => 'primary' ),
471 - $wgLang->date( $row->templog_timestamp ) . ' ' . $wgLang->time( $row->templog_timestamp )
 474+ $wgLang->date( $row->tmplog_timestamp ) . ' ' . $wgLang->time( $row->tmplog_timestamp )
472475 );
473476 $htmlOut .= Xml::tags( 'td', array( 'valign' => 'top', 'class' => 'primary' ),
474477 wfMsg ( 'centralnotice-user-links', $userLink, $userTalkLink )
475478 );
476479 $htmlOut .= Xml::tags( 'td', array( 'valign' => 'top', 'class' => 'primary' ),
477 - $row->templog_action
 480+ $row->tmplog_action
478481 );
479482 $htmlOut .= Xml::tags( 'td', array( 'valign' => 'top', 'class' => 'primary' ),
480483 $bannerLink
@@ -485,17 +488,17 @@
486489 // End log entry primary row
487490 $htmlOut .= Xml::closeElement( 'tr' );
488491
489 - if ( $row->templog_action !== 'removed' ) {
 492+ if ( $row->tmplog_action !== 'removed' ) {
490493 // Begin log entry secondary row
491 - $htmlOut .= Xml::openElement( 'tr', array( 'id' => 'cn-log-details-'.$row->templog_id, 'style' => 'display:none;' ) );
 494+ $htmlOut .= Xml::openElement( 'tr', array( 'id' => 'cn-log-details-'.$row->tmplog_id, 'style' => 'display:none;' ) );
492495
493496 $htmlOut .= Xml::tags( 'td', array( 'valign' => 'top' ),
494497 '&nbsp;' // force a table cell in older browsers
495498 );
496499 $htmlOut .= Xml::openElement( 'td', array( 'valign' => 'top', 'colspan' => '5' ) );
497 - if ( $row->templog_action == 'created' ) {
 500+ if ( $row->tmplog_action == 'created' ) {
498501 //$htmlOut .= $this->showInitialSettings( $row );
499 - } else if ( $row->templog_action == 'modified' ) {
 502+ } else if ( $row->tmplog_action == 'modified' ) {
500503 //$htmlOut .= $this->showChanges( $row );
501504 }
502505 $htmlOut .= Xml::closeElement( 'td' );
Index: trunk/extensions/CentralNotice/patches/patch-template_log.sql
@@ -1,22 +1,22 @@
22 -- Update to allow for logging of changes to banner settings.
33
44 CREATE TABLE IF NOT EXISTS /*$wgDBprefix*/cn_template_log (
5 - `templog_id` int unsigned NOT NULL PRIMARY KEY auto_increment,
6 - `templog_timestamp` binary(14) NOT NULL,
7 - `templog_user_id` int unsigned NOT NULL,
8 - `templog_action` enum('created','modified','removed') NOT NULL DEFAULT 'modified',
9 - `templog_template_id` int unsigned NOT NULL,
10 - `templog_template_name` varchar(255) DEFAULT NULL,
11 - `templog_begin_anon_display` tinyint(1) DEFAULT NULL,
12 - `templog_end_anon_display` tinyint(1) DEFAULT NULL,
13 - `templog_begin_account_display` tinyint(1) DEFAULT NULL,
14 - `templog_end_account_display` tinyint(1) DEFAULT NULL,
15 - `templog_begin_fundraising` tinyint(1) DEFAULT NULL,
16 - `templog_end_fundraising` tinyint(1) DEFAULT NULL,
17 - `templog_begin_landing_pages` varchar(255) DEFAULT NULL,
18 - `templog_end_landing_pages` varchar(255) DEFAULT NULL,
19 - `templog_content_change` tinyint(1) DEFAULT 0
 5+ `tmplog_id` int unsigned NOT NULL PRIMARY KEY auto_increment,
 6+ `tmplog_timestamp` binary(14) NOT NULL,
 7+ `tmplog_user_id` int unsigned NOT NULL,
 8+ `tmplog_action` enum('created','modified','removed') NOT NULL DEFAULT 'modified',
 9+ `tmplog_template_id` int unsigned NOT NULL,
 10+ `tmplog_template_name` varchar(255) DEFAULT NULL,
 11+ `tmplog_begin_anon_display` tinyint(1) DEFAULT NULL,
 12+ `tmplog_end_anon_display` tinyint(1) DEFAULT NULL,
 13+ `tmplog_begin_account_display` tinyint(1) DEFAULT NULL,
 14+ `tmplog_end_account_display` tinyint(1) DEFAULT NULL,
 15+ `tmplog_begin_fundraising` tinyint(1) DEFAULT NULL,
 16+ `tmplog_end_fundraising` tinyint(1) DEFAULT NULL,
 17+ `tmplog_begin_landing_pages` varchar(255) DEFAULT NULL,
 18+ `tmplog_end_landing_pages` varchar(255) DEFAULT NULL,
 19+ `tmplog_content_change` tinyint(1) DEFAULT 0
2020 ) /*$wgDBTableOptions*/;
21 -CREATE INDEX /*i*/templog_timestamp ON /*_*/cn_template_log (templog_timestamp);
22 -CREATE INDEX /*i*/templog_user_id ON /*_*/cn_template_log (templog_user_id, templog_timestamp);
23 -CREATE INDEX /*i*/templog_template_id ON /*_*/cn_template_log (templog_template_id, templog_timestamp);
\ No newline at end of file
 21+CREATE INDEX /*i*/tmplog_timestamp ON /*_*/cn_template_log (tmplog_timestamp);
 22+CREATE INDEX /*i*/tmplog_user_id ON /*_*/cn_template_log (tmplog_user_id, tmplog_timestamp);
 23+CREATE INDEX /*i*/tmplog_template_id ON /*_*/cn_template_log (tmplog_template_id, tmplog_timestamp);
\ No newline at end of file

Status & tagging log