r92917 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r92916‎ | r92917 | r92918 >
Date:23:11, 22 July 2011
Author:kaldari
Status:ok
Tags:
Comment:
more banner setting logging
Modified paths:
  • /trunk/extensions/CentralNotice/CentralNotice.db.php (modified) (history)
  • /trunk/extensions/CentralNotice/CentralNotice.i18n.php (modified) (history)
  • /trunk/extensions/CentralNotice/centralnotice.js (modified) (history)
  • /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
@@ -338,20 +338,9 @@
339339 // Get current banner
340340 $currentTemplate = $wgRequest->getText( 'template' );
341341
342 - // Pull banner settings from database
343 - $dbr = wfGetDB( DB_SLAVE );
344 - $row = $dbr->selectRow( 'cn_templates',
345 - array(
346 - 'tmp_display_anon',
347 - 'tmp_display_account',
348 - 'tmp_fundraising',
349 - 'tmp_landing_pages'
350 - ),
351 - array( 'tmp_name' => $currentTemplate ),
352 - __METHOD__
353 - );
 342+ $bannerSettings = CentralNoticeDB::getBannerSettings( $currentTemplate );
354343
355 - if ( !$row ) {
 344+ if ( !$bannerSettings ) {
356345 $this->showError( 'centralnotice-banner-doesnt-exist' );
357346 return;
358347 } else {
@@ -560,10 +549,10 @@
561550 $landingPages = $wgRequest->getVal( 'landingPages' );
562551 $body = $wgRequest->getVal( 'templateBody', $body );
563552 } else { // Use previously stored values
564 - $displayAnon = ( $row->tmp_display_anon == 1 );
565 - $displayAccount = ( $row->tmp_display_account == 1 );
566 - $fundraising = ( $row->tmp_fundraising == 1 );
567 - $landingPages = $row->tmp_landing_pages;
 553+ $displayAnon = ( $bannerSettings['anon'] == 1 );
 554+ $displayAccount = ( $bannerSettings['account'] == 1 );
 555+ $fundraising = ( $bannerSettings['fundraising'] == 1 );
 556+ $landingPages = $bannerSettings['landingpages'];
568557 // $body default is defined prior to message interface code
569558 }
570559
@@ -830,10 +819,10 @@
831820 // Log the creation of the banner
832821 $beginSettings = array();
833822 $endSettings = array(
834 - 'anon_display' => $displayAnon,
835 - 'account_display' => $displayAccount,
 823+ 'anon' => $displayAnon,
 824+ 'account' => $displayAccount,
836825 'fundraising' => $fundraising,
837 - 'landing_pages' => $landingPages
 826+ 'landingpages' => $landingPages
838827 );
839828 $this->logBannerChange( 'created', $bannerId, $beginSettings, $endSettings );
840829
@@ -851,6 +840,8 @@
852841 $this->showError( 'centralnotice-null-string' );
853842 return;
854843 }
 844+
 845+ $initialBannerSettings = CentralNoticeDB::getBannerSettings( $name );
855846
856847 $dbr = wfGetDB( DB_SLAVE );
857848 $res = $dbr->select( 'cn_templates', 'tmp_name',
@@ -875,6 +866,11 @@
876867 Title::newFromText( "centralnotice-template-{$name}", NS_MEDIAWIKI )
877868 );
878869 $article->doEdit( $body, '', EDIT_FORCE_BOT );
 870+
 871+ $bannerId = SpecialNoticeTemplate::getTemplateId( $name );
 872+ $finalBannerSettings = CentralNoticeDB::getBannerSettings( $name );
 873+ $this->logBannerChange( 'modified', $bannerId, $initialBannerSettings, $finalBannerSettings );
 874+
879875 return;
880876 }
881877 }
Index: trunk/extensions/CentralNotice/special/SpecialCentralNoticeLogs.php
@@ -49,13 +49,24 @@
5050
5151 $htmlOut .= Xml::openElement( 'form', array( 'method' => 'post' ) );
5252 $htmlOut .= Xml::element( 'h2', null, wfMsg( 'centralnotice-view-logs' ) );
53 - // TODO: interface for switching between log types.
5453 $htmlOut .= Xml::openElement( 'div', array( 'id' => 'cn-log-switcher' ) );
 54+ $title = SpecialPage::getTitleFor( 'CentralNoticeLogs' );
 55+ $fullUrl = $title->getFullUrl();
