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

Change subject: Allow external or per-namespace support URL
......................................................................


Allow external or per-namespace support URL

* $wgTranslateSupportUrl can now contain a full URL ('url' key).
* $wgTranslateSupportUrlNamespace is added to override the general
  configuration for specific namespaces.

Bug: T40635
Change-Id: I8c44b5e49056ee4baeb03b4197e6892faef5b84e
---
M Translate.php
M translationaids/SupportAid.php
2 files changed, 40 insertions(+), 14 deletions(-)

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



diff --git a/Translate.php b/Translate.php
index 06b206e..f34a0bc 100644
--- a/Translate.php
+++ b/Translate.php
@@ -335,18 +335,28 @@
 );
 
 /**
- * Experimental support for Ask help button.
- * Might change into hook later on.
- * This is an array with keys page and params.
+ * Experimental support for an "Ask" help button.
+ * Might change into a hook later on.
+ * This is an array with keys page, url and params.
  * - page is a title of a local wiki page
+ * - url is an URL to use as is (e.g. an issue tracker submission form)
+ *   which will override the page if set
  * - params is an array of key-value pairs of request params
- * -- param value can contain variable %MESSAGE% which will be replaced with
- *    full page name.
+ * -- each param value can contain the variable %MESSAGE%
+ *    which will be replaced with the full page name.
  * @since 2011-03-11
  */
 $wgTranslateSupportUrl = false;
 
 /**
+ * Like $wgTranslateSupportUrl, but for a specific namespace.
+ * Each $wgTranslateSupportUrl-like array needs to be the value
+ * assigned to the numerical ID of a namespace of the wiki.
+ * @since 2015.09
+ */
+$wgTranslateSupportUrlNamespace = array();
+
+/**
  * When unprivileged users open a translation editor, they will
  * see a message stating that a special permission is needed for translating
  * messages. If this variable is defined, there is a button which will
diff --git a/translationaids/SupportAid.php b/translationaids/SupportAid.php
index ade2631..c56ee06 100644
--- a/translationaids/SupportAid.php
+++ b/translationaids/SupportAid.php
@@ -28,19 +28,35 @@
         * @since 2015.09
         */
        public static function getSupportUrl( Title $title ) {
-               global $wgTranslateSupportUrl;
-               if ( !$wgTranslateSupportUrl ) {
-                       throw new TranslationHelperException( "Support page not 
configured" );
+               global $wgTranslateSupportUrl, $wgTranslateSupportUrlNamespace;
+               $namespace = $title->getNamespace();
+
+               // Fetch the configuration for this namespace if possible, or 
the default.
+               if ( isset( $wgTranslateSupportUrlNamespace[$namespace] ) ) {
+                       $config = $wgTranslateSupportUrlNamespace[$namespace];
+               } elseif ( $wgTranslateSupportUrl ) {
+                       $config = $wgTranslateSupportUrl;
                } else {
-                       $supportTitle = Title::newFromText( 
$wgTranslateSupportUrl['page'] );
-                       $supportParams = $wgTranslateSupportUrl['params'];
+                       throw new TranslationHelperException( "Support page not 
configured" );
                }
 
-               if ( $supportTitle ) {
-                       foreach ( $supportParams as &$value ) {
-                               $value = str_replace( '%MESSAGE%', 
$title->getPrefixedText(), $value );
+               // Preprocess params
+               $params = array();
+               if ( isset( $config['params'] ) ) {
+                       foreach ( $config['params'] as $key => $value ) {
+                               $params[$key] = str_replace( '%MESSAGE%', 
$title->getPrefixedText(), $value );
                        }
-                       return $supportTitle->getFullUrl( $supportParams );
+               }
+
+               // Return the URL or make one from the page
+               if ( isset( $config['url'] ) ) {
+                       return  wfAppendQuery( $config['url'], $params );
+               } elseif ( isset( $config['page'] ) ) {
+                       $page = Title::newFromText( $config['page'] );
+                       if ( !$page ) {
+                               throw new TranslationHelperException( "Support 
page not configured properly" );
+                       }
+                       return $page->getFullUrl( $params );
                } else {
                        throw new TranslationHelperException( "Support page not 
configured properly" );
                }

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I8c44b5e49056ee4baeb03b4197e6892faef5b84e
Gerrit-PatchSet: 7
Gerrit-Project: mediawiki/extensions/Translate
Gerrit-Branch: master
Gerrit-Owner: Nemo bis <federicol...@tiscali.it>
Gerrit-Reviewer: Nemo bis <federicol...@tiscali.it>
Gerrit-Reviewer: Nikerabbit <niklas.laxst...@gmail.com>
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