Extension:NotEvil

This extension (technically, an EditFilter hook function, not a regular extension) blocks any edit that contains a url unless the users is on the "Not Evil" list. An example mechanism for updating the not evil list using a protected wiki page is also provided.

The Not Evil list is simply a text file containing usernames who are allowed to make edits that include URLs.

This filter also attempts to deceive spammers into believing their edits have succeeded. This does mean that anonymous users who make legitimate edits containing non-spammy URLs get blocked without any feedback that they are getting blocked, but in real-life usage this is an astonishingly rare edge case (you would think it would be common, but when you are only blocking edits with URLs it actually isn't)

Development
This code is in use, and is highly effective, but could really use some cleanup and simplification. Help is welcome!


 * Is there a better way to detect which lines changed? The current method is slow, and I don't trust my own temp-file code.
 * Done! I have got code for this from Extension:SpamBlacklist —91.196.30.137 19:13, 9 June 2013 (UTC)


 * Can $basePath be removed or replaced with something provided by MediaWiki? it would make configuration simpler.
 * Use $IP. —Emufarmers(T 01:01, 30 April 2008 (UTC)
 * Thanks! Fixed. --Bob the Hamster 16:35, 15 February 2011 (UTC)


 * How could this filter be best implemented as a real extension, rather than just a $wgFilterCallback?
 * Would it be possible to implement NotEvilness as a real account permission?
 * The example script for refreshing the not.evil.txt file needs to be rewritten in php. Not everybody can run shell scripts (and even fewer have the pcregrep command that the example requires) but everybody who is running Mediawiki will be able to run php

Cleaned-up code
Update: the latest version (below) has support for internationalised domain name detection.

Here's some helping... I've cleaned up the code and separated it into two extensions, "TrustedLinks" and "UntrustedLinksLogger". You can check out the files here:
 * TrustedLinks.php
 * TrustedLinks.i18n.php
 * UntrustedLinksLogger.php
 * UntrustedLinksLogger.i18n.php

I'll write more on the talk page. --Laird (talk) 23:12, 9 July 2012 (UTC)

2013-07-09: Some improvements from Kazimierz Król
I have improved the following areas of the code:
 * Made it use the EditFilter hook instead of the obsolete $wgFilterCallback (that has been probably removed, because the extension was not working for me),
 * Fixed the sysop checking, because it was not working in the new MW versions,
 * Completely changed the diff generation and checking, should be faster and more reliable now. Code derived from Extension:SpamBlacklist. Now it only blocks adding or modifying external links and creating new pages containing such from normal (or unregistered) users. It does not block removing of external links nor duplicating existing external links on a page (this should be okay in terms of spam prevention).
 * Small changes in the e-mail notification procedure to make the messages more informative.

—91.196.30.137 19:13, 9 June 2013 (UTC)

Installation

 * 1) Copy the source code below and save it to a file named NotEvil.php in your MediaWiki extensions directory (preferably in a NotEvil subdirectory). It is recommended to save the file with the UNIX-type new line marks (LF), not DOS marks (CR+LF).
 * 2) Enable NotEvil by adding the following line to
 * (Adjust the code to reflect the actual file subdirectory and name).
 * (Adjust the code to reflect the actual file subdirectory and name).

Generating not.evil.txt
You can use a cron job like this to update the not.evil.txt file once an hour.