X-Git-Url: http://git.cyclocoop.org/?a=blobdiff_plain;f=includes%2FLinker.php;h=4ba3a755a3f597cf94c980db59409fc7bd0865f6;hb=d7bad7704f67dc887a77e4de7581931b7915d04b;hp=f0a2963cbb296a651d9035aa9524e057bd87ec95;hpb=46fdbb4c0ee144300e0cf277fde286136aea674d;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/Linker.php b/includes/Linker.php index f0a2963cbb..4ba3a755a3 100644 --- a/includes/Linker.php +++ b/includes/Linker.php @@ -192,7 +192,7 @@ class Linker { * @return string HTML attribute */ public static function link( - $target, $html = null, $customAttribs = array(), $query = array(), $options = array() + $target, $html = null, $customAttribs = [], $query = [], $options = [] ) { if ( !$target instanceof Title ) { wfWarn( __METHOD__ . ': Requires $target to be a Title object.', 2 ); @@ -210,7 +210,7 @@ class Linker { $ret = null; if ( !Hooks::run( 'LinkBegin', - array( $dummy, $target, &$html, &$customAttribs, &$query, &$options, &$ret ) ) + [ $dummy, $target, &$html, &$customAttribs, &$query, &$options, &$ret ] ) ) { return $ret; } @@ -227,14 +227,14 @@ class Linker { } } - $oldquery = array(); + $oldquery = []; if ( in_array( "forcearticlepath", $options, true ) && $query ) { $oldquery = $query; - $query = array(); + $query = []; } # Note: we want the href attribute first, for prettiness. - $attribs = array( 'href' => self::linkUrl( $target, $query, $options ) ); + $attribs = [ 'href' => self::linkUrl( $target, $query, $options ) ]; if ( in_array( 'forcearticlepath', $options, true ) && $oldquery ) { $attribs['href'] = wfAppendQuery( $attribs['href'], $oldquery ); } @@ -248,7 +248,7 @@ class Linker { } $ret = null; - if ( Hooks::run( 'LinkEnd', array( $dummy, $target, $options, &$html, &$attribs, &$ret ) ) ) { + if ( Hooks::run( 'LinkEnd', [ $dummy, $target, $options, &$html, &$attribs, &$ret ] ) ) { $ret = Html::rawElement( 'a', $attribs, $html ); } @@ -261,8 +261,8 @@ class Linker { * @return string */ public static function linkKnown( - $target, $html = null, $customAttribs = array(), - $query = array(), $options = array( 'known', 'noclasses' ) + $target, $html = null, $customAttribs = [], + $query = [], $options = [ 'known', 'noclasses' ] ) { return self::link( $target, $html, $customAttribs, $query, $options ); } @@ -315,11 +315,11 @@ class Linker { */ private static function linkAttribs( $target, $attribs, $options ) { global $wgUser; - $defaults = array(); + $defaults = []; if ( !in_array( 'noclasses', $options, true ) ) { # Now build the classes. - $classes = array(); + $classes = []; if ( in_array( 'broken', $options, true ) ) { $classes[] = 'new'; @@ -338,7 +338,7 @@ class Linker { $classes[] = $colour; # mw-redirect or stub } } - if ( $classes != array() ) { + if ( $classes != [] ) { $defaults['class'] = implode( ' ', $classes ); } } @@ -358,7 +358,7 @@ class Linker { # Finally, merge the custom attribs with the default ones, and iterate # over that, deleting all "false" attributes. - $ret = array(); + $ret = []; $merged = Sanitizer::mergeAttributes( $defaults, $attribs ); foreach ( $merged as $key => $val ) { # A false value suppresses the attribute, and we don't want the @@ -407,7 +407,7 @@ class Linker { */ public static function makeSelfLinkObj( $nt, $html = '', $query = '', $trail = '', $prefix = '' ) { $ret = "{$prefix}{$html}{$trail}"; - if ( !Hooks::run( 'SelfLinkBegin', array( $nt, &$html, &$trail, &$prefix, &$ret ) ) ) { + if ( !Hooks::run( 'SelfLinkBegin', [ $nt, &$html, &$trail, &$prefix, &$ret ] ) ) { return $ret; } @@ -493,16 +493,16 @@ class Linker { $alt = self::fnamePart( $url ); } $img = ''; - $success = Hooks::run( 'LinkerMakeExternalImage', array( &$url, &$alt, &$img ) ); + $success = Hooks::run( 'LinkerMakeExternalImage', [ &$url, &$alt, &$img ] ); if ( !$success ) { wfDebug( "Hook LinkerMakeExternalImage changed the output of external image " . "with url {$url} and alt text {$alt} to {$img}\n", true ); return $img; } return Html::element( 'img', - array( + [ 'src' => $url, - 'alt' => $alt ) ); + 'alt' => $alt ] ); } /** @@ -542,13 +542,13 @@ class Linker { * @return string HTML for an image, with links, wrappers, etc. */ public static function makeImageLink( Parser $parser, Title $title, - $file, $frameParams = array(), $handlerParams = array(), $time = false, + $file, $frameParams = [], $handlerParams = [], $time = false, $query = "", $widthOption = null ) { $res = null; $dummy = new DummyLinker; - if ( !Hooks::run( 'ImageBeforeProduceHTML', array( &$dummy, &$title, - &$file, &$frameParams, &$handlerParams, &$time, &$res ) ) ) { + if ( !Hooks::run( 'ImageBeforeProduceHTML', [ &$dummy, &$title, + &$file, &$frameParams, &$handlerParams, &$time, &$res ] ) ) { return $res; } @@ -659,11 +659,11 @@ class Linker { $s = self::makeBrokenImageLinkObj( $title, $fp['title'], '', '', '', $time == true ); } else { self::processResponsiveImages( $file, $thumb, $hp ); - $params = array( + $params = [ 'alt' => $fp['alt'], 'title' => $fp['title'], 'valign' => isset( $fp['valign'] ) ? $fp['valign'] : false, - 'img-class' => $fp['class'] ); + 'img-class' => $fp['class'] ]; if ( isset( $fp['border'] ) ) { $params['img-class'] .= ( $params['img-class'] !== '' ? ' ' : '' ) . 'thumbborder'; } @@ -686,7 +686,7 @@ class Linker { * @return array */ private static function getImageLinkMTOParams( $frameParams, $query = '', $parser = null ) { - $mtoParams = array(); + $mtoParams = []; if ( isset( $frameParams['link-url'] ) && $frameParams['link-url'] !== '' ) { $mtoParams['custom-url-link'] = $frameParams['link-url']; if ( isset( $frameParams['link-target'] ) ) { @@ -723,13 +723,13 @@ class Linker { * @return string */ public static function makeThumbLinkObj( Title $title, $file, $label = '', $alt, - $align = 'right', $params = array(), $framed = false, $manualthumb = "" + $align = 'right', $params = [], $framed = false, $manualthumb = "" ) { - $frameParams = array( + $frameParams = [ 'alt' => $alt, 'caption' => $label, 'align' => $align - ); + ]; if ( $framed ) { $frameParams['framed'] = true; } @@ -748,8 +748,8 @@ class Linker { * @param string $query * @return string */ - public static function makeThumbLink2( Title $title, $file, $frameParams = array(), - $handlerParams = array(), $time = false, $query = "" + public static function makeThumbLink2( Title $title, $file, $frameParams = [], + $handlerParams = [], $time = false, $query = "" ) { $exists = $file && $file->exists(); @@ -820,7 +820,7 @@ class Linker { # zoom icon still needs it, so we make a unique query for it. See bug 14771 $url = $title->getLocalURL( $query ); if ( $page ) { - $url = wfAppendQuery( $url, array( 'page' => $page ) ); + $url = wfAppendQuery( $url, [ 'page' => $page ] ); } if ( $manualthumb && !isset( $fp['link-title'] ) @@ -842,23 +842,23 @@ class Linker { if ( !$noscale && !$manualthumb ) { self::processResponsiveImages( $file, $thumb, $hp ); } - $params = array( + $params = [ 'alt' => $fp['alt'], 'title' => $fp['title'], 'img-class' => ( isset( $fp['class'] ) && $fp['class'] !== '' ? $fp['class'] . ' ' : '' ) . 'thumbimage' - ); + ]; $params = self::getImageLinkMTOParams( $fp, $query ) + $params; $s .= $thumb->toHtml( $params ); if ( isset( $fp['framed'] ) ) { $zoomIcon = ""; } else { - $zoomIcon = Html::rawElement( 'div', array( 'class' => 'magnify' ), - Html::rawElement( 'a', array( + $zoomIcon = Html::rawElement( 'div', [ 'class' => 'magnify' ], + Html::rawElement( 'a', [ 'href' => $url, 'class' => 'internal', - 'title' => wfMessage( 'thumbnail-more' )->text() ), + 'title' => wfMessage( 'thumbnail-more' )->text() ], "" ) ); } } @@ -929,7 +929,7 @@ class Linker { $redir = RepoGroup::singleton()->getLocalRepo()->checkRedirect( $title ); if ( $redir ) { - return self::linkKnown( $title, $encLabel, array(), wfCgiToArray( $query ) ); + return self::linkKnown( $title, $encLabel, [], wfCgiToArray( $query ) ); } $href = self::getUploadUrl( $title, $query ); @@ -939,7 +939,7 @@ class Linker { $encLabel . ''; } - return self::linkKnown( $title, $encLabel, array(), wfCgiToArray( $query ) ); + return self::linkKnown( $title, $encLabel, [], wfCgiToArray( $query ) ); } /** @@ -975,7 +975,7 @@ class Linker { * @return string HTML */ public static function makeMediaLinkObj( $title, $html = '', $time = false ) { - $img = wfFindFile( $title, array( 'time' => $time ) ); + $img = wfFindFile( $title, [ 'time' => $time ] ); return self::makeMediaLinkFile( $title, $img, $html ); } @@ -992,7 +992,7 @@ class Linker { */ public static function makeMediaLinkFile( Title $title, $file, $html = '' ) { if ( $file && $file->exists() ) { - $url = $file->getURL(); + $url = $file->getUrl(); $class = 'internal'; } else { $url = self::getUploadUrl( $title ); @@ -1005,14 +1005,14 @@ class Linker { } $ret = ''; - $attribs = array( + $attribs = [ 'href' => $url, 'class' => $class, 'title' => $alt - ); + ]; if ( !Hooks::run( 'LinkerMakeMediaLinkFile', - array( $title, $file, &$html, &$attribs, &$ret ) ) ) { + [ $title, $file, &$html, &$attribs, &$ret ] ) ) { wfDebug( "Hook LinkerMakeMediaLinkFile changed the output of link " . "with url {$url} and text {$html} to {$ret}\n", true ); return $ret; @@ -1049,7 +1049,7 @@ class Linker { * @return string */ public static function makeExternalLink( $url, $text, $escape = true, - $linktype = '', $attribs = array(), $title = null + $linktype = '', $attribs = [], $title = null ) { global $wgTitle; $class = "external"; @@ -1071,7 +1071,7 @@ class Linker { $attribs['rel'] = Parser::getExternalLinkRel( $url, $title ); $link = ''; $success = Hooks::run( 'LinkerMakeExternalLink', - array( &$url, &$text, &$link, &$attribs, $linktype ) ); + [ &$url, &$text, &$link, &$attribs, $linktype ] ); if ( !$success ) { wfDebug( "Hook LinkerMakeExternalLink changed the output of link " . "with url {$url} and text {$text} to {$link}\n", true ); @@ -1104,7 +1104,7 @@ class Linker { return self::link( $page, htmlspecialchars( $altUserName !== false ? $altUserName : $userName ), - array( 'class' => $classes ) + [ 'class' => $classes ] ); } @@ -1128,13 +1128,13 @@ class Linker { $blockable = !( $flags & self::TOOL_LINKS_NOBLOCK ); $addEmailLink = $flags & self::TOOL_LINKS_EMAIL && $userId; - $items = array(); + $items = []; if ( $talkable ) { $items[] = self::userTalkLink( $userId, $userText ); } if ( $userId ) { // check if the user has an edit - $attribs = array(); + $attribs = []; if ( $redContribsWhenNoEdits ) { if ( intval( $edits ) === 0 && $edits !== 0 ) { $user = User::newFromId( $userId ); @@ -1156,7 +1156,7 @@ class Linker { $items[] = self::emailLink( $userId, $userText ); } - Hooks::run( 'UserToolLinksEdit', array( $userId, $userText, &$items ) ); + Hooks::run( 'UserToolLinksEdit', [ $userId, $userText, &$items ] ); if ( $items ) { return wfMessage( 'word-separator' )->escaped() @@ -1329,7 +1329,7 @@ class Linker { global $wgLang; // Ensure all match positions are defined - $match += array( '', '', '', '' ); + $match += [ '', '', '', '' ]; $pre = $match[1] !== ''; $auto = $match[2]; @@ -1338,7 +1338,7 @@ class Linker { Hooks::run( 'FormatAutocomments', - array( &$comment, $pre, $auto, $post, $title, $local, $wikiId ) + [ &$comment, $pre, $auto, $post, $title, $local, $wikiId ] ); if ( $comment === null ) { @@ -1428,7 +1428,7 @@ class Linker { if ( strpos( $match[1], '%' ) !== false ) { $match[1] = strtr( rawurldecode( $match[1] ), - array( '<' => '<', '>' => '>' ) + [ '<' => '<', '>' => '>' ] ); } @@ -1438,7 +1438,7 @@ class Linker { } else { $text = $match[1]; } - $submatch = array(); + $submatch = []; $thelink = null; if ( preg_match( '/^' . $medians . '(.*)$/i', $match[1], $submatch ) ) { # Media link; trail not supported. @@ -1449,31 +1449,34 @@ class Linker { } } else { # Other kind of link - if ( preg_match( $wgContLang->linkTrail(), $match[3], $submatch ) ) { - $trail = $submatch[1]; - } else { - $trail = ""; - } - $linkRegexp = '/\[\[(.*?)\]\]' . preg_quote( $trail, '/' ) . '/'; + # Make sure its target is non-empty if ( isset( $match[1][0] ) && $match[1][0] == ':' ) { $match[1] = substr( $match[1], 1 ); } - list( $inside, $trail ) = Linker::splitTrail( $trail ); - - $linkText = $text; - $linkTarget = Linker::normalizeSubpageLink( $title, $match[1], $linkText ); - - $target = Title::newFromText( $linkTarget ); - if ( $target ) { - if ( $target->getText() == '' && !$target->isExternal() - && !$local && $title - ) { - $newTarget = clone $title; - $newTarget->setFragment( '#' . $target->getFragment() ); - $target = $newTarget; + if ( $match[1] !== false && $match[1] !== '' ) { + if ( preg_match( $wgContLang->linkTrail(), $match[3], $submatch ) ) { + $trail = $submatch[1]; + } else { + $trail = ""; } + $linkRegexp = '/\[\[(.*?)\]\]' . preg_quote( $trail, '/' ) . '/'; + list( $inside, $trail ) = Linker::splitTrail( $trail ); + + $linkText = $text; + $linkTarget = Linker::normalizeSubpageLink( $title, $match[1], $linkText ); + + $target = Title::newFromText( $linkTarget ); + if ( $target ) { + if ( $target->getText() == '' && !$target->isExternal() + && !$local && $title + ) { + $newTarget = clone $title; + $newTarget->setFragment( '#' . $target->getFragment() ); + $target = $newTarget; + } - $thelink = Linker::makeCommentLink( $target, $linkText . $inside, $wikiId ) . $trail; + $thelink = Linker::makeCommentLink( $target, $linkText . $inside, $wikiId ) . $trail; + } } } if ( $thelink ) { @@ -1506,7 +1509,7 @@ class Linker { * @return string HTML link */ public static function makeCommentLink( - Title $title, $text, $wikiId = null, $options = array() + Title $title, $text, $wikiId = null, $options = [] ) { if ( $wikiId !== null && !$title->isExternal() ) { $link = Linker::makeExternalLink( @@ -1519,7 +1522,7 @@ class Linker { /* escape = */ false // Already escaped ); } else { - $link = Linker::link( $title, $text, array(), array(), $options ); + $link = Linker::link( $title, $text, [], [], $options ); } return $link; @@ -1560,7 +1563,7 @@ class Linker { # Look at the first character if ( $target != '' && $target[0] === '/' ) { # / at end means we don't want the slash to be shown - $m = array(); + $m = []; $trailingSlashes = preg_match_all( '%(/+)$%', $target, $m ); if ( $trailingSlashes ) { $noslash = $target = substr( $target, 1, -strlen( $m[0][0] ) ); @@ -1807,13 +1810,13 @@ class Linker { $regex = $wgContLang->linkTrail(); $inside = ''; if ( $trail !== '' ) { - $m = array(); + $m = []; if ( preg_match( $regex, $trail, $m ) ) { $inside = $m[1]; $trail = $m[2]; } } - return array( $inside, $trail ); + return [ $inside, $trail ]; } /** @@ -1842,7 +1845,7 @@ class Linker { * @return string */ public static function generateRollback( $rev, IContextSource $context = null, - $options = array( 'verify' ) + $options = [ 'verify' ] ) { if ( $context === null ) { $context = RequestContext::getMain(); @@ -1892,15 +1895,15 @@ class Linker { // Up to the value of $wgShowRollbackEditCount revisions are counted $res = $dbr->select( 'revision', - array( 'rev_user_text', 'rev_deleted' ), + [ 'rev_user_text', 'rev_deleted' ], // $rev->getPage() returns null sometimes - array( 'rev_page' => $rev->getTitle()->getArticleID() ), + [ 'rev_page' => $rev->getTitle()->getArticleID() ], __METHOD__, - array( - 'USE INDEX' => array( 'revision' => 'page_timestamp' ), + [ + 'USE INDEX' => [ 'revision' => 'page_timestamp' ], 'ORDER BY' => 'rev_timestamp DESC', 'LIMIT' => $wgShowRollbackEditCount + 1 - ) + ] ); $editCount = 0; @@ -1945,21 +1948,21 @@ class Linker { global $wgShowRollbackEditCount, $wgMiserMode; // To config which pages are affected by miser mode - $disableRollbackEditCountSpecialPage = array( 'Recentchanges', 'Watchlist' ); + $disableRollbackEditCountSpecialPage = [ 'Recentchanges', 'Watchlist' ]; if ( $context === null ) { $context = RequestContext::getMain(); } $title = $rev->getTitle(); - $query = array( + $query = [ 'action' => 'rollback', 'from' => $rev->getUserText(), - 'token' => $context->getUser()->getEditToken( array( + 'token' => $context->getUser()->getEditToken( [ $title->getPrefixedText(), $rev->getUserText() - ) ), - ); + ] ), + ]; if ( $context->getRequest()->getBool( 'bot' ) ) { $query['bot'] = '1'; $query['hidediff'] = '1'; // bug 15999 @@ -1993,17 +1996,17 @@ class Linker { return self::link( $title, $editCount_output, - array( 'title' => $context->msg( 'tooltip-rollback' )->text() ), + [ 'title' => $context->msg( 'tooltip-rollback' )->text() ], $query, - array( 'known', 'noclasses' ) + [ 'known', 'noclasses' ] ); } else { return self::link( $title, $context->msg( 'rollbacklink' )->escaped(), - array( 'title' => $context->msg( 'tooltip-rollback' )->text() ), + [ 'title' => $context->msg( 'tooltip-rollback' )->text() ], $query, - array( 'known', 'noclasses' ) + [ 'known', 'noclasses' ] ); } } @@ -2058,9 +2061,9 @@ class Linker { if ( $restrictions ) { // Check backwards-compatible messages $msg = null; - if ( $restrictions === array( 'sysop' ) ) { + if ( $restrictions === [ 'sysop' ] ) { $msg = wfMessage( 'template-protected' ); - } elseif ( $restrictions === array( 'autoconfirmed' ) ) { + } elseif ( $restrictions === [ 'autoconfirmed' ] ) { $msg = wfMessage( 'template-semiprotected' ); } if ( $msg && !$msg->isDisabled() ) { @@ -2068,7 +2071,7 @@ class Linker { } else { // Construct the message from restriction-level-* // e.g. restriction-level-sysop, restriction-level-autoconfirmed - $msgs = array(); + $msgs = []; foreach ( $restrictions as $r ) { $msgs[] = wfMessage( "restriction-level-$r" )->parse(); } @@ -2080,15 +2083,15 @@ class Linker { $editLink = self::link( $titleObj, wfMessage( 'editlink' )->escaped(), - array(), - array( 'action' => 'edit' ) + [], + [ 'action' => 'edit' ] ); } else { $editLink = self::link( $titleObj, wfMessage( 'viewsourcelink' )->escaped(), - array(), - array( 'action' => 'edit' ) + [], + [ 'action' => 'edit' ] ); } $outText .= '
  • ' . self::link( $titleObj ) @@ -2128,7 +2131,7 @@ class Linker { foreach ( $hiddencats as $titleObj ) { # If it's hidden, it must exist - no need to check with a LinkBatch $outText .= '
  • ' - . self::link( $titleObj, null, array(), array(), 'known' ) + . self::link( $titleObj, null, [], [], 'known' ) . "
  • \n"; } $outText .= ''; @@ -2162,7 +2165,7 @@ class Linker { * @return string Contents of the title attribute (which you must HTML- * escape), or false for no title attribute */ - public static function titleAttrib( $name, $options = null, array $msgParams = array() ) { + public static function titleAttrib( $name, $options = null, array $msgParams = [] ) { $message = wfMessage( "tooltip-$name", $msgParams ); if ( !$message->exists() ) { $tooltip = false; @@ -2252,19 +2255,19 @@ class Linker { if ( $rev->getId() ) { // RevDelete links using revision ID are stable across // page deletion and undeletion; use when possible. - $query = array( + $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 = array( + $query = [ 'type' => 'archive', 'target' => $title->getPrefixedDBkey(), 'ids' => $rev->getTimestamp() - ); + ]; } return Linker::revDeleteLink( $query, $rev->isDeleted( Revision::DELETED_RESTRICTED ), $canHide ); @@ -2281,15 +2284,15 @@ class Linker { * @return string HTML "" 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 ) { + public static function revDeleteLink( $query = [], $restricted = false, $delete = true ) { $sp = SpecialPage::getTitleFor( 'Revisiondelete' ); $msgKey = $delete ? 'rev-delundel' : 'rev-showdeleted'; $html = wfMessage( $msgKey )->escaped(); $tag = $restricted ? 'strong' : 'span'; - $link = self::link( $sp, $html, array(), $query, array( 'known', 'noclasses' ) ); + $link = self::link( $sp, $html, [], $query, [ 'known', 'noclasses' ] ); return Xml::tags( $tag, - array( 'class' => 'mw-revdelundel-link' ), + [ 'class' => 'mw-revdelundel-link' ], wfMessage( 'parentheses' )->rawParams( $link )->escaped() ); } @@ -2306,7 +2309,7 @@ class Linker { $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 ); + return Xml::tags( 'span', [ 'class' => 'mw-revdelundel-link' ], $htmlParentheses ); } /* Deprecated methods */ @@ -2319,14 +2322,14 @@ class Linker { * * @return array */ - public static function tooltipAndAccesskeyAttribs( $name, array $msgParams = array() ) { + public static function tooltipAndAccesskeyAttribs( $name, array $msgParams = [] ) { # @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( + $attribs = [ 'title' => self::titleAttrib( $name, 'withaccess', $msgParams ), 'accesskey' => self::accesskey( $name ) - ); + ]; if ( $attribs['title'] === false ) { unset( $attribs['title'] ); } @@ -2350,9 +2353,9 @@ class Linker { if ( $tooltip === false ) { return ''; } - return Xml::expandAttributes( array( + return Xml::expandAttributes( [ 'title' => $tooltip - ) ); + ] ); } } @@ -2371,6 +2374,6 @@ class DummyLinker { * @return mixed */ public function __call( $fname, $args ) { - return call_user_func_array( array( 'Linker', $fname ), $args ); + return call_user_func_array( [ 'Linker', $fname ], $args ); } }