Followup r102785: fix typo in index name. Thanks to Platonides and his special page...
[lhc/web/wiklou.git] / includes / parser / CoreParserFunctions.php
index 3f95dd3..cd5e0a5 100644 (file)
@@ -35,6 +35,8 @@ class CoreParserFunctions {
                $parser->setFunctionHook( 'localurle',        array( __CLASS__, 'localurle'        ), SFH_NO_HASH );
                $parser->setFunctionHook( 'fullurl',          array( __CLASS__, 'fullurl'          ), SFH_NO_HASH );
                $parser->setFunctionHook( 'fullurle',         array( __CLASS__, 'fullurle'         ), SFH_NO_HASH );
+               $parser->setFunctionHook( 'canonicalurl',     array( __CLASS__, 'canonicalurl'     ), SFH_NO_HASH );
+               $parser->setFunctionHook( 'canonicalurle',    array( __CLASS__, 'canonicalurle'    ), SFH_NO_HASH );
                $parser->setFunctionHook( 'formatnum',        array( __CLASS__, 'formatnum'        ), SFH_NO_HASH );
                $parser->setFunctionHook( 'grammar',          array( __CLASS__, 'grammar'          ), SFH_NO_HASH );
                $parser->setFunctionHook( 'gender',           array( __CLASS__, 'gender'           ), SFH_NO_HASH );
@@ -95,9 +97,8 @@ class CoreParserFunctions {
        static function intFunction( $parser, $part1 = '' /*, ... */ ) {
                if ( strval( $part1 ) !== '' ) {
                        $args = array_slice( func_get_args(), 2 );
-                       $message = wfMessage( $part1, $args )->inLanguage( $parser->getOptions()->getUserLang() )->plain();
-                       $message = $parser->replaceVariables( $message ); // like MessageCache::transform()
-                       return $message;
+                       $message = wfMessage( $part1, $args )->inLanguage( $parser->getOptions()->getUserLangObj() )->plain();
+                       return array( $message, 'noparse' => false );
                } else {
                        return array( 'found' => false );
                }
@@ -218,6 +219,8 @@ class CoreParserFunctions {
        static function localurle( $parser, $s = '', $arg = null ) { return self::urlFunction( 'escapeLocalURL', $s, $arg ); }
        static function fullurl( $parser, $s = '', $arg = null ) { return self::urlFunction( 'getFullURL', $s, $arg ); }
        static function fullurle( $parser, $s = '', $arg = null ) { return self::urlFunction( 'escapeFullURL', $s, $arg ); }
+       static function canonicalurl( $parser, $s = '', $arg = null ) { return self::urlFunction( 'getCanonicalURL', $s, $arg ); }
+       static function canonicalurle( $parser, $s = '', $arg = null ) { return self::urlFunction( 'escapeCanonicalURL', $s, $arg ); }
 
        static function urlFunction( $func, $s = '', $arg = null ) {
                $title = Title::newFromText( $s );
@@ -620,7 +623,7 @@ class CoreParserFunctions {
 
        /**
         * Unicode-safe str_pad with the restriction that $length is forced to be <= 500
-        */
+        */
        static function pad( $string, $length, $padding = '0', $direction = STR_PAD_RIGHT ) {
                $lengthOfPadding = mb_strlen( $padding );
                if ( $lengthOfPadding == 0 ) return $string;
@@ -673,23 +676,36 @@ class CoreParserFunctions {
 
        /**
         * @param $parser Parser
-        * @param  $text
+        * @param $text String The sortkey to use
+        * @param $uarg String Either "noreplace" or "noerror" (in en)
+        *   both suppress errors, and noreplace does nothing if
+        *   a default sortkey already exists.
         * @return string
         */
-       public static function defaultsort( $parser, $text ) {
+       public static function defaultsort( $parser, $text, $uarg = '' ) {
+               static $magicWords = null;
+               if ( is_null( $magicWords ) ) {
+                       $magicWords = new MagicWordArray( array( 'defaultsort_noerror', 'defaultsort_noreplace' ) );
+               }
+               $arg = $magicWords->matchStartToEnd( $uarg );
+
                $text = trim( $text );
                if( strlen( $text ) == 0 )
                        return '';
                $old = $parser->getCustomDefaultSort();
-               $parser->setDefaultSort( $text );
-               if( $old === false || $old == $text )
+               if ( $old === false || $arg !== 'defaultsort_noreplace' ) {
+                       $parser->setDefaultSort( $text );
+               }
+
+               if( $old === false || $old == $text || $arg ) {
                        return '';
-               else
+               } else {
                        return( '<span class="error">' .
                                wfMsgForContent( 'duplicate-defaultsort',
                                                 htmlspecialchars( $old ),
                                                 htmlspecialchars( $text ) ) .
                                '</span>' );
+               }
        }
 
        // Usage {{filepath|300}}, {{filepath|nowiki}}, {{filepath|nowiki|300}} or {{filepath|300|nowiki}}
@@ -717,13 +733,13 @@ class CoreParserFunctions {
                if ( $file ) {
                        $url = $file->getFullUrl();
 
-                       // If a size is requested...                    
+                       // If a size is requested...
                        if ( is_integer( $size ) ) {
                                $mto = $file->transform( array( 'width' => $size ) );
                                // ... and we can
                                if ( $mto && !$mto->isError() ) {
                                        // ... change the URL to point to a thumbnail.
-                                       $url = wfExpandUrl( $mto->getUrl() );
+                                       $url = wfExpandUrl( $mto->getUrl(), PROTO_RELATIVE );
                                }
                        }
                        if ( $option == 'nowiki' ) {