jenkins-bot has submitted this change and it was merged.

Change subject: Making Translations work again...
......................................................................


Making Translations work again...

There was some code rot in here. Fixing it up in preperation
for deployment.

Change-Id: Ifd5b8de41269b8f37480462b5d9e79e937217c62
---
M includes/Banner.php
M includes/BannerMessage.php
M includes/BannerMessageGroup.php
M includes/CNDatabase.php
M special/SpecialCentralNotice.php
5 files changed, 41 insertions(+), 19 deletions(-)

Approvals:
  Adamw: Verified; Looks good to me, approved
  jenkins-bot: Verified



diff --git a/includes/Banner.php b/includes/Banner.php
index db492b9..fd01078 100644
--- a/includes/Banner.php
+++ b/includes/Banner.php
@@ -504,6 +504,7 @@
        /**
         * Updates any metadata required for banner/translation extension 
integration.
         *
+        * @param array  $pageResult        Return from 
WikiPage->doEditContent()
         * @param string $name              Raw name of banner
         * @param string $body              Body text of banner
         * @param array  $priorityLangs     Languages to emphasize during 
translation
diff --git a/includes/BannerMessage.php b/includes/BannerMessage.php
index e127751..ff6e9f8 100644
--- a/includes/BannerMessage.php
+++ b/includes/BannerMessage.php
@@ -7,14 +7,33 @@
        }
 
        function getTitle( $lang, $namespace = NS_MEDIAWIKI ) {
-               return Title::newFromText( $this->getDbKey( $lang ), $namespace 
);
+               return Title::newFromText( $this->getDbKey( $lang, $namespace 
), $namespace );
        }
 
-       function getDbKey( $lang = null ) {
+       /**
+        * Obtains the key of the message as stored in the database. This 
varies depending on namespace
+        *  - in the MediaWiki namespace messages are Centralnotice-{banner 
name}-{message name}/{lang}
+        *  -- except for the content language which is stored without the 
/{lang} extension
+        *  - in the CN Banner namespace messages are {banner name}-{message 
name}/{lang}
+        *
+        * @param string|null $lang      Language code
+        * @param int         $namespace Namespace to get key for
+        *
+        * @return string Message database key
+        * @throws MWException
+        */
+       function getDbKey( $lang = null, $namespace = NS_MEDIAWIKI ) {
                global $wgLanguageCode;
-               return ( $lang === null or $lang === $wgLanguageCode ) ?
-                       "Centralnotice-{$this->banner_name}-{$this->name}" :
-                       
"Centralnotice-{$this->banner_name}-{$this->name}/{$lang}";
+
+               if ( $namespace === NS_MEDIAWIKI ) {
+                       return ( $lang === null or $lang === $wgLanguageCode ) ?
+                               
"Centralnotice-{$this->banner_name}-{$this->name}" :
+                               
"Centralnotice-{$this->banner_name}-{$this->name}/{$lang}";
+               } elseif ( $namespace === NS_CN_BANNER ) {
+                       return "{$this->banner_name}-{$this->name}/{$lang}";
+               } else {
+                       throw new MWException( "Namespace '$namespace' not 
known for having CentralNotice messages." );
+               }
        }
 
        /**
@@ -51,7 +70,7 @@
                        if ( class_exists( 'ContentHandler' ) ) {
                                // MediaWiki 1.21+
                                $content = ContentHandler::makeContent( $text, 
$title );
-                               $wikiPage->doEditContent( $content, '/* CN 
admin */', EDIT_FORCE_BOT );
+                               $result = $wikiPage->doEditContent( $content, 
'/* CN admin */', EDIT_FORCE_BOT );
                        } else {
                                $wikiPage->doEdit( $translation, '/* CN admin 
*/', EDIT_FORCE_BOT );
                        }
@@ -85,9 +104,8 @@
         * This really is intended only for use on the original source language 
and qqq because
         * these languages are set via the CN UI; not the translate UI.
         *
-        * @param $field        Message name; should be BannerName-MessageName 
format
-        * @param $content      Contents of the message
-        * @param $lang         Language to update for
+        * @param WikiPage $page Page containing the message to protect
+        * @param User     $user User doing the protection (ie: the last one to 
edit the page)
         */
        protected function protectMessageInCnNamespaces( $page, $user ) {
                global $wgNoticeProtectGroup;
diff --git a/includes/BannerMessageGroup.php b/includes/BannerMessageGroup.php
index 374b7df..631a2e0 100644
--- a/includes/BannerMessageGroup.php
+++ b/includes/BannerMessageGroup.php
@@ -199,8 +199,7 @@
         * @return bool
         */
        public static function registerGroupHook( &$list ) {
-               global $wgCentralDBname;
-               $dbr = wfGetDB( DB_MASTER, array(), $wgCentralDBname );
+               $dbr = CNDatabase::getDb( DB_MASTER ); // Must be explicitly 
master for runs under a jobqueue
 
                // Create the base aggregate group
                $conf = array();
diff --git a/includes/CNDatabase.php b/includes/CNDatabase.php
index 194ac27..9e5e905 100644
--- a/includes/CNDatabase.php
+++ b/includes/CNDatabase.php
@@ -7,20 +7,22 @@
        /**
         * Gets a database object. Will be the master if the user is logged in.
         *
-        * @param string|bool $wiki        Wiki database to connect to, if 
false will be
-        *                                 the Infrastructure DB
-        * @param bool        $forceSlave  If true will force a slave 
connection; otherwise
-        *                                 this will return a master if logged 
in.
+        * @param int|bool    $force   If false will return a DB master/slave 
based on users permissions.
+        *                             Set to DB_MASTER or DB_SLAVE to force 
that type.
+        * @param string|bool $wiki    Wiki database to connect to, if false 
will be the Infrastructure DB
         *
         * @return DatabaseBase
         */
-       public static function getDb( $wiki = false, $forceSlave = false ) {
+       public static function getDb( $force = false, $wiki = false ) {
                global $wgCentralDBname;
                global $wgUser;
 
-               $dbmode = DB_SLAVE;
-               if ( $wgUser->isLoggedIn() && !$forceSlave ) {
+               if ( $wgUser->isAllowed( 'centralnotice-admin' ) ) {
                        $dbmode = DB_MASTER;
+               } elseif ( $force === false ) {
+                       $dbmode = DB_SLAVE;
+               } else {
+                       $dbmode = $force;
                }
 
                $db = ( $wiki === false ) ? $wgCentralDBname : $wiki;
diff --git a/special/SpecialCentralNotice.php b/special/SpecialCentralNotice.php
index 90be993..483e137 100644
--- a/special/SpecialCentralNotice.php
+++ b/special/SpecialCentralNotice.php
@@ -1104,8 +1104,10 @@
 
                        // Banner
                        $banner = new Banner( $row->tmp_name );
+                       $renderer = new BannerRenderer( $this->getContext(), 
$banner );
                        $htmlOut .= Xml::tags( 'td', array( 'valign' => 'top' ),
-                               $banner->previewFieldSet( $this->getContext(), 
true )
+                               $renderer->linkTo() . '<br/>' .
+                               $renderer->previewFieldSet()
                        );
 
                        $htmlOut .= Xml::closeElement( 'tr' );

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

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

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

Reply via email to