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 = '";
}
/**
* Finish one or more sublevels on the Table of Contents
+ *
+ * @return string
*/
- static function tocUnindent( $level ) {
+ public static function tocUnindent( $level ) {
return "\n" . str_repeat( "
\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
'
@@ -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 = " |