Merge "Fix deprecated of ApiQuery::setGeneratorContinue"
[lhc/web/wiklou.git] / includes / parser / CoreParserFunctions.php
index 3425b6b..faff0e7 100644 (file)
@@ -242,7 +242,12 @@ class CoreParserFunctions {
        }
 
        static function canonicalurle( $parser, $s = '', $arg = null ) {
-               return self::urlFunction( 'escapeCanonicalURL', $s, $arg );
+               $temp = self::urlFunction( 'getCanonicalURL', $s, $arg );
+               if ( !is_string( $temp ) ) {
+                       return $temp;
+               } else {
+                       return htmlspecialchars( $temp );
+               }
        }
 
        static function urlFunction( $func, $s = '', $arg = null ) {
@@ -360,9 +365,15 @@ class CoreParserFunctions {
         * @param string $text Desired title text
         * @return string
         */
-       static function displaytitle( $parser, $text = '' ) {
+       static function displaytitle( $parser, $text = '', $uarg = '' ) {
                global $wgRestrictDisplayTitle;
 
+               static $magicWords = null;
+               if ( is_null( $magicWords ) ) {
+                       $magicWords = new MagicWordArray( array( 'displaytitle_noerror', 'displaytitle_noreplace' ) );
+               }
+               $arg = $magicWords->matchStartToEnd( $uarg );
+
                // parse a limited subset of wiki markup (just the single quote items)
                $text = $parser->doQuotes( $text );
 
@@ -373,7 +384,7 @@ class CoreParserFunctions {
                // list of disallowed tags for DISPLAYTITLE
                // these will be escaped even though they are allowed in normal wiki text
                $bad = array( 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'div', 'blockquote', 'ol', 'ul', 'li', 'hr',
-                       'table', 'tr', 'th', 'td', 'dl', 'dd', 'caption', 'p', 'ruby', 'rb', 'rt', 'rp', 'br' );
+                       'table', 'tr', 'th', 'td', 'dl', 'dd', 'caption', 'p', 'ruby', 'rb', 'rt', 'rtc', 'rp', 'br' );
 
                // disallow some styles that could be used to bypass $wgRestrictDisplayTitle
                if ( $wgRestrictDisplayTitle ) {
@@ -408,13 +419,25 @@ class CoreParserFunctions {
                ) );
                $title = Title::newFromText( Sanitizer::stripAllTags( $text ) );
 
-               if ( !$wgRestrictDisplayTitle ) {
-                       $parser->mOutput->setDisplayTitle( $text );
-               } elseif ( $title instanceof Title
+               if ( !$wgRestrictDisplayTitle ||
+                       ( $title instanceof Title
                        && !$title->hasFragment()
-                       && $title->equals( $parser->mTitle )
+                       && $title->equals( $parser->mTitle ) )
                ) {
-                       $parser->mOutput->setDisplayTitle( $text );
+                       $old = $parser->mOutput->getProperty( 'displaytitle' );
+                       if ( $old === false || $arg !== 'displaytitle_noreplace' ) {
+                               $parser->mOutput->setDisplayTitle( $text );
+                       }
+                       if ( $old !== false && $old !== $text && !$arg ) {
+                               $converter = $parser->getConverterLanguage()->getConverter();
+                               return '<span class="error">' .
+                                       wfMessage( 'duplicate-displaytitle',
+                                               // Message should be parsed, but these params should only be escaped.
+                                               $converter->markNoConversion( wfEscapeWikiText( $old ) ),
+                                               $converter->markNoConversion( wfEscapeWikiText( $text ) )
+                                       )->inContentLanguage()->text() .
+                                       '</span>';
+                       }
                }
 
                return '';