5556
56 - $htmlOut .= Xml::radio( 'log_type', 'campaign', ( $this->logType == 'campaignsettings' ? true : false ) );
 57+ $htmlOut .= Xml::radio(
 58+ 'log_type',
 59+ 'campaign',
 60+ ( $this->logType == 'campaignsettings' ? true : false ),
 61+ array( 'onclick' => "switchLogs( '".$fullUrl."', 'campaignsettings' )" )
 62+ );
5763 $htmlOut .= Xml::label( wfMsg( 'centralnotice-campaign-settings' ), 'campaign' );
5864
59 - $htmlOut .= Xml::radio( 'log_type', 'banner', ( $this->logType == 'bannersettings' ? true : false ) );
 65+ $htmlOut .= Xml::radio(
 66+ 'log_type',
 67+ 'banner',
 68+ ( $this->logType == 'bannersettings' ? true : false ),
 69+ array( 'onclick' => "switchLogs( '".$fullUrl."', 'bannersettings' )" )
 70+ );
6071 $htmlOut .= Xml::label( wfMsg( 'centralnotice-banner-settings' ), 'banner' );
6172
6273 $htmlOut .= Xml::closeElement( 'div' );
@@ -497,9 +508,9 @@
498509 );
499510 $htmlOut .= Xml::openElement( 'td', array( 'valign' => 'top', 'colspan' => '5' ) );
500511 if ( $row->tmplog_action == 'created' ) {
501 - //$htmlOut .= $this->showInitialSettings( $row );
 512+ $htmlOut .= $this->showInitialSettings( $row );
502513 } else if ( $row->tmplog_action == 'modified' ) {
503 - //$htmlOut .= $this->showChanges( $row );
 514+ $htmlOut .= $this->showChanges( $row );
504515 }
505516 $htmlOut .= Xml::closeElement( 'td' );
506517
@@ -542,4 +553,67 @@
543554 $htmlOut .= Xml::closeElement( 'table' );
544555 return $htmlOut;
545556 }
 557+
 558+ function showInitialSettings( $row ) {
 559+ global $wgLang;
 560+ $details = '';
 561+ $details .= wfMsg (
 562+ 'centralnotice-log-label',
 563+ wfMsg ( 'centralnotice-anon' ),
 564+ ($row->tmplog_end_anon ? 'on' : 'off')
 565+ )."<br/>";
 566+ $details .= wfMsg (
 567+ 'centralnotice-log-label',
 568+ wfMsg ( 'centralnotice-account' ),
 569+ ($row->tmplog_end_account ? 'on' : 'off')
 570+ )."<br/>";
 571+ $details .= wfMsg (
 572+ 'centralnotice-log-label',
 573+ wfMsg ( 'centralnotice-fundraising' ),
 574+ ($row->tmplog_end_fundraising ? 'on' : 'off')
 575+ )."<br/>";
 576+ if ( $row->tmplog_end_landingpages ) {
 577+ $details .= wfMsg (
 578+ 'centralnotice-log-label',
 579+ wfMsg ( 'centralnotice-landingpages' ),
 580+ $row->tmplog_end_landingpages
 581+ )."<br/>";
 582+ }
 583+ return $details;
 584+ }
 585+
 586+ function showChanges( $row ) {
 587+ global $wgLang;
 588+ $details = '';
 589+ $details .= $this->testBooleanChange( 'anon', $row );
 590+ $details .= $this->testBooleanChange( 'account', $row );
 591+ $details .= $this->testBooleanChange( 'fundraising', $row );
 592+ if ( $row->tmplog_content_change ) {
 593+ // Show changes to banner content
 594+ $details .= wfMsg (
 595+ 'centralnotice-log-label',
 596+ wfMsg ( 'centralnotice-banner-content' ),
 597+ wfMsg ( 'centralnotice-banner-content-changed' )
 598+ )."<br/>";
 599+ }
 600+ return $details;
 601+ }
 602+
 603+ private function testBooleanChange( $param, $row ) {
 604+ $result = '';
 605+ $beginField = 'tmplog_begin_'.$param;
 606+ $endField = 'tmplog_end_'.$param;
 607+ if ( $row->$beginField !== $row->$endField ) {
 608+ $result .= wfMsg (
 609+ 'centralnotice-log-label',
 610+ wfMsg ( 'centralnotice-'.$param ),
 611+ wfMsg (
 612+ 'centralnotice-changed',
 613+ ( $row->$beginField ? wfMsg ( 'centralnotice-on' ) : wfMsg ( 'centralnotice-off' ) ),
 614+ ( $row->$endField ? wfMsg ( 'centralnotice-on' ) : wfMsg ( 'centralnotice-off' ) )
 615+ )
 616+ )."<br/>";
 617+ }
 618+ return $result;
 619+ }
