X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FLinker.php;h=918bebcd83f69824b2c179a309747f63e72f8bbd;hb=d9cab39cacd319dbb90cf608e6ccf215e0ad4713;hp=2274ff54bb122591a0d39fdfddf54b5675c94fae;hpb=cbcc75067abd10f83055164ed4db000ef97b5c29;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/Linker.php b/includes/Linker.php index 2274ff54bb..918bebcd83 100644 --- a/includes/Linker.php +++ b/includes/Linker.php @@ -12,6 +12,7 @@ class Linker { * Flags for userToolLinks() */ const TOOL_LINKS_NOBLOCK = 1; + const TOOL_LINKS_EMAIL = 2; /** * Get the appropriate HTML attributes to add to the "a" element of an ex- @@ -19,10 +20,11 @@ class Linker { * * @param $class String: the contents of the class attribute; if an empty * string is passed, which is the default value, defaults to 'external'. - * @deprecated Just pass the external class directly to something using Html::expandAttributes + * @return string + * @deprecated since 1.18 Just pass the external class directly to something using Html::expandAttributes */ static function getExternalLinkAttributes( $class = 'external' ) { - wfDeprecated( __METHOD__ ); + wfDeprecated( __METHOD__, '1.18' ); return self::getLinkAttributesInternal( '', $class ); } @@ -35,11 +37,12 @@ class Linker { * @param $unused String: unused * @param $class String: the contents of the class attribute; if an empty * string is passed, which is the default value, defaults to 'external'. + * @return string */ static function getInterwikiLinkAttributes( $title, $unused = null, $class = 'external' ) { global $wgContLang; - # FIXME: We have a whole bunch of handling here that doesn't happen in + # @todo FIXME: We have a whole bunch of handling here that doesn't happen in # getExternalLinkAttributes, why? $title = urldecode( $title ); $title = $wgContLang->checkTitleEncoding( $title ); @@ -56,6 +59,7 @@ class Linker { * not HTML-escaped * @param $unused String: unused * @param $class String: the contents of the class attribute, default none + * @return string */ static function getInternalLinkAttributes( $title, $unused = null, $class = '' ) { $title = urldecode( $title ); @@ -72,6 +76,7 @@ class Linker { * @param $class String: the contents of the class attribute, default none * @param $title Mixed: optional (unescaped) string to use in the title * attribute; if false, default to the name of the page we're linking to + * @return string */ static function getInternalLinkAttributesObj( $nt, $unused = null, $class = '', $title = false ) { if ( $title === false ) { @@ -82,6 +87,11 @@ class Linker { /** * Common code for getLinkAttributesX functions + * + * @param $title string + * @param $class string + * + * @return string */ private static function getLinkAttributesInternal( $title, $class ) { $title = htmlspecialchars( $title ); @@ -103,7 +113,7 @@ class Linker { * @param $threshold Integer: user defined threshold * @return String: CSS class */ - static function getLinkColour( $t, $threshold ) { + public static function getLinkColour( $t, $threshold ) { $colour = ''; if ( $t->isRedirect() ) { # Page is a redirect @@ -129,9 +139,14 @@ class Linker { * name of the target). * link() replaces the old functions in the makeLink() family. * + * @since 1.18 Method exists since 1.16 as non-static, made static in 1.18. + * You can call it using this if you want to keep compat with these: + * $linker = class_exists( 'DummyLinker' ) ? new DummyLinker() : new Linker(); + * $linker->link( ... ); + * * @param $target Title Can currently only be a Title, but this may * change to support Images, literal URLs, etc. - * @param $text string The HTML contents of the element, i.e., + * @param $html string The HTML contents of the element, i.e., * the link text. This is raw HTML and will not be escaped. If null, * defaults to the prefixed text of the Title; or if the Title is just a * fragment, the contents of the fragment. @@ -143,7 +158,7 @@ class Linker { * @param $query array The query string to append to the URL * you're linking to, in key => value array form. Query keys and values * will be URL-encoded. - * @param $options mixed String or array of strings: + * @param $options string|array String or array of strings: * 'known': Page is known to exist, so don't check if it does. * 'broken': Page is known not to exist, so don't check if it does. * 'noclasses': Don't add any classes automatically (includes "new", @@ -155,19 +170,19 @@ class Linker { * @return string HTML attribute */ public static function link( - $target, $text = null, $customAttribs = array(), $query = array(), $options = array() + $target, $html = null, $customAttribs = array(), $query = array(), $options = array() ) { wfProfileIn( __METHOD__ ); if ( !$target instanceof Title ) { wfProfileOut( __METHOD__ ); - return "$text"; + return "$html"; } $options = (array)$options; $dummy = new DummyLinker; // dummy linker instance for bc on the hooks $ret = null; - if ( !wfRunHooks( 'LinkBegin', array( $dummy, $target, &$text, + if ( !wfRunHooks( 'LinkBegin', array( $dummy, $target, &$html, &$customAttribs, &$query, &$options, &$ret ) ) ) { wfProfileOut( __METHOD__ ); return $ret; @@ -203,13 +218,13 @@ class Linker { $attribs, self::linkAttribs( $target, $customAttribs, $options ) ); - if ( is_null( $text ) ) { - $text = self::linkText( $target ); + if ( is_null( $html ) ) { + $html = self::linkText( $target ); } $ret = null; - if ( wfRunHooks( 'LinkEnd', array( $dummy, $target, $options, &$text, &$attribs, &$ret ) ) ) { - $ret = Html::rawElement( 'a', $attribs, $text ); + if ( wfRunHooks( 'LinkEnd', array( $dummy, $target, $options, &$html, &$attribs, &$ret ) ) ) { + $ret = Html::rawElement( 'a', $attribs, $html ); } wfProfileOut( __METHOD__ ); @@ -218,18 +233,22 @@ class Linker { /** * Identical to link(), except $options defaults to 'known'. + * @return string */ public static function linkKnown( - $target, $text = null, $customAttribs = array(), + $target, $html = null, $customAttribs = array(), $query = array(), $options = array( 'known', 'noclasses' ) ) { - return self::link( $target, $text, $customAttribs, $query, $options ); + return self::link( $target, $html, $customAttribs, $query, $options ); } /** * Returns the Url used to link to a Title * * @param $target Title + * @param $query Array: query parameters + * @param $options Array + * @return String */ private static function linkUrl( $target, $query, $options ) { wfProfileIn( __METHOD__ ); @@ -244,11 +263,11 @@ class Linker { # there's already an action specified, or unless 'edit' makes no sense # (i.e., for a nonexistent special page). if ( in_array( 'broken', $options ) && empty( $query['action'] ) - && $target->getNamespace() != NS_SPECIAL ) { + && !$target->isSpecialPage() ) { $query['action'] = 'edit'; $query['redlink'] = '1'; } - $ret = $target->getLinkUrl( $query ); + $ret = $target->getLinkURL( $query ); wfProfileOut( __METHOD__ ); return $ret; } @@ -257,6 +276,10 @@ class Linker { * Returns the array of attributes used when linking to the Title $target * * @param $target Title + * @param $attribs + * @param $options + * + * @return array */ private static function linkAttribs( $target, $attribs, $options ) { wfProfileIn( __METHOD__ ); @@ -317,6 +340,8 @@ class Linker { * Default text of the links to the Title $target * * @param $target Title + * + * @return string */ private static function linkText( $target ) { # We might be passed a non-Title by make*LinkObj(). Fail gracefully. @@ -347,11 +372,11 @@ class Linker { */ static function makeSizeLinkObj( $size, $nt, $text = '', $query = '', $trail = '', $prefix = '' ) { global $wgUser; - wfDeprecated( __METHOD__ ); + wfDeprecated( __METHOD__, '1.17' ); $threshold = $wgUser->getStubThreshold(); $colour = ( $size < $threshold ) ? 'stub' : ''; - // FIXME: replace deprecated makeColouredLinkObj by link() + // @todo FIXME: Replace deprecated makeColouredLinkObj by link() return self::makeColouredLinkObj( $nt, $colour, $text, $query, $trail, $prefix ); } @@ -361,17 +386,23 @@ class Linker { * despite $query not being used. * * @param $nt Title + * + * @return string */ - static function makeSelfLinkObj( $nt, $text = '', $query = '', $trail = '', $prefix = '' ) { - if ( $text == '' ) { - $text = htmlspecialchars( $nt->getPrefixedText() ); + public static function makeSelfLinkObj( $nt, $html = '', $query = '', $trail = '', $prefix = '' ) { + if ( $html == '' ) { + $html = htmlspecialchars( $nt->getPrefixedText() ); } list( $inside, $trail ) = self::splitTrail( $trail ); - return "{$prefix}{$text}{$inside}{$trail}"; + return "{$prefix}{$html}{$inside}{$trail}"; } + /** + * @param $title Title + * @return Title + */ static function normaliseSpecialPage( Title $title ) { - if ( $title->getNamespace() == NS_SPECIAL ) { + if ( $title->isSpecialPage() ) { list( $name, $subpage ) = SpecialPageFactory::resolveAlias( $title->getDBkey() ); if ( !$name ) { return $title; @@ -387,8 +418,12 @@ class Linker { /** * Returns the filename part of an url. * Used as alternative text for external images. + * + * @param $url string + * + * @return string */ - static function fnamePart( $url ) { + private static function fnamePart( $url ) { $basename = strrchr( $url, '/' ); if ( false === $basename ) { $basename = $url; @@ -401,8 +436,13 @@ class Linker { /** * Return the code for images which were added via external links, * via Parser::maybeMakeExternalImage(). + * + * @param $url + * @param $alt + * + * @return string */ - static function makeExternalImage( $url, $alt = '' ) { + public static function makeExternalImage( $url, $alt = '' ) { if ( $alt == '' ) { $alt = self::fnamePart( $url ); } @@ -451,7 +491,7 @@ class Linker { * @param $widthOption: Used by the parser to remember the user preference thumbnailsize * @return String: HTML for an image, with links, wrappers, etc. */ - static function makeImageLink2( Title $title, $file, $frameParams = array(), + public static function makeImageLink2( Title $title, $file, $frameParams = array(), $handlerParams = array(), $time = false, $query = "", $widthOption = null ) { $res = null; @@ -490,7 +530,14 @@ class Linker { $fp['align'] = 'none'; } if ( $file && !isset( $hp['width'] ) ) { - $hp['width'] = $file->getWidth( $page ); + if ( isset( $hp['height'] ) && $file->isVectorized() ) { + // If its a vector image, and user only specifies height + // we don't want it to be limited by its "normal" width. + global $wgSVGMaxSize; + $hp['width'] = $wgSVGMaxSize; + } else { + $hp['width'] = $file->getWidth( $page ); + } if ( isset( $fp['thumbnail'] ) || isset( $fp['framed'] ) || isset( $fp['frameless'] ) || !$hp['width'] ) { global $wgThumbLimits, $wgThumbUpright; @@ -568,10 +615,11 @@ class Linker { /** * Get the link parameters for MediaTransformOutput::toHtml() from given * frame parameters supplied by the Parser. - * @param $frameParams The frame parameters - * @param $query An optional query string to add to description page links + * @param $frameParams array The frame parameters + * @param $query string An optional query string to add to description page links + * @return array */ - static function getImageLinkMTOParams( $frameParams, $query = '' ) { + private static function getImageLinkMTOParams( $frameParams, $query = '' ) { $mtoParams = array(); if ( isset( $frameParams['link-url'] ) && $frameParams['link-url'] !== '' ) { $mtoParams['custom-url-link'] = $frameParams['link-url']; @@ -599,8 +647,9 @@ class Linker { * @param $params Array * @param $framed Boolean * @param $manualthumb String + * @return mixed */ - static function makeThumbLinkObj( Title $title, $file, $label = '', $alt, + public static function makeThumbLinkObj( Title $title, $file, $label = '', $alt, $align = 'right', $params = array(), $framed = false , $manualthumb = "" ) { $frameParams = array( @@ -626,10 +675,10 @@ class Linker { * @param string $query * @return mixed */ - static function makeThumbLink2( Title $title, $file, $frameParams = array(), + public static function makeThumbLink2( Title $title, $file, $frameParams = array(), $handlerParams = array(), $time = false, $query = "" ) { - global $wgStylePath; + global $wgStylePath, $wgContLang; $exists = $file && $file->exists(); # Shortcuts @@ -707,11 +756,16 @@ class Linker { if ( isset( $fp['framed'] ) ) { $zoomIcon = ""; } else { - $zoomIcon = '
' . - '' . - '
'; + $zoomIcon = Html::rawElement( 'div', array( 'class' => 'magnify' ), + Html::rawElement( 'a', array( + 'href' => $url, + 'class' => 'internal', + 'title' => wfMsg( 'thumbnail-more' ) ), + Html::element( 'img', array( + 'src' => $wgStylePath . '/common/images/magnify-clip' . ( $wgContLang->isRTL() ? '-rtl' : '' ) . '.png', + 'width' => 15, + 'height' => 11, + 'alt' => "" ) ) ) ); } } $s .= '
' . $zoomIcon . $fp['caption'] . "
"; @@ -722,43 +776,42 @@ class Linker { * Make a "broken" link to an image * * @param $title Title object - * @param $text String: link label in unescaped text form + * @param $html String: link label in htmlescaped text form * @param $query String: query string * @param $trail String: link trail (HTML fragment) * @param $prefix String: link prefix (HTML fragment) * @param $time Boolean: a file of a certain timestamp was requested * @return String */ - public static function makeBrokenImageLinkObj( $title, $text = '', $query = '', $trail = '', $prefix = '', $time = false ) { - global $wgEnableUploads, $wgUploadMissingFileUrl; - if ( $title instanceof Title ) { - wfProfileIn( __METHOD__ ); - $currentExists = $time ? ( wfFindFile( $title ) != false ) : false; - - list( $inside, $trail ) = self::splitTrail( $trail ); - if ( $text == '' ) - $text = htmlspecialchars( $title->getPrefixedText() ); - - if ( ( $wgUploadMissingFileUrl || $wgEnableUploads ) && !$currentExists ) { - $redir = RepoGroup::singleton()->getLocalRepo()->checkRedirect( $title ); + public static function makeBrokenImageLinkObj( $title, $html = '', $query = '', $trail = '', $prefix = '', $time = false ) { + global $wgEnableUploads, $wgUploadMissingFileUrl, $wgUploadNavigationUrl; + if ( ! $title instanceof Title ) { + return "{$prefix}{$html}{$trail}"; + } + wfProfileIn( __METHOD__ ); + $currentExists = $time ? ( wfFindFile( $title ) != false ) : false; - if ( $redir ) { - wfProfileOut( __METHOD__ ); - return self::linkKnown( $title, "$prefix$text$inside", array(), $query ) . $trail; - } + list( $inside, $trail ) = self::splitTrail( $trail ); + if ( $html == '' ) + $html = htmlspecialchars( $title->getPrefixedText() ); - $href = self::getUploadUrl( $title, $query ); + if ( ( $wgUploadMissingFileUrl || $wgUploadNavigationUrl || $wgEnableUploads ) && !$currentExists ) { + $redir = RepoGroup::singleton()->getLocalRepo()->checkRedirect( $title ); + if ( $redir ) { wfProfileOut( __METHOD__ ); - return '' . - "$prefix$text$inside$trail"; - } else { - wfProfileOut( __METHOD__ ); - return self::linkKnown( $title, "$prefix$text$inside", array(), $query ) . $trail; + return self::linkKnown( $title, "$prefix$html$inside", array(), $query ) . $trail; } + + $href = self::getUploadUrl( $title, $query ); + + wfProfileOut( __METHOD__ ); + return '' . + "$prefix$html$inside$trail"; } else { - return "{$prefix}{$text}{$trail}"; + wfProfileOut( __METHOD__ ); + return self::linkKnown( $title, "$prefix$html$inside", array(), $query ) . $trail; } } @@ -770,13 +823,15 @@ class Linker { * @return String: urlencoded URL */ protected static function getUploadUrl( $destFile, $query = '' ) { - global $wgUploadMissingFileUrl; + global $wgUploadMissingFileUrl, $wgUploadNavigationUrl; $q = 'wpDestFile=' . $destFile->getPartialUrl(); if ( $query != '' ) $q .= '&' . $query; if ( $wgUploadMissingFileUrl ) { return wfAppendQuery( $wgUploadMissingFileUrl, $q ); + } elseif( $wgUploadNavigationUrl ) { + return wfAppendQuery( $wgUploadNavigationUrl, $q ); } else { $upload = SpecialPage::getTitleFor( 'Upload' ); return $upload->getLocalUrl( $q ); @@ -787,13 +842,13 @@ class Linker { * Create a direct link to a given uploaded file. * * @param $title Title object. - * @param $text String: pre-sanitized HTML + * @param $html String: pre-sanitized HTML * @param $time string: MW timestamp of file creation time * @return String: HTML */ - public static function makeMediaLinkObj( $title, $text = '', $time = false ) { + public static function makeMediaLinkObj( $title, $html = '', $time = false ) { $img = wfFindFile( $title, array( 'time' => $time ) ); - return self::makeMediaLinkFile( $title, $img, $text ); + return self::makeMediaLinkFile( $title, $img, $html ); } /** @@ -801,13 +856,13 @@ class Linker { * This will make a broken link if $file is false. * * @param $title Title object. - * @param $file mixed File object or false - * @param $text String: pre-sanitized HTML + * @param $file File|bool mixed File object or false + * @param $html String: pre-sanitized HTML * @return String: HTML * * @todo Handle invalid or missing images better. */ - public static function makeMediaLinkFile( Title $title, $file, $text = '' ) { + public static function makeMediaLinkFile( Title $title, $file, $html = '' ) { if ( $file && $file->exists() ) { $url = $file->getURL(); $class = 'internal'; @@ -816,20 +871,24 @@ class Linker { $class = 'new'; } $alt = htmlspecialchars( $title->getText(), ENT_QUOTES ); - if ( $text == '' ) { - $text = $alt; + if ( $html == '' ) { + $html = $alt; } $u = htmlspecialchars( $url ); - return "{$text}"; + return "{$html}"; } /** - * Make a link to a special page given its name and, optionally, + * Make a link to a special page given its name and, optionally, * a message key from the link text. - * Usage example: $skin->specialLink( 'recentchanges' ) + * Usage example: Linker::specialLink( 'Recentchanges' ) + * + * @return string */ - static function specialLink( $name, $key = '' ) { - if ( $key == '' ) { $key = strtolower( $name ); } + public static function specialLink( $name, $key = '' ) { + if ( $key == '' ) { + $key = strtolower( $name ); + } return self::linkKnown( SpecialPage::getTitleFor( $name ) , wfMsg( $key ) ); } @@ -841,17 +900,18 @@ class Linker { * @param $escape Boolean: do we escape the link text? * @param $linktype String: type of external link. Gets added to the classes * @param $attribs Array of extra attributes to + * @return string */ - static function makeExternalLink( $url, $text, $escape = true, $linktype = '', $attribs = array() ) { + public static function makeExternalLink( $url, $text, $escape = true, $linktype = '', $attribs = array() ) { $class = "external"; - if ( isset($linktype) && $linktype ) { + if ( $linktype ) { $class .= " $linktype"; } - if ( isset($attribs['class']) && $attribs['class'] ) { + if ( isset( $attribs['class'] ) && $attribs['class'] ) { $class .= " {$attribs['class']}"; } $attribs['class'] = $class; - + if ( $escape ) { $text = htmlspecialchars( $text ); } @@ -869,17 +929,23 @@ class Linker { /** * Make user link (or user contributions for unregistered users) * @param $userId Integer: user id in database. - * @param $userText String: user name in database + * @param $userName String: user name in database. + * @param $altUserName String: text to display instead of the user name (optional) * @return String: HTML fragment - * @private + * @since 1.19 Method exists for a long time. $displayText was added in 1.19. */ - static function userLink( $userId, $userText ) { + public static function userLink( $userId, $userName, $altUserName = false ) { if ( $userId == 0 ) { - $page = SpecialPage::getTitleFor( 'Contributions', $userText ); + $page = SpecialPage::getTitleFor( 'Contributions', $userName ); } else { - $page = Title::makeTitle( NS_USER, $userText ); + $page = Title::makeTitle( NS_USER, $userName ); } - return self::link( $page, htmlspecialchars( $userText ), array( 'class' => 'mw-userlink' ) ); + + return self::link( + $page, + htmlspecialchars( $altUserName !== false ? $altUserName : $userName ), + array( 'class' => 'mw-userlink' ) + ); } /** @@ -889,7 +955,7 @@ class Linker { * @param $userText String: user name or IP address * @param $redContribsWhenNoEdits Boolean: should the contributions link be * red if the user has no edits? - * @param $flags Integer: customisation flags (e.g. Linker::TOOL_LINKS_NOBLOCK) + * @param $flags Integer: customisation flags (e.g. Linker::TOOL_LINKS_NOBLOCK and Linker::TOOL_LINKS_EMAIL) * @param $edits Integer: user edit count (optional, for performance) * @return String: HTML fragment */ @@ -898,7 +964,8 @@ class Linker { ) { global $wgUser, $wgDisableAnonTalk, $wgLang; $talkable = !( $wgDisableAnonTalk && 0 == $userId ); - $blockable = !$flags & self::TOOL_LINKS_NOBLOCK; + $blockable = !( $flags & self::TOOL_LINKS_NOBLOCK ); + $addEmailLink = $flags & self::TOOL_LINKS_EMAIL && $userId; $items = array(); if ( $talkable ) { @@ -921,8 +988,14 @@ class Linker { $items[] = self::blockLink( $userId, $userText ); } + if ( $addEmailLink && $wgUser->canSendEmail() ) { + $items[] = self::emailLink( $userId, $userText ); + } + + wfRunHooks( 'UserToolLinksEdit', array( $userId, $userText, &$items ) ); + if ( $items ) { - return ' (' . $wgLang->pipeList( $items ) . ')'; + return ' ' . wfMessage( 'parentheses' )->rawParams( $wgLang->pipeList( $items ) )->escaped() . ''; } else { return ''; } @@ -933,6 +1006,7 @@ class Linker { * @param $userId Integer: user identifier * @param $userText String: user name or IP address * @param $edits Integer: user edit count (optional, for performance) + * @return String */ public static function userToolLinksRedContribs( $userId, $userText, $edits = null ) { return self::userToolLinks( $userId, $userText, true, 0, $edits ); @@ -943,9 +1017,8 @@ class Linker { * @param $userId Integer: user id in database. * @param $userText String: user name in database. * @return String: HTML fragment with user talk link - * @private */ - static function userTalkLink( $userId, $userText ) { + public static function userTalkLink( $userId, $userText ) { $userTalkPage = Title::makeTitle( NS_USER_TALK, $userText ); $userTalkLink = self::link( $userTalkPage, wfMsgHtml( 'talkpagelinktext' ) ); return $userTalkLink; @@ -955,24 +1028,34 @@ class Linker { * @param $userId Integer: userid * @param $userText String: user name in database. * @return String: HTML fragment with block link - * @private */ - static function blockLink( $userId, $userText ) { + public static function blockLink( $userId, $userText ) { $blockPage = SpecialPage::getTitleFor( 'Block', $userText ); $blockLink = self::link( $blockPage, wfMsgHtml( 'blocklink' ) ); return $blockLink; } + /** + * @param $userId Integer: userid + * @param $userText String: user name in database. + * @return String: HTML fragment with e-mail user link + */ + public static function emailLink( $userId, $userText ) { + $emailPage = SpecialPage::getTitleFor( 'Emailuser', $userText ); + $emailLink = self::link( $emailPage, wfMsgHtml( 'emaillink' ) ); + return $emailLink; + } + /** * Generate a user link if the current user is allowed to view it * @param $rev Revision object. * @param $isPublic Boolean: show only if all users can see it * @return String: HTML fragment */ - static function revUserLink( $rev, $isPublic = false ) { + public static function revUserLink( $rev, $isPublic = false ) { if ( $rev->isDeleted( Revision::DELETED_USER ) && $isPublic ) { $link = wfMsgHtml( 'rev-deleted-user' ); - } else if ( $rev->userCan( Revision::DELETED_USER ) ) { + } elseif ( $rev->userCan( Revision::DELETED_USER ) ) { $link = self::userLink( $rev->getUser( Revision::FOR_THIS_USER ), $rev->getUserText( Revision::FOR_THIS_USER ) ); } else { @@ -990,10 +1073,10 @@ class Linker { * @param $isPublic Boolean: show only if all users can see it * @return string HTML */ - static function revUserTools( $rev, $isPublic = false ) { + public static function revUserTools( $rev, $isPublic = false ) { if ( $rev->isDeleted( Revision::DELETED_USER ) && $isPublic ) { $link = wfMsgHtml( 'rev-deleted-user' ); - } else if ( $rev->userCan( Revision::DELETED_USER ) ) { + } elseif ( $rev->userCan( Revision::DELETED_USER ) ) { $userId = $rev->getUser( Revision::FOR_THIS_USER ); $userText = $rev->getUserText( Revision::FOR_THIS_USER ); $link = self::userLink( $userId, $userText ) . @@ -1022,8 +1105,9 @@ class Linker { * @param $comment String * @param $title Mixed: Title object (to generate link to the section in autocomment) or null * @param $local Boolean: whether section links should refer to local page + * @return mixed|String */ - static function formatComment( $comment, $title = null, $local = false ) { + public static function formatComment( $comment, $title = null, $local = false ) { wfProfileIn( __METHOD__ ); # Sanitize text a bit: @@ -1039,6 +1123,9 @@ class Linker { return $comment; } + /** + * @var Title + */ static $autocommentTitle; static $autocommentLocal; @@ -1050,7 +1137,7 @@ class Linker { * Called by Linker::formatComment. * * @param $comment String: comment text - * @param $title An optional title object used to links to sections + * @param $title Title|null An optional title object used to links to sections * @param $local Boolean: whether section links should refer to local page * @return String: formatted comment */ @@ -1067,7 +1154,12 @@ class Linker { return $comment; } + /** + * @param $match + * @return string + */ private static function formatAutocommentsCallback( $match ) { + global $wgLang; $title = self::$autocommentTitle; $local = self::$autocommentLocal; @@ -1093,26 +1185,28 @@ class Linker { } if ( $sectionTitle ) { $link = self::link( $sectionTitle, - htmlspecialchars( wfMsgForContent( 'sectionlink' ) ), array(), array(), + $wgLang->getArrow(), array(), array(), 'noclasses' ); } else { $link = ''; } } - $auto = "$link$auto"; if ( $pre ) { # written summary $presep autocomment (summary /* section */) - $auto = wfMsgExt( 'autocomment-prefix', array( 'escapenoentities', 'content' ) ) . $auto; + $pre .= wfMsgExt( 'autocomment-prefix', array( 'escapenoentities', 'content' ) ); } if ( $post ) { # autocomment $postsep written summary (/* section */ summary) $auto .= wfMsgExt( 'colon-separator', array( 'escapenoentities', 'content' ) ); } $auto = '' . $auto . ''; - $comment = $pre . $auto . $post; + $comment = $pre . $link . $wgLang->getDirMark() . '' . $auto . $post . ''; return $comment; } + /** + * @var Title + */ static $commentContextTitle; static $commentLocal; @@ -1120,9 +1214,9 @@ class Linker { * Formats wiki links and media links in text; all other wiki formatting * is ignored * - * @todo Fixme: doesn't handle sub-links as in image thumb texts like the main parser + * @todo FIXME: Doesn't handle sub-links as in image thumb texts like the main parser * @param $comment String: text to format links in - * @param $title An optional title object used to links to sections + * @param $title Title|null An optional title object used to links to sections * @param $local Boolean: whether section links should refer to local page * @return String */ @@ -1138,6 +1232,10 @@ class Linker { return $html; } + /** + * @param $match + * @return mixed + */ protected static function formatLinksInCommentCallback( $match ) { global $wgContLang; @@ -1163,7 +1261,9 @@ class Linker { # Media link; trail not supported. $linkRegexp = '/\[\[(.*?)\]\]/'; $title = Title::makeTitleSafe( NS_FILE, $submatch[1] ); - $thelink = self::makeMediaLinkObj( $title, $text ); + if ( $title ) { + $thelink = self::makeMediaLinkObj( $title, $text ); + } } else { # Other kind of link if ( preg_match( $wgContLang->linkTrail(), $match[4], $submatch ) ) { @@ -1209,7 +1309,7 @@ class Linker { * @param $text * @return string */ - static function normalizeSubpageLink( $contextTitle, $target, &$text ) { + public static function normalizeSubpageLink( $contextTitle, $target, &$text ) { # Valid link forms: # Foobar -- normal # :Foobar -- override special treatment of prefix (images, language links) @@ -1234,7 +1334,7 @@ class Linker { # bug 7425 $target = trim( $target ); # Look at the first character - if ( $target != '' && $target { 0 } === '/' ) { + if ( $target != '' && $target[0] === '/' ) { # / at end means we don't want the slash to be shown $m = array(); $trailingSlashes = preg_match_all( '%(/+)$%', $target, $m ); @@ -1288,10 +1388,10 @@ class Linker { * @param $comment String * @param $title Mixed: Title object (to generate link to section in autocomment) or null * @param $local Boolean: whether section links should refer to local page - * @param $embraced Boolean: whether the formatted comment should be embraced with () + * * @return string */ - static function commentBlock( $comment, $title = null, $local = false, $embraced = true ) { + public static function commentBlock( $comment, $title = null, $local = false ) { // '*' used to be the comment inserted by the software way back // in antiquity in case none was provided, here for backwards // compatability, acc. to brion -ævar @@ -1299,10 +1399,8 @@ class Linker { return ''; } else { $formatted = self::formatComment( $comment, $title, $local ); - if ( $embraced ) { - $formatted = wfMessage( 'parentheses' )->rawParams( $formatted )->escaped(); - } - return Html::rawElement( 'span', array( 'class' => 'comment' ), $formatted ); + $formatted = wfMessage( 'parentheses' )->rawParams( $formatted )->escaped(); + return " $formatted"; } } @@ -1315,13 +1413,13 @@ class Linker { * @param $isPublic Boolean: show only if all users can see it * @return String: HTML fragment */ - static function revComment( Revision $rev, $local = false, $isPublic = false ) { + public static function revComment( Revision $rev, $local = false, $isPublic = false ) { if ( $rev->getRawComment() == "" ) { return ""; } if ( $rev->isDeleted( Revision::DELETED_COMMENT ) && $isPublic ) { $block = " " . wfMsgHtml( 'rev-deleted-comment' ) . ""; - } else if ( $rev->userCan( Revision::DELETED_COMMENT ) ) { + } elseif ( $rev->userCan( Revision::DELETED_COMMENT ) ) { $block = self::commentBlock( $rev->getComment( Revision::FOR_THIS_USER ), $rev->getTitle(), $local ); } else { @@ -1333,13 +1431,17 @@ class Linker { return $block; } + /** + * @param $size + * @return string + */ public static function formatRevisionSize( $size ) { if ( $size == 0 ) { $stxt = wfMsgExt( 'historyempty', 'parsemag' ); } else { global $wgLang; $stxt = wfMsgExt( 'nbytes', 'parsemag', $wgLang->formatNum( $size ) ); - $stxt = "($stxt)"; + $stxt = wfMessage( 'parentheses' )->rawParams( $stxt )->escaped(); } $stxt = htmlspecialchars( $stxt ); return "$stxt"; @@ -1347,25 +1449,32 @@ class Linker { /** * Add another level to the Table of Contents + * + * @return string */ - static function tocIndent() { + public static function tocIndent() { return "\n\n\n", $level > 0 ? $level : 0 ); } /** * parameter level defines if we are on an indentation level + * + * @return string */ - static function tocLine( $anchor, $tocline, $tocnumber, $level, $sectionIndex = false ) { + public static function tocLine( $anchor, $tocline, $tocnumber, $level, $sectionIndex = false ) { $classes = "toclevel-$level"; - if ( $sectionIndex !== false ) + if ( $sectionIndex !== false ) { $classes .= " tocsection-$sectionIndex"; + } return "\n
  • ' . $tocnumber . ' ' . @@ -1376,8 +1485,9 @@ class Linker { * End a Table Of Contents line. * tocUnindent() will be used instead if we're ending a line below * the new level. + * @return string */ - static function tocLineEnd() { + public static function tocLineEnd() { return "
  • \n"; } @@ -1388,7 +1498,7 @@ class Linker { * @param $lang mixed: Language code for the toc title * @return String: full html of the TOC */ - static function tocList( $toc, $lang = false ) { + public static function tocList( $toc, $lang = false ) { $title = wfMsgExt( 'toc', array( 'language' => $lang, 'escape' ) ); return '
    ' @@ -1401,7 +1511,7 @@ class Linker { * Generate a table of contents from a section tree * Currently unused. * - * @param $tree Return value of ParserOutput::getSections() + * @param $tree array Return value of ParserOutput::getSections() * @return String: HTML fragment */ public static function generateTOC( $tree ) { @@ -1410,7 +1520,7 @@ class Linker { foreach ( $tree as $section ) { if ( $section['toclevel'] > $lastLevel ) $toc .= self::tocIndent(); - else if ( $section['toclevel'] < $lastLevel ) + elseif ( $section['toclevel'] < $lastLevel ) $toc .= self::tocUnindent( $lastLevel - $section['toclevel'] ); else @@ -1433,17 +1543,17 @@ class Linker { * a space and ending with '>' * This *must* be at least '>' for no attribs * @param $anchor String: the anchor to give the headline (the bit after the #) - * @param $text String: the text of the header + * @param $html String: html for the text of the header * @param $link String: HTML to add for the section edit link * @param $legacyAnchor Mixed: a second, optional anchor to give for * backward compatibility (false to omit) * * @return String: HTML headline */ - public static function makeHeadline( $level, $attribs, $anchor, $text, $link, $legacyAnchor = false ) { + public static function makeHeadline( $level, $attribs, $anchor, $html, $link, $legacyAnchor = false ) { $ret = "$text" + . " $html" . ""; if ( $legacyAnchor !== false ) { $ret = "
    $ret"; @@ -1454,6 +1564,7 @@ class Linker { /** * Split a link trail, return the "inside" portion and the remainder of the trail * as a two-element array + * @return array */ static function splitTrail( $trail ) { global $wgContLang; @@ -1481,8 +1592,9 @@ class Linker { * other users. * * @param $rev Revision object + * @return string */ - static function generateRollback( $rev ) { + public static function generateRollback( $rev ) { return '[' . self::buildRollbackLink( $rev ) . ']'; @@ -1500,18 +1612,18 @@ class Linker { $query = array( 'action' => 'rollback', 'from' => $rev->getUserText(), - 'token' => $wgUser->editToken( array( $title->getPrefixedText(), $rev->getUserText() ) ), + 'token' => $wgUser->getEditToken( array( $title->getPrefixedText(), $rev->getUserText() ) ), ); if ( $wgRequest->getBool( 'bot' ) ) { $query['bot'] = '1'; $query['hidediff'] = '1'; // bug 15999 } - return self::link( - $title, + return self::link( + $title, wfMsgHtml( 'rollbacklink' ), array( 'title' => wfMsg( 'tooltip-rollback' ) ), - $query, - array( 'known', 'noclasses' ) + $query, + array( 'known', 'noclasses' ) ); } @@ -1611,7 +1723,7 @@ class Linker { * Format a size in bytes for output, using an appropriate * unit (B, KB, MB or GB) according to the magnitude in question * - * @param $size Size to format + * @param $size int Size to format * @return String */ public static function formatSize( $size ) { @@ -1688,7 +1800,7 @@ class Linker { } else { $accesskey = $message->plain(); if ( $accesskey === '' || $accesskey === '-' ) { - # FIXME: Per standard MW behavior, a value of '-' means to suppress the + # @todo FIXME: Per standard MW behavior, a value of '-' means to suppress the # attribute, but this is broken for accesskey: that might be a useful # value. $accesskey = false; @@ -1699,6 +1811,50 @@ class Linker { return self::$accesskeycache[$name] = $accesskey; } + /** + * Get a revision-deletion link, or disabled link, or nothing, depending + * on user permissions & the settings on the revision. + * + * Will use forward-compatible revision ID in the Special:RevDelete link + * if possible, otherwise the timestamp-based ID which may break after + * undeletion. + * + * @param User $user + * @param Revision $rev + * @param Revision $title + * @return string HTML fragment + */ + public static function getRevDeleteLink( User $user, Revision $rev, Title $title ) { + $canHide = $user->isAllowed( 'deleterevision' ); + if ( !$canHide && !( $rev->getVisibility() && $user->isAllowed( 'deletedhistory' ) ) ) { + return ''; + } + + if ( !$rev->userCan( Revision::DELETED_RESTRICTED, $user ) ) { + return Linker::revDeleteLinkDisabled( $canHide ); // revision was hidden from sysops + } else { + if ( $rev->getId() ) { + // RevDelete links using revision ID are stable across + // page deletion and undeletion; use when possible. + $query = array( + '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 = array( + 'type' => 'archive', + 'target' => $title->getPrefixedDBkey(), + 'ids' => $rev->getTimestamp() + ); + } + return Linker::revDeleteLink( $query, + $rev->isDeleted( Revision::DELETED_RESTRICTED ), $canHide ); + } + } + /** * Creates a (show/hide) link for deleting revisions/log entries * @@ -1711,10 +1867,10 @@ class Linker { */ public static function revDeleteLink( $query = array(), $restricted = false, $delete = true ) { $sp = SpecialPage::getTitleFor( 'Revisiondelete' ); - $text = $delete ? wfMsgHtml( 'rev-delundel' ) : wfMsgHtml( 'rev-showdeleted' ); + $html = $delete ? wfMsgHtml( 'rev-delundel' ) : wfMsgHtml( 'rev-showdeleted' ); $tag = $restricted ? 'strong' : 'span'; - $link = self::link( $sp, $text, array(), $query, array( 'known', 'noclasses' ) ); - return Xml::tags( $tag, array( 'class' => 'mw-revdelundel-link' ), "($link)" ); + $link = self::link( $sp, $html, array(), $query, array( 'known', 'noclasses' ) ); + return Xml::tags( $tag, array( 'class' => 'mw-revdelundel-link' ), wfMessage( 'parentheses' )->rawParams( $link )->escaped() ); } /** @@ -1726,66 +1882,12 @@ class Linker { * of appearance with CSS */ public static function revDeleteLinkDisabled( $delete = true ) { - $text = $delete ? wfMsgHtml( 'rev-delundel' ) : wfMsgHtml( 'rev-showdeleted' ); - return Xml::tags( 'span', array( 'class' => 'mw-revdelundel-link' ), "($text)" ); + $html = $delete ? wfMsgHtml( 'rev-delundel' ) : wfMsgHtml( 'rev-showdeleted' ); + return Xml::tags( 'span', array( 'class' => 'mw-revdelundel-link' ), wfMessage( 'parentheses' )->rawParams( $html )->escaped() ); } /* Deprecated methods */ - /** - * @deprecated since 1.16 Use link() - * - * This function is a shortcut to makeLinkObj(Title::newFromText($title),...). Do not call - * it if you already have a title object handy. See makeLinkObj for further documentation. - * - * @param $title String: the text of the title - * @param $text String: link text - * @param $query String: optional query part - * @param $trail String: optional trail. Alphabetic characters at the start of this string will - * be included in the link text. Other characters will be appended after - * the end of the link. - */ - static function makeLink( $title, $text = '', $query = '', $trail = '' ) { - wfProfileIn( __METHOD__ ); - $nt = Title::newFromText( $title ); - if ( $nt instanceof Title ) { - $result = self::makeLinkObj( $nt, $text, $query, $trail ); - } else { - wfDebug( 'Invalid title passed to self::makeLink(): "' . $title . "\"\n" ); - $result = $text == "" ? $title : $text; - } - - wfProfileOut( __METHOD__ ); - return $result; - } - - /** - * @deprecated since 1.16 Use link() - * - * This function is a shortcut to makeKnownLinkObj(Title::newFromText($title),...). Do not call - * it if you already have a title object handy. See makeKnownLinkObj for further documentation. - * - * @param $title String: the text of the title - * @param $text String: link text - * @param $query String: optional query part - * @param $trail String: optional trail. Alphabetic characters at the start of this string will - * be included in the link text. Other characters will be appended after - * the end of the link. - * @param $prefix String: Optional prefix - * @param $aprops String: extra attributes to the a-element - */ - static function makeKnownLink( - $title, $text = '', $query = '', $trail = '', $prefix = '', $aprops = '' - ) { - $nt = Title::newFromText( $title ); - if ( $nt instanceof Title ) { - return self::makeKnownLinkObj( $nt, $text, $query, $trail, $prefix , $aprops ); - } else { - wfDebug( 'Invalid title passed to self::makeKnownLink(): "' . $title . "\"\n" ); - return $text == '' ? $title : $text; - } - } - /** * @deprecated since 1.16 Use link() * @@ -1798,8 +1900,11 @@ class Linker { * @param $trail String: Optional trail. Alphabetic characters at the start of this string will * be included in the link text. Other characters will be appended after * the end of the link. + * @return string */ static function makeBrokenLink( $title, $text = '', $query = '', $trail = '' ) { + wfDeprecated( __METHOD__, '1.16' ); + $nt = Title::newFromText( $title ); if ( $nt instanceof Title ) { return self::makeBrokenLinkObj( $nt, $text, $query, $trail ); @@ -1809,30 +1914,6 @@ class Linker { } } - /** - * @deprecated since 1.16 Use link() - * - * This function is a shortcut to makeStubLinkObj(Title::newFromText($title),...). Do not call - * it if you already have a title object handy. See makeStubLinkObj for further documentation. - * - * @param $title String: the text of the title - * @param $text String: link text - * @param $query String: optional query part - * @param $trail String: optional trail. Alphabetic characters at the start of this string will - * be included in the link text. Other characters will be appended after - * the end of the link. - */ - static function makeStubLink( $title, $text = '', $query = '', $trail = '' ) { - wfDeprecated( __METHOD__ ); - $nt = Title::newFromText( $title ); - if ( $nt instanceof Title ) { - return self::makeStubLinkObj( $nt, $text, $query, $trail ); - } else { - wfDebug( 'Invalid title passed to self::makeStubLink(): "' . $title . "\"\n" ); - return $text == '' ? $title : $text; - } - } - /** * @deprecated since 1.16 Use link() * @@ -1848,8 +1929,11 @@ class Linker { * be included in the link text. Other characters will be appended after * the end of the link. * @param $prefix String: optional prefix. As trail, only before instead of after. + * @return string */ static function makeLinkObj( $nt, $text = '', $query = '', $trail = '', $prefix = '' ) { + # wfDeprecated( __METHOD__, '1.16' ); // See r105985 and it's revert. Somewhere still used. + wfProfileIn( __METHOD__ ); $query = wfCgiToArray( $query ); list( $inside, $trail ) = self::splitTrail( $trail ); @@ -1877,11 +1961,13 @@ class Linker { * @param $prefix String: text before link text * @param $aprops String: extra attributes to the a-element * @param $style String: style to apply - if empty, use getInternalLinkAttributesObj instead - * @return the a-element + * @return string the a-element */ static function makeKnownLinkObj( $title, $text = '', $query = '', $trail = '', $prefix = '' , $aprops = '', $style = '' ) { + # wfDeprecated( __METHOD__, '1.16' ); // See r105985 and it's revert. Somewhere still used. + wfProfileIn( __METHOD__ ); if ( $text == '' ) { @@ -1913,8 +1999,11 @@ class Linker { * be included in the link text. Other characters will be appended after * the end of the link. * @param $prefix String: Optional prefix + * @return string */ static function makeBrokenLinkObj( $title, $text = '', $query = '', $trail = '', $prefix = '' ) { + wfDeprecated( __METHOD__, '1.16' ); + wfProfileIn( __METHOD__ ); list( $inside, $trail ) = self::splitTrail( $trail ); @@ -1929,23 +2018,6 @@ class Linker { return $ret; } - /** - * @deprecated since 1.16 Use link() - * - * Make a brown link to a short article. - * - * @param $nt Title object of the target page - * @param $text String: link text - * @param $query String: optional query part - * @param $trail String: optional trail. Alphabetic characters at the start of this string will - * be included in the link text. Other characters will be appended after - * the end of the link. - * @param $prefix String: Optional prefix - */ - static function makeStubLinkObj( $nt, $text = '', $query = '', $trail = '', $prefix = '' ) { - return self::makeColouredLinkObj( $nt, 'stub', $text, $query, $trail, $prefix ); - } - /** * @deprecated since 1.16 Use link() * @@ -1959,8 +2031,11 @@ class Linker { * be included in the link text. Other characters will be appended after * the end of the link. * @param $prefix String: Optional prefix + * @return string */ static function makeColouredLinkObj( $nt, $colour, $text = '', $query = '', $trail = '', $prefix = '' ) { + wfDeprecated( __METHOD__, '1.16' ); + if ( $colour != '' ) { $style = self::getInternalLinkAttributesObj( $nt, $text, $colour ); } else { @@ -1969,65 +2044,12 @@ class Linker { return self::makeKnownLinkObj( $nt, $text, $query, $trail, $prefix, '', $style ); } - /** Obsolete alias */ - static function makeImage( $url, $alt = '' ) { - wfDeprecated( __METHOD__ ); - return self::makeExternalImage( $url, $alt ); - } - - /** - * Creates the HTML source for images - * @deprecated since 1.16 use makeImageLink2 - * - * @param $title Title object - * @param $label String: label text - * @param $alt String: alt text - * @param $align String: horizontal alignment: none, left, center, right) - * @param $handlerParams Array: parameters to be passed to the media handler - * @param $framed Boolean: shows image in original size in a frame - * @param $thumb Boolean: shows image as thumbnail in a frame - * @param $manualthumb String: image name for the manual thumbnail - * @param $valign String: vertical alignment: baseline, sub, super, top, text-top, middle, bottom, text-bottom - * @param $time String: timestamp of the file, set as false for current - * @return String - */ - static function makeImageLinkObj( $title, $label, $alt, $align = '', $handlerParams = array(), - $framed = false, $thumb = false, $manualthumb = '', $valign = '', $time = false ) - { - $frameParams = array( 'alt' => $alt, 'caption' => $label ); - if ( $align ) { - $frameParams['align'] = $align; - } - if ( $framed ) { - $frameParams['framed'] = true; - } - if ( $thumb ) { - $frameParams['thumbnail'] = true; - } - if ( $manualthumb ) { - $frameParams['manualthumb'] = $manualthumb; - } - if ( $valign ) { - $frameParams['valign'] = $valign; - } - $file = wfFindFile( $title, array( 'time' => $time ) ); - return self::makeImageLink2( $title, $file, $frameParams, $handlerParams, $time ); - } - - /** @deprecated use Linker::makeMediaLinkObj() */ - static function makeMediaLink( $name, $unused = '', $text = '', $time = false ) { - $nt = Title::makeTitleSafe( NS_FILE, $name ); - return self::makeMediaLinkObj( $nt, $text, $time ); - } - /** * Returns the attributes for the tooltip and access key. + * @return array */ public static function tooltipAndAccesskeyAttribs( $name ) { - global $wgEnableTooltipsAndAccesskeys; - if ( !$wgEnableTooltipsAndAccesskeys ) - return array(); - # FIXME: If Sanitizer::expandAttributes() treated "false" as "output + # @todo FIXME: If Sanitizer::expandAttributes() treated "false" as "output # no attribute" instead of "output '' as value for attribute", this # would be three lines. $attribs = array( @@ -2044,22 +2066,11 @@ class Linker { } /** - * @deprecated since 1.14 - * Returns raw bits of HTML, use titleAttrib() and accesskey() - */ - public static function tooltipAndAccesskey( $name ) { - return Xml::expandAttributes( self::tooltipAndAccesskeyAttribs( $name ) ); - } - - /** - * @deprecated since 1.14 * Returns raw bits of HTML, use titleAttrib() + * @return null|string */ public static function tooltip( $name, $options = null ) { - global $wgEnableTooltipsAndAccesskeys; - if ( !$wgEnableTooltipsAndAccesskeys ) - return ''; - # FIXME: If Sanitizer::expandAttributes() treated "false" as "output + # @todo FIXME: If Sanitizer::expandAttributes() treated "false" as "output # no attribute" instead of "output '' as value for attribute", this # would be two lines. $tooltip = self::titleAttrib( $name, $options ); @@ -2067,23 +2078,25 @@ class Linker { return ''; } return Xml::expandAttributes( array( - 'title' => self::titleAttrib( $name, $options ) + 'title' => $tooltip ) ); } } +/** + * @since 1.18 + */ class DummyLinker { - + /** * Use PHP's magic __call handler to transform instance calls to a dummy instance * into static calls to the new Linker for backwards compatibility. * * @param $fname String Name of called method * @param $args Array Arguments to the method + * @return mixed */ - function __call( $fname, $args ) { + public function __call( $fname, $args ) { return call_user_func_array( array( 'Linker', $fname ), $args ); } - } -