X-Git-Url: https://git.cyclocoop.org/%27.WWW_URL.%27admin/?a=blobdiff_plain;f=includes%2FLinker.php;h=049fb07284ab3114c3b63732a7f711a8b0437474;hb=12a9cf3110c9ea840b20f74b3d4a968c92d8b446;hp=731317e5d0e7c7277048422551e47d38d63dcc93;hpb=f186496005a47a09aed6d46feea7302fe9d5f0e2;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/Linker.php b/includes/Linker.php index 731317e5d0..049fb07284 100644 --- a/includes/Linker.php +++ b/includes/Linker.php @@ -114,15 +114,20 @@ class Linker { } else { $text = $html; // null } + if ( in_array( 'known', $options, true ) ) { return $linkRenderer->makeKnownLink( $target, $text, $customAttribs, $query ); - } elseif ( in_array( 'broken', $options, true ) ) { + } + + if ( in_array( 'broken', $options, true ) ) { return $linkRenderer->makeBrokenLink( $target, $text, $customAttribs, $query ); - } elseif ( in_array( 'noclasses', $options, true ) ) { + } + + if ( in_array( 'noclasses', $options, true ) ) { return $linkRenderer->makePreloadedLink( $target, $text, '', $customAttribs, $query ); - } else { - return $linkRenderer->makeLink( $target, $text, $customAttribs, $query ); } + + return $linkRenderer->makeLink( $target, $text, $customAttribs, $query ); } /** @@ -193,9 +198,9 @@ class Linker { getFormattedNsText( $namespace ); } return $context->msg( 'invalidtitle-knownnamespace', $namespace, $name, $title )->text(); - } else { - return $context->msg( 'invalidtitle-unknownnamespace', $namespace, $title )->text(); } + + return $context->msg( 'invalidtitle-unknownnamespace', $namespace, $title )->text(); } /** @@ -207,14 +212,12 @@ class Linker { if ( $target->getNamespace() == NS_SPECIAL && !$target->isExternal() ) { list( $name, $subpage ) = MediaWikiServices::getInstance()->getSpecialPageFactory()-> resolveAlias( $target->getDBkey() ); - if ( !$name ) { - return $target; + if ( $name ) { + return SpecialPage::getTitleValueFor( $name, $subpage, $target->getFragment() ); } - $ret = SpecialPage::getTitleValueFor( $name, $subpage, $target->getFragment() ); - return $ret; - } else { - return $target; } + + return $target; } /** @@ -259,7 +262,9 @@ class Linker { return Html::element( 'img', [ 'src' => $url, - 'alt' => $alt ] ); + 'alt' => $alt + ] + ); } /** @@ -730,12 +735,15 @@ class Linker { if ( $wgUploadMissingFileUrl ) { return wfAppendQuery( $wgUploadMissingFileUrl, $q ); - } elseif ( $wgUploadNavigationUrl ) { + } + + if ( $wgUploadNavigationUrl ) { return wfAppendQuery( $wgUploadNavigationUrl, $q ); - } else { - $upload = SpecialPage::getTitleFor( 'Upload' ); - return $upload->getLocalURL( $q ); } + + $upload = SpecialPage::getTitleFor( 'Upload' ); + + return $upload->getLocalURL( $q ); } /** @@ -910,10 +918,12 @@ class Linker { * @param int $flags Customisation flags (e.g. Linker::TOOL_LINKS_NOBLOCK * and Linker::TOOL_LINKS_EMAIL). * @param int|null $edits User edit count (optional, for performance) + * @param bool $useParentheses (optional) Wrap comments in parentheses where needed * @return string HTML fragment */ public static function userToolLinks( - $userId, $userText, $redContribsWhenNoEdits = false, $flags = 0, $edits = null + $userId, $userText, $redContribsWhenNoEdits = false, $flags = 0, $edits = null, + $useParentheses = true ) { global $wgUser, $wgDisableAnonTalk, $wgLang; $talkable = !( $wgDisableAnonTalk && $userId == 0 ); @@ -956,14 +966,23 @@ class Linker { Hooks::run( 'UserToolLinksEdit', [ $userId, $userText, &$items ] ); - if ( $items ) { + if ( !$items ) { + return ''; + } + + if ( $useParentheses ) { return wfMessage( 'word-separator' )->escaped() . '' . wfMessage( 'parentheses' )->rawParams( $wgLang->pipeList( $items ) )->escaped() . ''; - } else { - return ''; } + + $tools = []; + foreach ( $items as $tool ) { + $tools[] = Html::rawElement( 'span', [], $tool ); + } + return ' ' . + implode( ' ', $tools ) . ''; } /** @@ -987,10 +1006,11 @@ class Linker { public static function userTalkLink( $userId, $userText ) { $userTalkPage = Title::makeTitle( NS_USER_TALK, $userText ); $moreLinkAttribs['class'] = 'mw-usertoollinks-talk'; - $userTalkLink = self::link( $userTalkPage, - wfMessage( 'talkpagelinktext' )->escaped(), - $moreLinkAttribs ); - return $userTalkLink; + + return self::link( $userTalkPage, + wfMessage( 'talkpagelinktext' )->escaped(), + $moreLinkAttribs + ); } /** @@ -1002,10 +1022,11 @@ class Linker { public static function blockLink( $userId, $userText ) { $blockPage = SpecialPage::getTitleFor( 'Block', $userText ); $moreLinkAttribs['class'] = 'mw-usertoollinks-block'; - $blockLink = self::link( $blockPage, - wfMessage( 'blocklink' )->escaped(), - $moreLinkAttribs ); - return $blockLink; + + return self::link( $blockPage, + wfMessage( 'blocklink' )->escaped(), + $moreLinkAttribs + ); } /** @@ -1016,10 +1037,10 @@ class Linker { public static function emailLink( $userId, $userText ) { $emailPage = SpecialPage::getTitleFor( 'Emailuser', $userText ); $moreLinkAttribs['class'] = 'mw-usertoollinks-mail'; - $emailLink = self::link( $emailPage, - wfMessage( 'emaillink' )->escaped(), - $moreLinkAttribs ); - return $emailLink; + return self::link( $emailPage, + wfMessage( 'emaillink' )->escaped(), + $moreLinkAttribs + ); } /** @@ -1096,9 +1117,7 @@ class Linker { # Render autocomments and make links: $comment = self::formatAutocomments( $comment, $title, $local, $wikiId ); - $comment = self::formatLinksInComment( $comment, $title, $local, $wikiId ); - - return $comment; + return self::formatLinksInComment( $comment, $title, $local, $wikiId ); } /** @@ -1155,9 +1174,11 @@ class Linker { $section = $auto; # Remove links that a user may have manually put in the autosummary # This could be improved by copying as much of Parser::stripSectionName as desired. - $section = str_replace( '[[:', '', $section ); - $section = str_replace( '[[', '', $section ); - $section = str_replace( ']]', '', $section ); + $section = str_replace( [ + '[[:', + '[[', + ']]' + ], '', $section ); // We don't want any links in the auto text to be linked, but we still // want to show any [[ ]] @@ -1452,16 +1473,15 @@ class Linker { // compatibility, acc. to brion -ævar if ( $comment == '' || $comment == '*' ) { return ''; + } + $formatted = self::formatComment( $comment, $title, $local, $wikiId ); + if ( $useParentheses ) { + $formatted = wfMessage( 'parentheses' )->rawParams( $formatted )->escaped(); + $classNames = 'comment'; } else { - $formatted = self::formatComment( $comment, $title, $local, $wikiId ); - if ( $useParentheses ) { - $formatted = wfMessage( 'parentheses' )->rawParams( $formatted )->escaped(); - $classNames = 'comment'; - } else { - $classNames = 'comment comment--without-parentheses'; - } - return " $formatted"; + $classNames = 'comment comment--without-parentheses'; } + return " $formatted"; } /** @@ -1575,11 +1595,18 @@ class Linker { * * @since 1.16.3 * @param string $toc Html of the Table Of Contents - * @param string|Language|bool $lang Language for the toc title, defaults to user language + * @param string|Language|bool|null $lang Language for the toc title, defaults to user language. + * The types string and bool are deprecated. * @return string Full html of the TOC */ - public static function tocList( $toc, $lang = false ) { - $lang = wfGetLangObj( $lang ); + public static function tocList( $toc, $lang = null ) { + global $wgLang; + $lang = $lang ?? $wgLang; + if ( !is_object( $lang ) ) { + wfDeprecated( __METHOD__ . ' with type other than Language for $lang', '1.33' ); + $lang = wfGetLangObj( $lang ); + } + $title = wfMessage( 'toc' )->inLanguage( $lang )->escaped(); return '
' @@ -1611,10 +1638,11 @@ class Linker { * * @since 1.16.3. $lang added in 1.17 * @param array $tree Return value of ParserOutput::getSections() - * @param string|Language|bool $lang Language for the toc title, defaults to user language + * @param string|Language|bool|null $lang Language for the toc title, defaults to user language. + * The types string and bool are deprecated. * @return string HTML fragment */ - public static function generateTOC( $tree, $lang = false ) { + public static function generateTOC( $tree, $lang = null ) { $toc = ''; $lastLevel = 0; foreach ( $tree as $section ) { @@ -1661,12 +1689,10 @@ class Linker { $fallbackAnchor = htmlspecialchars( $fallbackAnchor ); $fallback = ""; } - $ret = "$html" . $link . ""; - - return $ret; } /** @@ -1871,51 +1897,10 @@ class Linker { } return self::link( $title, $html, $attrs, $query, $options ); - } else { - $html = $context->msg( 'rollbacklink' )->escaped(); - return self::link( $title, $html, $attrs, $query, $options ); - } - } - - /** - * @deprecated since 1.28, use TemplatesOnThisPageFormatter directly - * - * Returns HTML for the "templates used on this page" list. - * - * Make an HTML list of templates, and then add a "More..." link at - * the bottom. If $more is null, do not add a "More..." link. If $more - * is a Title, make a link to that title and use it. If $more is a string, - * directly paste it in as the link (escaping needs to be done manually). - * Finally, if $more is a Message, call toString(). - * - * @since 1.16.3. $more added in 1.21 - * @param Title[] $templates Array of templates - * @param bool $preview Whether this is for a preview - * @param bool $section Whether this is for a section edit - * @param Title|Message|string|null $more An escaped link for "More..." of the templates - * @return string HTML output - */ - public static function formatTemplates( $templates, $preview = false, - $section = false, $more = null - ) { - wfDeprecated( __METHOD__, '1.28' ); - - $type = false; - if ( $preview ) { - $type = 'preview'; - } elseif ( $section ) { - $type = 'section'; } - if ( $more instanceof Message ) { - $more = $more->toString(); - } - - $formatter = new TemplatesOnThisPageFormatter( - RequestContext::getMain(), - MediaWikiServices::getInstance()->getLinkRenderer() - ); - return $formatter->format( $templates, $type, $more ); + $html = $context->msg( 'rollbacklink' )->escaped(); + return self::link( $title, $html, $attrs, $query, $options ); } /** @@ -1945,23 +1930,6 @@ class Linker { return $outText; } - /** - * @deprecated since 1.28, use Language::formatSize() directly - * - * Format a size in bytes for output, using an appropriate - * unit (B, KB, MB or GB) according to the magnitude in question - * - * @since 1.16.3 - * @param int $size Size to format - * @return string - */ - public static function formatSize( $size ) { - wfDeprecated( __METHOD__, '1.28' ); - - global $wgLang; - return htmlspecialchars( $wgLang->formatSize( $size ) ); - } - /** * Given the id of an interface element, constructs the appropriate title * attribute from the system messages. (Note, this is usually the id but @@ -2070,27 +2038,26 @@ class Linker { if ( !$rev->userCan( Revision::DELETED_RESTRICTED, $user ) ) { return self::revDeleteLinkDisabled( $canHide ); // revision was hidden from sysops + } + if ( $rev->getId() ) { + // RevDelete links using revision ID are stable across + // page deletion and undeletion; use when possible. + $query = [ + 'type' => 'revision', + 'target' => $title->getPrefixedDBkey(), + 'ids' => $rev->getId() + ]; } else { - if ( $rev->getId() ) { - // RevDelete links using revision ID are stable across - // page deletion and undeletion; use when possible. - $query = [ - 'type' => 'revision', - 'target' => $title->getPrefixedDBkey(), - 'ids' => $rev->getId() - ]; - } else { - // Older deleted entries didn't save a revision ID. - // We have to refer to these by timestamp, ick! - $query = [ - 'type' => 'archive', - 'target' => $title->getPrefixedDBkey(), - 'ids' => $rev->getTimestamp() - ]; - } - return self::revDeleteLink( $query, - $rev->isDeleted( Revision::DELETED_RESTRICTED ), $canHide ); + // Older deleted entries didn't save a revision ID. + // We have to refer to these by timestamp, ick! + $query = [ + 'type' => 'archive', + 'target' => $title->getPrefixedDBkey(), + 'ids' => $rev->getTimestamp() + ]; } + return self::revDeleteLink( $query, + $rev->isDeleted( Revision::DELETED_RESTRICTED ), $canHide ); } /**