Microchip08 has uploaded a new change for review. https://gerrit.wikimedia.org/r/136624
Change subject: Do not add ?uselang= on the default language ...................................................................... Do not add ?uselang= on the default language Adding ?uselang= is only useful when the language in question is different to that of the wiki's default. This commit removes the ?uselang= parameter if the two languages are the same (for example, on an English wiki, ?uselang=de would remain, but ?uselang=en would be stripped from the links). Change-Id: I6a9191ae67a6d7acacef5ce21358d797c72169ab --- M StickToThatLanguage.hooks.php 1 file changed, 17 insertions(+), 14 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/StickToThatLanguage refs/changes/24/136624/1 diff --git a/StickToThatLanguage.hooks.php b/StickToThatLanguage.hooks.php index a3b6b42..6c4f02c 100644 --- a/StickToThatLanguage.hooks.php +++ b/StickToThatLanguage.hooks.php @@ -78,7 +78,7 @@ */ public static function onSkinTemplateOutputPageBeforeExec( \SkinTemplate &$sk, \QuickTemplate &$tpl ) { global $egSTTLanguageDisplaySelector, $egSTTLanguageTopLanguages; - if( ! $egSTTLanguageDisplaySelector ) { + if ( ! $egSTTLanguageDisplaySelector ) { return true; // option for disabling the selector is active } @@ -96,14 +96,14 @@ ? Ext::getUserLanguageCodes( $user ) // display users preferred languages on top : $egSTTLanguageTopLanguages; - foreach( \Language::fetchLanguageNames() as $code => $name ) { - if( $code === $sk->getLanguage()->getCode() ) { + foreach ( \Language::fetchLanguageNames() as $code => $name ) { + if ( $code === $sk->getLanguage()->getCode() ) { continue; // don't add language the page is displayed in } // set 'uselang' and in case this was a GET request also all other parameters when switching language $urlParams = array( 'uselang' => $code ); - if( ! $sk->getRequest()->wasPosted() ) { + if ( ! $sk->getRequest()->wasPosted() ) { $urlParams += $sk->getRequest()->getValues(); unset( $urlParams['title'] ); // don't want the 'title' twice } @@ -119,7 +119,7 @@ ); $topIndex = array_search( $code, $topLanguages ); - if( $topIndex !== false ) { + if ( $topIndex !== false ) { // language is considered a 'top' language $url['class'] .= ' sttl-toplang'; $topLangUrls[ $topIndex ] = $url; @@ -128,7 +128,7 @@ } } - if( count( $topLangUrls ) ) { // can be empty when the only language in here is the one displayed! + if ( count( $topLangUrls ) ) { // can be empty when the only language in here is the one displayed! // make sure top languages are still in defined order and there are no gaps: ksort( $topLangUrls ); $topLangUrls = array_values( $topLangUrls ); @@ -163,7 +163,7 @@ // add styles for the language selector: global $egSTTLanguageDisplaySelector; - if( $egSTTLanguageDisplaySelector ) { + if ( $egSTTLanguageDisplaySelector ) { // add styles for language selector (has to be done separately for non-JS version): $out->addModuleStyles( 'sticktothatlanguage' ); $out->addModules( 'sticktothatlanguage' ); @@ -188,7 +188,7 @@ public static function onLinkBegin( $skin, $target, &$text, &$customAttribs, &$query, &$options, &$ret ) { global $wgLang, $wgParser; - if( is_string( $query ) ) { + if ( is_string( $query ) ) { // this check is not yet in MW core (pending on review in 1.20). This can actually be a string $query = wfCgiToArray( $query ); } @@ -203,7 +203,7 @@ // NOTE: we can't just add 'uselang' in case it is different from the sites global language (e.g. 'en') // because a users language could still be different than that language. - if( array_key_exists( 'uselang', $query ) ) { // only add it if there is no uselang set to that link already! + if ( array_key_exists( 'uselang', $query ) ) { // only add it if there is no uselang set to that link already! // this will add the 'uselang' parameter to each link generated with Linker::link() $query[ 'uselang' ] = $wgLang->getCode(); } @@ -221,7 +221,7 @@ * @return bool true */ public static function onGetLocalUrlInternally( \Title $title, &$url ) { - global $wgLang; + global $wgLang, $wgLanguageCode; /* * We have to do this here as well, since content parsing could still come here instead of the onLinkBegin. @@ -230,9 +230,12 @@ self::causeCacheFragmentation(); // don't add uselang if there is a uselang set to that url already! - if( !preg_match( '/[&\?]uselang=/i', $url ) ) { - // this will add the 'uselang' parameter to each link returned by Title::getLocalURL() - $url = wfAppendQuery( $url, 'uselang=' . $wgLang->getCode() ); + if ( !preg_match( '/[&\?]uselang=/i', $url ) ) { + // nor if language code is the default + if ( $wgLang->getCode() !== $wgLanguageCode ) { + // this will add the 'uselang' parameter to each link returned by Title::getLocalURL() + $url = wfAppendQuery( $url, 'uselang=' . $wgLang->getCode() ); + } } return true; @@ -244,7 +247,7 @@ */ private static function causeCacheFragmentation() { global $wgParser; - if( $wgParser->getOptions() !== null ) { // if not parsing anything right now, this is set to null + if ( $wgParser->getOptions() !== null ) { // if not parsing anything right now, this is set to null /* This will trigger cache fragmentation. The parser options will set some flag internally for generating a language specific parser cache key. This is basically the same what the -- To view, visit https://gerrit.wikimedia.org/r/136624 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I6a9191ae67a6d7acacef5ce21358d797c72169ab Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/StickToThatLanguage Gerrit-Branch: master Gerrit-Owner: Microchip08 <doug...@chippy.ch> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits