Page MenuHomePhabricator

Allow disabling $wgNoFollowLinks is some namespaces
Closed, ResolvedPublic

Description

The attached patch adds a new config option, $wgNoFollowNsExceptions, which
allows disabling rel="nofollow" attributes from external links in some
namespaces while leaving them enabled in others. This allows, for example,
enabling rel="nofollow" only in talk pages, or everywhere outside the main
namespace.


Version: unspecified
Severity: enhancement

Event Timeline

bzimport raised the priority of this task from to Medium.Nov 21 2014, 9:11 PM
bzimport added a project: MediaWiki-Parser.
bzimport set Reference to bz5523.
bzimport added a subscriber: Unknown Object (MLST).

Patch against SVN HEAD to add the $wgNoFollowNsExceptions config option. Added default param

attachment wgNoFollowNsExceptions.diff ignored as obsolete

Tested the patch: It works, but needs an extra "= null" after the first
occurrence of "$ns" to avoid a spurious warning. I won't upload a new patch for
this -- if someone knows how to edit the patch, feel free to do so.

Comment on attachment 1509
Patch against SVN HEAD to add the $wgNoFollowNsExceptions config option. Added default param

Index: mediawiki-svn/phase3/includes/Linker.php

  • mediawiki-svn/phase3/includes/Linker.php (revision 13561)

+++ mediawiki-svn/phase3/includes/Linker.php (working copy)
@@ -732,10 +732,10 @@

	}

	/** @todo document */
  • function makeExternalLink( $url, $text, $escape = true, $linktype = '' ) {

+ function makeExternalLink( $url, $text, $escape = true, $linktype = '', $ns = NULL) {

		$style = $this->getExternalLinkAttributes( $url, $text, 'external ' . $linktype );
  • global $wgNoFollowLinks;
  • if( $wgNoFollowLinks ) {

+ global $wgNoFollowLinks, $wgNoFollowNsExceptions;
+ if( $wgNoFollowLinks && !(isset($ns) && in_array($ns, $wgNoFollowNsExceptions)) ) {

			$style .= ' rel="nofollow"';
		}
		$url = htmlspecialchars( $url );

Index: mediawiki-svn/phase3/includes/Parser.php

  • mediawiki-svn/phase3/includes/Parser.php (revision 13561)

+++ mediawiki-svn/phase3/includes/Parser.php (working copy)
@@ -1190,7 +1190,7 @@

    1. This means that users can paste URLs directly into the text
    2. Funny characters like ö aren't valid in URLs anyway
    3. This was changed in August 2004
  • $s .= $sk->makeExternalLink( $url, $text, false, $linktype ) . $dtrail . $trail;

+ $s .= $sk->makeExternalLink( $url, $text, false, $linktype, $this->mTitle->getNamespace() ) . $dtrail . $trail;

  1. Register link in the output object.
  2. Replace unnecessary URL escape codes with the referenced character

@@ -1270,7 +1270,7 @@

				$text = $this->maybeMakeExternalImage( $url );
				if ( $text === false ) {
					# Not an image, make a link
  • $text = $sk->makeExternalLink( $url, $wgContLang->markNoConversion($url), true, 'free' );

+ $text = $sk->makeExternalLink( $url, $wgContLang->markNoConversion($url), true, 'free', $this->mTitle->getNamespace() );

  1. Register it in the output object...
  2. Replace unnecessary URL escape codes with their equivalent characters $pasteurized = Parser::replaceUnusualEscapes( $url );

Index: mediawiki-svn/phase3/includes/DefaultSettings.php

  • mediawiki-svn/phase3/includes/DefaultSettings.php (revision 13561)

+++ mediawiki-svn/phase3/includes/DefaultSettings.php (working copy)
@@ -1719,6 +1719,12 @@
$wgNoFollowLinks = true;

/
+ * Namespaces in which $wgNoFollowLinks doesn't apply.
+ * See Language.php for a list of namespaces.
+ */
+$wgNoFollowNsExceptions = array();
+
+/

  • Specifies the minimal length of a user password. If set to
  • 0, empty passwords are allowed. */

Well, that's not really what i intended but i think that was the corrected patch?

robchur wrote:

We have the attachments feature to provide patches.

I know, Rob. I used its edit link, and thought it would save as an attachment
too. But something went wrong :s

Come on, the right way to do it is to upload as a new attachment, and mark it as
obsoleting the previous one. The "obsoletes" feature is there for exactly that
reason.

This was a mistake, sorry. These are the cases when you want an 'edit' button to
clean the mess. :(

Fixed patch, see comments

Attached:

Change 180213 had a related patch set uploaded (by Cmcmahon):
QA: WIP add test for Flow in Recent Changes

https://gerrit.wikimedia.org/r/180213

Patch-For-Review

Change 180213 merged by jenkins-bot:
QA: add test for Flow in Recent Changes

https://gerrit.wikimedia.org/r/180213