Merged r16826-16858 of branches/SerbianVariants.
authorRobert Stojnić <rainman@users.mediawiki.org>
Sun, 8 Oct 2006 13:37:08 +0000 (13:37 +0000)
committerRobert Stojnić <rainman@users.mediawiki.org>
Sun, 8 Oct 2006 13:37:08 +0000 (13:37 +0000)
Enabled aliased variants e.g. ?title=Article&variant=sr-ec => /sr-ec/Article
and added variants to google sitemap.
To enable aliases put: $wgVariantArticlePath = "$wgScriptPath/$2/$1";
to LocalSettings.php, and make aliases from /$variants/ to index.php

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

index 7233a24..49d02b2 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..ceacea0 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->getLocalVariantURL($code)
                                        );
                                $vcount ++;
                        }
index 0e86063..0e54e8c 100644 (file)
@@ -811,6 +811,35 @@ class Title {
                return $url;
        }
 
+       /**
+        * Get a real URL referring to this title in some of the variant
+        *
+        * @param string $variant variant name
+        * @return string the URL
+        * @access public
+        */
+       function getFullVariantURL( $variant = '' ) {
+               global $wgServer, $wgRequest;
+
+               $url=''; // this function should not be called for interwiki
+
+               if ( '' == $this->mInterwiki ) {
+                       $url = $this->getLocalVariantURL( $variant );
+
+                       if ($wgRequest->getVal('action') != 'render') {
+                               $url = $wgServer . $url;
+                       }
+               }
+
+               # Finally, add the fragment.
+               if ( '' != $this->mFragment ) {
+                       $url .= '#' . $this->mFragment;
+               }        
+
+               return $url;
+       }
+
+
        /**
         * Get a URL with no fragment or server name.  If this page is generated
         * with action=render, $wgServer is prepended.
@@ -867,6 +896,30 @@ class Title {
                return $url;
        }
 
+       /**
+        * Similar to getLocalURL, except it uses $wgVariantArticlePath
+        * and gets the URL with no fragment or server name, but in a 
+   * certain language variant (relevant only to languages with variants)
+        * @param string $variant caption of variant
+        * @return string the URL
+        * @access public
+        */
+       function getLocalVariantURL( $variant='' ) {
+               global $wgVariantArticlePath,$wgScript;
+               if($variant=='') return $this->getLocalURL();
+
+               if($wgVariantArticlePath==false)
+                       $wgVariantArticlePath = "$wgScript?title=$1&variant=$2";
+
+               $dbkey = wfUrlencode( $this->getPrefixedDBkey() );
+               $url = str_replace( '$1', $dbkey, $wgVariantArticlePath );
+               $code = urlencode( $variant );
+               $url = str_replace( '$2', $code, $url );
+
+               return $url;
+               
+       }
+
        /**
         * Get an HTML-escaped version of the URL form, suitable for
         * using in a link, without a server name or fragment
index a949ad4..64206bb 100644 (file)
@@ -96,6 +96,14 @@ class LanguageConverter {
                        return $req;
                }
 
+               // check the syntax /code/ArticleTitle
+               $script = $_SERVER['SCRIPT_NAME'];
+               $variants = implode('|',$this->mVariants);
+               if(preg_match("/($variants)$/",$script,$matches)){
+                       $this->mPreferredVariant = $matches[1];
+                       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..e55490a 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->getFullVariantURL($vCode), $date, $this->priority( $namespace ) );
+                                               $length += strlen( $entry );
+                                               $this->write( $this->file, $entry );
+                                       }
+                               }
                        }
                        if ( $this->file ) {
                                $this->write( $this->file, $this->closeFile() );