MaxSem has uploaded a new change for review.

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


Change subject: Extract variant-related code into a separate function
......................................................................

Extract variant-related code into a separate function

In addition to reducing a reeeeeally long function, this is needed for mobile
where we need to render these on a separate special page.

Change-Id: I3bbc00b29e4000939b40b231aed4c9e894b6f393
---
M includes/SkinTemplate.php
1 file changed, 40 insertions(+), 29 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/86/87486/1

diff --git a/includes/SkinTemplate.php b/includes/SkinTemplate.php
index ccfb3db..d2bc223 100644
--- a/includes/SkinTemplate.php
+++ b/includes/SkinTemplate.php
@@ -1039,35 +1039,7 @@
                        wfRunHooks( 'SkinTemplateNavigation', array( &$this, 
&$content_navigation ) );
 
                        if ( $userCanRead && !$wgDisableLangConversion ) {
-                               $pageLang = $title->getPageLanguage();
-                               // Gets list of language variants
-                               $variants = $pageLang->getVariants();
-                               // Checks that language conversion is enabled 
and variants exist
-                               // And if it is not in the special namespace
-                               if ( count( $variants ) > 1 ) {
-                                       // Gets preferred variant (note that 
user preference is
-                                       // only possible for wiki content 
language variant)
-                                       $preferred = 
$pageLang->getPreferredVariant();
-                                       if ( Action::getActionName( $this ) === 
'view' ) {
-                                               $params = 
$request->getQueryValues();
-                                               unset( $params['title'] );
-                                       } else {
-                                               $params = array();
-                                       }
-                                       // Loops over each variant
-                                       foreach ( $variants as $code ) {
-                                               // Gets variant name from 
language code
-                                               $varname = 
$pageLang->getVariantname( $code );
-                                               // Appends variant link
-                                               
$content_navigation['variants'][] = array(
-                                                       'class' => ( $code == 
$preferred ) ? 'selected' : false,
-                                                       'text' => $varname,
-                                                       'href' => 
$title->getLocalURL( array( 'variant' => $code ) + $params ),
-                                                       'lang' => wfBCP47( 
$code ),
-                                                       'hreflang' => wfBCP47( 
$code ),
-                                               );
-                                       }
-                               }
+                               $content_navigation['variants'] = 
$this->getVariantLinks();
                        }
                } else {
                        // If it's not content, it's got to be a special page
@@ -1296,6 +1268,45 @@
        function getNameSpaceKey() {
                return $this->getTitle()->getNamespaceKey();
        }
+
+       /**
+        * Returns array of links used for language variants
+        * @return array
+        */
+       public function getVariantLinks() {
+               $title = $this->getRelevantTitle();
+               $pageLang = $title->getPageLanguage();
+               // Gets list of language variants
+               $variants = $pageLang->getVariants();
+               // Checks that language conversion is enabled and variants exist
+               // And if it is not in the special namespace
+               $result = array();
+               if ( count( $variants ) > 1 ) {
+                       // Gets preferred variant (note that user preference is
+                       // only possible for wiki content language variant)
+                       $preferred = $pageLang->getPreferredVariant();
+                       if ( Action::getActionName( $this ) === 'view' ) {
+                               $params = $this->getRequest()->getQueryValues();
+                               unset( $params['title'] );
+                       } else {
+                               $params = array();
+                       }
+                       // Loops over each variant
+                       foreach ( $variants as $code ) {
+                               // Gets variant name from language code
+                               $varname = $pageLang->getVariantname( $code );
+                               // Appends variant link
+                               $result[] = array(
+                                       'class' => ( $code == $preferred ) ? 
'selected' : false,
+                                       'text' => $varname,
+                                       'href' => $title->getLocalURL( array( 
'variant' => $code ) + $params ),
+                                       'lang' => wfBCP47( $code ),
+                                       'hreflang' => wfBCP47( $code ),
+                               );
+                       }
+               }
+               return $result;
+       }
 }
 
 /**

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I3bbc00b29e4000939b40b231aed4c9e894b6f393
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: MaxSem <[email protected]>

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

Reply via email to