Extension:ProtectSource

Description
This extension protects protected pages. It blocks access to the source of pages that are protected against editing. It not only hides the source code, it suppresses the load completely.

If a non-privileged user tries to access the source code of a protected page, the following error message is returned: "Sorry, this is a protected page. You do not have the proper permissions to view the source."

Restriction criteria:
 * the page must be protected against editing
 * the user must be unable to delete (this default user right is customizable, see below)

If the restriction criteria fit, it disables the following (from all manual or system links and by manual URL parameter access): The extension does not
 * source view
 * comparing diffs on the history page (still the user can see the history list and view previous page versions in parsed mode)
 * raw access
 * source view of deleted pages ("view / restore" links are suppressed)
 * protect the MediaWiki namespace
 * You could include protected content nontheless by using  and protecting  Template:Some Template 


 * remove the (diff) link (as it appears on many special pages)
 * remove the [view source] page tab.
 * Links to error messages are not user friendly, but the site-wide conditional clauses could be expensive and not worth the usability if only a few pages are protected on the wiki. If wanted nontheless, the [view source] page tab can be hidden if the restriction criteria fit (see here). This trick is not possbile for the (diff) links since they currently (as of MW 1.16) have no own id or CSS class.


 * The extension makes no sense
 * without disabled API (use )
 * without disabled Special:Export (disabling it only for protected pages would be nice, atm it's safer to disable it completely manually)
 * when you protect pages only for "new and unregistered users".

Warning
This restriction is against the spirit of MediaWiki. On the other hand not every wiki is Wikipedia and you might have good reasons to protect page sources.

This extension may not be safe against all ways to access the source of a protected page. But the most obvious ones have been blocked. Please post on the discussion page if you find other loopholes.

If you have any other extensions installed that use the MediaWiki::performAction hook it is possible that they will not be processed; therefore, a custom hook called AlternatePerformAction is added to replace MediaWiki::performAction. You will need to change any hook references in other extensions from "MediaWikiPerformAction" to "AlternatePerformAction". To find out if one of your extensions may be affected grep "MediaWikiPerformAction" in your extension folder (and its subfolders).

Don't start mass protecting pages just to block source access. Note that those can not be edited by normal users.

Although the MediaWiki namespace is protected against editing by default, the source of those pages is not blocked (pages like MediaWiki:Common.css wouldn't work).

Download & Installation
Download and extract it into your extensions folder: Add this to 'LocalSettings.php' in your wiki installation folder.
 * ProtectSource0.1.1.tar
 * ProtectSource0.1.1.zip

Configuration
You can customize the user right to which the blocked access applies by using $wgProtectSourceUserRight. Example: This would override the default 'delete' and apply to users who are not allowed to move pages (only users who can move would be able to access the source code of protected pages).

Please note: When you protect a page you select a user group which is privileged to edit the page. No matter what you set as, that priviliged user group can access the page source code nontheless (since they can edit it).

Contribution
In theory this extension should work on MW 1.12.0 and above. Nontheless it would be nice if this was tested.
 * Please report bugs on the discussion page.
 * Please test it for any ways to access the source code or snippets of it.
 * Translations can be posted here.
 * Tested and working on MW 1.17.0 --Subfader 17:09, 23 June 2011 (UTC)
 * Tested and working on MW 1.16.5 --Subfader 20:11, 6 September 2011 (UTC)
 * Tested and working on MW 1.16alpha --Subfader 12:59, 12 August 2009 (UTC)

Known loopholes

 * Results on Special:Search can return tiny parts of the source code of protected pages (but the user needs to know what to search for).

Versions

 * 0.1.1 (2011-09-11) - i18n: i18n improved, added protectSource-desc, translations added: nl, fr, se