From: Robert Stojnić Date: Sun, 8 Oct 2006 13:37:08 +0000 (+0000) Subject: Merged r16826-16858 of branches/SerbianVariants. X-Git-Tag: 1.31.0-rc.0~55587 X-Git-Url: http://git.cyclocoop.org/%28?a=commitdiff_plain;h=59c03118f8eee7d2c5d4039776fe94a006312675;p=lhc%2Fweb%2Fwiklou.git Merged r16826-16858 of branches/SerbianVariants. 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 --- diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 7233a24b76..49d02b2bc6 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -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; diff --git a/includes/SkinTemplate.php b/includes/SkinTemplate.php index 482680e632..ceacea0114 100644 --- a/includes/SkinTemplate.php +++ b/includes/SkinTemplate.php @@ -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 ++; } diff --git a/includes/Title.php b/includes/Title.php index 0e86063ee4..0e54e8cb8b 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -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 diff --git a/languages/LanguageConverter.php b/languages/LanguageConverter.php index a949ad4e0b..64206bb1a6 100644 --- a/languages/LanguageConverter.php +++ b/languages/LanguageConverter.php @@ -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 diff --git a/maintenance/generateSitemap.php b/maintenance/generateSitemap.php index a0b6979d0d..e55490a587 100644 --- a/maintenance/generateSitemap.php +++ b/maintenance/generateSitemap.php @@ -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() );