X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FOutputPage.php;h=2423315cb9e0bdc61493c8dcaa588b14e49ea5aa;hb=5466734477584e877187613fa0568dad17ed9c9f;hp=a5f5fab08ac8e3b06fea742c823967582339ea56;hpb=82cc194a7d39f69c054be7c6008a9e435fd3b988;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/OutputPage.php b/includes/OutputPage.php index a5f5fab08a..2423315cb9 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -1758,6 +1758,7 @@ class OutputPage extends ContextSource { * or else addWikiTextAsContent() if $interface is false. */ public function addWikiText( $text, $linestart = true, $interface = true ) { + wfDeprecated( __METHOD__, '1.32' ); $title = $this->getTitle(); if ( !$title ) { throw new MWException( 'Title is null' ); @@ -1934,19 +1935,14 @@ class OutputPage extends ContextSource { private function addWikiTextTitleInternal( $text, Title $title, $linestart, $tidy, $interface, $wrapperClass = null ) { - global $wgParser; - - $popts = $this->parserOptions(); - $oldTidy = $popts->setTidy( $tidy ); - $popts->setInterfaceMessage( (bool)$interface ); + if ( !$tidy ) { + wfDeprecated( 'disabling tidy', '1.32' ); + } - $parserOutput = $wgParser->getFreshParser()->parse( - $text, $title, $popts, - $linestart, true, $this->mRevisionId + $parserOutput = $this->parseInternal( + $text, $title, $linestart, $tidy, $interface, /*language*/null ); - $popts->setTidy( $oldTidy ); - $this->addParserOutput( $parserOutput, [ 'enableSectionEditLinks' => false, 'wrapperDivClass' => $wrapperClass ?? '', @@ -2086,6 +2082,9 @@ class OutputPage extends ContextSource { /** * Parse wikitext and return the HTML. * + * @todo The output is wrapped in a
iff $interface is false; it's + * probably best to always strip the wrapper. + * * @param string $text * @param bool $linestart Is this the start of a line? * @param bool $interface Use interface language (instead of content language) while parsing @@ -2094,54 +2093,146 @@ class OutputPage extends ContextSource { * @param Language|null $language Target language object, will override $interface * @throws MWException * @return string HTML + * @deprecated since 1.32, due to untidy output and inconsistent wrapper; + * use parseAsContent() if $interface is default value or false, or else + * parseAsInterface() if $interface is true. */ public function parse( $text, $linestart = true, $interface = false, $language = null ) { + wfDeprecated( __METHOD__, '1.33' ); + return $this->parseInternal( + $text, $this->getTitle(), $linestart, /*tidy*/false, $interface, $language + )->getText( [ + 'enableSectionEditLinks' => false, + ] ); + } + + /** + * Parse wikitext *in the page content language* and return the HTML. + * The result will be language-converted to the user's preferred variant. + * Output will be tidy. + * + * @param string $text Wikitext in the page content language + * @param bool $linestart Is this the start of a line? (Defaults to true) + * @throws MWException + * @return string HTML + * @since 1.32 + */ + public function parseAsContent( $text, $linestart = true ) { + return $this->parseInternal( + $text, $this->getTitle(), $linestart, /*tidy*/true, /*interface*/false, /*language*/null + )->getText( [ + 'enableSectionEditLinks' => false, + 'wrapperDivClass' => '' + ] ); + } + + /** + * Parse wikitext *in the user interface language* and return the HTML. + * The result will not be language-converted, as user interface messages + * are already localized into a specific variant. + * Output will be tidy. + * + * @param string $text Wikitext in the user interface language + * @param bool $linestart Is this the start of a line? (Defaults to true) + * @throws MWException + * @return string HTML + * @since 1.32 + */ + public function parseAsInterface( $text, $linestart = true ) { + return $this->parseInternal( + $text, $this->getTitle(), $linestart, /*tidy*/true, /*interface*/true, /*language*/null + )->getText( [ + 'enableSectionEditLinks' => false, + 'wrapperDivClass' => '' + ] ); + } + + /** + * Parse wikitext *in the user interface language*, strip + * paragraph wrapper, and return the HTML. + * The result will not be language-converted, as user interface messages + * are already localized into a specific variant. + * Output will be tidy. Outer paragraph wrapper will only be stripped + * if the result is a single paragraph. + * + * @param string $text Wikitext in the user interface language + * @param bool $linestart Is this the start of a line? (Defaults to true) + * @throws MWException + * @return string HTML + * @since 1.32 + */ + public function parseInlineAsInterface( $text, $linestart = true ) { + return Parser::stripOuterParagraph( + $this->parseAsInterface( $text, $linestart ) + ); + } + + /** + * Parse wikitext, strip paragraph wrapper, and return the HTML. + * + * @param string $text + * @param bool $linestart Is this the start of a line? + * @param bool $interface Use interface language (instead of content language) while parsing + * language sensitive magic words like GRAMMAR and PLURAL + * @return string HTML + * @deprecated since 1.32, due to untidy output and confusing default + * for $interface. Use parseInlineAsInterface() if $interface is + * the default value or false, or else use + * Parser::stripOuterParagraph($outputPage->parseAsContent(...)). + */ + public function parseInline( $text, $linestart = true, $interface = false ) { + wfDeprecated( __METHOD__, '1.33' ); + $parsed = $this->parseInternal( + $text, $this->getTitle(), $linestart, /*tidy*/false, $interface, /*language*/null + )->getText( [ + 'enableSectionEditLinks' => false, + 'wrapperDivClass' => '', /* no wrapper div */ + ] ); + return Parser::stripOuterParagraph( $parsed ); + } + + /** + * Parse wikitext and return the HTML (internal implementation helper) + * + * @param string $text + * @param Title The title to use + * @param bool $linestart Is this the start of a line? + * @param bool $tidy Whether the output should be tidied + * @param bool $interface Use interface language (instead of content language) while parsing + * language sensitive magic words like GRAMMAR and PLURAL. This also disables + * LanguageConverter. + * @param Language|null $language Target language object, will override $interface + * @throws MWException + * @return ParserOutput + */ + private function parseInternal( $text, $title, $linestart, $tidy, $interface, $language ) { global $wgParser; - if ( is_null( $this->getTitle() ) ) { + if ( is_null( $title ) ) { throw new MWException( 'Empty $mTitle in ' . __METHOD__ ); } $popts = $this->parserOptions(); - if ( $interface ) { - $popts->setInterfaceMessage( true ); - } + $oldTidy = $popts->setTidy( $tidy ); + $oldInterface = $popts->setInterfaceMessage( (bool)$interface ); + if ( $language !== null ) { $oldLang = $popts->setTargetLanguage( $language ); } $parserOutput = $wgParser->getFreshParser()->parse( - $text, $this->getTitle(), $popts, + $text, $title, $popts, $linestart, true, $this->mRevisionId ); - if ( $interface ) { - $popts->setInterfaceMessage( false ); - } + $popts->setTidy( $oldTidy ); + $popts->setInterfaceMessage( $oldInterface ); + if ( $language !== null ) { $popts->setTargetLanguage( $oldLang ); } - return $parserOutput->getText( [ - 'enableSectionEditLinks' => false, - ] ); - } - - /** - * Parse wikitext, strip paragraphs, and return the HTML. - * - * @todo This doesn't work as expected at all. If $interface is false, there's always a - * wrapping
, so stripOuterParagraph() does nothing. - * - * @param string $text - * @param bool $linestart Is this the start of a line? - * @param bool $interface Use interface language (instead of content language) while parsing - * language sensitive magic words like GRAMMAR and PLURAL - * @return string HTML - */ - public function parseInline( $text, $linestart = true, $interface = false ) { - $parsed = $this->parse( $text, $linestart, $interface ); - return Parser::stripOuterParagraph( $parsed ); + return $parserOutput; } /** @@ -2460,6 +2551,7 @@ class OutputPage extends ContextSource { !$this->haveCacheVaryCookies() ) { if ( $config->get( 'UseESI' ) ) { + wfDeprecated( '$wgUseESI = true', '1.33' ); # We'll purge the proxy cache explicitly, but require end user agents # to revalidate against the proxy on each visit. # Surrogate-Control controls our CDN, Cache-Control downstream caches @@ -2773,7 +2865,7 @@ class OutputPage extends ContextSource { } } else { $this->prepareErrorPage( $this->msg( 'permissionserrors' ) ); - $this->addWikiText( $this->formatPermissionsErrorMessage( $errors, $action ) ); + $this->addWikiTextAsInterface( $this->formatPermissionsErrorMessage( $errors, $action ) ); } } @@ -2834,7 +2926,7 @@ class OutputPage extends ContextSource { * then the warning is a bit more obvious. If the lag is * lower than $wgSlaveLagWarning, then no warning is shown. * - * @param int $lag Slave lag + * @param int $lag Replica lag */ public function showLagWarning( $lag ) { $config = $this->getConfig(); @@ -4044,7 +4136,7 @@ class OutputPage extends ContextSource { * * Is equivalent to: * - * $wgOut->addWikiText( "
\n" + * $wgOut->addWikiTextAsInterface( "
\n" * . wfMessage( 'some-error' )->plain() . "\n
" ); * * The newline after the opening div is needed in some wikitext. See T21226. @@ -4073,7 +4165,7 @@ class OutputPage extends ContextSource { } $s = str_replace( '$' . ( $n + 1 ), $this->msg( $name, $args )->plain(), $s ); } - $this->addWikiText( $s ); + $this->addWikiTextAsInterface( $s ); } /** @@ -4109,8 +4201,8 @@ class OutputPage extends ContextSource { * Helper function to setup the PHP implementation of OOUI to use in this request. * * @since 1.26 - * @param String $skinName The Skin name to determine the correct OOUI theme - * @param String $dir Language direction + * @param string $skinName The Skin name to determine the correct OOUI theme + * @param string $dir Language direction */ public static function setupOOUI( $skinName = 'default', $dir = 'ltr' ) { $themes = ResourceLoaderOOUIModule::getSkinThemeMap();