Commiting diff -r 16826:16966 of serbianvariants.
authorRobert Stojnić <rainman@users.mediawiki.org>
Thu, 12 Oct 2006 10:34:49 +0000 (10:34 +0000)
committerRobert Stojnić <rainman@users.mediawiki.org>
Thu, 12 Oct 2006 10:34:49 +0000 (10:34 +0000)
Enable engine for aliases like /sr-ec/Article_title
Put variants into google sitemap.

includes/DefaultSettings.php
includes/SkinTemplate.php
includes/Title.php
languages/LanguageConverter.php
maintenance/generateSitemap.php

index fcc1dc1..6e35b71 100644 (file)
@@ -124,6 +124,7 @@ $wgStylePath   = "{$wgScriptPath}/skins";
 $wgStyleDirectory = "{$IP}/skins";
 $wgStyleSheetPath = &$wgStylePath;
 $wgArticlePath      = "{$wgScript}?title=$1";
+$wgVariantArticlePath = false;
 $wgUploadPath       = "{$wgScriptPath}/images";
 $wgUploadDirectory     = "{$IP}/images";
 $wgHashedUploadDirectory       = true;
index 482680e..0aec865 100644 (file)
@@ -765,7 +765,7 @@ class SkinTemplate extends Skin {
                                $content_actions['varlang-' . $vcount] = array(
                                                'class' => $selected,
                                                'text' => $varname,
-                                               'href' => $this->mTitle->getLocalUrl( $actstr . 'variant=' . urlencode( $code ) )
+                                               'href' => $this->mTitle->getLocalURL('',$code)
                                        );
                                $vcount ++;
                        }
index e8ce669..6d06e37 100644 (file)
@@ -769,14 +769,15 @@ class Title {
         *
         * @param string $query an optional query string, not used
         *      for interwiki links
+        * @param string $variant language variant of url (for sr, zh..)
         * @return string the URL
         * @access public
         */
-       function getFullURL( $query = '' ) {
+       function getFullURL( $query = '', $variant = false ) {
                global $wgContLang, $wgServer, $wgRequest;
 
                if ( '' == $this->mInterwiki ) {
-                       $url = $this->getLocalUrl( $query );
+                       $url = $this->getLocalUrl( $query, $variant );
 
                        // Ugly quick hack to avoid duplicate prefixes (bug 4571 etc)
                        // Correct fix would be to move the prepending elsewhere.
@@ -816,11 +817,20 @@ class Title {
         * with action=render, $wgServer is prepended.
         * @param string $query an optional query string; if not specified,
         *      $wgArticlePath will be used.
+        * @param string $variant language variant of url (for sr, zh..)
         * @return string the URL
         * @access public
         */
-       function getLocalURL( $query = '' ) {
+       function getLocalURL( $query = '', $variant = false ) {
                global $wgArticlePath, $wgScript, $wgServer, $wgRequest;
+               global $wgVariantArticlePath, $wgContLang, $wgUser;
+
+               // internal links should point to same variant as current page (only anonymous users)
+               if($variant == false && $wgContLang->hasVariants() && !$wgUser->isLoggedIn()){
+                       $pref = $wgContLang->getPreferredVariant(false);
+                       if($pref != $wgContLang->getCode())
+                               $variant = $pref;
+               }
 
                if ( $this->isExternal() ) {
                        $url = $this->getFullURL();
@@ -834,7 +844,17 @@ class Title {
                } else {
                        $dbkey = wfUrlencode( $this->getPrefixedDBkey() );
                        if ( $query == '' ) {
-                               $url = str_replace( '$1', $dbkey, $wgArticlePath );
+                               if($variant!=false && $wgContLang->hasVariants()){
+                                       if($wgVariantArticlePath==false)
+                                               $variantArticlePath =  "$wgScript?title=$1&variant=$2"; // default
+                                       else 
+                                               $variantArticlePath = $wgVariantArticlePath;
+                                       
+                                       $url = str_replace( '$1', $dbkey, $variantArticlePath );
+                                       $url = str_replace( '$2', urlencode( $variant ), $url );                                        
+                               }
+                               else 
+                                       $url = str_replace( '$1', $dbkey, $wgArticlePath );
                        } else {
                                global $wgActionPaths;
                                $url = false;
@@ -896,12 +916,13 @@ class Title {
         * internal hostname for the server from the exposed one.
         *
         * @param string $query an optional query string
+        * @param string $variant language variant of url (for sr, zh..)
         * @return string the URL
         * @access public
         */
-       function getInternalURL( $query = '' ) {
+       function getInternalURL( $query = '', $variant = false ) {
                global $wgInternalServer;
-               $url = $wgInternalServer . $this->getLocalURL( $query );
+               $url = $wgInternalServer . $this->getLocalURL( $query, $variant );
                wfRunHooks( 'GetInternalURL', array( &$this, &$url, $query ) );
                return $url;
        }
@@ -1698,10 +1719,23 @@ class Title {
         * @access public
         */
        function getSquidURLs() {
-               return array(
+               global $wgContLang;
+
+               $urls = array(
                        $this->getInternalURL(),
                        $this->getInternalURL( 'action=history' )
                );
+
+               // purge variant urls as well
+               if($wgContLang->hasVariants()){
+                       $variants = $wgContLang->getVariants();
+                       foreach($variants as $vCode){
+                               if($vCode==$wgContLang->getCode()) continue; // we don't want default variant
+                               $urls[] = $this->getInternalURL('',$vCode);
+                       }
+               }
+
+               return $urls;
        }
 
        function purgeSquid() {
index a949ad4..a39f9ca 100644 (file)
@@ -96,6 +96,13 @@ class LanguageConverter {
                        return $req;
                }
 
+               // check the syntax /code/ArticleTitle
+               $scriptBase = basename( $_SERVER['SCRIPT_NAME'] );
+               if(in_array($scriptBase,$this->mVariants)){
+                       $this->mPreferredVariant = $scriptBase;
+                       return $this->mPreferredVariant;
+               }
+
                // get language variant preference from logged in users
                // Don't call this on stub objects because that causes infinite 
                // recursion during initialisation
index a0b6979..b8d6a5d 100644 (file)
@@ -264,6 +264,16 @@ class GenerateSitemap {
                                $entry = $this->fileEntry( $title->getFullURL(), $date, $this->priority( $namespace ) );
                                $length += strlen( $entry );
                                $this->write( $this->file, $entry );
+                               // generate pages for language variants
+                               if($wgContLang->hasVariants()){
+                                       $variants = $wgContLang->getVariants();
+                                       foreach($variants as $vCode){
+                                               if($vCode==$wgContLang->getCode()) continue; // we don't want default variant
+                                               $entry = $this->fileEntry( $title->getFullURL('',$vCode), $date, $this->priority( $namespace ) );
+                                               $length += strlen( $entry );
+                                               $this->write( $this->file, $entry );
+                                       }
+                               }
                        }
                        if ( $this->file ) {
                                $this->write( $this->file, $this->closeFile() );