Index: trunk/extensions/CentralNotice/special/SpecialNoticeTemplate.php |
— | — | @@ -338,20 +338,9 @@ |
339 | 339 | // Get current banner |
340 | 340 | $currentTemplate = $wgRequest->getText( 'template' ); |
341 | 341 | |
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 ); |
354 | 343 | |
355 | | - if ( !$row ) { |
| 344 | + if ( !$bannerSettings ) { |
356 | 345 | $this->showError( 'centralnotice-banner-doesnt-exist' ); |
357 | 346 | return; |
358 | 347 | } else { |
— | — | @@ -560,10 +549,10 @@ |
561 | 550 | $landingPages = $wgRequest->getVal( 'landingPages' ); |
562 | 551 | $body = $wgRequest->getVal( 'templateBody', $body ); |
563 | 552 | } 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']; |
568 | 557 | // $body default is defined prior to message interface code |
569 | 558 | } |
570 | 559 | |
— | — | @@ -830,10 +819,10 @@ |
831 | 820 | // Log the creation of the banner |
832 | 821 | $beginSettings = array(); |
833 | 822 | $endSettings = array( |
834 | | - 'anon_display' => $displayAnon, |
835 | | - 'account_display' => $displayAccount, |
| 823 | + 'anon' => $displayAnon, |
| 824 | + 'account' => $displayAccount, |
836 | 825 | 'fundraising' => $fundraising, |
837 | | - 'landing_pages' => $landingPages |
| 826 | + 'landingpages' => $landingPages |
838 | 827 | ); |
839 | 828 | $this->logBannerChange( 'created', $bannerId, $beginSettings, $endSettings ); |
840 | 829 | |
— | — | @@ -851,6 +840,8 @@ |
852 | 841 | $this->showError( 'centralnotice-null-string' ); |
853 | 842 | return; |
854 | 843 | } |
| 844 | + |
| 845 | + $initialBannerSettings = CentralNoticeDB::getBannerSettings( $name ); |
855 | 846 | |
856 | 847 | $dbr = wfGetDB( DB_SLAVE ); |
857 | 848 | $res = $dbr->select( 'cn_templates', 'tmp_name', |
— | — | @@ -875,6 +866,11 @@ |
876 | 867 | Title::newFromText( "centralnotice-template-{$name}", NS_MEDIAWIKI ) |
877 | 868 | ); |
878 | 869 | $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 | + |
879 | 875 | return; |
880 | 876 | } |
881 | 877 | } |
Index: trunk/extensions/CentralNotice/special/SpecialCentralNoticeLogs.php |
— | — | @@ -49,13 +49,24 @@ |
50 | 50 | |
51 | 51 | $htmlOut .= Xml::openElement( 'form', array( 'method' => 'post' ) ); |
52 | 52 | $htmlOut .= Xml::element( 'h2', null, wfMsg( 'centralnotice-view-logs' ) ); |
53 | | - // TODO: interface for switching between log types. |
54 | 53 | $htmlOut .= Xml::openElement( 'div', array( 'id' => 'cn-log-switcher' ) ); |
| 54 | + $title = SpecialPage::getTitleFor( 'CentralNoticeLogs' ); |
| 55 | + $fullUrl = $title->getFullUrl(); |
55 | 56 | |
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 | + ); |
57 | 63 | $htmlOut .= Xml::label( wfMsg( 'centralnotice-campaign-settings' ), 'campaign' ); |
58 | 64 | |
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 | + ); |
60 | 71 | $htmlOut .= Xml::label( wfMsg( 'centralnotice-banner-settings' ), 'banner' ); |
61 | 72 | |
62 | 73 | $htmlOut .= Xml::closeElement( 'div' ); |
— | — | @@ -497,9 +508,9 @@ |
498 | 509 | ); |
499 | 510 | $htmlOut .= Xml::openElement( 'td', array( 'valign' => 'top', 'colspan' => '5' ) ); |
500 | 511 | if ( $row->tmplog_action == 'created' ) { |
501 | | - //$htmlOut .= $this->showInitialSettings( $row ); |
| 512 | + $htmlOut .= $this->showInitialSettings( $row ); |
502 | 513 | } else if ( $row->tmplog_action == 'modified' ) { |
503 | | - //$htmlOut .= $this->showChanges( $row ); |
| 514 | + $htmlOut .= $this->showChanges( $row ); |
504 | 515 | } |
505 | 516 | $htmlOut .= Xml::closeElement( 'td' ); |
506 | 517 | |
— | — | @@ -542,4 +553,67 @@ |
543 | 554 | $htmlOut .= Xml::closeElement( 'table' ); |
544 | 555 | return $htmlOut; |
545 | 556 | } |
| 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 | + } |
546 | 620 | } |
Index: trunk/extensions/CentralNotice/patches/patch-template_log.sql |
— | — | @@ -7,14 +7,14 @@ |
8 | 8 | `tmplog_action` enum('created','modified','removed') NOT NULL DEFAULT 'modified', |
9 | 9 | `tmplog_template_id` int unsigned NOT NULL, |
10 | 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, |
| 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, |
15 | 15 | `tmplog_begin_fundraising` tinyint(1) DEFAULT NULL, |
16 | 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, |
| 17 | + `tmplog_begin_landingpages` varchar(255) DEFAULT NULL, |
| 18 | + `tmplog_end_landingpages` varchar(255) DEFAULT NULL, |
19 | 19 | `tmplog_content_change` tinyint(1) DEFAULT 0 |
20 | 20 | ) /*$wgDBTableOptions*/; |
21 | 21 | CREATE INDEX /*i*/tmplog_timestamp ON /*_*/cn_template_log (tmplog_timestamp); |
Index: trunk/extensions/CentralNotice/CentralNotice.i18n.php |
— | — | @@ -163,6 +163,12 @@ |
164 | 164 | 'centralnotice-log-label' => '<span class="cn-log-label">$1:</span> $2', |
165 | 165 | 'centralnotice-campaign-settings' => 'Campaign settings', |
166 | 166 | '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', |
167 | 173 | ); |
168 | 174 | |
169 | 175 | /** Message documentation (Message documentation) |
Index: trunk/extensions/CentralNotice/CentralNotice.db.php |
— | — | @@ -235,6 +235,41 @@ |
236 | 236 | } |
237 | 237 | |
238 | 238 | /** |
| 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 | + /** |
239 | 274 | * Lookup function for active banners under a given language/project/location. This function is |
240 | 275 | * called by SpecialBannerListLoader::getJsonList() in order to build the banner list JSON for |
241 | 276 | * each project. |
Index: trunk/extensions/CentralNotice/centralnotice.js |
— | — | @@ -12,6 +12,10 @@ |
13 | 13 | thisDetails.style.display = "table-row"; |
14 | 14 | } |
15 | 15 | } |
| 16 | +function switchLogs( baseUrl, logType ) { |
| 17 | + encodeURIComponent( logType ); |
| 18 | + window.location = baseUrl + '?log=' + logType; |
| 19 | +} |
16 | 20 | function selectProjects( selectAll ) { |
17 | 21 | var selectBox = document.getElementById('projects[]'); |
18 | 22 | var firstSelect = selectBox.options.length - 1; |