X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=includes%2Fparser%2FParser.php;h=7f3bb237590cc38b1c5cc10df2ad96ef27898927;hp=d15288af90b27e38bc962219a5235ed31ad3cd1b;hb=c58f4f99856ebe4f8dd42c0d4c07bfdfa1ec74cd;hpb=e900893531e76fb8f80c1c9b5be459fd02862c3c diff --git a/includes/parser/Parser.php b/includes/parser/Parser.php index d15288af90..7f3bb23759 100644 --- a/includes/parser/Parser.php +++ b/includes/parser/Parser.php @@ -1051,9 +1051,10 @@ class Parser { /** * Get the language object for language conversion * @deprecated since 1.32, just use getTargetLanguage() - * @return Language|null + * @return Language */ public function getConverterLanguage() { + wfDeprecated( __METHOD__, '1.32' ); return $this->getTargetLanguage(); } @@ -1548,7 +1549,7 @@ class Parser { $text = $this->doBlockLevels( $text, $linestart ); - $this->replaceLinkHolders( $text ); + $this->replaceLinkHoldersPrivate( $text ); /** * The input doesn't get language converted if @@ -2436,7 +2437,10 @@ class Parser { $prefix = ''; } - $useSubpages = $this->areSubpagesAllowed(); + # Some namespaces don't allow subpages + $useSubpages = $this->nsInfo->hasSubpages( + $this->mTitle->getNamespace() + ); # Loop for each link for ( ; $line !== false && $line !== null; $a->next(), $line = $a->current() ) { @@ -2509,7 +2513,9 @@ class Parser { # Make subpage if necessary if ( $useSubpages ) { - $link = $this->maybeDoSubpageLink( $origLink, $text ); + $link = Linker::normalizeSubpageLink( + $this->mTitle, $origLink, $text + ); } else { $link = $origLink; } @@ -2626,7 +2632,7 @@ class Parser { $holders->merge( $this->handleInternalLinks2( $text ) ); } # cloak any absolute URLs inside the image markup, so handleExternalLinks() won't touch them - $s .= $prefix . $this->armorLinks( + $s .= $prefix . $this->armorLinksPrivate( $this->makeImage( $nt, $text, $holders ) ) . $trail; continue; } @@ -2669,7 +2675,7 @@ class Parser { # Fetch and register the file (file title may be different via hooks) list( $file, $nt ) = $this->fetchFileAndTitle( $nt, $options ); # Cloak with NOPARSE to avoid replacement in handleExternalLinks - $s .= $prefix . $this->armorLinks( + $s .= $prefix . $this->armorLinksPrivate( Linker::makeMediaLinkFile( $nt, $file, $text ) ) . $trail; continue; } @@ -2680,7 +2686,7 @@ class Parser { # batch file existence checks for NS_FILE and NS_MEDIA if ( $iw == '' && $nt->isAlwaysKnown() ) { $this->mOutput->addLink( $nt ); - $s .= $this->makeKnownLinkHolder( $nt, $text, $trail, $prefix ); + $s .= $this->makeKnownLinkHolderPrivate( $nt, $text, $trail, $prefix ); } else { # Links will be added to the output link list after checking $s .= $holders->makeHolder( $nt, $text, [], $trail, $prefix ); @@ -2701,8 +2707,27 @@ class Parser { * @param string $trail * @param string $prefix * @return string HTML-wikitext mix oh yuck + * @deprecated since 1.34; should not be used outside parser class. */ protected function makeKnownLinkHolder( $nt, $text = '', $trail = '', $prefix = '' ) { + wfDeprecated( __METHOD__, '1.34' ); + return $this->makeKnownLinkHolderPrivate( $nt, $text, $trail, $prefix ); + } + + /** + * Render a forced-blue link inline; protect against double expansion of + * URLs if we're in a mode that prepends full URL prefixes to internal links. + * Since this little disaster has to split off the trail text to avoid + * breaking URLs in the following text without breaking trails on the + * wiki links, it's been made into a horrible function. + * + * @param Title $nt + * @param string $text + * @param string $trail + * @param string $prefix + * @return string HTML-wikitext mix oh yuck + */ + private function makeKnownLinkHolderPrivate( $nt, $text = '', $trail = '', $prefix = '' ) { list( $inside, $trail ) = Linker::splitTrail( $trail ); if ( $text == '' ) { @@ -2713,7 +2738,7 @@ class Parser { $nt, new HtmlArmor( "$prefix$text$inside" ) ); - return $this->armorLinks( $link ) . $trail; + return $this->armorLinksPrivate( $link ) . $trail; } /** @@ -2725,8 +2750,24 @@ class Parser { * * @param string $text More-or-less HTML * @return string Less-or-more HTML with NOPARSE bits + * @deprecated since 1.34; should not be used outside parser class. */ public function armorLinks( $text ) { + wfDeprecated( __METHOD__, '1.34' ); + return $this->armorLinksPrivate( $text ); + } + + /** + * Insert a NOPARSE hacky thing into any inline links in a chunk that's + * going to go through further parsing steps before inline URL expansion. + * + * Not needed quite as much as it used to be since free links are a bit + * more sensible these days. But bracketed links are still an issue. + * + * @param string $text More-or-less HTML + * @return string Less-or-more HTML with NOPARSE bits + */ + private function armorLinksPrivate( $text ) { return preg_replace( '/\b((?i)' . $this->mUrlProtocols . ')/', self::MARKER_PREFIX . "NOPARSE$1", $text ); } @@ -2734,9 +2775,11 @@ class Parser { /** * Return true if subpage links should be expanded on this page. * @return bool + * @deprecated since 1.34; should not be used outside parser class. */ public function areSubpagesAllowed() { # Some namespaces don't allow subpages + wfDeprecated( __METHOD__, '1.34' ); return $this->nsInfo->hasSubpages( $this->mTitle->getNamespace() ); } @@ -2747,8 +2790,10 @@ class Parser { * @param string &$text The link text, modified as necessary * @return string The full name of the link * @private + * @deprecated since 1.34; should not be used outside parser class. */ public function maybeDoSubpageLink( $target, &$text ) { + wfDeprecated( __METHOD__, '1.34' ); return Linker::normalizeSubpageLink( $this->mTitle, $target, $text ); } @@ -3227,8 +3272,10 @@ class Parser { * @param string $s * * @return array + * @deprecated since 1.34; appears to be unused. */ public static function splitWhitespace( $s ) { + wfDeprecated( __METHOD__, '1.34' ); $ltrimmed = ltrim( $s ); $w1 = substr( $s, 0, strlen( $s ) - strlen( $ltrimmed ) ); $trimmed = rtrim( $ltrimmed ); @@ -3291,8 +3338,10 @@ class Parser { * @param array $args * * @return array + * @deprecated since 1.34; appears to be unused in core. */ public static function createAssocArgs( $args ) { + wfDeprecated( __METHOD__, '1.34' ); $assocArgs = []; $index = 1; foreach ( $args as $arg ) { @@ -3504,7 +3553,9 @@ class Parser { $ns = NS_TEMPLATE; # Split the title into page and subpage $subpage = ''; - $relative = $this->maybeDoSubpageLink( $part1, $subpage ); + $relative = Linker::normalizeSubpageLink( + $this->mTitle, $part1, $subpage + ); if ( $part1 !== $relative ) { $part1 = $relative; $ns = $this->mTitle->getNamespace(); @@ -4587,7 +4638,7 @@ class Parser { # turns into # link text with suffix # Do this before unstrip since link text can contain strip markers - $safeHeadline = $this->replaceLinkHoldersText( $headline ); + $safeHeadline = $this->replaceLinkHoldersTextPrivate( $headline ); # Avoid insertion of weird stuff like by expanding the relevant sections $safeHeadline = $this->mStripState->unstripBoth( $safeHeadline ); @@ -5301,8 +5352,20 @@ class Parser { * * @param string &$text * @param int $options + * @deprecated since 1.34; should not be used outside parser class. */ public function replaceLinkHolders( &$text, $options = 0 ) { + $this->replaceLinkHoldersPrivate( $text, $options ); + } + + /** + * Replace "" link placeholders with actual links, in the buffer + * Placeholders created in Linker::link() + * + * @param string &$text + * @param int $options + */ + private function replaceLinkHoldersPrivate( &$text, $options = 0 ) { $this->mLinkHolders->replace( $text ); } @@ -5312,8 +5375,21 @@ class Parser { * * @param string $text * @return string + * @deprecated since 1.34; should not be used outside parser class. */ public function replaceLinkHoldersText( $text ) { + wfDeprecated( __METHOD__, '1.34' ); + return $this->replaceLinkHoldersTextPrivate( $text ); + } + + /** + * Replace "" link placeholders with plain text of links + * (not HTML-formatted). + * + * @param string $text + * @return string + */ + private function replaceLinkHoldersTextPrivate( $text ) { return $this->mLinkHolders->replaceText( $text ); } @@ -5446,16 +5522,16 @@ class Parser { switch ( $paramName ) { case 'gallery-internal-alt': - $alt = $this->stripAltText( $match, false ); + $alt = $this->stripAltTextPrivate( $match, false ); break; case 'gallery-internal-link': - $linkValue = $this->stripAltText( $match, false ); + $linkValue = $this->stripAltTextPrivate( $match, false ); if ( preg_match( '/^-{R|(.*)}-$/', $linkValue ) ) { // Result of LanguageConverter::markNoConversion // invoked on an external link. $linkValue = substr( $linkValue, 4, -2 ); } - list( $type, $target ) = $this->parseLinkParameter( $linkValue ); + list( $type, $target ) = $this->parseLinkParameterPrivate( $linkValue ); if ( $type === 'link-url' ) { $link = $target; $this->mOutput->addExternalLink( $target ); @@ -5493,8 +5569,18 @@ class Parser { /** * @param MediaHandler $handler * @return array + * @deprecated since 1.34; should not be used outside parser class. */ public function getImageParams( $handler ) { + wfDeprecated( __METHOD__, '1.34' ); + return $this->getImageParamsPrivate( $handler ); + } + + /** + * @param MediaHandler $handler + * @return array + */ + private function getImageParamsPrivate( $handler ) { if ( $handler ) { $handlerClass = get_class( $handler ); } else { @@ -5591,7 +5677,7 @@ class Parser { # Get parameter map $handler = $file ? $file->getHandler() : false; - list( $paramMap, $mwArray ) = $this->getImageParams( $handler ); + list( $paramMap, $mwArray ) = $this->getImageParamsPrivate( $handler ); if ( !$file ) { $this->addTrackingCategory( 'broken-file-category' ); @@ -5641,12 +5727,12 @@ class Parser { # manualthumb? downstream behavior seems odd with # missing manual thumbs. $validated = true; - $value = $this->stripAltText( $value, $holders ); + $value = $this->stripAltTextPrivate( $value, $holders ); break; case 'link': list( $paramName, $value ) = - $this->parseLinkParameter( - $this->stripAltText( $value, $holders ) + $this->parseLinkParameterPrivate( + $this->stripAltTextPrivate( $value, $holders ) ); if ( $paramName ) { $validated = true; @@ -5723,7 +5809,7 @@ class Parser { if ( !isset( $params['frame']['alt'] ) ) { # No alt text, use the "caption" for the alt text if ( $caption !== '' ) { - $params['frame']['alt'] = $this->stripAltText( $caption, $holders ); + $params['frame']['alt'] = $this->stripAltTextPrivate( $caption, $holders ); } else { # No caption, fall back to using the filename for the # alt text @@ -5731,7 +5817,7 @@ class Parser { } } # Use the "caption" for the tooltip text - $params['frame']['title'] = $this->stripAltText( $caption, $holders ); + $params['frame']['title'] = $this->stripAltTextPrivate( $caption, $holders ); } $params['handler']['targetlang'] = $this->getTargetLanguage()->getCode(); @@ -5767,8 +5853,32 @@ class Parser { * - When `type` is `null` or `'no-link'`: `false` * - When `type` is `'link-url'`: URL string corresponding to given value * - When `type` is `'link-title'`: Title object corresponding to given value + * @deprecated since 1.34; should not be used outside parser class. */ public function parseLinkParameter( $value ) { + wfDeprecated( __METHOD__, '1.34' ); + return $this->parseLinkParameterPrivate( $value ); + } + + /** + * Parse the value of 'link' parameter in image syntax (`[[File:Foo.jpg|link=]]`). + * + * Adds an entry to appropriate link tables. + * + * @since 1.32 + * @param string $value + * @return array of `[ type, target ]`, where: + * - `type` is one of: + * - `null`: Given value is not a valid link target, use default + * - `'no-link'`: Given value is empty, do not generate a link + * - `'link-url'`: Given value is a valid external link + * - `'link-title'`: Given value is a valid internal link + * - `target` is: + * - When `type` is `null` or `'no-link'`: `false` + * - When `type` is `'link-url'`: URL string corresponding to given value + * - When `type` is `'link-title'`: Title object corresponding to given value + */ + private function parseLinkParameterPrivate( $value ) { $chars = self::EXT_LINK_URL_CLASS; $addr = self::EXT_LINK_ADDR; $prots = $this->mUrlProtocols; @@ -5797,15 +5907,26 @@ class Parser { * @param string $caption * @param LinkHolderArray|bool $holders * @return mixed|string + * @deprecated since 1.34; should not be used outside parser class. */ protected function stripAltText( $caption, $holders ) { + wfDeprecated( __METHOD__, '1.34' ); + return $this->stripAltTextPrivate( $caption, $holders ); + } + + /** + * @param string $caption + * @param LinkHolderArray|bool $holders + * @return mixed|string + */ + private function stripAltTextPrivate( $caption, $holders ) { # Strip bad stuff out of the title (tooltip). We can't just use # replaceLinkHoldersText() here, because if this function is called # from handleInternalLinks2(), mLinkHolders won't be up-to-date. if ( $holders ) { $tooltip = $holders->replaceText( $caption ); } else { - $tooltip = $this->replaceLinkHoldersText( $caption ); + $tooltip = $this->replaceLinkHoldersTextPrivate( $caption ); } # make sure there are no placeholders in thumbnail attributes