Anomie has uploaded a new change for review.

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

Change subject: Edit translations for all jump wikis on central wiki
......................................................................

Edit translations for all jump wikis on central wiki

Fortunately jump wikis don't have questions or options, so we only have
to worry about mapping the election's ID (which we do in the same way we
do elsewhere, by title lookup).

Bug: 72576
Change-Id: Ifcf2ac4b0f9544a3968df52c2f653f15ee2f6426
---
M i18n/en.json
M i18n/qqq.json
M includes/pages/TranslatePage.php
3 files changed, 101 insertions(+), 7 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/SecurePoll 
refs/changes/52/173052/1

diff --git a/i18n/en.json b/i18n/en.json
index 2635c25..79f44cb 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -87,6 +87,8 @@
        "securepoll-dump-no-urandom": "Cannot open /dev/urandom. \nTo maintain 
voter privacy, encrypted election records are only publically available when 
they can be shuffled with a secure random number stream.",
        "securepoll-urandom-not-supported": "This server does not support 
cryptographic random number generation.\nTo maintain voter privacy, encrypted 
election records are only publically available when they can be shuffled with a 
secure random number stream.",
        "securepoll-translate-title": "Translate: $1",
+       "securepoll-translate-redirect": "Messages for this election must be 
configured on $1",
+       "securepoll-translate-redirect-otherwiki": "the main wiki",
        "securepoll-translate-label-comment": "Reason: ",
        "securepoll-invalid-language": "Invalid language code \"$1\"",
        "securepoll-header-trans-id": "ID",
diff --git a/i18n/qqq.json b/i18n/qqq.json
index fefc122..92ff987 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -80,6 +80,8 @@
        "securepoll-dump-no-urandom": "Do not translate 
\"/dev/urandom\".\n\nServers running Microsoft Windows will present 
[[MediaWiki:Securepoll-urandom-not-supported/en|Securepoll-urandom-not-supported]]
 instead.",
        "securepoll-urandom-not-supported": "As to the meaning of 
''cryptographic random number'', see [[:wikipedia:Cryptographically secure 
pseudorandom number generator]] for reference.\n\nThe /dev/urandom 
cryptographic random number generation device is not supported on servers 
running Microsoft Windows. On other platforms the 
[[MediaWiki:Securepoll-dump-no-urandom/en|Securepoll-dump-no-urandom]] message 
is generated if opening of the /dev/urandom device fails.",
        "securepoll-translate-title": "Used as page title. Parameters:\n* $1 - 
title of election\n{{Identical|Translate}}",
+       "securepoll-translate-redirect": "Text displayed when trying to edit 
messages for a multi-wiki poll on the wrong wiki.\n\nParameters:\n* $1 - HTML 
of a link to the correct wiki. Displayed text is either the wiki name or 
{{msg-mw|securepoll-translate-redirect-otherwiki}}",
+       "securepoll-translate-redirect-otherwiki": "Used with 
{{msg-mw|securepoll-translate-redirect}} when no name is available for the 
target wiki.",
        "securepoll-translate-label-comment": "Label for the \"edit summary\" 
field on Special:SecurePoll/translate.\n{{Identical|Reason}}",
        "securepoll-invalid-language": "Parameters:\n* $1 - language code",
        "securepoll-header-trans-id": "{{optional}}\n{{Identical|ID}}",
diff --git a/includes/pages/TranslatePage.php b/includes/pages/TranslatePage.php
index 1b13238..82868b5 100644
--- a/includes/pages/TranslatePage.php
+++ b/includes/pages/TranslatePage.php
@@ -26,6 +26,31 @@
                $wgOut->setPageTitle( wfMsg( 'securepoll-translate-title',
                        $this->election->getMessage( 'title' ) ) );
 
