Adamw has submitted this change and it was merged.

Change subject: (FR #1077) Make banner logs work again
......................................................................


(FR #1077) Make banner logs work again

https://mingle.corp.wikimedia.org/projects/fundraiser_2012/cards/1077

I broke the banner log pager in https://gerrit.wikimedia.org/r/#/c/79184/

This fixes it.

Change-Id: I009aaeecbad667d73f492c5573baa6df8a35cc3a
---
M CentralNotice.i18n.php
M CentralNoticeBannerLogPager.php
M CentralNoticeCampaignLogPager.php
M includes/Banner.php
4 files changed, 52 insertions(+), 29 deletions(-)

Approvals:
  Adamw: Looks good to me, approved
  Siebrand: Looks good to me, but someone else must approve



diff --git a/CentralNotice.i18n.php b/CentralNotice.i18n.php
index 1807d90..7d1a192 100644
--- a/CentralNotice.i18n.php
+++ b/CentralNotice.i18n.php
@@ -171,6 +171,8 @@
        'centralnotice-fundraising' => 'Fundraising',
        'centralnotice-autolink' => 'Automatic link creation',
        'centralnotice-landingpages' => 'Landing pages',
+       'centralnotice-controller_mixin' => 'Controller mixins',
+       'centralnotice-category' => 'Banner category',
        'centralnotice-banner-content' => 'Banner content',
        'centralnotice-banner-content-changed' => 'Changed',
        'centralnotice-filters' => 'Log filters',
@@ -574,6 +576,8 @@
 {{Identical|Fundraising}}',
        'centralnotice-autolink' => 'Label for a setting. Used as parameter 
<code>$1</code> of {{msg-mw|Centralnotice-log-label}}',
        'centralnotice-landingpages' => 'Label for a setting. Used as parameter 
<code>$1</code> of {{msg-mw|Centralnotice-log-label}}',
+       'centralnotice-controller_mixin' => 'Label for a setting. Used as 
parameter <code>$1</code> of {{msg-mw|Centralnotice-log-label}} (a mixin is a 
small bit of code added to change base functionality)',
+       'centralnotice-category' => 'Label for a setting. Used as parameter 
<code>$1</code> of {{msg-mw|Centralnotice-log-label}}',
        'centralnotice-banner-content' => 'On the 
[[meta:Special:CentralNoticeLogs|Central Notice Logs]] special page, this is a 
radio button which shows log entries associated to edits to the MediaWiki pages 
(one per banner) which define the structure ("content") of every banner and can 
use other (sub)messages as translatable variables, whose changes are in 
contrast shown by {{msg-mw|centralnotice-banner-messages}} button.
 Related messages:
 *{{msg-mw|centralnotice-campaign-settings}}
diff --git a/CentralNoticeBannerLogPager.php b/CentralNoticeBannerLogPager.php
index d0d132f..07a1460 100644
--- a/CentralNoticeBannerLogPager.php
+++ b/CentralNoticeBannerLogPager.php
@@ -174,16 +174,28 @@
                return $details;
        }
 
-       function showChanges( $row ) {
-               $details = $this->testBooleanChange( 'anon', $row );
-               $details .= $this->testBooleanChange( 'account', $row );
-               $details .= $this->testTextChange( 'category', $row );
-               $details .= $this->testBooleanChange( 'autolink', $row );
-               $details .= $this->testTextChange( 'landingpages', $row );
-               $details .= $this->testTextChange( 'controller_mixin', $row );
-               $details .= $this->testTextChange( 'prioritylangs', $row );
-               $details .= $this->testTextChange( 'devices', $row );
-               if ( $row->tmplog_content_change ) {
+       function showChanges( $newrow ) {
+               $oldrow = false;
+               if ( $newrow->tmplog_action === 'modified' ) {
+                       $db = CNDatabase::getDb();
+                       $oldrow = $db->selectRow(
+                               array( 'cn_template_log' => 'cn_template_log' ),
+                               '*',
+                               array( 'tmplog_template_id' => 
$newrow->tmplog_template_id, "tmplog_id < {$newrow->tmplog_id}" ),
+                               __METHOD__,
+                               array( 'ORDER BY' => 'tmplog_id DESC', 'LIMIT' 
=> '1' )
+                       );
+               }
+
+               $details = $this->testBooleanChange( 'anon', $newrow, $oldrow );
+               $details .= $this->testBooleanChange( 'account', $newrow, 
$oldrow );
+               $details .= $this->testTextChange( 'category', $newrow, $oldrow 
);
+               $details .= $this->testBooleanChange( 'autolink', $newrow, 
$oldrow );
+               $details .= $this->testTextChange( 'landingpages', $newrow, 
$oldrow );
+               $details .= $this->testTextChange( 'controller_mixin', $newrow, 
$oldrow );
+               $details .= $this->testTextChange( 'prioritylangs', $newrow, 
$oldrow );
+               $details .= $this->testTextChange( 'devices', $newrow, $oldrow 
);
+               if ( $newrow->tmplog_content_change ) {
                        // Show changes to banner content
                        $details .= $this->msg (
                                'centralnotice-log-label',
@@ -194,11 +206,13 @@
                return $details;
        }
 
-       private function testBooleanChange( $param, $row ) {
+       private function testBooleanChange( $param, $newrow, $oldrow ) {
                $result = '';
-               $beginField = 'tmplog_begin_'.$param;
                $endField = 'tmplog_end_'.$param;
-               if ( $row->$beginField !== $row->$endField ) {
+
+               $oldval = ( $oldrow ) ? $oldrow->$endField : 0;
+
+               if ( $oldval !== $newrow->$endField ) {
                        // Give grep a chance to find the usages:
                        // centralnotice-anon, centralnotice-account, 
centralnotice-fundraising, centralnotice-autolink
                        $result .= $this->msg(
@@ -206,27 +220,31 @@
                                $this->msg( 'centralnotice-' . $param )->text(),
                                $this->msg(
                                        'centralnotice-changed',
-                                       ( $row->$beginField ? $this->msg( 
'centralnotice-on' )->text() : $this->msg( 'centralnotice-off' )->text() ),
-                                       ( $row->$endField ? $this->msg( 
'centralnotice-on' )->text() : $this->msg( 'centralnotice-off' )->text() )
+                                       ( $oldval ? $this->msg( 
'centralnotice-on' )->text() : $this->msg( 'centralnotice-off' )->text() ),
+                                       ( $newrow->$endField ? $this->msg( 
'centralnotice-on' )->text() : $this->msg( 'centralnotice-off' )->text() )
                                )->text()
                        )->text() . "<br/>";
                }
                return $result;
        }
 
-       private function testTextChange( $param, $row ) {
+       private function testTextChange( $param, $newrow, $oldrow ) {
                $result = '';
-               $beginField = 'tmplog_begin_'.$param;
                $endField = 'tmplog_end_'.$param;
-               if ( $row->$beginField !== $row->$endField ) {
-                       // Give grep a chance to find the usages: 
centralnotice-landingpages, centralnotice-prioritylangs
+
+               $oldval = ( ( $oldrow ) ? $oldrow->$endField : '' ) ?: '';
+               $newval = ( $newrow->$endField ) ?: '';
+
+               if ( $oldval !== $newval ) {
+                       // Give grep a chance to find the usages: 
centralnotice-landingpages, centralnotice-prioritylangs,
+                       // centralnotice-controller_mixin, 
centralnotice-category
                        $result .= $this->msg(
                                'centralnotice-log-label',
                                $this->msg( 'centralnotice-'.$param )->text(),
                                $this->msg(
                                        'centralnotice-changed',
-                                       $row->$beginField,
-                                       $row->$endField
+                                       $oldval,
+                                       $newval
                                )->text()
                        )->text() . "<br/>";
                }
diff --git a/CentralNoticeCampaignLogPager.php 
b/CentralNoticeCampaignLogPager.php
index d967509..08ac5f6 100644
--- a/CentralNoticeCampaignLogPager.php
+++ b/CentralNoticeCampaignLogPager.php
@@ -302,9 +302,10 @@
        /**
         * @param $param
         * @param $row
+        * @param array $oldrow Required because this is a stupid heirarchy -- 
@see CentralNoticeBannerLogPager
         * @return string
         */
-       private function testBooleanChange( $param, $row ) {
+       private function testBooleanChange( $param, $row, $oldrow ) {
                $result = '';
                $beginField = 'notlog_begin_' . $param;
                $endField = 'notlog_end_' . $param;
diff --git a/includes/Banner.php b/includes/Banner.php
index 3b25baa..fb0c5de 100644
--- a/includes/Banner.php
+++ b/includes/Banner.php
@@ -434,7 +434,7 @@
         * @param DatabaseBase $db
         */
        protected function saveBasicData( $db ) {
-               if ( $this->setBasicDataDirty( false ) ) {
+               if ( $this->dirtyFlags['basic'] ) {
                        $db->update( 'cn_templates',
                                array(
                                         'tmp_display_anon'    => 
(int)$this->allocateAnon,
@@ -547,7 +547,7 @@
         * @param DatabaseBase $db
         */
        protected function saveDeviceTargetData( $db ) {
-               if ( $this->markDeviceTargetDataDirty( false ) ) {
+               if ( $this->dirtyFlags['devices'] ) {
                        // Remove all entries from the table for this banner
                        $db->delete( 'cn_template_devices', array( 'tmp_id' => 
$this->getId() ), __METHOD__ );
 
@@ -655,7 +655,7 @@
         * @param DatabaseBase $db
         */
        protected function saveMixinData( $db ) {
-               if ( $this->markMixinDataDirty( false ) ) {
+               if ( $this->dirtyFlags['mixins'] ) {
                        $db->delete( 'cn_template_mixins',
                                array( 'tmp_id' => $this->getId() ),
                                __METHOD__
@@ -745,7 +745,7 @@
        protected function savePriorityLanguageData() {
                global $wgNoticeUseTranslateExtension;
 
-               if ( $wgNoticeUseTranslateExtension && 
$this->markPriorityLanguageDataDirty( false ) ) {
+               if ( $wgNoticeUseTranslateExtension && 
$this->dirtyFlags['prioritylang'] ) {
                        TranslateMetadata::set(
                                BannerMessageGroup::getTranslateGroupName( 
$this->getName() ),
                                'prioritylangs',
@@ -825,7 +825,7 @@
        protected function saveBodyContent() {
                global $wgNoticeUseTranslateExtension;
 
-               if ( $this->markBodyContentDirty( false ) ) {
+               if ( $this->dirtyFlags['content'] ) {
                        $wikiPage = new WikiPage( $this->getTitle() );
 
                        $contentObj = ContentHandler::makeContent( 
$this->bodyContent, $wikiPage->getTitle() );
@@ -1002,8 +1002,7 @@
 
                        $db->commit( __METHOD__ );
 
-                       // These all should have been set in the individual 
save functions, but just
-                       // to make sure.
+                       // Clear the dirty flags
                        foreach ( $this->dirtyFlags as $flag => &$value ) { 
$value = false; }
 
                        if ( $this->runTranslateJob ) {
@@ -1440,6 +1439,7 @@
                        'tmplog_action'        => $action,
                        'tmplog_template_id'   => $this->getId(),
                        'tmplog_template_name' => $this->getName(),
+                       'tmplog_content_change'=> 
(int)$this->dirtyFlags['content'],
                );
 
                foreach ( $endSettings as $key => $value ) {

-- 
To view, visit https://gerrit.wikimedia.org/r/87308
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I009aaeecbad667d73f492c5573baa6df8a35cc3a
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/CentralNotice
Gerrit-Branch: master
Gerrit-Owner: Mwalker <[email protected]>
Gerrit-Reviewer: Adamw <[email protected]>
Gerrit-Reviewer: Siebrand <[email protected]>
Gerrit-Reviewer: jenkins-bot

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to