$isbn: ISBN to show information for
$output: OutputPage object in use
-'BrokenLink': Before the HTML is created for a broken (i.e. red) link
-&$linker: Linker instance
-$nt: the page title
-$query: the URL query string passed in
-&$u: the URL of this link
-&$style: the inline CSS style
-&$prefix: a prefix prepended to the linked text
-&$text: the text placed by the user in the wiki-link
-&$inside: any additional alphanumeric characters placed after the wiki-link,
-that are made part of the link text
-&$trail: text placed immediately after the HTML link
-
'CategoryPageView': before viewing a categorypage in CategoryPage::view
$catpage: CategoryPage instance
$specialPageAliases: associative array of magic words synonyms
$lang: laguage code (string)
+'LinkBegin': Used when generating internal and interwiki links in
+Linker::link(), before processing starts. Return false to skip default proces-
+sing and return $ret. See documentation for Linker::link() for details on the
+expected meanings of parameters.
+$skin: the Skin object
+$target: the Title that the link is pointing to
+&$text: the contents that the <a> tag should have (raw HTML); null means "de-
+ fault"
+&$customAttribs: the HTML attributes that the <a> tag should have, in associa-
+ tive array form, with keys and values unescaped. Should be merged with de-
+ fault values, with a value of false meaning to suppress the attribute.
+&$query: the query string to add to the generated URL (the bit after the "?"),
+ in associative array form, with keys and values unescaped.
+&$options: the options. Can include 'known', 'broken', 'noclasses'.
+&$ret: the value to return if your hook returns false.
+
+'LinkEnd': Used when generating internal and interwiki links in Linker::link(),
+just before the function returns a value. If you return true, an <a> element
+with HTML attributes $attribs and contents $text will be returned. If you re-
+turn false, $ret will be returned.
+$skin: the Skin object
+$target: the Title object that the link is pointing to
+$options: the options. Will always include either 'known' or 'broken', and may
+ include 'noclasses'.
+&$text: the final (raw HTML) contents of the <a> tag, after processing.
+&$attribs: the final HTML attributes of the <a> tag, after processing, in asso-
+ ciative array form.
+&$ret: the value to return if your hook returns false.
+
'LinkerMakeExternalImage': At the end of Linker::makeExternalImage() just before the return
&$url: the image url
&$alt: the image's alt text
*/
public function link( $target, $text = null, $customAttribs = array(), $query = array(), $options = array() ) {
wfProfileIn( __METHOD__ );
+ $ret = null;
+ if( !wfRunHooks( 'LinkBegin', array( $this, $target, &$text,
+ &$customAttribs, &$query, &$options, &$ret ) ) ) {
+ wfProfileOut( __METHOD__ );
+ return $ret;
+ }
+
if( !$target instanceof Title ) {
throw new MWException( 'Linker::link passed invalid target' );
}
$text = $this->linkText( $target );
}
- $ret = Xml::openElement( 'a', $attribs )
- . $text
- . Xml::closeElement( 'a' );
+ $ret = null;
+ if( wfRunHooks( 'LinkEnd', array( $this, $target, $options, &$text,
+ &$attribs, &$ret ) ) ) {
+ $ret = Xml::openElement( 'a', $attribs )
+ . $text
+ . Xml::closeElement( 'a' );
+ }
wfProfileOut( __METHOD__ );
return $ret;
private function linkUrl( $target, $query, $options ) {
wfProfileIn( __METHOD__ );
+ # We don't want to include fragments for broken links, because they
+ # generally make no sense.
+ if( in_array( 'broken', $options ) and $target->mFragment !== '' ) {
+ $target = clone $target;
+ $target->mFragment = '';
+ }
+
# If it's a broken link, add the appropriate query pieces, unless
# there's already an action specified, or unless 'edit' makes no sense
# (i.e., for a nonexistent special page).
if( !in_array( 'noclasses', $options ) ) {
wfProfileIn( __METHOD__ . '-getClasses' );
- # Build the classes.
+ # Now build the classes.
$classes = array();
if( in_array( 'broken', $options ) ) {
}
/**
+ * @deprecated 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.
*
* the end of the link.
*/
function makeLink( $title, $text = '', $query = '', $trail = '' ) {
+ wfDeprecated( __METHOD__ );
wfProfileIn( __METHOD__ );
$nt = Title::newFromText( $title );
if ( $nt instanceof Title ) {
}
/**
+ * @deprecated 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.
*
* the end of the link.
*/
function makeKnownLink( $title, $text = '', $query = '', $trail = '', $prefix = '',$aprops = '') {
+ wfDeprecated( __METHOD__ );
$nt = Title::newFromText( $title );
if ( $nt instanceof Title ) {
return $this->makeKnownLinkObj( $nt, $text, $query, $trail, $prefix , $aprops );
}
/**
+ * @deprecated Use link()
+ *
* This function is a shortcut to makeBrokenLinkObj(Title::newFromText($title),...). Do not call
* it if you already have a title object handy. See makeBrokenLinkObj for further documentation.
*
* the end of the link.
*/
function makeBrokenLink( $title, $text = '', $query = '', $trail = '' ) {
+ wfDeprecated( __METHOD__ );
$nt = Title::newFromText( $title );
if ( $nt instanceof Title ) {
return $this->makeBrokenLinkObj( $nt, $text, $query, $trail );
}
/**
- * @deprecated use makeColouredLinkObj
+ * @deprecated 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.
* the end of the link.
*/
function makeStubLink( $title, $text = '', $query = '', $trail = '' ) {
+ wfDeprecated( __METHOD__ );
$nt = Title::newFromText( $title );
if ( $nt instanceof Title ) {
return $this->makeStubLinkObj( $nt, $text, $query, $trail );
}
/**
+ * @deprecated Use link()
+ *
* Make a link for a title which may or may not be in the database. If you need to
* call this lots of times, pre-fill the link cache with a LinkBatch, otherwise each
* call to this will result in a DB query.
* @param $prefix String: optional prefix. As trail, only before instead of after.
*/
function makeLinkObj( Title $nt, $text= '', $query = '', $trail = '', $prefix = '' ) {
+ wfDeprecated( __METHOD__ );
global $wgUser;
wfProfileIn( __METHOD__ );
- if ( $nt->isExternal() ) {
- $u = $nt->getFullURL();
- $link = $nt->getPrefixedURL();
- if ( '' == $text ) { $text = $nt->getPrefixedText(); }
- $style = $this->getInterwikiLinkAttributes( $link, $text, 'extiw' );
-
- $inside = '';
- if ( '' != $trail ) {
- $m = array();
- if ( preg_match( '/^([a-z]+)(.*)$$/sD', $trail, $m ) ) {
- $inside = $m[1];
- $trail = $m[2];
- }
- }
- $t = "<a href=\"{$u}\"{$style}>{$text}{$inside}</a>";
+ $query = wfCgiToArray( $query );
+ list( $inside, $trail ) = Linker::splitTrail( $trail );
+ if( $text === '' ) {
+ $text = $this->linkText( $nt );
+ }
- wfProfileOut( __METHOD__ );
- return $t;
- } elseif ( $nt->isAlwaysKnown() ) {
- # Image links, special page links and self-links with fragments are always known.
- $retVal = $this->makeKnownLinkObj( $nt, $text, $query, $trail, $prefix );
- } else {
- wfProfileIn( __METHOD__.'-immediate' );
+ $ret = $this->link( $nt, "$prefix$text$inside", array(), $query,
+ 'noclasses' ) . $trail;
- # Handles links to special pages which do not exist in the database:
- if( $nt->getNamespace() == NS_SPECIAL ) {
- if( SpecialPage::exists( $nt->getDBkey() ) ) {
- $retVal = $this->makeKnownLinkObj( $nt, $text, $query, $trail, $prefix );
- } else {
- $retVal = $this->makeBrokenLinkObj( $nt, $text, $query, $trail, $prefix );
- }
- wfProfileOut( __METHOD__.'-immediate' );
- wfProfileOut( __METHOD__ );
- return $retVal;
- }
-
- # Work out link colour immediately
- $aid = $nt->getArticleID() ;
- if ( 0 == $aid ) {
- $retVal = $this->makeBrokenLinkObj( $nt, $text, $query, $trail, $prefix );
- } else {
- $colour = '';
- if ( $nt->isContentPage() ) {
- $threshold = $wgUser->getOption('stubthreshold');
- $colour = $this->getLinkColour( $nt, $threshold );
- }
- $retVal = $this->makeColouredLinkObj( $nt, $colour, $text, $query, $trail, $prefix );
- }
- wfProfileOut( __METHOD__.'-immediate' );
- }
wfProfileOut( __METHOD__ );
- return $retVal;
+ return $ret;
}
/**
+ * @deprecated Use link()
+ *
* Make a link for a title which definitely exists. This is faster than makeLinkObj because
* it doesn't have to do a database query. It's also valid for interwiki titles and special
* pages.
* @return the a-element
*/
function makeKnownLinkObj( Title $title, $text = '', $query = '', $trail = '', $prefix = '' , $aprops = '', $style = '' ) {
+ wfDeprecated( __METHOD__ );
wfProfileIn( __METHOD__ );
- $nt = $this->normaliseSpecialPage( $title );
-
- $u = $nt->escapeLocalURL( $query );
- if ( $nt->getFragment() != '' ) {
- if( $nt->getPrefixedDbkey() == '' ) {
- $u = '';
- if ( '' == $text ) {
- $text = htmlspecialchars( $nt->getFragment() );
- }
- }
- $u .= $nt->getFragmentForURL();
- }
if ( $text == '' ) {
- $text = htmlspecialchars( $nt->getPrefixedText() );
- }
- if ( $style == '' ) {
- $style = $this->getInternalLinkAttributesObj( $nt, $text );
+ $text = $this->linkText( $title );
}
+ $attribs = Sanitizer::mergeAttributes(
+ Sanitizer::decodeTagAttributes( $aprops ),
+ Sanitizer::decodeTagAttributes( $style )
+ );
+ $query = wfCgiToArray( $query );
+ list( $inside, $trail ) = Linker::splitTrail( $trail );
- if ( $aprops !== '' ) $aprops = " $aprops";
+ $ret = $this->link( $title, "$prefix$text$inside", $attribs, $query,
+ array( 'known', 'noclasses' ) ) . $trail;
- list( $inside, $trail ) = Linker::splitTrail( $trail );
- $r = "<a href=\"{$u}\"{$style}{$aprops}>{$prefix}{$text}{$inside}</a>{$trail}";
wfProfileOut( __METHOD__ );
- return $r;
+ return $ret;
}
/**
+ * @deprecated Use link()
+ *
* Make a red link to the edit page of a given title.
*
* @param $nt Title object of the target page
* the end of the link.
*/
function makeBrokenLinkObj( Title $title, $text = '', $query = '', $trail = '', $prefix = '' ) {
+ wfDeprecated( __METHOD__ );
wfProfileIn( __METHOD__ );
- $nt = $this->normaliseSpecialPage( $title );
-
- if( $nt->getNamespace() == NS_SPECIAL ) {
- $q = $query;
- } else if ( '' == $query ) {
- $q = 'action=edit&redlink=1';
- } else {
- $q = 'action=edit&redlink=1&'.$query;
- }
- $u = $nt->escapeLocalURL( $q );
-
- $titleText = $nt->getPrefixedText();
- if ( '' == $text ) {
- $text = htmlspecialchars( $titleText );
- }
- $titleAttr = wfMsg( 'red-link-title', $titleText );
- $style = $this->getInternalLinkAttributesObj( $nt, $text, 'new', $titleAttr );
list( $inside, $trail ) = Linker::splitTrail( $trail );
+ if( $text === '' ) {
+ $text = $this->linkText( $title );
+ }
+ $nt = $this->normaliseSpecialPage( $title );
- wfRunHooks( 'BrokenLink', array( &$this, $nt, $query, &$u, &$style, &$prefix, &$text, &$inside, &$trail ) );
- $s = "<a href=\"{$u}\"{$style}>{$prefix}{$text}{$inside}</a>{$trail}";
+ $ret = $this->link( $title, "$prefix$text$inside", array(),
+ wfCgiToArray( $query ), 'broken' ) . $trail;
wfProfileOut( __METHOD__ );
- return $s;
+ return $ret;
}
/**
- * @deprecated use makeColouredLinkObj
+ * @deprecated Use link()
*
* Make a brown link to a short article.
*
}
/**
+ * @deprecated Use link()
+ *
* Make a coloured link.
*
* @param $nt Title object of the target page
* the end of the link.
*/
function makeColouredLinkObj( $nt, $colour, $text = '', $query = '', $trail = '', $prefix = '' ) {
+ wfDeprecated( __METHOD__ );
if($colour != ''){
$style = $this->getInternalLinkAttributesObj( $nt, $text, $colour );
} else $style = '';