User:Subfader/ProtectSource

Description
This Extension protects protected pages. It blocks access to the source of pages that are protected against editing (it not only hides it, it suppresses the load completely). If a non-privileged user tries to access protected page source, 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 (admins / sysops who would not be allowed by the set user right still can edit because of the page protection restriction)
 * 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)
 * remove the (diff) link (like on many special pages) or
 * 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 have no own CSS id or class.


 * The extension makes no sense without
 * disabled API ($wgEnableAPI = false;)
 * disabled Special:Export (Disabling it only for protected pages would be nice, atm it's safer to disable it completely manually.)

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 extension may be affected grep "MediaWikiPerformAction" in your extension folder (and its subfolders).

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

Configuration
You can customize the user right to which the blocked access applies by using $wgProtectSourceUserRight. Example: This would apply to users who are not allowed to move pages.

Authors
The extension was written by Lisa Ridley with little influences by Subfader who now maintains it more or less.

Contribution

 * Please test it for any ways to access the source code or snippets of it.
 * Please report bugs on the discussion page.
 * Translations can be posted here. Please sign your posts.