+               $jumpUrl = $this->election->getProperty( 'jump-url' );
+               if ( $jumpUrl ) {
+                       $jumpId = $this->election->getProperty( 'jump-id' );
+                       if ( !$jumpId ) {
+                               throw new MWException( 'Configuration error: no 
jump-id' );
+                       }
+                       $jumpUrl .= "/edit/$jumpId";
+                       if ( count( $params ) > 1 ) {
+                               $jumpUrl .= '/' . join( '/', array_slice( 
$params, 1 ) );
+                       }
+
+                       $wiki = $this->election->getProperty( 'main-wiki' );
+                       if ( $wiki ) {
+                               $wiki = WikiMap::getWikiName( $wiki );
+                       } else {
+                               $wiki = $this->msg( 
'securepoll-edit-redirect-otherwiki' )->text();
+                       }
+
+                       $wgOut->addWikiMsg( 'securepoll-edit-redirect',
+                               Message::rawParam( Linker::makeExternalLink( 
$jumpUrl, $wiki ) )
+                       );
+
+                       return;
+               }
+
                $this->isAdmin = $this->election->isAdmin( $wgUser );
 
                $primary = $this->election->getLanguage();
@@ -164,6 +189,7 @@
 
                $entities = array_merge( array( $this->election ), 
$this->election->getDescendants() );
                $replaceBatch = array();
+               $jumpReplaceBatch = array();
                foreach ( $entities as $entity ) {
                        foreach ( $entity->getMessageNames() as $messageName ) {
                                $controlName = 'trans_' . $entity->getId() . 
'_' . $messageName;
@@ -175,17 +201,81 @@
                                                'msg_key' => $messageName,
                                                'msg_text' => $value
                                        );
+
+                                       // Jump wikis don't have subentities
+                                       if ( $entity === $this->election ) {
+                                               $jumpReplaceBatch[] = array(
+                                                       'msg_entity' => 
$entity->getId(),
+                                                       'msg_lang' => 
$secondary,
+                                                       'msg_key' => 
$messageName,
+                                                       'msg_text' => $value
+                                               );
+                                       }
                                }
                        }
                }
                if ( $replaceBatch ) {
-                       $dbw = $this->context->getDB();
-                       $dbw->replace(
-                               'securepoll_msgs',
-                               array( array( 'msg_entity', 'msg_lang', 
'msg_key' ) ),
-                               $replaceBatch,
-                               __METHOD__
-                       );
+                       $wikis = $this->election->getProperty( 'wikis' );
+                       if ( $wikis ) {
+                               $wikis = explode( "\n", $wikis );
+                       } else {
+                               $wikis = array();
+                       }
+
+                       $dbws = array();
+                       try {
+                               // First, the main wiki
+                               $dbw = $this->context->getDB();
+                               $dbw->begin();
+                               $dbws[] = $dbw;
+                               $dbw->replace(
+                                       'securepoll_msgs',
+                                       array( array( 'msg_entity', 'msg_lang', 
'msg_key' ) ),
+                                       $replaceBatch,
+                                       __METHOD__
+                               );
+
+                               // Then each jump-wiki
+                               foreach ( $wikis as $dbname ) {
+                                       if ( $dbname === wfWikiID() ) {
+                                               continue;
+                                       }
+
+                                       $dbw = wfGetDB( DB_MASTER, array(), 
$dbname );
+                                       $dbw->begin();
+                                       $dbws[] = $dbw;
+
+                                       $id = $dbw->selectField( 
'securepoll_elections', 'el_entity', array(
+                                               'el_title' => 
$this->election->title
+                                       ) );
+                                       if ( !$id ) {
+                                               // WTF?
+                                               continue;
+                                       }
+
+                                       foreach ( $jumpReplaceBatch as &$row ) {
+                                               $row['msg_entity'] = $id;
+                                       }
+                                       unset( $row );
+
+                                       $dbw->replace(
+                                               'securepoll_msgs',
+                                               array( array( 'msg_entity', 
'msg_lang', 'msg_key' ) ),
+                                               $jumpReplaceBatch,
+                                               __METHOD__
+                                       );
+                               }
+
+                               // Now commit all the transactions at once
+                               foreach ( $dbws as $dbw ) {
+                                       $dbw->commit();
+                               }
+                       } catch ( Exception $ex ) {
+                               foreach ( $dbws as $dbw ) {
+                                       $dbw->rollback();
+                               }
+                               throw $ex;
+                       }
 
                        if ( $wgSecurePollUseNamespace ) {
                                list( $title, $content ) = 
SecurePollContentHandler::makeContentFromElection(

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ifcf2ac4b0f9544a3968df52c2f653f15ee2f6426
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/SecurePoll
Gerrit-Branch: master
Gerrit-Owner: Anomie <[email protected]>

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

Reply via email to