From: Marius Hoch Date: Mon, 12 Nov 2012 22:52:43 +0000 (+0100) Subject: Implement static public Parser::getExternalLinkRel X-Git-Tag: 1.31.0-rc.0~21459^2 X-Git-Url: http://git.cyclocoop.org/%24href?a=commitdiff_plain;h=d067e090eaf5fe1059c80cac0d25b572253d7b1e;p=lhc%2Fweb%2Fwiklou.git Implement static public Parser::getExternalLinkRel I've implemented the function Parser::getExternalLinkRel which gives the 'rel' attribute for a given link in a given NS. Per Tim's suggestion, as it's currently impossible to invoke the logic in Parser::getExternalLinkAttribs externally. Change-Id: Id0bfed81e2afd6730d820b6c9a4a09155a557f37 --- diff --git a/includes/parser/Parser.php b/includes/parser/Parser.php index 9dad1e5be9..d9fcdf9d4a 100644 --- a/includes/parser/Parser.php +++ b/includes/parser/Parser.php @@ -1606,7 +1606,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 @@ -1619,13 +1637,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(); }