546620 }
Index: trunk/extensions/CentralNotice/patches/patch-template_log.sql
@@ -7,14 +7,14 @@
88 `tmplog_action` enum('created','modified','removed') NOT NULL DEFAULT 'modified',
99 `tmplog_template_id` int unsigned NOT NULL,
1010 `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,
 11+ `tmplog_begin_anon` tinyint(1) DEFAULT NULL,
 12+ `tmplog_end_anon` tinyint(1) DEFAULT NULL,
 13+ `tmplog_begin_account` tinyint(1) DEFAULT NULL,
 14+ `tmplog_end_account` tinyint(1) DEFAULT NULL,
1515 `tmplog_begin_fundraising` tinyint(1) DEFAULT NULL,
1616 `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,
 17+ `tmplog_begin_landingpages` varchar(255) DEFAULT NULL,
 18+ `tmplog_end_landingpages` varchar(255) DEFAULT NULL,
1919 `tmplog_content_change` tinyint(1) DEFAULT 0
2020 ) /*$wgDBTableOptions*/;
2121 CREATE INDEX /*i*/tmplog_timestamp ON /*_*/cn_template_log (tmplog_timestamp);
Index: trunk/extensions/CentralNotice/CentralNotice.i18n.php
@@ -163,6 +163,12 @@
164164 'centralnotice-log-label' => '<span class="cn-log-label">$1:</span> $2',
165165 'centralnotice-campaign-settings' => 'Campaign settings',
166166 'centralnotice-banner-settings' => 'Banner settings',
 167+ 'centralnotice-anon' => 'Display to anonymous users',
 168+ 'centralnotice-account' => 'Display to logged in users',
 169+ 'centralnotice-fundraising' => 'Fundraising',
 170+ 'centralnotice-landingpages' => 'Landing pages',
 171+ 'centralnotice-banner-content' => 'Banner content',
 172+ 'centralnotice-banner-content-changed' => 'Changed',
167173 );
168174
169175 /** Message documentation (Message documentation)
Index: trunk/extensions/CentralNotice/CentralNotice.db.php
@@ -235,6 +235,41 @@
236236 }
237237
238238 /**
 239+ * Return settings for a banner
 240+ * @param $bannerName string name of banner
 241+ * @return an array of banner settings
 242+ */
 243+ static function getBannerSettings( $bannerName ) {
 244+ global $wgCentralDBname;
 245+
 246+ $banner = array();
 247+
 248+ $dbr = wfGetDB( DB_SLAVE, array(), $wgCentralDBname );
 249+
 250+ $row = $dbr->selectRow( 'cn_templates',
 251+ array(
 252+ 'tmp_display_anon',
 253+ 'tmp_display_account',
 254+ 'tmp_fundraising',
 255+ 'tmp_landing_pages'
 256+ ),
 257+ array( 'tmp_name' => $bannerName ),
 258+ __METHOD__
 259+ );
 260+
 261+ if ( $row ) {
 262+ $banner = array(
 263+ 'anon' => $row->tmp_display_anon,
 264+ 'account' => $row->tmp_display_account,
 265+ 'fundraising' => $row->tmp_fundraising,
 266+ 'landingpages' => $row->tmp_landing_pages
 267+ );
 268+ }
 269+
 270+ return $banner;
 271+ }
 272+
 273+ /**
239274 * Lookup function for active banners under a given language/project/location. This function is
240275 * called by SpecialBannerListLoader::getJsonList() in order to build the banner list JSON for
241276 * each project.
Index: trunk/extensions/CentralNotice/centralnotice.js
@@ -12,6 +12,10 @@
1313 thisDetails.style.display = "table-row";
1414 }
1515 }
 16+function switchLogs( baseUrl, logType ) {
 17+ encodeURIComponent( logType );
 18+ window.location = baseUrl + '?log=' + logType;
 19+}
1620 function selectProjects( selectAll ) {
1721 var selectBox = document.getElementById('projects[]');
1822 var firstSelect = selectBox.options.length - 1;

Follow-up revisions

RevisionCommit summaryAuthorDate
r95527MFT r92917 - r95526awjrichards21:29, 25 August 2011

Status & tagging log