X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FLinker.php;h=1578bd7b3abad14c87455a9614acf3272467292a;hb=f3ed84491e44ed936351e90963794fe931be7447;hp=dd899fec7ba830980fcb16351ecfd115ae7b1a58;hpb=e9f4e3858797133e782d0248f10af5af1e0981e1;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/Linker.php b/includes/Linker.php index dd899fec7b..1578bd7b3a 100644 --- a/includes/Linker.php +++ b/includes/Linker.php @@ -166,6 +166,8 @@ class Linker { * "stub", "mw-redirect", "extiw"). Only use the class attribute * provided, if any, so you get a simple blue link with no funny i- * cons. + * 'forcearticlepath': Use the article path always, even with a querystring. + * Has compatibility issues on some setups, so avoid wherever possible. * @return string HTML attribute */ public function link( $target, $text = null, $customAttribs = array(), $query = array(), $options = array() ) { @@ -188,15 +190,7 @@ class Linker { # If we don't know whether the page exists, let's find out. wfProfileIn( __METHOD__ . '-checkPageExistence' ); if( !in_array( 'known', $options ) and !in_array( 'broken', $options ) ) { - if( $target->getNamespace() == NS_SPECIAL ) { - if( SpecialPage::exists( $target->getDbKey() ) ) { - $options []= 'known'; - } else { - $options []= 'broken'; - } - } elseif( $target->isAlwaysKnown() or - ($target->getPrefixedText() == '' and $target->getFragment() != '') - or $target->exists() ) { + if( $target->isKnown() ) { $options []= 'known'; } else { $options []= 'broken'; @@ -204,8 +198,18 @@ class Linker { } wfProfileOut( __METHOD__ . '-checkPageExistence' ); + $oldquery = array(); + if( in_array( "forcearticlepath", $options ) && $query ){ + $oldquery = $query; + $query = array(); + } + # Note: we want the href attribute first, for prettiness. $attribs = array( 'href' => $this->linkUrl( $target, $query, $options ) ); + if( in_array( 'forcearticlepath', $options ) && $oldquery ){ + $attribs['href'] = wfAppendQuery( $attribs['href'], wfArrayToCgi( $oldquery ) ); + } + $attribs = array_merge( $attribs, $this->linkAttribs( $target, $customAttribs, $options ) @@ -215,17 +219,21 @@ class Linker { } $ret = null; - if( wfRunHooks( 'LinkEnd', array( $this, $target, $options, &$text, - &$attribs, &$ret ) ) ) { - $ret = Xml::openElement( 'a', $attribs ) - . $text - . Xml::closeElement( 'a' ); + if( wfRunHooks( 'LinkEnd', array( $this, $target, $options, &$text, &$attribs, &$ret ) ) ) { + $ret = Xml::openElement( 'a', $attribs ) . $text . Xml::closeElement( 'a' ); } wfProfileOut( __METHOD__ ); return $ret; } + /** + * Identical to link(), except $options defaults to 'known'. + */ + public function linkKnown( $target, $text = null, $customAttribs = array(), $query = array(), $options = 'known' ) { + return $this->link( $target, $text, $customAttribs, $query, $options ); + } + private function linkUrl( $target, $query, $options ) { wfProfileIn( __METHOD__ ); # We don't want to include fragments for broken links, because they @@ -267,7 +275,7 @@ class Linker { } # Note that redirects never count as stubs here. - if ( $target->isRedirect() ) { + if ( !in_array( 'broken', $options ) && $target->isRedirect() ) { $classes[] = 'mw-redirect'; } elseif( $target->isContentPage() ) { # Check for stub. @@ -283,7 +291,10 @@ class Linker { } # Get a default title attribute. - if( in_array( 'known', $options ) ) { + if( $target->getPrefixedText() == '' ) { + # A link like [[#Foo]]. This used to mean an empty title + # attribute, but that's silly. Just don't output a title. + } elseif( in_array( 'known', $options ) ) { $defaults['title'] = $target->getPrefixedText(); } else { $defaults['title'] = wfMsg( 'red-link-title', $target->getPrefixedText() ); @@ -432,7 +443,6 @@ class Linker { * @param $prefix String: optional prefix. As trail, only before instead of after. */ function makeLinkObj( $nt, $text= '', $query = '', $trail = '', $prefix = '' ) { - global $wgUser; wfProfileIn( __METHOD__ ); $query = wfCgiToArray( $query ); @@ -617,7 +627,7 @@ class Linker { $img = ''; $success = wfRunHooks('LinkerMakeExternalImage', array( &$url, &$alt, &$img ) ); if(!$success) { - wfDebug("Hook LinkerMakeExternalImage changed the output of external image with url {$url} and alt text {$alt} to {$img}", true); + wfDebug("Hook LinkerMakeExternalImage changed the output of external image with url {$url} and alt text {$alt} to {$img}\n", true); return $img; } return Xml::element( 'img', @@ -687,6 +697,9 @@ class Linker { * bottom, text-bottom) * alt Alternate text for image (i.e. alt attribute). Plain text. * caption HTML for image caption. + * link-url URL to link to + * link-title Title object to link to + * no-link Boolean, suppress description link * * @param array $handlerParams Associative array of media handler parameters, to be passed * to transform(). Typical keys are "width" and "page". @@ -715,11 +728,12 @@ class Linker { $page = isset( $hp['page'] ) ? $hp['page'] : false; if ( !isset( $fp['align'] ) ) $fp['align'] = ''; if ( !isset( $fp['alt'] ) ) $fp['alt'] = ''; + # Backward compatibility, title used to always be equal to alt text + if ( !isset( $fp['title'] ) ) $fp['title'] = $fp['alt']; $prefix = $postfix = ''; - if ( 'center' == $fp['align'] ) - { + if ( 'center' == $fp['align'] ) { $prefix = '
'; $postfix = '
'; $fp['align'] = 'none'; @@ -750,7 +764,6 @@ class Linker { } if ( isset( $fp['thumbnail'] ) || isset( $fp['manualthumb'] ) || isset( $fp['framed'] ) ) { - # Create a thumbnail. Alignment depends on language # writing direction, # right aligned for left-to-right- # languages ("Western languages"), left-aligned @@ -783,15 +796,26 @@ class Linker { if ( !$thumb ) { $s = $this->makeBrokenImageLinkObj( $title, '', '', '', '', $time==true ); } else { - $s = $thumb->toHtml( array( - 'desc-link' => true, - 'desc-query' => $query, + $params = array( 'alt' => $fp['alt'], + 'title' => $fp['title'], 'valign' => isset( $fp['valign'] ) ? $fp['valign'] : false , - 'img-class' => isset( $fp['border'] ) ? 'thumbborder' : false ) ); + 'img-class' => isset( $fp['border'] ) ? 'thumbborder' : false ); + if ( !empty( $fp['link-url'] ) ) { + $params['custom-url-link'] = $fp['link-url']; + } elseif ( !empty( $fp['link-title'] ) ) { + $params['custom-title-link'] = $fp['link-title']; + } elseif ( !empty( $fp['no-link'] ) ) { + // No link + } else { + $params['desc-link'] = true; + $params['desc-query'] = $query; + } + + $s = $thumb->toHtml( $params ); } if ( '' != $fp['align'] ) { - $s = "
{$s}
"; + $s = "
{$s}
"; } return str_replace("\n", ' ',$prefix.$s.$postfix); } @@ -823,6 +847,8 @@ class Linker { $page = isset( $hp['page'] ) ? $hp['page'] : false; if ( !isset( $fp['align'] ) ) $fp['align'] = 'right'; if ( !isset( $fp['alt'] ) ) $fp['alt'] = ''; + # Backward compatibility, title used to always be equal to alt text + if ( !isset( $fp['title'] ) ) $fp['title'] = $fp['alt']; if ( !isset( $fp['caption'] ) ) $fp['caption'] = ''; if ( empty( $hp['width'] ) ) { @@ -836,7 +862,7 @@ class Linker { } else { if ( isset( $fp['manualthumb'] ) ) { # Use manually specified thumbnail - $manual_title = Title::makeTitleSafe( NS_IMAGE, $fp['manualthumb'] ); + $manual_title = Title::makeTitleSafe( NS_FILE, $fp['manualthumb'] ); if( $manual_title ) { $manual_img = wfFindFile( $manual_title ); if ( $manual_img ) { @@ -865,10 +891,13 @@ class Linker { } } - if( $page ) { - $query = $query ? '&page=' . urlencode( $page ) : 'page=' . urlencode( $page ); - } + # ThumbnailImage::toHtml() already adds page= onto the end of DjVu URLs + # So we don't need to pass it here in $query. However, the URL for the + # 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, 'page=' . urlencode( $page ) ); + } $more = htmlspecialchars( wfMsg( 'thumbnail-more' ) ); @@ -882,6 +911,7 @@ class Linker { } else { $s .= $thumb->toHtml( array( 'alt' => $fp['alt'], + 'title' => $fp['title'], 'img-class' => 'thumbimage', 'desc-link' => true, 'desc-query' => $query ) ); @@ -941,7 +971,7 @@ class Linker { /** @deprecated use Linker::makeMediaLinkObj() */ function makeMediaLink( $name, $unused = '', $text = '', $time = false ) { - $nt = Title::makeTitleSafe( NS_IMAGE, $name ); + $nt = Title::makeTitleSafe( NS_FILE, $name ); return $this->makeMediaLinkObj( $nt, $text, $time ); } @@ -989,22 +1019,37 @@ class Linker { wfMsg( $key ) ); } - /** @todo document */ + /** + * Make an external link + * @param String $url URL to link to + * @param String $text text of link + * @param boolean $escape Do we escape the link text? + * @param String $linktype Type of external link. Gets added to the classes + * @param array $attribs Array of extra attributes to
+ * + * @TODO! @FIXME! This is a really crappy implementation. $linktype and + * 'external' are mashed into the class attrib for the link (which is made + * into a string). Then, if we've got additional params in $attribs, we + * add to it. People using this might want to change the classes (or other + * default link attributes), but passing $attribsText is just messy. Would + * make a lot more sense to make put the classes into $attribs, let the + * hook play with them, *then* expand it all at once. + */ function makeExternalLink( $url, $text, $escape = true, $linktype = '', $attribs = array() ) { $attribsText = $this->getExternalLinkAttributes( $url, $text, 'external ' . $linktype ); - if ( $attribs ) { - $attribsText .= Xml::expandAttributes( $attribs ); - } $url = htmlspecialchars( $url ); if( $escape ) { $text = htmlspecialchars( $text ); } $link = ''; - $success = wfRunHooks('LinkerMakeExternalLink', array( &$url, &$text, &$link ) ); + $success = wfRunHooks('LinkerMakeExternalLink', array( &$url, &$text, &$link, &$attribs, $linktype ) ); if(!$success) { - wfDebug("Hook LinkerMakeExternalLink changed the output of link with url {$url} and text {$text} to {$link}", true); + wfDebug("Hook LinkerMakeExternalLink changed the output of link with url {$url} and text {$text} to {$link}\n", true); return $link; } + if ( $attribs ) { + $attribsText .= Xml::expandAttributes( $attribs ); + } return ''.$text.''; } @@ -1021,7 +1066,7 @@ class Linker { } else { $page = Title::makeTitle( NS_USER, $userText ); } - return $this->link( $page, htmlspecialchars( $userText ) ); + return $this->link( $page, htmlspecialchars( $userText ), array( 'class' => 'mw-userlink' ) ); } /** @@ -1035,7 +1080,7 @@ class Linker { * @return string */ public function userToolLinks( $userId, $userText, $redContribsWhenNoEdits = false, $flags = 0, $edits=null ) { - global $wgUser, $wgDisableAnonTalk, $wgSysopUserBans; + global $wgUser, $wgDisableAnonTalk, $wgSysopUserBans, $wgLang; $talkable = !( $wgDisableAnonTalk && 0 == $userId ); $blockable = ( $wgSysopUserBans || 0 == $userId ) && !$flags & self::TOOL_LINKS_NOBLOCK; @@ -1061,7 +1106,7 @@ class Linker { } if( $items ) { - return ' (' . implode( ' | ', $items ) . ')'; + return ' (' . $wgLang->pipeList( $items ) . ')'; } else { return ''; } @@ -1231,7 +1276,7 @@ class Linker { } if ( $sectionTitle ) { $link = $this->link( $sectionTitle, - wfMsgForContent( 'sectionlink' ), array(), array(), + htmlspecialchars( wfMsgForContent( 'sectionlink' ) ), array(), array(), 'noclasses' ); } else { $link = ''; @@ -1339,6 +1384,7 @@ class Linker { * @return string HTML */ 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 ) ) { @@ -1403,8 +1449,8 @@ class Linker { . "\n" . '\n"; @@ -1497,11 +1543,21 @@ class Linker { * @param string $anchor The anchor to give the headline (the bit after the #) * @param string $text The text of the header * @param string $link HTML to add for the section edit link + * @param mixed $legacyAnchor A second, optional anchor to give for + * backward compatibility (false to omit) * * @return string HTML headline */ - public function makeHeadline( $level, $attribs, $anchor, $text, $link ) { - return "$text"; + public function makeHeadline( $level, $attribs, $anchor, $text, $link, $legacyAnchor = false ) { + $ret = "" + . "$text" + . ""; + if ( $legacyAnchor !== false ) { + $ret = "$ret"; + } + return $ret; } /** @@ -1561,6 +1617,7 @@ class Linker { ); if( $wgRequest->getBool( 'bot' ) ) { $query['bot'] = '1'; + $query['hidediff'] = '1'; // bug 15999 } $query['token'] = $wgUser->editToken( array( $title->getPrefixedText(), $rev->getUserText() ) ); @@ -1578,12 +1635,9 @@ class Linker { * @param bool $section Whether this is for a section edit * @return string HTML output */ - public function formatTemplates( $templates, $preview = false, $section = false) { - global $wgUser; + public function formatTemplates( $templates, $preview = false, $section = false ) { wfProfileIn( __METHOD__ ); - $sk = $wgUser->getSkin(); - $outText = ''; if ( count( $templates ) > 0 ) { # Do a batch existence check @@ -1602,7 +1656,7 @@ class Linker { } else { $outText .= wfMsgExt( 'templatesused', array( 'parse' ) ); } - $outText .= '