Jump to content

Extension:PageEditRestrictions

From mediawiki.org
MediaWiki extensions manual
PageEditRestrictions
Release status: unmaintained
Implementation User rights
Description Restrict editing to a page, by matching that page with a regular expression.

Access is decided by:

  • Matching a verified e-mail address to the logged in user's e-mail address.
  • MediaWiki user group rights configuration
Author(s) Pim Bax
Latest version 1.0.0 (2017-05-30)
MediaWiki 1.23+
PHP 5.3+
Database changes No
License GNU General Public License 3.0 or later
Download

The PageEditRestrictions extension provides a way to restrict editing to a page, by matching that page with a regular expression. Access is decided by:

  • Matching a verified e-mail address to the logged in user's e-mail address.
  • MediaWiki user group rights configuration

Usage

[edit]

This extension allows you to restrict editing to a page, by matching that page with a regular expression on the MediaWiki:Pageeditrestrictions-restricted-pages page. This expression can also be prefixed by an index followed by a hashtag. This will make only conditions also prefixed by the same index apply to that page.

These conditions need to be listed on MediaWiki:Pageeditrestrictions-condition, where any wikitext can be used, where $1 will be replaced with the email address of the user trying to edit the page, and $2 will be replaced with the page name of the page that is being edited. Again, conditions can be prefixed with an index and a hashtag, which will restrict that condition to only be applied to the pages that matched a regular expression which both had an index defined to it, and for which that index matches this index.

If the condition does not name a specific address, but instead starts with an @ sign, all email addresses within that domain will be matched.

Conditions are case-insensitive, regular expressions for pages are not.


Configuration pages

[edit]

MediaWiki:Pageeditrestrictions-restricted-pages

[edit]
# List conditions to test the user's email address against.
# If one of the conditions is met, editing access will be granted.
# Use $1 in place of the user's email address and $2 in place of the page name.
# Lines starting with a # will be ignored.
# this page includes preloaded examples

^(Foo.*Bar|Bar.*Foo)
1 # ^Main page$
^User:.*/private
^Project:.*

MediaWiki:Pageeditrestrictions-condition

[edit]
# lines starting with # are a comment.
# List conditions to test the user's email address against.
# If one of the conditions is met, editing access will be granted.
# Use $1 in place of the user's email address and $2 in place of the page name.

# this page includes preloaded examples

1 # admin@example.com
1 # @allowed-domain.com
{{Emailcheck|$2}}
{{AllowedDomain|$1}}
2 # unapplied@example.com

In this example we use two example templates to verify an email address. However this can be configured as desired. Usage of, for example, Semantic MediaWiki is possible.

Template:Emailcheck:

{{#ifeq:{{{1}}}|Foo Bar|john.doe@example.com|somebody@example.com}}

Template:AllowedDomain:

{{#switch:{{#explode:{{{1|}}}|@|-1}}
|gmail.com = {{{1}}}
|hotmail.com = {{{1}}}
|#default = not allowed
}} }}

These example pages will restrict any page that contains both Foo and Bar in its name to be edited only by the email address that results from Template:Emailcheck. This comes down to john.doe@example.com being allowed to edit the article Foo Bar, and somebody@example.com being allowed to edit all of the other matched articles for this rule. Other than that, gmail.com and hotmail.com email addresses are also allowed to edit those pages, as their email address is returned from Template:AllowedDomain. Any other address is disallowed, as the phrase "not allowed" does not match their email address.

On the "Main page" article, only admin@example.com is allowed to edit, but also anybody with an email address on the allowed-domain.com domain. The other conditions are not applied to this page, as it is prefixed by an index.

Finally, the email address unapplied@example.com is not specifically allowed to edit any restricted pages, since it is prefixed by an index that does not match any pages.

Note that using a template will make it possible for any user to change these conditions. It is highly recommended to protect these templates from being edited, to prevent users from granting themselves access by editing the templates to show their own email address.

Installation

[edit]
  • Download and place the file(s) in a directory called PageEditRestrictions in your extensions/ folder.
  • Add the following code at the bottom of your LocalSettings.php file:
    require_once "$IP/extensions/PageEditRestrictions/PageEditRestrictions.php";
    
  • Yes Done – Navigate to Special:Version on your wiki to verify that the extension is successfully installed.

Version history

[edit]

Author: Pim Bax

  • Version 1.0 (2017-05-30) - Initial version

See also

[edit]