From: Legoktm Date: Fri, 23 Sep 2016 00:29:21 +0000 (+0000) Subject: Revert "Move wfEscapeWikiText() to Parser::escapeWikitext()" X-Git-Tag: 1.31.0-rc.0~5371^2 X-Git-Url: https://git.cyclocoop.org/%27.WWW_URL.%27admin/?a=commitdiff_plain;h=3172dfe21eb84e113fe356b3494c33585168bf4b;p=lhc%2Fweb%2Fwiklou.git Revert "Move wfEscapeWikiText() to Parser::escapeWikitext()" Apparently it is possible for Parser::mParserOptions to not be set in some cases. I'll try again later. This reverts commit bda74bff6e180b5a6bb2cc68e12ae391d53789a3. Bug: T146433 Change-Id: Idb6d1b20995d5f86b712abb386ab987356c4f560 --- diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index ee5ebd0bcd..0e596530c3 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -1656,8 +1656,6 @@ function wfClientAcceptsGzip( $force = false ) { } /** - * @deprecated since 1.28, use Parser::escapeWikitext() directly - * * Escapes the given text so that it may be output using addWikiText() * without any linking, formatting, etc. making its way through. This * is achieved by substituting certain characters with HTML entities. @@ -1667,8 +1665,47 @@ function wfClientAcceptsGzip( $force = false ) { * @return string */ function wfEscapeWikiText( $text ) { - global $wgParser; - return $wgParser->escapeWikitext( $text ); + global $wgEnableMagicLinks; + static $repl = null, $repl2 = null; + if ( $repl === null ) { + $repl = [ + '"' => '"', '&' => '&', "'" => ''', '<' => '<', + '=' => '=', '>' => '>', '[' => '[', ']' => ']', + '{' => '{', '|' => '|', '}' => '}', ';' => ';', + "\n#" => "\n#", "\r#" => "\r#", + "\n*" => "\n*", "\r*" => "\r*", + "\n:" => "\n:", "\r:" => "\r:", + "\n " => "\n ", "\r " => "\r ", + "\n\n" => "\n ", "\r\n" => " \n", + "\n\r" => "\n ", "\r\r" => "\r ", + "\n\t" => "\n ", "\r\t" => "\r ", // "\n\t\n" is treated like "\n\n" + "\n----" => "\n----", "\r----" => "\r----", + '__' => '__', '://' => '://', + ]; + + $magicLinks = array_keys( array_filter( $wgEnableMagicLinks ) ); + // We have to catch everything "\s" matches in PCRE + foreach ( $magicLinks as $magic ) { + $repl["$magic "] = "$magic "; + $repl["$magic\t"] = "$magic "; + $repl["$magic\r"] = "$magic "; + $repl["$magic\n"] = "$magic "; + $repl["$magic\f"] = "$magic "; + } + + // And handle protocols that don't use "://" + global $wgUrlProtocols; + $repl2 = []; + foreach ( $wgUrlProtocols as $prot ) { + if ( substr( $prot, -1 ) === ':' ) { + $repl2[] = preg_quote( substr( $prot, 0, -1 ), '/' ); + } + } + $repl2 = $repl2 ? '/\b(' . implode( '|', $repl2 ) . '):/i' : '/^(?!)/'; + } + $text = substr( strtr( "\n$text", $repl ), 1 ); + $text = preg_replace( $repl2, '$1:', $text ); + return $text; } /** diff --git a/includes/parser/CoreParserFunctions.php b/includes/parser/CoreParserFunctions.php index b3dc17c215..01cce028a2 100644 --- a/includes/parser/CoreParserFunctions.php +++ b/includes/parser/CoreParserFunctions.php @@ -594,98 +594,98 @@ class CoreParserFunctions { if ( is_null( $t ) ) { return ''; } - return $parser->escapeWikitext( $t->getText() ); + return wfEscapeWikiText( $t->getText() ); } - public static function pagenamee( Parser $parser, $title = null ) { + public static function pagenamee( $parser, $title = null ) { $t = Title::newFromText( $title ); if ( is_null( $t ) ) { return ''; } - return $parser->escapeWikitext( $t->getPartialURL() ); + return wfEscapeWikiText( $t->getPartialURL() ); } - public static function fullpagename( Parser $parser, $title = null ) { + public static function fullpagename( $parser, $title = null ) { $t = Title::newFromText( $title ); if ( is_null( $t ) || !$t->canTalk() ) { return ''; } - return $parser->escapeWikitext( $t->getPrefixedText() ); + return wfEscapeWikiText( $t->getPrefixedText() ); } - public static function fullpagenamee( Parser $parser, $title = null ) { + public static function fullpagenamee( $parser, $title = null ) { $t = Title::newFromText( $title ); if ( is_null( $t ) || !$t->canTalk() ) { return ''; } - return $parser->escapeWikitext( $t->getPrefixedURL() ); + return wfEscapeWikiText( $t->getPrefixedURL() ); } - public static function subpagename( Parser $parser, $title = null ) { + public static function subpagename( $parser, $title = null ) { $t = Title::newFromText( $title ); if ( is_null( $t ) ) { return ''; } - return $parser->escapeWikitext( $t->getSubpageText() ); + return wfEscapeWikiText( $t->getSubpageText() ); } - public static function subpagenamee( Parser $parser, $title = null ) { + public static function subpagenamee( $parser, $title = null ) { $t = Title::newFromText( $title ); if ( is_null( $t ) ) { return ''; } - return $parser->escapeWikitext( $t->getSubpageUrlForm() ); + return wfEscapeWikiText( $t->getSubpageUrlForm() ); } - public static function rootpagename( Parser $parser, $title = null ) { + public static function rootpagename( $parser, $title = null ) { $t = Title::newFromText( $title ); if ( is_null( $t ) ) { return ''; } - return $parser->escapeWikitext( $t->getRootText() ); + return wfEscapeWikiText( $t->getRootText() ); } - public static function rootpagenamee( Parser $parser, $title = null ) { + public static function rootpagenamee( $parser, $title = null ) { $t = Title::newFromText( $title ); if ( is_null( $t ) ) { return ''; } - return $parser->escapeWikitext( wfUrlencode( str_replace( ' ', '_', $t->getRootText() ) ) ); + return wfEscapeWikiText( wfUrlencode( str_replace( ' ', '_', $t->getRootText() ) ) ); } - public static function basepagename( Parser $parser, $title = null ) { + public static function basepagename( $parser, $title = null ) { $t = Title::newFromText( $title ); if ( is_null( $t ) ) { return ''; } - return $parser->escapeWikitext( $t->getBaseText() ); + return wfEscapeWikiText( $t->getBaseText() ); } - public static function basepagenamee( Parser $parser, $title = null ) { + public static function basepagenamee( $parser, $title = null ) { $t = Title::newFromText( $title ); if ( is_null( $t ) ) { return ''; } - return $parser->escapeWikitext( wfUrlencode( str_replace( ' ', '_', $t->getBaseText() ) ) ); + return wfEscapeWikiText( wfUrlencode( str_replace( ' ', '_', $t->getBaseText() ) ) ); } - public static function talkpagename( Parser $parser, $title = null ) { + public static function talkpagename( $parser, $title = null ) { $t = Title::newFromText( $title ); if ( is_null( $t ) || !$t->canTalk() ) { return ''; } - return $parser->escapeWikitext( $t->getTalkPage()->getPrefixedText() ); + return wfEscapeWikiText( $t->getTalkPage()->getPrefixedText() ); } - public static function talkpagenamee( Parser $parser, $title = null ) { + public static function talkpagenamee( $parser, $title = null ) { $t = Title::newFromText( $title ); if ( is_null( $t ) || !$t->canTalk() ) { return ''; } - return $parser->escapeWikitext( $t->getTalkPage()->getPrefixedURL() ); + return wfEscapeWikiText( $t->getTalkPage()->getPrefixedURL() ); } - public static function subjectpagename( Parser $parser, $title = null ) { + public static function subjectpagename( $parser, $title = null ) { $t = Title::newFromText( $title ); if ( is_null( $t ) ) { return ''; } - return $parser->escapeWikitext( $t->getSubjectPage()->getPrefixedText() ); + return wfEscapeWikiText( $t->getSubjectPage()->getPrefixedText() ); } - public static function subjectpagenamee( Parser $parser, $title = null ) { + public static function subjectpagenamee( $parser, $title = null ) { $t = Title::newFromText( $title ); if ( is_null( $t ) ) { return ''; } - return $parser->escapeWikitext( $t->getSubjectPage()->getPrefixedURL() ); + return wfEscapeWikiText( $t->getSubjectPage()->getPrefixedURL() ); } /** diff --git a/includes/parser/Parser.php b/includes/parser/Parser.php index 0fb021cc03..7c18798f2e 100644 --- a/includes/parser/Parser.php +++ b/includes/parser/Parser.php @@ -6028,62 +6028,4 @@ class Parser { OutputPage::setupOOUI(); $this->mOutput->setEnableOOUI( true ); } - - /** - * Escapes the given text so that it may be output using addWikiText() - * without any linking, formatting, etc. making its way through. This - * is achieved by substituting certain characters with HTML entities. - * As required by the callers, "" is not used. - * - * @since 1.28 - * - * @param string $text Text to be escaped - * @return string - */ - public function escapeWikitext( $text ) { - static $repl = null, $repl2 = null; - if ( $repl === null ) { - $repl = [ - '"' => '"', '&' => '&', "'" => ''', '<' => '<', - '=' => '=', '>' => '>', '[' => '[', ']' => ']', - '{' => '{', '|' => '|', '}' => '}', ';' => ';', - "\n#" => "\n#", "\r#" => "\r#", - "\n*" => "\n*", "\r*" => "\r*", - "\n:" => "\n:", "\r:" => "\r:", - "\n " => "\n ", "\r " => "\r ", - "\n\n" => "\n ", "\r\n" => " \n", - "\n\r" => "\n ", "\r\r" => "\r ", - "\n\t" => "\n ", "\r\t" => "\r ", // "\n\t\n" is treated like "\n\n" - "\n----" => "\n----", "\r----" => "\r----", - '__' => '__', '://' => '://', - ]; - - $magicLinks = array_keys( array_filter( [ - 'ISBN' => $this->mOptions->getMagicISBNLinks(), - 'PMID' => $this->mOptions->getMagicPMIDLinks(), - 'RFC' => $this->mOptions->getMagicRFCLinks(), - ] ) ); - // We have to catch everything "\s" matches in PCRE - foreach ( $magicLinks as $magic ) { - $repl["$magic "] = "$magic "; - $repl["$magic\t"] = "$magic "; - $repl["$magic\r"] = "$magic "; - $repl["$magic\n"] = "$magic "; - $repl["$magic\f"] = "$magic "; - } - - // And handle protocols that don't use "://" - global $wgUrlProtocols; - $repl2 = []; - foreach ( $wgUrlProtocols as $prot ) { - if ( substr( $prot, -1 ) === ':' ) { - $repl2[] = preg_quote( substr( $prot, 0, -1 ), '/' ); - } - } - $repl2 = $repl2 ? '/\b(' . implode( '|', $repl2 ) . '):/i' : '/^(?!)/'; - } - $text = substr( strtr( "\n$text", $repl ), 1 ); - $text = preg_replace( $repl2, '$1:', $text ); - return $text; - } }