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

When I followed the instructions found on this page, the patch did not work. However, when I followed the instructions in the READEME that came with the patch (1.6.3), things worked fine. This page told me to add the code for LocalSettings.php to the end of the file, whereas the READEME told me to add it right after require_once( "includes/DefaultSettings.php" );

Point being, you might want to edit this page a bit to specify the correct location for the code. Ditto for the MediaWiki page about the patch.

Can someone tell me how I might restrict a Category?

Nicholas E. May: I specified to place the config after the "require" because some novice users reported bug after putting the config at the most top of the LocalSettings.php file. I can clarify a bit more, but I don't think your problem is related to that.

Jerome

I think I found a bug. When I create a page and manually restrict it, the page does not show up in the search results.

When I create a page that has a title that matches this $wgRegexRestrict = array("^Secure:", "^Secret "), it is properly restricted, but it shows up in search results. These results display quite a bit of the actual text on the page.

I have such eror when i click on Category Link

«1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE cl_to = `page`.page_title AND `page`.page_restrictions NOT LIKE '%view=1%'' at line 7 (localhost)».

Tony: for now it's not a bug, just a lack of the patch.

Regex restriction is a "light solution" to restrict pages based on their title. The restriction works only when accessing the page. It would add cpu load to check the regex restriction everywhere it's necessary (actually many checks are made with SQL, I don't know if we have the same regex in SQL and what could be the cpu overload).

Jerome

Hi T O X I N,

Thanks for the report. You have a new patch to download and test :) (v0.64). It includes as well the hebrew translation (see changelog)

Jerome

There is a problem in the latest patch on the Special:Recentchangeslinked page. There is SQL error if restriction is enabled. I think the query should also join with the pages table.

A database query syntax error has occurred. This may indicate a bug in the software. The last attempted database query was:

(SQL query hidden)

from within function "wfSpecialRecentchangeslinked". MySQL returned error "1054: Unknown column 'rc_title' in 'on clause' (localhost)".

Wrong SQL error in the last post, it should be:

A database query syntax error has occurred. This may indicate a bug in the software. The last attempted database query was:

(SQL query hidden)

from within function "wfSpecialRecentchangeslinked". MySQL returned error "1054: Unknown column 'page_restrictions' in 'where clause' (localhost)".

Just for those that wondered...0.64 patch works with 1.6.5. I have it running just fine at my site.

YONG...I cannot duplicate the error you describe. Both 1.6.3 and 1.6.5 with patch 0.64 does not give this error. I would suggest that you rename your LocalSettings.php and rerun the installer and see if that does not fix your problem. Don't forget to add the restrict data back into LocalSettings.php when you are done!

Anybody please made Wiki 1.6.5 patched version

You can get the files already patched at www.taac.us/mediawiki-1.6...

If you have any problems let me know and I will see what I can do.

Anthony

thanx for the patched 1.6.5 anthony.

#Polish translation by Janusz 'Ency' Doro?y?ski 2006-05-16
#Restrict patch (meta.wikimedia.org/wiki/P...
'restrict' => 'Zastrze?enie',
'restrictthispage' => 'Zastrze?enie tej strony',
'unrestrict' => 'Zdj?cie zastrze?enia',
'unrestrictthispage' => 'Zdj?cie zastrze?enia tej strony',
'restricttitle' => 'Strona zastrze?ona',
'restricttext' => 'Ta strona jest zastrze?ona. Aby mie? do niej wgl?d musisz by? w grupie u?ytkowników \'restrict\' lub \'viewrestrict\'.',
'restrictedpages' => 'Strony zastrze?one',
'restrictlogpage' => 'Dziennik (log) zastrze?e?',
'restrictlogtext' => 'Poni?ej jest lista zastrze?e? stron. Zobacz [[{{ns:4}}:Strony zastrze?one]] z dodatkowymi informacjami.',
'restrictedarticle' => 'zastrze?ono [[$1]]',
'unrestrictedarticle' => 'zdj?to zastrze?enie [[$1]]',
'restrictsub' => '(Zastrze?enie \'[[$1]]\')',
'confirmrestrict' => 'Potwierd? zastrze?enie',
'confirmrestricttext' => 'Czy naprawd? chcesz zastrzec t? stron??',
'restrictcomment' => 'Powod zastrze?enia',
'unrestrictsub' => '(Zdj?cie zastrze?enia \'[[$1]]\')',
'confirmunrestricttext' => 'Czy naprawd? chcesz zdj?? zastrze?enie tej stron??',
'confirmunrestrict' => 'Potwierd? zdj?cie zastrze?enia',
'unrestrictcomment' => 'Powód zdj?cia zastrze?enia',
'restrictreason' => '(podaj powód)',
'tooltip-restrict' => 'Zastrze? t? stron?',
'notallowedtomoverestrictedpagetext' => 'Przeniesienie tej strony mog? wykona? tylko u?ytkownicy z grupy \'restrict\'.',
'restrictedpagespagetext' => 'Ta strona podaje list? wszystkich zastrze?onych stron tej wiki.',
'regexrestrictedpagespagetext' => 'Zastrze?enie dotyczy wszytkich tytu?ów artyku?ów spe?niaj?cych warunki regularnych wyra?e?: ',

Please, Jerome, take note of the workaround to access protected pages found in meta.wikimedia.org/wiki/T...

I supposed you would see it here sooner than there

I cannot reproduce the bug in comment 165. Not sure what version he is using but in version 1.6.5 it is fixed.

Anthony

No problem with redirections, I confirm...

Jerome

I have used your pre-patched archive ( mediawiki-1.6.3-restriction-patch-beta-0.64.tar.gz) for seting up my wiki. But I can't find the 'restrict' or the 'viewrestrict' group in the 'User rights management' page. Do I need to make these groups on my own? If so, do I just put
" $wgGroupPermissions['restrict']['restrict']= true; " in 'DefaultSettings.php'?

Thank you for your help.

Cipher

Cipher:

As written above near the archive link : "(do not forget to enable restriction feature, read the doc above)" (see section 'Configure').

Jerome

I copied and pasted the configure section into LocalSettings.php already. But the groups did not show up in the user rights page. Which is why I am confused.

Thanks

Cipher

I have created a patch file for MW 1.6.6 with the Polish Translation in comment 164 included. You can find the patch file at www.taac.us/restrict/rest...

Keep in mind that I use Windows XP so there is no guarentee that it will work with Linux. There seems to be a way to convert the patch file to work with linux and if someone can let me know how that would be great.

For those that need the already patched files, they are at www.taac.us/restrict/medi...

As always, if there is any problems, feel free to let me know.

Anthony

Thanks Anthony for this contrib.

I will publish soon a new version of the patch with a different way to manage restricted pages (no SQL modification, and regex restricted pages are treated exactly like the manually restricted pages).

Jerome

Cipher: Did you log in as a sysop ?

Jerome

Yes I did. I even tried the admin log in. But nothing seems to be working. I also looked into the 'DefaultSettings.php' file where the groups should be at ( I think ), but there is nothing regarding restriction groups.

^^;;

Cipher

Cipher: strange... nothing concerning groups has to be added in the DefaultSettings.php. Send me this file by mail so I can investigate more (remove db passwd :) ).

Jerome

'DefaultSettings.php' doesn't have password for the database. Is this the file you want?

Also, where can I find your e-mail address? ^^;;

Thanks
Cipher

Cipher: oups sorry, I mean the LocalSettings.php. Nothing to add or modify in the DefaultSettings.php (if well patched).

Jerome

Ok, I send the LocalSettings.php file of my wiki to restrict-mediawiki-list-subscribe@conseil-recherche-innovation.net.

I hope this is the right address. ^^;;

Thank you very much

Cipher

<b>This is a rerelease to to a bug in the previous patch and zip. Please upgrade if you used the patch or zip from comment 171. Sorry!</b>

I have created a patch file for MW 1.6.6 with the Polish Translation in comment 164 included. You can find the patch file at www.taac.us/restrict/restriction-beta-0.65.mediawiki-1.6.6.patch

Keep in mind that I use Windows XP so there is no guarentee that it will work with Linux. There seems to be a way to convert the patch file to work with linux and if someone can let me know how that would be great.

For those that need the already patched files, they are at www.taac.us/restrict/mediawiki-1.6.6.zip

As always, if there is any problems, feel free to let me know.

Anthony

I installed the patch 0.62 for 1.5.8 on my media wiki version 1.5.5

It seems to work very well, except there is some funny charators on the tab and title's of restrcted pages...

On the tab of a user in the groups viewrestrict and restrict
&lt;unrestrict&gt;
&lt;restrict&gt;

From a restricted page as user not in "viewresrict"
&lt;restricttitle&gt;
<restricttext>

Is there any fix for this? other than that it works fine. The problom is I dont know how to upgrade my wiki from 1.5.5 to 1.6.x to try your new patch... I suppose I'll look in to upgrading it and trying the new patch. But if there is a simple fix for the above problom that would be killer..

Thanks for this great media wiki extension...

Jake

Of course after I ask the questions I find the answer from above...

Thanks "tof"...

just add the following to the languages/Language.php

#Restrict patch (meta.wikimedia.org/wiki/P...
#
'restrict' => 'Restrict',
'restrictthispage' => 'Restrict this page',
'unrestrict' => 'Unrestrict',
'unrestrictthispage' => 'Unrestrict this page',
'restricttitle' => 'Restricted page',
'restricttext' => 'This page is restricted. To view it you have to be member of the \'restrict\' group or \'viewrestrict\' group.',
'restrictedpages' => 'Restricted pages',
'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' => 'Confirm the restriction',
'confirmrestricttext' => 'Do you really want to restrict this page?',
'restrictcomment' => 'Reason for restricting',
'unrestrictsub' => '(Unrestrict \'[[$1]]\')',
'confirmunrestricttext' => 'Do you really want to unrestrict this page?',
'confirmunrestrict' => 'Confirm unrestriction',
'unrestrictcomment' => 'Reason for unrestricting',
'restrictreason' => '(give a reason)',
'tooltip-restrict' => 'Restrict this page',
'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 : ',

Cipher: please read carrefuly ! the contact address is restrict-mediawiki/at/conseil-recherche-innovation.net (your posted on the mailing list subscription :)

Jerome

can someone please explain how to install this? i cant get it to work :(

Hi Jerome:

Sorry, my RL has been a real pain for a while.. -_-;; .. and as for the contact, I tried to find it.. But I can't make heads and tails on the contact page. ^^;; I can't read French.

Can you be a little clearer on where your e-mail address is? Thank you very much.

Cipher

Hi Cipher:

I cannot be more explicit !! See above in this blog note (title "Mailing list and contact") or in comment #182 or read this : "To contact me : restrict-mediawiki/at/conseil-recherche-innovation.net"

Replace /at/ with @ of course !!

Cheers, Jerome

O.o.. ops.. my bad.. ^^;; yea. I just send it to that address.

Thank you very much for helping me,

Cipher

I am also having the same problem as Yong, above:

A database query syntax error has occurred. This may indicate a bug in the software. The last attempted database query was:

(SQL query hidden)

from within function "wfSpecialRecentchangeslinked". MySQL returned error "1054: Unknown column 'page_restrictions' in 'where clause' (localhost)".

This seems to be related to not having FROM `page` in the MySQL query, only `pagelinks` and `recentchanges`?

Running 0.64 patch, against Mediawiki 1.6.6

Hi all,

I published a new version of the patch, with many changes (see changelog). Problems with sql requests should be minimised. Please test this version and give feedbacks.

Thank you for all the comments and contributions received until now. It's a good motivation for me!

Jerome

Great work Jerome!

I am forced to use the prepatched archived installation, and yet I have so many changes since the previous (1.5.8) version that I will spend some serious time getting everything back to a working environment. This is one of the most useful patches for MW I ever used.

Happy coding!

Hi mrproper,

Thanks. I know many people use previous versions of MW, but it si difficult to adapt the patch for the different versions. I (we) should do it but in the actual context it impossible for me due to time considerations.

Maybe should we to switch to a more confortable platform than this blog note!

Jerome

Hi,

your patch is very nice... but...work only with group "restrict".
About "Creating Restricted Areas / Virtual Wiki spaces" is there some extension? I want to create a private area "Area A" for the group A... after i want to create a private area "Area B" for the group B... after i vant create a group C that have access to "Area A" and "Area B".

Some help...

Is there anyway to restrict a page to a different group other then the restrict and viewrestrict groups?

I was patching mediawiki 1.6.7 and i got the following error:

patching file ./includes/DefaultSettings.php
Hunk #1 FAILED at 1933.
1 out of 1 hunk FAILED -- saving rejects to file ./includes/DefaultSettings.php.rej

I went back and noticed there were two mentions of it for earlier versions but no-one seems to have come across it in the latest version. Is there anything i can do about this error? If you need me to forward any information I'm more than willing.

Thanks for any help you can give.

Regards,
Jaime

Many thanks for this excellent patch.

Like other users, I'd like to be able to make different restrictions for different groups.

Just a bump to let you know that 1.7.0 is out now. I tried to work on it but ran into problems beyond my knowledge so if anyone else wants to take a stab at it, that would be great.

Anthony

<p>Thanks Anthony. I read that on Mediawiki-l but no time to try the patch. I will have a look now.<br />
<br />
Jerome</p>

I'd like to add my thanks too for this patch; it's very useful.

My wishlist for the patch:
* different restrictions for different groups (seems this is a popular request)
* some level of LDAP integration whereby restricted page access gould be checked agains an LDAP group

<p>Thanks Owen. I note your requests.<br />
<br />
But for now I have to fight with the 26 rejected hunks because of the new MW version...<br />
<br />
Jerome</p>

OK, understood. By the way, I think I noticed a bug in the patch; in Article::updateRestrictions, the line

$restrictions .= ":view=1";

should be

$flat .= ":view=1";

... I think :)

Thanks again for your patch!

Owen

Another bug, I think. In Skin.php, function bottomLinks(), replace

if( $wgEnableRestrict == true && $wgUser->isAllowed('viewrestrict')) { $s .= $sep . $this->restrictThisPage(); }

with

if( $wgEnableRestrict == true && $wgUser->isAllowed('restrict')) { $s .= $sep . $this->restrictThisPage(); }

All the best,

Owen

Pages