Mwalker has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/50768


Change subject: (bug 45366) CentralNotice using wrong DB for logging
......................................................................

(bug 45366) CentralNotice using wrong DB for logging

CentralNotice was not correctly querying the master DB when performing
logging operations. Instead it was querying the slave which could
result in dblag related issues.

Additionally -- this patch fixes bugs wrt translation when using the
newly refactored code.

Change-Id: I49a53304ca8352bb62a21873274fc42331a60bdd
---
M includes/Banner.php
M includes/BannerMessageGroup.php
2 files changed, 13 insertions(+), 7 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/CentralNotice 
refs/changes/68/50768/1

diff --git a/includes/Banner.php b/includes/Banner.php
index f164f91..458f9a0 100644
--- a/includes/Banner.php
+++ b/includes/Banner.php
@@ -1,10 +1,15 @@
 <?php
 
 class Banner {
+       /** @var string Canonical name of the banner (eg, without the 
Centralnotice-template) */
        var $name;
 
-       function __construct( $name ) {
+       /** @var bool If true will force DB read connections to use the master. 
Writes always are performed on the master. */
+       protected var $forceDbMaster = false;
+
+       function __construct( $name, $useMaster = false ) {
                $this->name = $name;
+               $this->forceDbMaster = $useMaster;
        }
 
        function getName() {
@@ -20,7 +25,7 @@
        }
 
        function getId() {
-               return Banner::getTemplateId( $this->name );
+               return Banner::getTemplateId( $this->name, $this->forceDbMaster 
);
        }
 
        function getMessageField( $field_name ) {
@@ -427,8 +432,9 @@
                return $banners;
        }
 
-       static function getTemplateId( $templateName ) {
-               $dbr = wfGetDB( DB_SLAVE );
+       static function getTemplateId( $templateName, $useMaster = false ) {
+               $dbr = ( $useMaster ) ? wfGetDB( DB_MASTER ) : wfGetDB( 
DB_SLAVE );
+
                $templateName = htmlspecialchars( $templateName );
                $res = $dbr->select(
                        'cn_templates',
@@ -576,7 +582,7 @@
        static function logBannerChange( $action, $banner, $user, 
$beginSettings = array(), $endSettings = array() ) {
                $dbw = wfGetDB( DB_MASTER );
 
-               $bannerObj = new Banner( $banner );
+               $bannerObj = new Banner( $banner, true );
                $log = array(
                        'tmplog_timestamp'     => $dbw->timestamp(),
                        'tmplog_user_id'       => $user->getId(),
diff --git a/includes/BannerMessageGroup.php b/includes/BannerMessageGroup.php
index 74be4f3..6d49b20 100644
--- a/includes/BannerMessageGroup.php
+++ b/includes/BannerMessageGroup.php
@@ -44,7 +44,7 @@
                )->inContentLanguage()->plain();
 
                // Extract the list of message fields from the banner source.
-               $fields = SpecialNoticeTemplate::extractMessageFields( 
$bannerSource );
+               $fields = Banner::extractMessageFields( $bannerSource );
 
                // The MediaWiki page name convention for messages is the same 
as the
                // convention for banners themselves, except that it doesn't 
include
@@ -58,7 +58,7 @@
                }
 
                // Build the array of message definitions.
-               foreach ( $fields[1] as $msgName ) {
+               foreach ( $fields as $msgName => $msgCount ) {
                        $defkey = $msgDefKeyPrefix . $msgName;
                        $msgkey = $msgKeyPrefix . $msgName;
                        $definitions[$msgkey] = wfMessage( $defkey 
)->inContentLanguage()->plain();

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I49a53304ca8352bb62a21873274fc42331a60bdd
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/CentralNotice
Gerrit-Branch: master
Gerrit-Owner: Mwalker <[email protected]>

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

Reply via email to