Localisation updates from http://translatewiki.net.
[lhc/web/wiklou.git] / languages / Language.php
index e648ee2..7475d2f 100644 (file)
@@ -54,6 +54,7 @@ class FakeConverter {
        function convert( $t ) { return $t; }
        function convertTo( $text, $variant ) { return $text; }
        function convertTitle( $t ) { return $t->getPrefixedText(); }
+       function convertNamespace( $ns ) { return $this->mLang->getFormattedNsText( $ns ); }
        function getVariants() { return array( $this->mLang->getCode() ); }
        function getPreferredVariant() { return $this->mLang->getCode(); }
        function getDefaultVariant() { return $this->mLang->getCode(); }
@@ -419,6 +420,16 @@ class Language {
         */
        public function setNamespaces( array $namespaces ) {
                $this->namespaceNames = $namespaces;
+               $this->mNamespaceIds = null;
+       }
+
+       /**
+        * Resets all of the namespace caches. Mainly used for testing
+        */
+       public function resetNamespaces( ) {
+               $this->namespaceNames = null;
+               $this->mNamespaceIds = null;
+               $this->namespaceAliases = null;
        }
 
        /**
@@ -3471,8 +3482,22 @@ class Language {
                                }
                        }
                }
-               // If all else fails, return the original string.
-               return $str;
+
+               // If all else fails, return a standard duration or timestamp description.
+               $time = strtotime( $str, 0 );
+               if ( $time === false ) { // Unknown format. Return it as-is in case.
+                       return $str;
+               } elseif ( $time !== strtotime( $str, 1 ) ) { // It's a relative timestamp.
+                       // $time is relative to 0 so it's a duration length.
+                       return $this->formatDuration( $time );
+               } else { // It's an absolute timestamp.
+                       if ( $time === 0 ) {
+                               // wfTimestamp() handles 0 as current time instead of epoch.
+                               return $this->timeanddate( '19700101000000' );
+                       } else {
+                               return $this->timeanddate( $time );
+                       }
+               }
        }
 
        /**
@@ -3536,6 +3561,16 @@ class Language {
                return $this->mConverter->convertTitle( $title );
        }
 
+       /**
+        * Convert a namespace index to a string in the preferred variant
+        *
+        * @param $ns int
+        * @return string
+        */
+       public function convertNamespace( $ns ) {
+               return $this->mConverter->convertNamespace( $ns );
+       }
+
        /**
         * Check if this is a language with variants
         *
@@ -3669,15 +3704,24 @@ class Language {
        }
 
        /**
-        * Enclose a string with the "no conversion" tag. This is used by
-        * various functions in the Parser
+        * Prepare external link text for conversion. When the text is
+        * a URL, it shouldn't be converted, and it'll be wrapped in
+        * the "raw" tag (-{R| }-) to prevent conversion.
+        *
+        * This function is called "markNoConversion" for historical
+        * reasons.
         *
-        * @param $text String: text to be tagged for no conversion
-        * @param $noParse bool
+        * @param $text String: text to be used for external link
+        * @param $noParse bool: wrap it without confirming it's a real URL first
         * @return string the tagged text
         */
        public function markNoConversion( $text, $noParse = false ) {
-               return $this->mConverter->markNoConversion( $text, $noParse );
+               // Excluding protocal-relative URLs may avoid many false positives.
+               if ( $noParse || preg_match( '/^(?:' . wfUrlProtocolsWithoutProtRel() . ')/', $text ) ) {
+                       return $this->mConverter->markNoConversion( $text );
+               } else {
+                       return $text;
+               }
        }
 
        /**