* (bug 6300) Bug fixes for sr: variants
authorNiklas Laxström <nikerabbit@users.mediawiki.org>
Fri, 16 Jun 2006 22:30:39 +0000 (22:30 +0000)
committerNiklas Laxström <nikerabbit@users.mediawiki.org>
Fri, 16 Jun 2006 22:30:39 +0000 (22:30 +0000)
* Patch from Robert Stojnic

RELEASE-NOTES
includes/Parser.php
languages/LanguageConverter.php
languages/LanguageSr.php

index 250e4d1..f896e0e 100644 (file)
@@ -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 ==
 
index 3ec1cd1..ada2708 100644 (file)
@@ -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
index e9ce1db..53cf67e 100644 (file)
@@ -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 )
index 9846064..fa2b95b 100644 (file)
@@ -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 {