Merge "Implement static public Parser::getExternalLinkRel"
This commit is contained in:
commit
0a32a34775
1 changed files with 21 additions and 8 deletions
|
|
@ -1614,7 +1614,25 @@ class Parser {
|
|||
wfProfileOut( __METHOD__ );
|
||||
return $s;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the rel attribute for a particular external link.
|
||||
*
|
||||
* @since 1.21
|
||||
* @param $url String|bool optional URL, to extract the domain from for rel =>
|
||||
* nofollow if appropriate
|
||||
* @param $title Title optional Title, for wgNoFollowNsExceptions lookups
|
||||
* @return string|null rel attribute for $url
|
||||
*/
|
||||
public static function getExternalLinkRel( $url = false, $title = null ) {
|
||||
global $wgNoFollowLinks, $wgNoFollowNsExceptions, $wgNoFollowDomainExceptions;
|
||||
$ns = $title ? $title->getNamespace() : false;
|
||||
if ( $wgNoFollowLinks && !in_array( $ns, $wgNoFollowNsExceptions ) &&
|
||||
!wfMatchesDomainList( $url, $wgNoFollowDomainExceptions ) )
|
||||
{
|
||||
return 'nofollow';
|
||||
}
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
* Get an associative array of additional HTML attributes appropriate for a
|
||||
* particular external link. This currently may include rel => nofollow
|
||||
|
|
@ -1627,13 +1645,8 @@ class Parser {
|
|||
*/
|
||||
function getExternalLinkAttribs( $url = false ) {
|
||||
$attribs = array();
|
||||
global $wgNoFollowLinks, $wgNoFollowNsExceptions, $wgNoFollowDomainExceptions;
|
||||
$ns = $this->mTitle->getNamespace();
|
||||
if ( $wgNoFollowLinks && !in_array( $ns, $wgNoFollowNsExceptions ) &&
|
||||
!wfMatchesDomainList( $url, $wgNoFollowDomainExceptions ) )
|
||||
{
|
||||
$attribs['rel'] = 'nofollow';
|
||||
}
|
||||
$attribs['rel'] = self::getExternalLinkRel( $url, $this->mTitle );
|
||||
|
||||
if ( $this->mOptions->getExternalLinkTarget() ) {
|
||||
$attribs['target'] = $this->mOptions->getExternalLinkTarget();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue