Laboratoire pédagogique du Greta du Velay

Laboratoire pédagogique du Greta du Velay

Restrict pages under MediaWiki

Temps de lecture estimé à 5 min. 30 sec.
(Voir le billet en français)

This patch is deprecated.

Here is a patch to enable article restriction under MediaWiki. Pages can be articles or categories. It adds a new |restrict| tab link allowing members of the group restrict to restrict pages. Users member of the group viewrestrict can read (and modify) the restricted pages. Others users cannot see, search, export, etc, the restricted pages. You can still |protect| them for editing. A restricted page is distinguished by a red background tab, and you have a special page (Special:Restrictedpages) to list the restricted pages. All restriction/unrestriction actions are loggued in the wiki log. It is also possible to restrict pages or namespaces by providing a regular expression array matching titles, and to restrict new pages by default. Optionaly the user's pages can be restricted to their owner. Currently it is localized in English, German, Dutch, Swedish, Catalan, Finnish, Russian, Hebrew, Polish, Czech, Spanish and French. This feature is mainly useful for intranet relying on WikiMedia as a non-encyclopedic content management system, like e-learning platforms or informational systems. To respect the wiki philosophy, it is not appropriate to use it to restrict public access! To install restriction-patch, download MediaWiki (do a security backup if you patch your own installation), or see below to dowload a pre-patched archive.

Apply patch

mv restriction-version.mediawiki-version.patch ./mediawiki-version cd ./mediawiki-version patch -p0 < restriction-version.mediawiki-version.patch

Configure

First, install MediaWiki as usual (to create the database and the LocalSettings.php file). Once your wiki works fine you have to enable restriction. It is disabled by default. So add in your ./LocalSettings.php file (at the bottom of the file) :
/**
  * If true, a new menu action allows to restrict pages access to 'restrict' group users.
  * If false, all previously restricted pages are accessible again.
  */
  $wgEnableRestrict = true;

  /**
  * If true, new pages are restricted by default for 'restrict' group users.
  */
  $wgRestrictNewPages = false;

  /**
  * If true restrict user pages to their owner (as well as viewrestrict/restrict members)
  */
  $wgUserPageRestrict = false;

  /**
  * when wgUserPageRestrict and this option are true, allows user pages to be read but not edited by others?
  * added to restrict version beta-0.8.2
  */
  $wgUserReadRestrict = false;

  /**
  * Regular expression array to restrict matching pages
  * eg. $wgRegexRestrict = array("^Secure:", "^Secret ");
  *     restrict all pages where title is like 'Secure:...' or 'Secret ...'
  * with restrict version beta-0.8.1 you can also use Inverse regex matching
  * eg. $wgRegexRestrict = array("!!Public.*", ".*");
  *     any pages starting with "Public" is un-restricted and all others are restricted.
  */
  $wgRegexRestrict = array();

  /**
   * If true do not add recent changes entry for restricted pages
   */
  $wgNoRecentChangesRestrict = true;

  /**
   * If true hide log entries related to restriction, except for 'restrict' or 'viewrestrict' users (Special:Log page)
   */
  $wgHideRestrictLog = true;

  /**
   * MediaWiki permissions setup
   */
  $wgGroupPermissions['restrict']['restrict'] = true;
  $wgGroupPermissions['restrict']['viewrestrict'] = true;
  $wgGroupPermissions['viewrestrict']['viewrestrict'] = true;
  // with restrict version beta-0.8.2 when $wgUserPageRestrict and $wgUserReadRestrict is true
  // 'authors' group members get 'edituser' rights and can edit other users pages and sub pages.
  $wgGroupPermissions['authors']['edituser'] = true;
By default nobody is able to restrict page. Go to the User rights management page (in special pages) and add users in group restrict (allow to view and restrict pages) or viewrestrict (allow only to view restricted pages). Here is a FAQ on metawiki. If $wgUserPageRestrict is true, user pages are restricted to their respective owner, as well as members of the viewrestrict group. Don't write sensible information in page titles, they could be retrieved in some cases. This is beta and GPL, test and feedback welcome !

Get the patch

Mailing list and contact

You can subscribe to the mailing list to discuss about this patch, receive news, etc. Send an empty mail to restrict-mediawiki-list-subscribe@... and reply to the confirmation mail. To contact me (no personal support, use this blog) : restrict-mediawiki/at/conseil-recherche-innovation.net (Jérôme Combaz)

Changelog

Version beta-0.72 for MW 1.6.6/1.6.7/1.6.8 (09-01-2006)
  • Spanish translation (thanks to Victor Fariña from Queres tecnologias)
  • Czech translation (thanks to Michal Ciza)
Version beta-0.71 for MW 1.6.6/1.6.7 (07-13-2006)
  • Two bugs in Articles.php and Skin.php (thanks to Owen, see here)
Version beta-0.70 for MW 1.6.6/1.6.7 (06-06-2006)
  • SQL requests are not modified anymore to check the restriction (better sustenability of the patch)
  • Now restricted pages and *regex* restricted pages are treated in the same way. So none of pages title should be listed whatever the protection mechanism choosed, nor during a search request
  • Regex restriction include the namespace, so it is now possible to restrict whole namespaces (eg. "^Talk:" restrict all talk pages)
  • Image partialy restricted (not listed but file accessible via HTTP)
  • The SpecialVersion page informs that MW is patched
  • Correction of text error on the unrestrict page (thanks to Mathaba)
  • Polish translation (thanks to Janusz 'Ency' Dorozynski)
Version beta-0.64 for MW 1.6.3 (05-01-2006)
  • Bug in SpecialCategories page (thanks to T O X I N)
  • Hebrew translation (thanks to Yuval Hager)
  • Bug in OutputPage.php (thanks again to Yuval Hager)
Version beta-0.63 for MW 1.6.3 (04-20-2006)
  • Upgrade for 1.6.3 (thanks to Anthony for his help)
  • Russian translation (thanks to T O X I N)
  • Finnish translation (thanks to Tuomas Helin)
Version beta-0.62 for MW 1.5.5/1.5.6 (02-13-2005)
  • Catalan translation (thanks to Pau Cabot)
  • Small mistake (comma) in swedish translation
Version beta-0.61 for MW 1.5.5/1.5.6 (01-18-2006)
  • Swedish translation (thanks to Samuel Lampa)
  • Dutch translation (thanks to Peter De Baets)
Version beta-0.6 for MW 1.5.3 (12-15-2005)
  • $wgHideRestrictLog option is back
Version beta-0.59 for MW 1.5.1/1.5.2 (10-31-2005)
  • Allow to restrict new pages by default ($wgRestrictNewPages option)
  • Bug : 'ArticleProtectComplete' hook function remplaced by 'ArticleRestrictComplete' (stupid mistake !)
Version beta-0.58 (10-07-2005)
  • Restriction by regular expression test on title.
  • Bug which avoided to view restricted pages in special pages (only 'restrict' group can see it, not possible to add 'viewrestrict' group) (thanks to Karen O'Flaherty)
  • German translation updated (thanks to Hugo Wirz)
  • French and english translations updated.
  • Bug in Broken Redirects special page SQL request
  • Categories special page hide restricted categories for non allowed users
  • No more modifications in monobook stylesheet than one style added (see bottom of /skins/monobook/main.css file).
Version beta-0.57 (09-18-2005)
  • Stupid cosmetic bug which avoid patch working if user page restriction enabled (thanks to Christophe Berger)
Version beta-0.56 (09-11-2005)
  • Bug "variables can be passed by reference in mediawiki\includes\Article.php on line 1703" with some PHP configurations (thanks to Chunho Lee)
Version beta-0.55 (09-07-2005)
  • First public release for MediaWiki 1.5

Commentaires

<p>Thanks Owen.<br />
<br />
You are right. These bugs were included during a big update of MW. Sorry for that. A new version (0.71) is online.<br />
<br />
I think that early or late I will not be able to follow all the MW changes and adapt the patch in time. I don't understand why MW does not provide a true API for ACL concerns.<br />
<br />
Jerome</p>

Did anyone ever get all of the bugs worked out of MW 1.7.1? I'm running into all sorts of problems after updating. I think for now I'll just stick with 1.6.7

<p>Hi Andy and all,<br />
<br />
The patch doesn't work for 1.7.1. As you see many modifications are rejected when patching, due to MW changes.<br />
<br />
<span style="color: red; font-weight: bold;">I think I will not update this patch anymore. I am thinking about an extension, what is more stable when MW updates. <!--I spoke with Petr Andreev, author of the NamespacePermissions Extension. We will join our efforts to provide a nice restriction extension which combines the features and ideas of this patch and its extension.--><br /></span> <br />
I cannot give any date for the first release, just subscribe to the mailing list to keep in touch :) (<a href="mailto:restrict-mediawiki-list-subscribe@conseil-recherche-innovation.net">restrict-mediawiki-list-subscribe@conseil-recherche-innovation.net</a>)<br />
<br />
Read you,<br />
Jerome</p>

I have subscribed to your email list and am happy to help. I can see there are several things you could do to make the patch more maintainable. Could you post a summary of what you plan to do? Perhaps on the Wikimedia page so everyone can see?

RE:
I think I will not update this patch anymore. I am thinking about an extension, what is more stable when MW updates. I spoke with Petr Andreev, author of the NamespacePermissions Extension. We will join our efforts to provide a nice restriction extension which combines the features and ideas of this patch and its extension.

I think that's a great idea. Good Luck.
Maybe some sort of ACL model??

Regards,

I agree that this discussion should be moved to Wikimedia site. By the way, running rebuildall.php will removes all links to (special:whatlinkshere) templates. I think that is a bug. (mw 1.6.7 / patch 0.71)

I have made a patch to this patch for restricting access to menu items in the MediaWiki:Sidebar. I have posted it on the bandit-project web site:
www.bandit-project.org/in...

It is only like 20 lines of code. Enjoy.

Hi.I would like to translate restriction messages to Czech language. I have got a problem with it. I ve tried to edit a /languages/MessagesCs.php and put text bellow to the end of that file. If i set the czech language in my user preferences I still cant see my czech restriction messages. Where is a problem? Could you help me?

Thanks

#Restrict patch (meta.wikimedia.org/wiki/P...
'restrict' => 'Omezit p?ístup',
'restrictthispage' => 'Omezit p?ístup na tuto stránku',
'unrestrict' => 'Zve?ejnit',
'unrestrictthispage' => 'Zve?ejnit tuto stránku',
'restricttitle' => 'Stránka s omezeným p?ístupem',
'restricttext' => 'Na tuto stránku je omezený p?ístup. Z?ejm? nemáte oprávn?ní k jejímu ?tení',
'restrictedpages' => 'Stránky s omezeným p?ístupem',
'restrictlogpage' => 'Restriction_log',
'restrictlogtext' => 'Below is a list of page restrictions. See [[{{ns:4}}:Restricted page]] for more information.',
'restrictedarticle' => 'restricted [[$1]]',
'unrestrictedarticle' => 'unrestricted [[$1]]',
'restrictsub' => '(Restrict \'[[$1]]\')',
'confirmrestrict' => 'Potvrzení omezení p?ístupu',
'confirmrestricttext' => 'Opravdu chcete omezit p?ístup k této stránce?',
'restrictcomment' => 'D?vod pro omezení',
'unrestrictsub' => '(Unrestrict \'[[$1]]\')',
'confirmunrestricttext' => 'Opravdu chcete zve?ejnit tuto stránku?',
'confirmunrestrict' => 'Potvrzení zve?ejn?ní',
'unrestrictcomment' => 'D?vod zve?ejn?ní',
'restrictreason' => '(give a reason)',
'tooltip-restrict' => 'Omezit p?ístup',
'notallowedtomoverestrictedpagetext' => 'To move this page, you have to be member of the \'restrict\' group.',
'restrictedpagespagetext' => 'This page lists all restricted pages in the wiki. ',
'regexrestrictedpagespagetext' => 'All page titles matching this/these regular expression(s) are also restricted : ',

Hello,

I just tryed this patch with mediawiki 1.6.8 and it seems to work. The only "Problem" I have: the [[Special:Restrictedpages]] doesn't list any pages. But I guess I can live with that by now ;)

Good job :)

I too have the same problem. The patch works fine but the Special:Restrictedpages page does not even load, HTML Page Source is empty.

I'm using mediawiki 1.6.8 and patch version 0.71...

I'm not sure if the page ever work as I just noticed it does not right now...

RE:
208. Le jeudi 31 août 2006 à 11h20, par FIZ

Hello,

I just tryed this patch with mediawiki 1.6.8 and it seems to work. The only "Problem" I have: the [[Special:Restrictedpages]] doesn't list any pages. But I guess I can live with that by now ;)

Good job :)

209. Le jeudi 31 août 2006 à 19h36, par Jake

I too have the same problem. The patch works fine but the Special:Restrictedpages page does not even load, HTML Page Source is empty.

I'm using mediawiki 1.6.8 and patch version 0.71...

I'm not sure if the page ever work as I just noticed it does not right now...
END RE

Hey I figured it out... I think the patch did not create mediawikisintall/includes/SpecialRestrictedpages.php... if you open the patch file and search for "SpecialRest" you can see where the page start from line 862 "+<?php" and ends at line 941 "+?>" copy all those lines into WikiInstallDir/includes/SpecialRestrictpages.php but you have to remove all of the "+" signs at the start of each line...

Good luck FIZ

Jake

<p>I do not have any problem regarding the Special:Restrictedpages on my running version. Download and test the full archive.<br />
<br />
Jerome</p>

Does anyone knows something about a possible extension for Mediawiki 1.7 because i realy Need it for my job! thank's for response.

Does anyone know how to restrict special pages?

Thank You

does it's possible to create new group? and restrict acces to certain pages only for this group?

I have adjusted the patch to work with MediaWiki 1.7.1

It is not very well tested. So it is maybe not a good idea to use it in a productive environment without extensive testing.

www.zedlitz.de/restrictio...

<p>Thanks you very much, JesperZedlitz. I will have a look on your work and maybe publish this version will on the blog.<br />
<br />
Jerome</p>

My wishes are to be able to restrict users from editing other user's User Pages. Is this possible with this patch? I am fustrated ans I can not find the correct combination of settings, alone to do this with the patch. PLease help. I am using MediaWiki 1.6.8.

Pour un newby très intéressé, une question qui vous paraîtra débile, et pourtant !
- comment lancer le patch sur Debian ?

<p>@Vaddy : avez-vous essayé la procédure décrite ici ? sous debian probablement aucun problème. Le paquet 'patch' doit cependant être installé.<br />
<br />
Jerome</p>

How do we apply the patch?

At the top of this page there is something that says "Apply patch" followed by some ambiguous code. Is this some sort of command line instructions we are to deploy?

Isn't there a way to replace one file with another by FTP, or to revise the file by manually replacing text?

To apply the patch, upload the patch to your directory where mediawiki lives, then run the command

patch -p0 < restriction-version.mediawiki-version.patch

for example

patch -p0 < restriction-beta-0.8.mediawiki-1.7.1.patch

<p>Thanks Pupster.<br />
<br />
Another way is to download the full patched version of mediawiki. A link is provided above in the post.<br />
<br />
Jerome</p>

Hi. I applied your patch to my MW 1.5.3, and this is THE feature I needed. I mean, nothing more, nothing less. Really great thanks. However... I'm about to move to 1.8. In the ideal world, I would like this patch to be applied again on 1.8, and with my database still "remembering" all pages restricted before. Is it possible, forseen, forseenable?... This "remembering" question might be silly, but I have no clue how this works in reality. I just subscribed to the mailing list. I hope to have more news then. Thanks again.

Cedric

I'm really confused. A friend of mine has me working on his wiki, version 1.6.8 and I really want to install this patch. I downloaded the restriction-beta-0.72.mediawiki-1.6.8.patch and have no idea where to install it in the wiki and where are you suppose to run the command

patch -p0 < restriction-version.mediawiki-version.patch???

Also, we already have pages up and users using our wiki. Can we still apply this patch?

In short, I pretty much need a step-by-step that is in laymen's terms and not wiki jargon :)

I'm a total novice when it comes to all of this so thank you in advance :)

Hi! I had just setup pre-patched archive and everything works BUT restricting log entries.

RecentChanges show both restriction log entries and restricted pages history even for not logged in users.

I copied LocalSettings.php part as is with no custom changes whatever.

The wiki is setup in Ukrainian if that matters.

What can be wrong? Any help would be much appreciated!

Hi to all
Is there a way to associate articles to a group A and then make them visible only to that group A and not to other groups?
Restrict option lock all the page with articles to the other grous and they are unable to open the mail page.
I would like that some user can open their owner mail page.
Thank you
Stefano

<p>@Stef : the group A that you mention is the 'restrict' group of the patch...<br />
<br />
Jerome</p>

Is there a quick way to uninstall this patch, without re-installing mediawiki from scratch? Thanks

<p>Just replace modified files with original files. The genuine files should have a .orig extension. The database modifications will be ignored, and will be removed when you will change the protect statut of articles.<br />
<br />
Jerome</p>

Hey,
Is it possible to have restricted pages searchable if a memeber of the 'viewrestrict' or 'restrict' group is the one doing the searching? It seems to me that this makes a lot of sense from a functionality point of view.

-Steve

<p>I think it's the current behaviour.<br />
<br />
Jerome</p>

Hi Jerome,

Thanks for all your help with this patch. It really helped me get my site up and running. Now, however, I'm looking to open things up, so I won't need a complicated restriction extension. It's too bad that you're switching wikis! Good luck with it.

I have adjusted the MW 1.7.1 patch to (mostly) work with MediaWiki 1.10.0

It is not very well tested. So it is maybe not a good idea to use it in a productive environment without extensive testing.

See: meta.wikimedia.org/wiki/P...

I'm having some trouble with the $wgRestrictNewPages option, It doesn't seem to work with th update for MW1.10. I have verified that it does work with MW1.6.7 and the older 0.64 patch, although the new page appears in the recent changes unlike edits to restricted pages.

I'm not sure if I broke this in the 0.8.+ updates, or if it was broken by some previous change. perhaps the 0.70 change regarding "SQL requests are not modified anymore to check the restriction". I'm assuming that it was already broken in the 0.8 update.
Can anyone verify that $wgRestrictNewPages was still working with the use of patch versions 0.70, 0.71, 0.72, or 0.8? to help track down the problem?

Hi Jerome,

Thanks for all your help with this patch. It really helped me get my site up and running. It’s too bad that you’re switching wikis! I just want to say Thank you.

There's a extension that offer restricted access to your wiki, based on gropus and categories.
See: http://www.mediawiki.org/wiki/Extension:Restrict_access_by_category_and_...

Pages