From: Niklas Laxström Date: Fri, 16 Jun 2006 22:30:39 +0000 (+0000) Subject: * (bug 6300) Bug fixes for sr: variants X-Git-Tag: 1.31.0-rc.0~56761 X-Git-Url: http://git.cyclocoop.org/%24action?a=commitdiff_plain;h=7818d542f05405d95b31ff7cbafdc08024f62704;p=lhc%2Fweb%2Fwiklou.git * (bug 6300) Bug fixes for sr: variants * Patch from Robert Stojnic --- diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 250e4d1052..f896e0ec79 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -514,6 +514,7 @@ Some default configuration options have changed: * Introduce {{NUMBEROFADMINS}} magic word * Update to Slovak translation (sk) * Update to Alemannic localization (gsw) +* (bug 6300) Bug fixes for sr: variants == Compatibility == diff --git a/includes/Parser.php b/includes/Parser.php index 3ec1cd1bc2..ada2708e26 100644 --- a/includes/Parser.php +++ b/includes/Parser.php @@ -2898,6 +2898,12 @@ class Parser } $title = Title::newFromText( $part1, $ns ); + $checkVariantLink = sizeof($wgContLang->getVariants())>1; + # Check for language variants if the template is not found + if($checkVariantLink && $title->getArticleID() == 0){ + $wgContLang->findVariantLink($part1, $title); + } + if ( !is_null( $title ) ) { if ( !$title->isExternal() ) { # Check for excessive inclusion diff --git a/languages/LanguageConverter.php b/languages/LanguageConverter.php index e9ce1db838..53cf67e932 100644 --- a/languages/LanguageConverter.php +++ b/languages/LanguageConverter.php @@ -145,7 +145,12 @@ class LanguageConverter { $marker = '|' . $wgParser->UniqPrefix() . '[\-a-zA-Z0-9]+'; else $marker = ""; - $reg = '/<[^>]+>|&[a-z#][a-z0-9]+;' . $marker . '/'; + + // this one is needed when the text is inside an html markup + $htmlfix = '|<[^>]+=\"[^(>=)]*$|^[^(<>=\")]*\"[^>]*>'; + + $reg = '/<[^>]+>|&[a-z#][a-z0-9]+;' . $marker . $htmlfix . '/'; + $matches = preg_split($reg, $text, -1, PREG_SPLIT_OFFSET_CAPTURE); @@ -393,7 +398,7 @@ class LanguageConverter { if(isset($cache[$v])) continue; $cache[$v] = 1; - $varnt = Title::newFromText( $v ); + $varnt = Title::newFromText( $v, $ns ); if( $varnt && $varnt->getArticleID() > 0 ) { $nt = $varnt; if( !$wgDisableLangConversion ) diff --git a/languages/LanguageSr.php b/languages/LanguageSr.php index 9846064f42..fa2b95b688 100644 --- a/languages/LanguageSr.php +++ b/languages/LanguageSr.php @@ -68,7 +68,30 @@ class SrConverter extends LanguageConverter { */ function parseManualRule($rule, $flags) { - $choices = explode($this->mMarkup['varsep'], $rule); + $echoices = preg_split("/(<[^>]+>)/",$rule,-1,PREG_SPLIT_DELIM_CAPTURE); + $choices = array(); + + // check if we did a split across an HTML tag + // if so, glue them back together + + $ctold = ''; + foreach($echoices as $ct){ + if($ct==''); + else if(preg_match('/<[^>]+>/',$ct)){ + $ctold.=$ct; + } + else{ + $c = explode($this->mMarkup['varsep'],$ct); + if(count($c)>1){ + $choices[]=$ctold.array_shift($c); + $ctold=array_pop($c); + $choices=array_merge($choices,$c); + } + else $ctold.=array_pop($c); + } + } + if($ctold!='') $choices[]=$ctold; + $carray = array(); if(sizeof($choices) == 1) { if(in_array('W', $flags)) { @@ -118,6 +141,56 @@ class SrConverter extends LanguageConverter { return $carray; } + /* + * Override function from LanguageConvertor + * Additional checks: + * - There should be no conversion for Talk pages + */ + function getPreferredVariant(){ + global $wgTitle; + if($wgTitle!=NULL && $wgTitle->isTalkPage()){ + return $this->mMainLanguageCode; + } + return parent::getPreferredVariant(); + } + + + /* + * A function wrapper, if there is no selected variant, + * leave the link names as they were + */ + function findVariantLink( &$link, &$nt ) { + $oldlink=$link; + parent::findVariantLink($link,$nt); + if($this->getPreferredVariant()==$this->mMainLanguageCode) + $link=$oldlink; + } + + + /* + * We want our external link captions to be converted in variants, + * so we return the original text instead -{$text}-, except for URLs + */ + function markNoConversion($text) { + if(preg_match("/^https?:\/\/|ftp:\/\/|irc:\/\//",$text)) + return parent::markNoConversion($text); + return $text; + } + + /* + * An ugly function wrapper for parsing Image titles + * (to prevent image name conversion) + */ + function autoConvert($text, $toVariant=false) { + global $wgTitle; + if($wgTitle->getNameSpace()==NS_IMAGE){ + $imagename = $wgTitle->getNsText(); + if(preg_match("/^$imagename:/",$text)) return $text; + } + return parent::autoConvert($text,$toVariant); + } + + } class LanguageSr extends LanguageSr_ec {