jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/372388 )

Change subject: Introduce TranslateUtils::getEditorUrl
......................................................................


Introduce TranslateUtils::getEditorUrl

This allows creating links that open the translation in the
message editor. It falls back to action=edit for unknown messages.

To implement this, I added MessageHandle::getInternalKey which
figures out the correct format for Special:Translate.

Used this new method in two special pages which provide edit links:
* Special:Translations
* Special:SearchTranslations

Change-Id: Id0ba1e05386ca9e04360440a0ba593bdf84d6dd2
---
M TranslateUtils.php
M specials/SpecialSearchTranslations.php
M specials/SpecialTranslations.php
M utils/MessageHandle.php
4 files changed, 64 insertions(+), 26 deletions(-)

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



diff --git a/TranslateUtils.php b/TranslateUtils.php
index c6d26ab..9de73fa 100644
--- a/TranslateUtils.php
+++ b/TranslateUtils.php
@@ -402,4 +402,23 @@
 
                return wfGetDB( $index );
        }
+
+       /**
+        * Get an URL that points to an editor for this message handle.
+        * @param MessageHandle $handle
+        * @return string Domain relative URL
+        * @since 2017.10
+        */
+       public static function getEditorUrl( MessageHandle $handle ) {
+               if ( !$handle->isValid() ) {
+                       return $handle->getTitle()->getLocalURL( [ 'action' => 
'edit' ] );
+               }
+
+               $title = SpecialPageFactory::getPage( 'Translate' 
)->getPageTitle();
+               return $title->getLocalURL( [
+                       'showMessage' => $handle->getInternalKey(),
+                       'group' => $handle->getGroup()->getId(),
+                       'language' => $handle->getCode(),
+               ] );
+       }
 }
diff --git a/specials/SpecialSearchTranslations.php 
b/specials/SpecialSearchTranslations.php
index 8ff9400..2c30099 100644
--- a/specials/SpecialSearchTranslations.php
+++ b/specials/SpecialSearchTranslations.php
@@ -191,7 +191,7 @@
                                $resultAttribs['data-translation'] = 
$helpers->getTranslation();
                                $resultAttribs['data-group'] = $groupId;
 
-                               $uri = $title->getLocalURL( [ 'action' => 
'edit' ] );
+                               $uri = TranslateUtils::getEditorUrl( $handle );
                                $link = Html::element(
                                        'a',
                                        [ 'href' => $uri ],
diff --git a/specials/SpecialTranslations.php b/specials/SpecialTranslations.php
index a93a3ca..da0793d 100644
--- a/specials/SpecialTranslations.php
+++ b/specials/SpecialTranslations.php
@@ -37,9 +37,9 @@
        public function execute( $par ) {
                $this->setHeaders();
                $this->outputHeader();
-               $this->includeAssets();
 
                $out = $this->getOutput();
+               $out->addModuleStyles( 'ext.translate.legacy' );
 
                $par = (string)$par;
 
@@ -216,7 +216,6 @@
 
                $canTranslate = $this->getUser()->isAllowed( 'translate' );
 
-               $ajaxPageList = [];
                $historyText = '&#160;<sup>' .
                        $this->msg( 'translate-translations-history-short' 
)->escaped() .
                        '</sup>&#160;';
@@ -225,7 +224,6 @@
                foreach ( $res as $s ) {
                        $key = $s->page_title;
                        $tTitle = Title::makeTitle( $s->page_namespace, $key );
-                       $ajaxPageList[] = $tTitle->getPrefixedDBkey();
                        $tHandle = new MessageHandle( $tTitle );
 
                        $code = $tHandle->getCode();
@@ -233,16 +231,11 @@
                        $text = TranslateUtils::getLanguageName( $code, 
$this->getLanguage()->getCode() );
                        $text .= $separator;
                        $text .= $this->msg( 'parentheses' )->params( $code 
)->plain();
-                       $text = htmlspecialchars( $text );
-
-                       if ( $canTranslate ) {
-                               $tools['edit'] = 
TranslationHelpers::ajaxEditLink(
-                                       $tTitle,
-                                       $text
-                               );
-                       } else {
-                               $tools['edit'] = $this->makeLink( $tTitle, 
$text );
-                       }
+                       $tools['edit'] = Html::element(
+                               'a',
+                               [ 'href' => TranslateUtils::getEditorUrl( 
$tHandle ) ],
+                               $text
+                       );
 
                        $tools['history'] = $this->makeLink(
                                $tTitle,
@@ -280,17 +273,5 @@
 
                $out .= Xml::closeElement( 'table' );
                $this->getOutput()->addHTML( $out );
-
-               $vars = [ 'trlKeys' => $ajaxPageList ];
-               $this->getOutput()->addScript( Skin::makeVariablesScript( $vars 
) );
-       }
-
-       /**
-        * Add JavaScript assets
-        */
-       private function includeAssets() {
-               $out = $this->getOutput();
-               TranslationHelpers::addModules( $out );
-               $out->addModuleStyles( 'ext.translate.legacy' );
        }
 }
diff --git a/utils/MessageHandle.php b/utils/MessageHandle.php
index 7a9bb39..1b9eaaa 100644
--- a/utils/MessageHandle.php
+++ b/utils/MessageHandle.php
@@ -250,4 +250,42 @@
 
                return $res !== false;
        }
+
+       /**
+        * This returns the key that can be used for showMessage parameter for 
Special:Translate
+        * for regular message groups. It is not possible to automatically 
determine this key
+        * from the title alone.
+        * @return string
+        * @since 2017.10
+        */
+       public function getInternalKey() {
+               global $wgContLang;
+
+               $key = $this->getKey();
+
+               if ( !MWNamespace::isCapitalized( 
$this->getTitle()->getNamespace() ) ) {
+                       return $key;
+               }
+
+               $group = $this->getGroup();
+               $keys = [];
+               // We cannot reliably map from the database key to the internal 
key if
+               // capital links setting is enabled for the namespace.
+               if ( method_exists( $group, 'getKeys' ) ) {
+                       $keys = $group->getKeys();
+               } else {
+                       $keys = array_keys( $group->getDefinitions() );
+               }
+
+               if ( in_array( $key, $keys, true ) ) {
+                       return $key;
+               }
+
+               $lcKey = $wgContLang->lcfirst( $key );
+               if ( in_array( $lcKey, $keys, true ) ) {
+                       return $lcKey;
+               }
+
+               return "BUG:$key";
+       }
 }

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Id0ba1e05386ca9e04360440a0ba593bdf84d6dd2
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/Translate
Gerrit-Branch: master
Gerrit-Owner: Nikerabbit <niklas.laxst...@gmail.com>
Gerrit-Reviewer: Amire80 <amir.ahar...@mail.huji.ac.il>
Gerrit-Reviewer: Catrope <r...@wikimedia.org>
Gerrit-Reviewer: Nikerabbit <niklas.laxst...@gmail.com>
Gerrit-Reviewer: Reedy <re...@wikimedia.org>
Gerrit-Reviewer: Siebrand <siebr...@kitano.nl>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to