diff options
author | Pierre Schmitz <pierre@archlinux.de> | 2013-01-18 16:46:04 +0100 |
---|---|---|
committer | Pierre Schmitz <pierre@archlinux.de> | 2013-01-18 16:46:04 +0100 |
commit | 63601400e476c6cf43d985f3e7b9864681695ed4 (patch) | |
tree | f7846203a952e38aaf66989d0a4702779f549962 /includes/Linker.php | |
parent | 8ff01378c9e0207f9169b81966a51def645b6a51 (diff) |
Update to MediaWiki 1.20.2
this update includes:
* adjusted Arch Linux skin
* updated FluxBBAuthPlugin
* patch for https://bugzilla.wikimedia.org/show_bug.cgi?id=44024
Diffstat (limited to 'includes/Linker.php')
-rw-r--r-- | includes/Linker.php | 415 |
1 files changed, 301 insertions, 114 deletions
diff --git a/includes/Linker.php b/includes/Linker.php index 575f2841..56626bd7 100644 --- a/includes/Linker.php +++ b/includes/Linker.php @@ -1,5 +1,26 @@ <?php /** + * Methods to make links and related items. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * http://www.gnu.org/copyleft/gpl.html + * + * @file + */ + +/** * Some internal bits split of from Skin.php. These functions are used * for primarily page content: links, embedded images, table of contents. Links * are also used in the skin. @@ -20,6 +41,7 @@ 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'. + * @return string * @deprecated since 1.18 Just pass the external class directly to something using Html::expandAttributes */ static function getExternalLinkAttributes( $class = 'external' ) { @@ -36,6 +58,7 @@ 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; @@ -57,6 +80,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 ); @@ -73,6 +97,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 ) { @@ -114,9 +139,9 @@ class Linker { if ( $t->isRedirect() ) { # Page is a redirect $colour = 'mw-redirect'; - } elseif ( $threshold > 0 && - $t->exists() && $t->getLength() < $threshold && - $t->isContentPage() ) { + } elseif ( $threshold > 0 && $t->isContentPage() && + $t->exists() && $t->getLength() < $threshold + ) { # Page is a stub $colour = 'stub'; } @@ -173,6 +198,12 @@ class Linker { wfProfileOut( __METHOD__ ); return "<!-- ERROR -->$html"; } + + if( is_string( $query ) ) { + // some functions withing core using this still hand over query strings + wfDeprecated( __METHOD__ . ' with parameter $query as string (should be array)', '1.20' ); + $query = wfCgiToArray( $query ); + } $options = (array)$options; $dummy = new DummyLinker; // dummy linker instance for bc on the hooks @@ -229,6 +260,7 @@ class Linker { /** * Identical to link(), except $options defaults to 'known'. + * @return string */ public static function linkKnown( $target, $html = null, $customAttribs = array(), @@ -243,6 +275,7 @@ class Linker { * @param $target Title * @param $query Array: query parameters * @param $options Array + * @return String */ private static function linkUrl( $target, $query, $options ) { wfProfileIn( __METHOD__ ); @@ -312,7 +345,7 @@ class Linker { } elseif ( in_array( 'known', $options ) ) { $defaults['title'] = $target->getPrefixedText(); } else { - $defaults['title'] = wfMsg( 'red-link-title', $target->getPrefixedText() ); + $defaults['title'] = wfMessage( 'red-link-title', $target->getPrefixedText() )->text(); } # Finally, merge the custom attribs with the default ones, and iterate @@ -380,6 +413,11 @@ class Linker { * despite $query not being used. * * @param $nt Title + * @param $html String [optional] + * @param $query String [optional] + * @param $trail String [optional] + * @param $prefix String [optional] + * * * @return string */ @@ -392,6 +430,31 @@ class Linker { } /** + * Get a message saying that an invalid title was encountered. + * This should be called after a method like Title::makeTitleSafe() returned + * a value indicating that the title object is invalid. + * + * @param $context IContextSource context to use to get the messages + * @param $namespace int Namespace number + * @param $title string Text of the title, without the namespace part + */ + public static function getInvalidTitleDescription( IContextSource $context, $namespace, $title ) { + global $wgContLang; + + // First we check whether the namespace exists or not. + if ( MWNamespace::exists( $namespace ) ) { + if ( $namespace == NS_MAIN ) { + $name = $context->msg( 'blanknamespace' )->text(); + } else { + $name = $wgContLang->getFormattedNsText( $namespace ); + } + return $context->msg( 'invalidtitle-knownnamespace', $namespace, $name, $title )->text(); + } else { + return $context->msg( 'invalidtitle-unknownnamespace', $namespace, $title )->text(); + } + } + + /** * @param $title Title * @return Title */ @@ -456,7 +519,8 @@ class Linker { * Given parameters derived from [[Image:Foo|options...]], generate the * HTML that that syntax inserts in the page. * - * @param $title Title object + * @param $parser Parser object + * @param $title Title object of the file (not the currently viewed page) * @param $file File object, or false if it doesn't exist * @param $frameParams Array: associative array of parameters external to the media handler. * Boolean parameters are indicated by presence or absence, the value is arbitrary and @@ -472,6 +536,7 @@ class Linker { * valign Vertical alignment (baseline, sub, super, top, text-top, middle, * bottom, text-bottom) * alt Alternate text for image (i.e. alt attribute). Plain text. + * class HTML for image classes. Plain text. * caption HTML for image caption. * link-url URL to link to * link-title Title object to link to @@ -483,9 +548,10 @@ class Linker { * @param $time String: timestamp of the file, set as false for current * @param $query String: query params for desc url * @param $widthOption: Used by the parser to remember the user preference thumbnailsize + * @since 1.20 * @return String: HTML for an image, with links, wrappers, etc. */ - public static function makeImageLink2( Title $title, $file, $frameParams = array(), + public static function makeImageLink( /*Parser*/ $parser, Title $title, $file, $frameParams = array(), $handlerParams = array(), $time = false, $query = "", $widthOption = null ) { $res = null; @@ -515,6 +581,9 @@ class Linker { if ( !isset( $fp['title'] ) ) { $fp['title'] = ''; } + if ( !isset( $fp['class'] ) ) { + $fp['class'] = ''; + } $prefix = $postfix = ''; @@ -558,16 +627,20 @@ class Linker { } if ( isset( $fp['thumbnail'] ) || isset( $fp['manualthumb'] ) || isset( $fp['framed'] ) ) { - global $wgContLang; - # Create a thumbnail. Alignment depends on language - # writing direction, # right aligned for left-to-right- - # languages ("Western languages"), left-aligned - # for right-to-left-languages ("Semitic languages") + # Create a thumbnail. Alignment depends on the writing direction of + # the page content language (right-aligned for LTR languages, + # left-aligned for RTL languages) # - # If thumbnail width has not been provided, it is set + # If a thumbnail width has not been provided, it is set # to the default user option as specified in Language*.php if ( $fp['align'] == '' ) { - $fp['align'] = $wgContLang->alignEnd(); + if( $parser instanceof Parser ) { + $fp['align'] = $parser->getTargetLanguage()->alignEnd(); + } else { + # backwards compatibility, remove with makeImageLink2() + global $wgContLang; + $fp['align'] = $wgContLang->alignEnd(); + } } return $prefix . self::makeThumbLink2( $title, $file, $fp, $hp, $time, $query ) . $postfix; } @@ -594,9 +667,12 @@ class Linker { $params = array( 'alt' => $fp['alt'], 'title' => $fp['title'], - 'valign' => isset( $fp['valign'] ) ? $fp['valign'] : false , - 'img-class' => isset( $fp['border'] ) ? 'thumbborder' : false ); - $params = self::getImageLinkMTOParams( $fp, $query ) + $params; + 'valign' => isset( $fp['valign'] ) ? $fp['valign'] : false, + 'img-class' => $fp['class'] ); + if ( isset( $fp['border'] ) ) { + $params['img-class'] .= ( $params['img-class'] !== '' ) ? ' thumbborder' : 'thumbborder'; + } + $params = self::getImageLinkMTOParams( $fp, $query, $parser ) + $params; $s = $thumb->toHtml( $params ); } @@ -607,18 +683,37 @@ class Linker { } /** + * See makeImageLink() + * When this function is removed, remove if( $parser instanceof Parser ) check there too + * @deprecated since 1.20 + */ + public static function makeImageLink2( Title $title, $file, $frameParams = array(), + $handlerParams = array(), $time = false, $query = "", $widthOption = null ) { + return self::makeImageLink( null, $title, $file, $frameParams, + $handlerParams, $time, $query, $widthOption ); + } + + /** * 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 */ - private static function getImageLinkMTOParams( $frameParams, $query = '' ) { + private static function getImageLinkMTOParams( $frameParams, $query = '', $parser = null ) { $mtoParams = array(); if ( isset( $frameParams['link-url'] ) && $frameParams['link-url'] !== '' ) { $mtoParams['custom-url-link'] = $frameParams['link-url']; if ( isset( $frameParams['link-target'] ) ) { $mtoParams['custom-target-link'] = $frameParams['link-target']; } + if ( $parser ) { + $extLinkAttrs = $parser->getExternalLinkAttribs( $frameParams['link-url'] ); + foreach ( $extLinkAttrs as $name => $val ) { + // Currently could include 'rel' and 'target' + $mtoParams['parser-extlink-'.$name] = $val; + } + } } elseif ( isset( $frameParams['link-title'] ) && $frameParams['link-title'] !== '' ) { $mtoParams['custom-title-link'] = self::normaliseSpecialPage( $frameParams['link-title'] ); } elseif ( !empty( $frameParams['no-link'] ) ) { @@ -640,6 +735,7 @@ class Linker { * @param $params Array * @param $framed Boolean * @param $manualthumb String + * @return mixed */ public static function makeThumbLinkObj( Title $title, $file, $label = '', $alt, $align = 'right', $params = array(), $framed = false , $manualthumb = "" ) @@ -736,13 +832,14 @@ class Linker { $s .= self::makeBrokenImageLinkObj( $title, $fp['title'], '', '', '', $time == true ); $zoomIcon = ''; } elseif ( !$thumb ) { - $s .= htmlspecialchars( wfMsg( 'thumbnail_error', '' ) ); + $s .= wfMessage( 'thumbnail_error', '' )->escaped(); $zoomIcon = ''; } else { $params = array( 'alt' => $fp['alt'], 'title' => $fp['title'], - 'img-class' => 'thumbimage' ); + 'img-class' => ( isset( $fp['class'] ) && $fp['class'] !== '' ) ? $fp['class'] . ' thumbimage' : 'thumbimage' + ); $params = self::getImageLinkMTOParams( $fp, $query ) + $params; $s .= $thumb->toHtml( $params ); if ( isset( $fp['framed'] ) ) { @@ -752,7 +849,7 @@ class Linker { Html::rawElement( 'a', array( 'href' => $url, 'class' => 'internal', - 'title' => wfMsg( 'thumbnail-more' ) ), + 'title' => wfMessage( 'thumbnail-more' )->text() ), Html::element( 'img', array( 'src' => $wgStylePath . '/common/images/magnify-clip' . ( $wgContLang->isRTL() ? '-rtl' : '' ) . '.png', 'width' => 15, @@ -848,7 +945,7 @@ class Linker { * This will make a broken link if $file is false. * * @param $title Title object. - * @param $file File|false mixed File object or false + * @param $file File|bool mixed File object or false * @param $html String: pre-sanitized HTML * @return String: HTML * @@ -882,7 +979,7 @@ class Linker { $key = strtolower( $name ); } - return self::linkKnown( SpecialPage::getTitleFor( $name ) , wfMsg( $key ) ); + return self::linkKnown( SpecialPage::getTitleFor( $name ) , wfMessage( $key )->text() ); } /** @@ -892,6 +989,7 @@ 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 <a> + * @return string */ public static function makeExternalLink( $url, $text, $escape = true, $linktype = '', $attribs = array() ) { $class = "external"; @@ -923,7 +1021,7 @@ class Linker { * @param $userName String: user name in database. * @param $altUserName String: text to display instead of the user name (optional) * @return String: HTML fragment - * @since 1.19 Method exists for a long time. $displayText was added in 1.19. + * @since 1.19 Method exists for a long time. $altUserName was added in 1.19. */ public static function userLink( $userId, $userName, $altUserName = false ) { if ( $userId == 0 ) { @@ -973,7 +1071,7 @@ class Linker { } $contribsPage = SpecialPage::getTitleFor( 'Contributions', $userText ); - $items[] = self::link( $contribsPage, wfMsgHtml( 'contribslink' ), $attribs ); + $items[] = self::link( $contribsPage, wfMessage( 'contribslink' )->escaped(), $attribs ); } if ( $blockable && $wgUser->isAllowed( 'block' ) ) { $items[] = self::blockLink( $userId, $userText ); @@ -986,7 +1084,10 @@ class Linker { wfRunHooks( 'UserToolLinksEdit', array( $userId, $userText, &$items ) ); if ( $items ) { - return ' <span class="mw-usertoollinks">(' . $wgLang->pipeList( $items ) . ')</span>'; + return wfMessage( 'word-separator' )->plain() + . '<span class="mw-usertoollinks">' + . wfMessage( 'parentheses' )->rawParams( $wgLang->pipeList( $items ) )->escaped() + . '</span>'; } else { return ''; } @@ -997,6 +1098,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 ); @@ -1010,7 +1112,7 @@ class Linker { */ public static function userTalkLink( $userId, $userText ) { $userTalkPage = Title::makeTitle( NS_USER_TALK, $userText ); - $userTalkLink = self::link( $userTalkPage, wfMsgHtml( 'talkpagelinktext' ) ); + $userTalkLink = self::link( $userTalkPage, wfMessage( 'talkpagelinktext' )->escaped() ); return $userTalkLink; } @@ -1021,7 +1123,7 @@ class Linker { */ public static function blockLink( $userId, $userText ) { $blockPage = SpecialPage::getTitleFor( 'Block', $userText ); - $blockLink = self::link( $blockPage, wfMsgHtml( 'blocklink' ) ); + $blockLink = self::link( $blockPage, wfMessage( 'blocklink' )->escaped() ); return $blockLink; } @@ -1032,7 +1134,7 @@ class Linker { */ public static function emailLink( $userId, $userText ) { $emailPage = SpecialPage::getTitleFor( 'Emailuser', $userText ); - $emailLink = self::link( $emailPage, wfMsgHtml( 'emaillink' ) ); + $emailLink = self::link( $emailPage, wfMessage( 'emaillink' )->escaped() ); return $emailLink; } @@ -1044,12 +1146,12 @@ class Linker { */ public static function revUserLink( $rev, $isPublic = false ) { if ( $rev->isDeleted( Revision::DELETED_USER ) && $isPublic ) { - $link = wfMsgHtml( 'rev-deleted-user' ); + $link = wfMessage( 'rev-deleted-user' )->escaped(); } elseif ( $rev->userCan( Revision::DELETED_USER ) ) { $link = self::userLink( $rev->getUser( Revision::FOR_THIS_USER ), $rev->getUserText( Revision::FOR_THIS_USER ) ); } else { - $link = wfMsgHtml( 'rev-deleted-user' ); + $link = wfMessage( 'rev-deleted-user' )->escaped(); } if ( $rev->isDeleted( Revision::DELETED_USER ) ) { return '<span class="history-deleted">' . $link . '</span>'; @@ -1065,14 +1167,15 @@ class Linker { */ public static function revUserTools( $rev, $isPublic = false ) { if ( $rev->isDeleted( Revision::DELETED_USER ) && $isPublic ) { - $link = wfMsgHtml( 'rev-deleted-user' ); + $link = wfMessage( 'rev-deleted-user' )->escaped(); } 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 ) . - ' ' . self::userToolLinks( $userId, $userText ); + $link = self::userLink( $userId, $userText ) + . wfMessage( 'word-separator' )->plain() + . self::userToolLinks( $userId, $userText ); } else { - $link = wfMsgHtml( 'rev-deleted-user' ); + $link = wfMessage( 'rev-deleted-user' )->escaped(); } if ( $rev->isDeleted( Revision::DELETED_USER ) ) { return ' <span class="history-deleted">' . $link . '</span>'; @@ -1095,6 +1198,7 @@ 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 */ public static function formatComment( $comment, $title = null, $local = false ) { wfProfileIn( __METHOD__ ); @@ -1126,7 +1230,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 */ @@ -1155,41 +1259,45 @@ class Linker { $pre = $match[1]; $auto = $match[2]; $post = $match[3]; - $link = ''; - if ( $title ) { - $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 = Sanitizer::normalizeSectionNameWhitespace( $section ); # bug 22784 - if ( $local ) { - $sectionTitle = Title::newFromText( '#' . $section ); - } else { - $sectionTitle = Title::makeTitleSafe( $title->getNamespace(), - $title->getDBkey(), $section ); + $comment = null; + wfRunHooks( 'FormatAutocomments', array( &$comment, $pre, $auto, $post, $title, $local ) ); + if ( $comment === null ) { + $link = ''; + if ( $title ) { + $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 = Sanitizer::normalizeSectionNameWhitespace( $section ); # bug 22784 + if ( $local ) { + $sectionTitle = Title::newFromText( '#' . $section ); + } else { + $sectionTitle = Title::makeTitleSafe( $title->getNamespace(), + $title->getDBkey(), $section ); + } + if ( $sectionTitle ) { + $link = self::link( $sectionTitle, + $wgLang->getArrow(), array(), array(), + 'noclasses' ); + } else { + $link = ''; + } } - if ( $sectionTitle ) { - $link = self::link( $sectionTitle, - $wgLang->getArrow(), array(), array(), - 'noclasses' ); - } else { - $link = ''; + if ( $pre ) { + # written summary $presep autocomment (summary /* section */) + $pre .= wfMessage( 'autocomment-prefix' )->inContentLanguage()->escaped(); } + if ( $post ) { + # autocomment $postsep written summary (/* section */ summary) + $auto .= wfMessage( 'colon-separator' )->inContentLanguage()->escaped(); + } + $auto = '<span class="autocomment">' . $auto . '</span>'; + $comment = $pre . $link . $wgLang->getDirMark() . '<span dir="auto">' . $auto . $post . '</span>'; } - if ( $pre ) { - # written summary $presep autocomment (summary /* section */) - $pre .= wfMsgExt( 'autocomment-prefix', array( 'escapenoentities', 'content' ) ); - } - if ( $post ) { - # autocomment $postsep written summary (/* section */ summary) - $auto .= wfMsgExt( 'colon-separator', array( 'escapenoentities', 'content' ) ); - } - $auto = '<span class="autocomment">' . $auto . '</span>'; - $comment = $pre . $link . $wgLang->getDirMark() . '<span dir="auto">' . $auto . $post . '</span>'; return $comment; } @@ -1205,7 +1313,7 @@ class Linker { * * @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 */ @@ -1399,7 +1507,8 @@ class Linker { return ''; } else { $formatted = self::formatComment( $comment, $title, $local ); - return " <span class=\"comment\" dir=\"auto\">($formatted)</span>"; + $formatted = wfMessage( 'parentheses' )->rawParams( $formatted )->escaped(); + return " <span class=\"comment\">$formatted</span>"; } } @@ -1417,12 +1526,12 @@ class Linker { return ""; } if ( $rev->isDeleted( Revision::DELETED_COMMENT ) && $isPublic ) { - $block = " <span class=\"comment\">" . wfMsgHtml( 'rev-deleted-comment' ) . "</span>"; + $block = " <span class=\"comment\">" . wfMessage( 'rev-deleted-comment' )->escaped() . "</span>"; } elseif ( $rev->userCan( Revision::DELETED_COMMENT ) ) { $block = self::commentBlock( $rev->getComment( Revision::FOR_THIS_USER ), $rev->getTitle(), $local ); } else { - $block = " <span class=\"comment\">" . wfMsgHtml( 'rev-deleted-comment' ) . "</span>"; + $block = " <span class=\"comment\">" . wfMessage( 'rev-deleted-comment' )->escaped() . "</span>"; } if ( $rev->isDeleted( Revision::DELETED_COMMENT ) ) { return " <span class=\"history-deleted\">$block</span>"; @@ -1436,13 +1545,11 @@ class Linker { */ public static function formatRevisionSize( $size ) { if ( $size == 0 ) { - $stxt = wfMsgExt( 'historyempty', 'parsemag' ); + $stxt = wfMessage( 'historyempty' )->escaped(); } else { - global $wgLang; - $stxt = wfMsgExt( 'nbytes', 'parsemag', $wgLang->formatNum( $size ) ); - $stxt = "($stxt)"; + $stxt = wfMessage( 'nbytes' )->numParams( $size )->escaped(); + $stxt = wfMessage( 'parentheses' )->rawParams( $stxt )->escaped(); } - $stxt = htmlspecialchars( $stxt ); return "<span class=\"history-size\">$stxt</span>"; } @@ -1484,6 +1591,7 @@ 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 */ public static function tocLineEnd() { return "</li>\n"; @@ -1493,11 +1601,13 @@ class Linker { * Wraps the TOC in a table and provides the hide/collapse javascript. * * @param $toc String: html of the Table Of Contents - * @param $lang mixed: Language code for the toc title + * @param $lang String|Language|false: Language for the toc title, defaults to user language * @return String: full html of the TOC */ public static function tocList( $toc, $lang = false ) { - $title = wfMsgExt( 'toc', array( 'language' => $lang, 'escape' ) ); + $lang = wfGetLangObj( $lang ); + $title = wfMessage( 'toc' )->inLanguage( $lang )->escaped(); + return '<table id="toc" class="toc"><tr><td>' . '<div id="toctitle"><h2>' . $title . "</h2></div>\n" @@ -1509,7 +1619,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 ) { @@ -1562,6 +1672,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; @@ -1589,38 +1700,102 @@ class Linker { * other users. * * @param $rev Revision object + * @param $context IContextSource context to use or null for the main context. + * @return string */ - public static function generateRollback( $rev ) { - return '<span class="mw-rollback-link">[' - . self::buildRollbackLink( $rev ) - . ']</span>'; + public static function generateRollback( $rev, IContextSource $context = null ) { + if ( $context === null ) { + $context = RequestContext::getMain(); + } + + return '<span class="mw-rollback-link">' + . $context->msg( 'brackets' )->rawParams( + self::buildRollbackLink( $rev, $context ) )->plain() + . '</span>'; } /** * Build a raw rollback link, useful for collections of "tool" links * * @param $rev Revision object + * @param $context IContextSource context to use or null for the main context. * @return String: HTML fragment */ - public static function buildRollbackLink( $rev ) { - global $wgRequest, $wgUser; + public static function buildRollbackLink( $rev, IContextSource $context = null ) { + global $wgShowRollbackEditCount, $wgMiserMode; + + // To config which pages are effected by miser mode + $disableRollbackEditCountSpecialPage = array( 'Recentchanges', 'Watchlist' ); + + if ( $context === null ) { + $context = RequestContext::getMain(); + } + $title = $rev->getTitle(); $query = array( 'action' => 'rollback', 'from' => $rev->getUserText(), - 'token' => $wgUser->getEditToken( array( $title->getPrefixedText(), $rev->getUserText() ) ), + 'token' => $context->getUser()->getEditToken( array( $title->getPrefixedText(), $rev->getUserText() ) ), ); - if ( $wgRequest->getBool( 'bot' ) ) { + if ( $context->getRequest()->getBool( 'bot' ) ) { $query['bot'] = '1'; $query['hidediff'] = '1'; // bug 15999 } - return self::link( - $title, - wfMsgHtml( 'rollbacklink' ), - array( 'title' => wfMsg( 'tooltip-rollback' ) ), - $query, - array( 'known', 'noclasses' ) - ); + + $disableRollbackEditCount = false; + if( $wgMiserMode ) { + foreach( $disableRollbackEditCountSpecialPage as $specialPage ) { + if( $context->getTitle()->isSpecial( $specialPage ) ) { + $disableRollbackEditCount = true; + break; + } + } + } + + if( !$disableRollbackEditCount && is_int( $wgShowRollbackEditCount ) && $wgShowRollbackEditCount > 0 ) { + $dbr = wfGetDB( DB_SLAVE ); + + // Up to the value of $wgShowRollbackEditCount revisions are counted + $res = $dbr->select( 'revision', + array( 'rev_id', 'rev_user_text' ), + // $rev->getPage() returns null sometimes + array( 'rev_page' => $rev->getTitle()->getArticleID() ), + __METHOD__, + array( 'USE INDEX' => 'page_timestamp', + 'ORDER BY' => 'rev_timestamp DESC', + 'LIMIT' => $wgShowRollbackEditCount + 1 ) + ); + + $editCount = 0; + while( $row = $dbr->fetchObject( $res ) ) { + if( $rev->getUserText() != $row->rev_user_text ) { + break; + } + $editCount++; + } + + if( $editCount > $wgShowRollbackEditCount ) { + $editCount_output = $context->msg( 'rollbacklinkcount-morethan' )->numParams( $wgShowRollbackEditCount )->parse(); + } else { + $editCount_output = $context->msg( 'rollbacklinkcount' )->numParams( $editCount )->parse(); + } + + return self::link( + $title, + $editCount_output, + array( 'title' => $context->msg( 'tooltip-rollback' )->text() ), + $query, + array( 'known', 'noclasses' ) + ); + } else { + return self::link( + $title, + $context->msg( 'rollbacklink' )->escaped(), + array( 'title' => $context->msg( 'tooltip-rollback' )->text() ), + $query, + array( 'known', 'noclasses' ) + ); + } } /** @@ -1647,35 +1822,38 @@ class Linker { # Construct the HTML $outText = '<div class="mw-templatesUsedExplanation">'; if ( $preview ) { - $outText .= wfMsgExt( 'templatesusedpreview', array( 'parse' ), count( $templates ) ); + $outText .= wfMessage( 'templatesusedpreview' )->numParams( count( $templates ) ) + ->parseAsBlock(); } elseif ( $section ) { - $outText .= wfMsgExt( 'templatesusedsection', array( 'parse' ), count( $templates ) ); + $outText .= wfMessage( 'templatesusedsection' )->numParams( count( $templates ) ) + ->parseAsBlock(); } else { - $outText .= wfMsgExt( 'templatesused', array( 'parse' ), count( $templates ) ); + $outText .= wfMessage( 'templatesused' )->numParams( count( $templates ) ) + ->parseAsBlock(); } $outText .= "</div><ul>\n"; - usort( $templates, array( 'Title', 'compare' ) ); + usort( $templates, 'Title::compare' ); foreach ( $templates as $titleObj ) { $r = $titleObj->getRestrictions( 'edit' ); if ( in_array( 'sysop', $r ) ) { - $protected = wfMsgExt( 'template-protected', array( 'parseinline' ) ); + $protected = wfMessage( 'template-protected' )->parse(); } elseif ( in_array( 'autoconfirmed', $r ) ) { - $protected = wfMsgExt( 'template-semiprotected', array( 'parseinline' ) ); + $protected = wfMessage( 'template-semiprotected' )->parse(); } else { $protected = ''; } if ( $titleObj->quickUserCan( 'edit' ) ) { $editLink = self::link( $titleObj, - wfMsg( 'editlink' ), + wfMessage( 'editlink' )->text(), array(), array( 'action' => 'edit' ) ); } else { $editLink = self::link( $titleObj, - wfMsg( 'viewsourcelink' ), + wfMessage( 'viewsourcelink' )->text(), array(), array( 'action' => 'edit' ) ); @@ -1696,14 +1874,13 @@ class Linker { * @return String: HTML output */ public static function formatHiddenCategories( $hiddencats ) { - global $wgLang; wfProfileIn( __METHOD__ ); $outText = ''; if ( count( $hiddencats ) > 0 ) { # Construct the HTML $outText = '<div class="mw-hiddenCategoriesExplanation">'; - $outText .= wfMsgExt( 'hiddencategories', array( 'parse' ), $wgLang->formatnum( count( $hiddencats ) ) ); + $outText .= wfMessage( 'hiddencategories' )->numParams( count( $hiddencats ) )->parseAsBlock(); $outText .= "</div><ul>\n"; foreach ( $hiddencats as $titleObj ) { @@ -1719,7 +1896,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 ) { @@ -1855,18 +2032,19 @@ class Linker { * Creates a (show/hide) link for deleting revisions/log entries * * @param $query Array: query parameters to be passed to link() - * @param $restricted Boolean: set to true to use a <strong> instead of a <span> + * @param $restricted Boolean: set to true to use a "<strong>" instead of a "<span>" * @param $delete Boolean: set to true to use (show/hide) rather than (show) * - * @return String: HTML <a> link to Special:Revisiondelete, wrapped in a + * @return String: HTML "<a>" link to Special:Revisiondelete, wrapped in a * span to allow for customization of appearance with CSS */ public static function revDeleteLink( $query = array(), $restricted = false, $delete = true ) { $sp = SpecialPage::getTitleFor( 'Revisiondelete' ); - $html = $delete ? wfMsgHtml( 'rev-delundel' ) : wfMsgHtml( 'rev-showdeleted' ); + $msgKey = $delete ? 'rev-delundel' : 'rev-showdeleted'; + $html = wfMessage( $msgKey )->escaped(); $tag = $restricted ? 'strong' : 'span'; $link = self::link( $sp, $html, array(), $query, array( 'known', 'noclasses' ) ); - return Xml::tags( $tag, array( 'class' => 'mw-revdelundel-link' ), "($link)" ); + return Xml::tags( $tag, array( 'class' => 'mw-revdelundel-link' ), wfMessage( 'parentheses' )->rawParams( $link )->escaped() ); } /** @@ -1878,8 +2056,10 @@ class Linker { * of appearance with CSS */ public static function revDeleteLinkDisabled( $delete = true ) { - $html = $delete ? wfMsgHtml( 'rev-delundel' ) : wfMsgHtml( 'rev-showdeleted' ); - return Xml::tags( 'span', array( 'class' => 'mw-revdelundel-link' ), "($html)" ); + $msgKey = $delete ? 'rev-delundel' : 'rev-showdeleted'; + $html = wfMessage( $msgKey )->escaped(); + $htmlParentheses = wfMessage( 'parentheses' )->rawParams( $html )->escaped(); + return Xml::tags( 'span', array( 'class' => 'mw-revdelundel-link' ), $htmlParentheses ); } /* Deprecated methods */ @@ -1896,6 +2076,7 @@ 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' ); @@ -1924,6 +2105,7 @@ 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. @@ -1955,7 +2137,7 @@ 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 = '' @@ -1993,6 +2175,7 @@ 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' ); @@ -2024,6 +2207,7 @@ 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' ); @@ -2038,6 +2222,7 @@ class Linker { /** * Returns the attributes for the tooltip and access key. + * @return array */ public static function tooltipAndAccesskeyAttribs( $name ) { # @todo FIXME: If Sanitizer::expandAttributes() treated "false" as "output @@ -2058,6 +2243,7 @@ class Linker { /** * Returns raw bits of HTML, use titleAttrib() + * @return null|string */ public static function tooltip( $name, $options = null ) { # @todo FIXME: If Sanitizer::expandAttributes() treated "false" as "output @@ -2084,6 +2270,7 @@ class DummyLinker { * * @param $fname String Name of called method * @param $args Array Arguments to the method + * @return mixed */ public function __call( $fname, $args ) { return call_user_func_array( array( 'Linker', $fname ), $args ); |