Nemo bis has uploaded a new change for review. https://gerrit.wikimedia.org/r/236260
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, 49 insertions(+), 15 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Translate refs/changes/60/236260/1 diff --git a/Translate.php b/Translate.php index 06b206e..44c4449 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 = false; + +/** * 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 0279f42..37fac14 100644 --- a/translationaids/SupportAid.php +++ b/translationaids/SupportAid.php @@ -28,20 +28,44 @@ * @since 2015-09 */ static function getSupportUrl( $title = null ) { - global $wgTranslateSupportUrl; - if ( !$wgTranslateSupportUrl ) { - throw new TranslationHelperException( "Support page not configured" ); - } else { - $supportTitle = Title::newFromText( $wgTranslateSupportUrl['page'] ); - $supportParams = $wgTranslateSupportUrl['params']; - } - $title = $this->handle->getTitle(); - if ( $supportTitle ) { + $namespace = $title->getNamespace(); + + // Fetch the configuration for this namespace if possible, or the default. + global $wgTranslateSupportUrl, $wgTranslateSupportUrlNamespace; + $supportConfig = false; + if ( $wgTranslateSupportUrlNamespace && + array_key_exists( $namespace, $wgTranslateSupportUrlNamespace ) ) { + $supportConfig = $wgTranslateSupportUrlNamespace; + elseif ( $wgTranslateSupportUrl ) { + $supportConfig = $wgTranslateSupportUrl; + } else { + throw new TranslationHelperException( "Support page not configured" ); + } + + if ( array_key_exists( 'page', $supportConfig ) { + $supportTitle = Title::newFromText( $supportConfig['page'] ); + } else { + $supportTitle = false; + } + if ( array_key_exists( 'params', $supportConfig ) { + $supportParams = $supportConfig['params']; foreach ( $supportParams as &$value ) { $value = str_replace( '%MESSAGE%', $title->getPrefixedText(), $value ); } - return $supportTitle->getFullUrl( $supportParams ); + } else { + $supportParams = false; + } + if ( array_key_exists( 'url', $supportConfig ) { + $supportUrlBase = $supportConfig['url']; + } else { + $supportUrlBase = false; + } + + if ( $supportUrlBase && $supportParams ) { + return wfAppendQuery( $supportUrlBase, $supportParams ); + } elseif ( $supportTitle && $supportParams ) { + return $supportTitle->getFullUrl( $supportParams ); } 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: newchange Gerrit-Change-Id: I8c44b5e49056ee4baeb03b4197e6892faef5b84e Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Translate Gerrit-Branch: master Gerrit-Owner: Nemo bis <federicol...@tiscali.it> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits