Difference between revisions of "Manual:MediaWiki: Toegang beperken"

From OchaWiki
Jump to navigation Jump to search
(Created page with "<languages /> <translate><!--T:22--> For help customizing user rights, see <tvar|1>{{ll|Manual:User rights}}</>.</translate> <translate><!--T:23--> This page contains examples...")
 
Line 1: Line 1:
 
<languages />
 
<languages />
<translate><!--T:22--> For help customizing user rights, see <tvar|1>{{ll|Manual:User rights}}</>.</translate>
+
<!--T:22--> For help customizing user rights, see <tvar|1>{{ll|Manual:User rights}}</>.
<translate><!--T:23--> This page contains examples useful for restricting access.</translate>
+
<!--T:23--> This page contains examples useful for restricting access.
 +
 
 +
<!--T:24--> Most of the examples need changes to MediaWiki configuration file <tvar|1><code>{{ll|Manual:LocalSettings.php|LocalSettings.php}}</code></>.
 +
<!--T:25--> Snippets of code with no accompanying instructions must be added to <tvar|1><code>LocalSettings.php</code></> to take effect.
 +
<!--T:26--> To add one or more lines to the file, follow these steps:
  
<translate><!--T:24--> Most of the examples need changes to MediaWiki configuration file <tvar|1><code>{{ll|Manual:LocalSettings.php|LocalSettings.php}}</code></>.</translate>
 
<translate><!--T:25--> Snippets of code with no accompanying instructions must be added to <tvar|1><code>LocalSettings.php</code></> to take effect.</translate>
 
<translate><!--T:26--> To add one or more lines to the file, follow these steps:</translate>
 
  
<translate>
 
 
<!--T:27-->
 
<!--T:27-->
# If there is a <tvar|1><code>?></code></> at the end of the file, remove it.</translate> <translate><!--T:28--> It's unnecessary and may cause problems in certain situations.</translate>
+
# If there is a <tvar|1><code>?></code></> at the end of the file, remove it. <!--T:28--> It's unnecessary and may cause problems in certain situations.
<translate>
+
 
 
<!--T:29-->
 
<!--T:29-->
# Add the line to the '''end''' of the file, using a text editor.</translate> <translate><!--T:30--> It doesn't matter if there are some blank lines above or below the addition.</translate> <translate><!--T:31--> '''Do not use Windows Notepad''', which may add a "[[w:Byte Order Mark|Byte Order Mark]]" (BOM) and prevent the file from being read correctly.</translate> <translate><!--T:32--> Typical symptoms of BOMs include white pages and errors about headers already being sent.</translate> <translate><!--T:33--> To remove a BOM, you'll have to edit the file in a [[w:hex editor|hex editor]].</translate> <translate><!--T:34--> Windows WordPad seems to work fine, as does [[w:Notepad++|Notepad++]].</translate> <translate><!--T:35--> Removal of BOMs can also be accomplished using the [[w:Vim (text_editor)|Vim text editor]] by opening the file in Vim, typing :set nobomb, and resaving the file.</translate> <translate><!--T:36--> If you're using a Mac, TextEdit will also do the job.</translate>
+
# Add the line to the '''end''' of the file, using a text editor. <!--T:30--> It doesn't matter if there are some blank lines above or below the addition. <!--T:31--> '''Do not use Windows Notepad''', which may add a "[[w:Byte Order Mark|Byte Order Mark]]" (BOM) and prevent the file from being read correctly. <!--T:32--> Typical symptoms of BOMs include white pages and errors about headers already being sent. <!--T:33--> To remove a BOM, you'll have to edit the file in a [[w:hex editor|hex editor]]. <!--T:34--> Windows WordPad seems to work fine, as does [[w:Notepad++|Notepad++]]. <!--T:35--> Removal of BOMs can also be accomplished using the [[w:Vim (text_editor)|Vim text editor]] by opening the file in Vim, typing :set nobomb, and resaving the file. <!--T:36--> If you're using a Mac, TextEdit will also do the job.
 +
 
  
<translate>
 
 
<!--T:37-->
 
<!--T:37-->
 
For more detailed information on editing <tvar|1><code>LocalSettings.php</code></>, read <tvar|2>{{ll|Manual:LocalSettings.php}}</>.
 
For more detailed information on editing <tvar|1><code>LocalSettings.php</code></>, read <tvar|2>{{ll|Manual:LocalSettings.php}}</>.
</translate>
+
 
  
 
__TOC__
 
__TOC__
  
 
{{anchor|Simple private wiki|Disable anonymous reading}}
 
{{anchor|Simple private wiki|Disable anonymous reading}}
<translate>
+
 
 
==Simple private wiki== <!--T:1-->
 
==Simple private wiki== <!--T:1-->
  
 
<!--T:38-->
 
<!--T:38-->
 
For the common [[w:use case|use case]] of "a private wiki, for oneself and approved others", you need to:
 
For the common [[w:use case|use case]] of "a private wiki, for oneself and approved others", you need to:
</translate>
 
  
*[[#Restrict viewing of all pages|<translate><!--T:39--> Restrict viewing</translate>]]
 
*[[#Restrict editing of all pages|<translate><!--T:40--> Restrict editing</translate>]]
 
*[[#Restrict account creation|<translate><!--T:41--> Restrict account creation</translate>]]
 
  
{{warning|1=<translate><!--T:42--> See the warnings in the sections below; this is simple "general use" code, and may or may not match your requirements.</translate>}}
+
*[[#Restrict viewing of all pages|<!--T:39--> Restrict viewing]]
 +
*[[#Restrict editing of all pages|<!--T:40--> Restrict editing]]
 +
*[[#Restrict account creation|<!--T:41--> Restrict account creation]]
 +
 
 +
{{warning|1=<!--T:42--> See the warnings in the sections below; this is simple "general use" code, and may or may not match your requirements.}}
  
 
<syntaxhighlight lang="php">
 
<syntaxhighlight lang="php">
Line 46: Line 46:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
<translate><!--T:43--> Depending on what extensions you have installed, you may want to whitelist more pages.</translate>
+
<!--T:43--> Depending on what extensions you have installed, you may want to whitelist more pages.
<translate><!--T:44--> For example if you are using the <tvar|1>{{ll|Extension:ConfirmAccount}}</> extension, you probably want Special:RequestAccount whitelisted.</translate>
+
<!--T:44--> For example if you are using the <tvar|1>{{ll|Extension:ConfirmAccount}}</> extension, you probably want Special:RequestAccount whitelisted.
<translate><!--T:45--> If the content language of your wiki is not English, you may have to use the translated name of the special pages in question.</translate>
+
<!--T:45--> If the content language of your wiki is not English, you may have to use the translated name of the special pages in question.
  
 
{{anchor|Restrict account creation}}
 
{{anchor|Restrict account creation}}
<translate>
+
 
 
==Restrict account creation== <!--T:2-->
 
==Restrict account creation== <!--T:2-->
  
 
<!--T:46-->
 
<!--T:46-->
 
To restrict account creation, you need to edit <tvar|1>''LocalSettings.php''</> in the root path of your MediaWiki installation.
 
To restrict account creation, you need to edit <tvar|1>''LocalSettings.php''</> in the root path of your MediaWiki installation.
</translate>
+
 
  
 
<syntaxhighlight lang="php">
 
<syntaxhighlight lang="php">
Line 63: Line 63:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
{{note|1=<translate><!--T:47--> You can use the <tvar|1>{{ll|Extension:ConfirmAccount|ConfirmAccount}}</> extension if you want to set up an account confirmation queue.</translate> (<translate><!--T:48--> If not you may still proceed as follows.</translate>)}}
+
{{note|1=<!--T:47--> You can use the <tvar|1>{{ll|Extension:ConfirmAccount|ConfirmAccount}}</> extension if you want to set up an account confirmation queue. (<!--T:48--> If not you may still proceed as follows.)}}
 +
 
 +
{{note|1=<!--T:49--> New users will still be able to be created by sysops, in the following manner:}}
  
{{note|1=<translate><!--T:49--> New users will still be able to be created by sysops, in the following manner:</translate>}}
 
  
<translate>
 
 
<!--T:50-->
 
<!--T:50-->
#Go to <tvar|1>{{blue|Special:Userlogin}}</>, when logged in as a sysop.</translate>
+
#Go to <tvar|1>{{blue|Special:Userlogin}}</>, when logged in as a sysop.
<translate>
+
 
 
<!--T:51-->
 
<!--T:51-->
#Click on "Create an account" link to get to the account creation form.</translate>
+
#Click on "Create an account" link to get to the account creation form.
<translate>
+
 
 
<!--T:52-->
 
<!--T:52-->
#Enter a username and an email address, and click the "by email" button.</translate> <translate><!--T:53--> Note you need <tvar|1>{{ll|Manual:$wgEnableEmail|$wgEnableEmail{{=}}true}}</> or else the sysop must pick a password and send it to the user.</translate>
+
#Enter a username and an email address, and click the "by email" button. <!--T:53--> Note you need <tvar|1>{{ll|Manual:$wgEnableEmail|$wgEnableEmail{{=}}true}}</> or else the sysop must pick a password and send it to the user.
<translate>
+
 
 
<!--T:54-->
 
<!--T:54-->
#The account will be created with a random password which is then emailed to the given address (as with the "forgot password" feature).</translate> <translate><!--T:55--> The user will be requested to change password at first login; when they do this, the email address will also be marked as confirmed.</translate>
+
#The account will be created with a random password which is then emailed to the given address (as with the "forgot password" feature). <!--T:55--> The user will be requested to change password at first login; when they do this, the email address will also be marked as confirmed.
#:<small><translate><!--T:56--> When you click the "create account" button instead, you have to manually send the user their password.</translate> <translate><!--T:57--> If you've set <tvar|1>{{ll|Manual:$wgMinimalPasswordLength|$wgMinimalPasswordLength{{=}}0}}</> (default configuration up to version 1.15) and you've left the password field blank, the user will be emailed an email address confirmation request but will be unable to access <tvar|2>{{ll|Manual:Interface/Special pages summary|Special:Confirmemail}}</> to perform the confirmation.</translate> <translate><!--T:58--> Instead, the user will get an error (unless you've added it to <tvar|1>{{ll|Manual:$wgWhitelistRead|$wgWhitelistRead}}</>); the user will be able to login with a blank password and then confirm email, but their password will not have been reset (it will have to be reset manually).</translate></small>
+
#:<small><!--T:56--> When you click the "create account" button instead, you have to manually send the user their password. <!--T:57--> If you've set <tvar|1>{{ll|Manual:$wgMinimalPasswordLength|$wgMinimalPasswordLength{{=}}0}}</> (default configuration up to version 1.15) and you've left the password field blank, the user will be emailed an email address confirmation request but will be unable to access <tvar|2>{{ll|Manual:Interface/Special pages summary|Special:Confirmemail}}</> to perform the confirmation. <!--T:58--> Instead, the user will get an error (unless you've added it to <tvar|1>{{ll|Manual:$wgWhitelistRead|$wgWhitelistRead}}</>); the user will be able to login with a blank password and then confirm email, but their password will not have been reset (it will have to be reset manually).</small>
 +
 
 +
<!--T:59--> It may be appropriate to edit the text displayed when a non-user attempts to log in.
 +
<!--T:60--> This can be done at <tvar|1>[[MediaWiki:Nosuchuser]]</>, when logged in as a sysop.
 +
<!--T:61--> Use plain text without any special formatting, as the formatting is ignored and the text is literally rendered.
 +
<!--T:62--> (Might have changed, see <tvar|1>[[Mediazilla:12952|bug 12952]]</>).
  
<translate><!--T:59--> It may be appropriate to edit the text displayed when a non-user attempts to log in.</translate>
 
<translate><!--T:60--> This can be done at <tvar|1>[[MediaWiki:Nosuchuser]]</>, when logged in as a sysop.</translate>
 
<translate><!--T:61--> Use plain text without any special formatting, as the formatting is ignored and the text is literally rendered.</translate>
 
<translate><!--T:62--> (Might have changed, see <tvar|1>[[Mediazilla:12952|bug 12952]]</>).</translate>
 
  
<translate>
 
 
<!--T:63-->
 
<!--T:63-->
 
You may also modify the contents of the email sent to new users by editing the page <tvar|1>[[MediaWiki:Createaccount-text]]</>.
 
You may also modify the contents of the email sent to new users by editing the page <tvar|1>[[MediaWiki:Createaccount-text]]</>.
Line 92: Line 92:
 
<!--T:64-->
 
<!--T:64-->
 
To prevent even sysops from creating accounts:
 
To prevent even sysops from creating accounts:
</translate>
+
 
  
 
<syntaxhighlight lang="php">
 
<syntaxhighlight lang="php">
Line 100: Line 100:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
<translate>
+
 
 
<!--T:65-->
 
<!--T:65-->
 
To add a message on top of the login form, modify <tvar|1>[[MediaWiki:Loginprompt]]</>.
 
To add a message on top of the login form, modify <tvar|1>[[MediaWiki:Loginprompt]]</>.
  
 
==Restrict editing== <!--T:3-->
 
==Restrict editing== <!--T:3-->
</translate>
+
 
  
 
{{anchor|Restrict editing of all pages}}
 
{{anchor|Restrict editing of all pages}}
<translate>
+
 
 
===Restrict editing of all pages=== <!--T:4-->
 
===Restrict editing of all pages=== <!--T:4-->
</translate>
 
<translate><!--T:67--> Users will still be able to read pages with these modifications, and they can view the source by using [[<tvar|1>Special:Export</>/Article name]] or other methods.</translate>
 
<translate><!--T:68--> See also <tvar|1>[[Mediazilla:1859|bug 1859]]</>.</translate>
 
  
<translate><!--T:69--> See <tvar|1>{{ll|Help:User rights}}</> and <tvar|2>{{ll|Manual:$wgGroupPermissions}}</>.</translate>
+
<!--T:67--> Users will still be able to read pages with these modifications, and they can view the source by using [[<tvar|1>Special:Export</>/Article name]] or other methods.
<translate><!--T:70--> If you use <tvar|1>{{ll|Extension:AbuseFilter}}</>, any wiki admin can also put various restrictions in place.</translate>
+
<!--T:68--> See also <tvar|1>[[Mediazilla:1859|bug 1859]]</>.
 +
 
 +
<!--T:69--> See <tvar|1>{{ll|Help:User rights}}</> and <tvar|2>{{ll|Manual:$wgGroupPermissions}}</>.
 +
<!--T:70--> If you use <tvar|1>{{ll|Extension:AbuseFilter}}</>, any wiki admin can also put various restrictions in place.
 +
 
  
<translate>
 
 
<!--T:71-->
 
<!--T:71-->
 
Some examples of how to protect all pages from editing (not reading) by certain classes of users:
 
Some examples of how to protect all pages from editing (not reading) by certain classes of users:
Line 125: Line 125:
 
<!--T:72-->
 
<!--T:72-->
 
Requires that a user be registered before they can edit.
 
Requires that a user be registered before they can edit.
</translate>
+
 
  
 
<syntaxhighlight lang="php">
 
<syntaxhighlight lang="php">
Line 131: Line 131:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
<translate>
+
 
 
====Restrict editing by all non-sysop users==== <!--T:6-->
 
====Restrict editing by all non-sysop users==== <!--T:6-->
  
 
<!--T:73-->
 
<!--T:73-->
 
Requires that a user be a member of the administrators (sysop) usergroup.
 
Requires that a user be a member of the administrators (sysop) usergroup.
</translate>
+
 
  
 
<syntaxhighlight lang="php">
 
<syntaxhighlight lang="php">
Line 144: Line 144:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
<translate>
+
 
 
====Restrict editing by absolutely everyone==== <!--T:7-->
 
====Restrict editing by absolutely everyone==== <!--T:7-->
</translate>
+
 
 
<syntaxhighlight lang="php">
 
<syntaxhighlight lang="php">
 
$wgGroupPermissions['*']['edit'] = false;
 
$wgGroupPermissions['*']['edit'] = false;
Line 153: Line 153:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
<translate>
+
 
 
===Restrict editing of an entire namespace=== <!--T:8-->
 
===Restrict editing of an entire namespace=== <!--T:8-->
</translate>
+
 
 
{{MW 1.10|and after}}
 
{{MW 1.10|and after}}
<translate><!--T:74--> Starting from MediaWiki version 1.10, it is possible to protect entire namespaces using the <tvar|1>{{ll|Manual:$wgNamespaceProtection|$wgNamespaceProtection}}</> variable.</translate>
+
<!--T:74--> Starting from MediaWiki version 1.10, it is possible to protect entire namespaces using the <tvar|1>{{ll|Manual:$wgNamespaceProtection|$wgNamespaceProtection}}</> variable.
<translate><!--T:75--> Examples:</translate>
+
<!--T:75--> Examples:
  
 
<syntaxhighlight lang="php">
 
<syntaxhighlight lang="php">
Line 179: Line 179:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
<translate>
+
 
 
<!--T:76-->
 
<!--T:76-->
 
Note that in the last case it's assumed that a custom namespace exists and that <code>NS_POLICY</code> is a defined constant equal to the namespace number.  See [[Manual:Using custom namespaces]] and [[Manual:Namespace_constants]] for a list of MediaWiki's core namespaces.
 
Note that in the last case it's assumed that a custom namespace exists and that <code>NS_POLICY</code> is a defined constant equal to the namespace number.  See [[Manual:Using custom namespaces]] and [[Manual:Namespace_constants]] for a list of MediaWiki's core namespaces.
</translate>
+
 
  
 
{{anchor|Restrict editing of certain specific pages}}
 
{{anchor|Restrict editing of certain specific pages}}
<translate>
+
 
 
===Restrict editing of certain specific pages=== <!--T:9-->
 
===Restrict editing of certain specific pages=== <!--T:9-->
</translate>
 
<translate><!--T:77--> Use the {{<tvar|1>ll|Manual:Administrators#Protection</>|Protect}} feature.</translate>
 
<translate><!--T:78--> By default, any sysop can protect pages so only other sysops can edit them.</translate>
 
<translate><!--T:79--> In 1.9 and higher, by default they can also protect pages so only "autoconfirmed" users (with accounts older than a configured period) can edit them.</translate>
 
<translate><!--T:80--> This does not require editing configuration files.</translate>
 
  
<translate><!--T:81--> If you want to restrict editing to groups with specific permissions, edit <tvar|1>{{ll|Manual:$wgRestrictionLevels|$wgRestrictionLevels}}</>.</translate>
+
<!--T:77--> Use the {{<tvar|1>ll|Manual:Administrators#Protection</>|Protect}} feature.
<translate><!--T:82--> To prevent actions other than edit and move, use <tvar|1>{{ll|Manual:$wgRestrictionTypes|$wgRestrictionTypes}}</>.</translate>
+
<!--T:78--> By default, any sysop can protect pages so only other sysops can edit them.
 +
<!--T:79--> In 1.9 and higher, by default they can also protect pages so only "autoconfirmed" users (with accounts older than a configured period) can edit them.
 +
<!--T:80--> This does not require editing configuration files.
 +
 
 +
<!--T:81--> If you want to restrict editing to groups with specific permissions, edit <tvar|1>{{ll|Manual:$wgRestrictionLevels|$wgRestrictionLevels}}</>.
 +
<!--T:82--> To prevent actions other than edit and move, use <tvar|1>{{ll|Manual:$wgRestrictionTypes|$wgRestrictionTypes}}</>.
 +
 
  
<translate>
 
 
===Restrict editing of all but a few pages=== <!--T:10-->
 
===Restrict editing of all but a few pages=== <!--T:10-->
</translate>
 
<translate><!--T:83--> To impose a blanket restriction on editing for all pages, but allow a few (such as sandboxes, join request pages, etc.) to be more generously editable, you can use the <tvar|1>{{ll|Extension:EditSubpages|nsp=0}}</> extension.</translate>
 
<translate><!--T:84--> This may not fit too often, but you could also use the [[<tvar|1>#Restrict editing of certain specific pages</>|Restrict editing of certain specific pages]] method mentioned above, with all name spaces protected, and only a special one editable by everyone which has all the pages you want editable.</translate>
 
  
<translate>
+
<!--T:83--> To impose a blanket restriction on editing for all pages, but allow a few (such as sandboxes, join request pages, etc.) to be more generously editable, you can use the <tvar|1>{{ll|Extension:EditSubpages|nsp=0}}</> extension.
 +
<!--T:84--> This may not fit too often, but you could also use the [[<tvar|1>#Restrict editing of certain specific pages</>|Restrict editing of certain specific pages]] method mentioned above, with all name spaces protected, and only a special one editable by everyone which has all the pages you want editable.
 +
 
 +
 
 
===Restrict editing for certain IP address ranges=== <!--T:11-->
 
===Restrict editing for certain IP address ranges=== <!--T:11-->
</translate>
 
<translate><!--T:85--> Schools and other institutions may want to block all edits not from a few specified [[w:IP address|IP address]] ranges.</translate>
 
<translate><!--T:86--> To do so, see <tvar|1>{{ll|Manual:Block and unblock}}</>.</translate>
 
<translate><!--T:87--> The only way to do this at present <!-- that I know of--> without modifying the code is to go to <tvar|1>[[Special:Blockip]]</> and systematically {{<tvar|2>ll|Help:Range blocks</>|rangeblock}} every one of the address ranges that you don't want to be able to edit.</translate>
 
<translate><!--T:88--> This will work for all future versions of MediaWiki.</translate>
 
<translate><!--T:89--> It will not work on a per-namespace basis.</translate>
 
  
<translate>
+
<!--T:85--> Schools and other institutions may want to block all edits not from a few specified [[w:IP address|IP address]] ranges.
 +
<!--T:86--> To do so, see <tvar|1>{{ll|Manual:Block and unblock}}</>.
 +
<!--T:87--> The only way to do this at present <!-- that I know of--> without modifying the code is to go to <tvar|1>[[Special:Blockip]]</> and systematically {{<tvar|2>ll|Help:Range blocks</>|rangeblock}} every one of the address ranges that you don't want to be able to edit.
 +
<!--T:88--> This will work for all future versions of MediaWiki.
 +
<!--T:89--> It will not work on a per-namespace basis.
 +
 
 +
 
 
===Restrict editing by a particular user=== <!--T:12-->
 
===Restrict editing by a particular user=== <!--T:12-->
</translate>
 
<translate><!--T:90--> Use the user {{<tvar|1>ll|Manual:Block and unblock</>|blocking}} functionality to deprive a user of all edit access.</translate>
 
<translate><!--T:91--> MediaWiki does not include a possibility to give rights to separate users directly; instead rights are always given to a user group.</translate>
 
<translate><!--T:92--> There is no way in the core software to change permissions of particular users in order to restrict or allow editing particular pages, except by changing their usergroup.</translate>
 
  
<translate>
+
<!--T:90--> Use the user {{<tvar|1>ll|Manual:Block and unblock</>|blocking}} functionality to deprive a user of all edit access.
 +
<!--T:91--> MediaWiki does not include a possibility to give rights to separate users directly; instead rights are always given to a user group.
 +
<!--T:92--> There is no way in the core software to change permissions of particular users in order to restrict or allow editing particular pages, except by changing their usergroup.
 +
 
 +
 
 
===Restrict creating of all pages=== <!--T:13-->
 
===Restrict creating of all pages=== <!--T:13-->
</translate>
 
  
{{note|1=<translate><!--T:93--> Revoking the ''edit'' right already prevents affected users from creating new pages and talk pages.</translate>}}
+
 
 +
{{note|1=<!--T:93--> Revoking the ''edit'' right already prevents affected users from creating new pages and talk pages.}}
  
 
<syntaxhighlight lang="php">
 
<syntaxhighlight lang="php">
Line 235: Line 235:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
<translate>
+
 
 
===Restrict creating pages in certain namespaces=== <!--T:14-->
 
===Restrict creating pages in certain namespaces=== <!--T:14-->
</translate>
 
<translate><!--T:94--> There are separate rights for creating talk pages (<tvar|1>createtalk</>) and creating non-talk pages (<tvar|2>createpage</>).</translate>
 
<translate><!--T:95--> If you need per-namespace control finer than that, it is not possible in core MediaWiki, and requires an extension such as <tvar|1>{{ll|Extension:Lockdown}}</>.</translate>
 
  
<translate>
+
<!--T:94--> There are separate rights for creating talk pages (<tvar|1>createtalk</>) and creating non-talk pages (<tvar|2>createpage</>).
 +
<!--T:95--> If you need per-namespace control finer than that, it is not possible in core MediaWiki, and requires an extension such as <tvar|1>{{ll|Extension:Lockdown}}</>.
 +
 
 +
 
 
==Restrict access to uploaded files== <!--T:15-->
 
==Restrict access to uploaded files== <!--T:15-->
</translate>
 
: ''&rarr; {{ll|Manual:Image authorization}}, {{ll|Manual:img_auth.php|img_auth.php}}, {{ll|Manual:User rights#List of permissions|2=<translate><!--T:96--> Manual:User rights (read)</translate>}}''
 
  
<translate><!--T:97--> If you have enabled the ability to upload files, these will be served directly by the underlying web server.</translate>
+
: ''&rarr; {{ll|Manual:Image authorization}}, {{ll|Manual:img_auth.php|img_auth.php}}, {{ll|Manual:User rights#List of permissions|2=<!--T:96--> Manual:User rights (read)}}''
<translate><!--T:98--> As a result, '''{{<tvar|1>red</>|account-based access to the file is unrestricted by default}}'''.</translate>
+
 
 +
<!--T:97--> If you have enabled the ability to upload files, these will be served directly by the underlying web server.
 +
<!--T:98--> As a result, '''{{<tvar|1>red</>|account-based access to the file is unrestricted by default}}'''.
  
 
{{uploaded-files-access-restriction-info}}
 
{{uploaded-files-access-restriction-info}}
  
<translate>
+
 
 
=== Example for access restriction to uploaded files in the server configuration === <!--T:16-->
 
=== Example for access restriction to uploaded files in the server configuration === <!--T:16-->
</translate>
+
 
<translate><!--T:99--> If sensitive files are uploaded to an internet-accessible wiki, you may wish to add restrictions on where these can be accessed from.</translate>
+
<!--T:99--> If sensitive files are uploaded to an internet-accessible wiki, you may wish to add restrictions on where these can be accessed from.
<translate><!--T:100--> On Apache, if your local network were 10.1.2.*, you could restrict serving files to local addresses with:</translate>
+
<!--T:100--> On Apache, if your local network were 10.1.2.*, you could restrict serving files to local addresses with:
  
 
<pre>
 
<pre>
Line 265: Line 265:
 
</pre>
 
</pre>
  
<translate>
+
 
 
==Restrict viewing== <!--T:17-->
 
==Restrict viewing== <!--T:17-->
</translate>
+
 
  
 
{{anchor|Restrict viewing of all pages}}
 
{{anchor|Restrict viewing of all pages}}
<translate>
+
 
 
===Restrict viewing of all pages=== <!--T:18-->
 
===Restrict viewing of all pages=== <!--T:18-->
</translate>
 
{{warning|1=<translate><!--T:101--> If you want anonymous users to be unable to view the wiki markup/code, you should not allow them to edit any page (see [[<tvar|1>#Restrict editing of all pages</>|#Restrict editing of all pages]] above).</translate> <translate><!--T:102--> If they can edit any page, they can use {{<tvar|1>ll|Help:Templates</>|template inclusion}} to view even pages they can't edit.</translate> <translate><!--T:103--> This may be possible to avoid by using <tvar|1>{{ll|Manual:$wgNonincludableNamespaces|$wgNonincludableNamespaces}}</></translate>}}
 
  
{{warning|1=<translate><!--T:104--> This method allows any visitor to view the wiki after creating an account.</translate> <translate><!--T:105--> You may wish to combine it with [[<tvar|1>#Restrict account creation</>|#Restrict account creation]] above.</translate>}}
+
{{warning|1=<!--T:101--> If you want anonymous users to be unable to view the wiki markup/code, you should not allow them to edit any page (see [[<tvar|1>#Restrict editing of all pages</>|#Restrict editing of all pages]] above). <!--T:102--> If they can edit any page, they can use {{<tvar|1>ll|Help:Templates</>|template inclusion}} to view even pages they can't edit. <!--T:103--> This may be possible to avoid by using <tvar|1>{{ll|Manual:$wgNonincludableNamespaces|$wgNonincludableNamespaces}}</>}}
  
{{warning|1=<translate><!--T:106--> Uploaded images will still be viewable to anyone who knows the image directory's name.</translate> <translate><!--T:107--> Either point <tvar|1>{{ll|Manual:$wgUploadPath|$wgUploadPath}}</> to the <tvar|2>img_auth.php</> script and follow the instructions in <tvar|3>{{ll|Manual:Image authorization}}</>, or use some external method to protect images, like .htaccess.</translate>}}
+
{{warning|1=<!--T:104--> This method allows any visitor to view the wiki after creating an account. <!--T:105--> You may wish to combine it with [[<tvar|1>#Restrict account creation</>|#Restrict account creation]] above.}}
 +
 
 +
{{warning|1=<!--T:106--> Uploaded images will still be viewable to anyone who knows the image directory's name. <!--T:107--> Either point <tvar|1>{{ll|Manual:$wgUploadPath|$wgUploadPath}}</> to the <tvar|2>img_auth.php</> script and follow the instructions in <tvar|3>{{ll|Manual:Image authorization}}</>, or use some external method to protect images, like .htaccess.}}
 +
 
 +
{{note|1=<!--T:108--> If anonymous users can't view your page, neither can search engines. <!--T:109--> Your site will not be indexed on Google.}}
  
{{note|1=<translate><!--T:108--> If anonymous users can't view your page, neither can search engines.</translate> <translate><!--T:109--> Your site will not be indexed on Google.</translate>}}
 
  
<translate>
 
 
<!--T:110-->
 
<!--T:110-->
 
Add this line to your LocalSettings.php file:
 
Add this line to your LocalSettings.php file:
</translate>
+
 
  
 
<syntaxhighlight lang="php">
 
<syntaxhighlight lang="php">
Line 297: Line 297:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
<translate><!--T:122--> The <tvar|1><code>{{ll|Manual:$wgWhitelistRead|$wgWhitelistRead}}</code></> setting allows users to view the main page.</translate>
+
<!--T:122--> The <tvar|1><code>{{ll|Manual:$wgWhitelistRead|$wgWhitelistRead}}</code></> setting allows users to view the main page.
<translate><!--T:123--> If page names have more than one word, use a space "<tvar|1> </>" between them, not an underscore "<tvar|2>_</>".</translate>
+
<!--T:123--> If page names have more than one word, use a space "<tvar|1> </>" between them, not an underscore "<tvar|2>_</>".
 +
 
  
<translate>
 
 
<!--T:124-->
 
<!--T:124-->
 
In addition to the main page of such a private site, you could give access to the Recentchanges page (if you think that its content isn't private) for feed readers by adding "Special:Recentchanges" to <tvar|1><code>{{ll|Manual:$wgWhitelistRead|$wgWhitelistRead}}</code></>.
 
In addition to the main page of such a private site, you could give access to the Recentchanges page (if you think that its content isn't private) for feed readers by adding "Special:Recentchanges" to <tvar|1><code>{{ll|Manual:$wgWhitelistRead|$wgWhitelistRead}}</code></>.
Line 306: Line 306:
 
<!--T:125-->
 
<!--T:125-->
 
If you need to protect even the sidebar, main page, or login screen for any reason, it's recommended that you use higher-level authentication such as <tvar|1>.htpasswd</> or equivalent.
 
If you need to protect even the sidebar, main page, or login screen for any reason, it's recommended that you use higher-level authentication such as <tvar|1>.htpasswd</> or equivalent.
</translate>
 
  
{{note|1=<translate><!--T:126--> Although <tvar|1>[[Special:Listusers]]</> won't be available, it can be determined if a username is correct from Userlogin errors.</translate> <translate><!--T:127--> You may want to give a common text for <tvar|1>[[MediaWiki:wrongpassword]]</> and <tvar|2>[[MediaWiki:nosuchusershort]]</>.</translate>}}
 
  
<translate>
+
{{note|1=<!--T:126--> Although <tvar|1>[[Special:Listusers]]</> won't be available, it can be determined if a username is correct from Userlogin errors. <!--T:127--> You may want to give a common text for <tvar|1>[[MediaWiki:wrongpassword]]</> and <tvar|2>[[MediaWiki:nosuchusershort]]</>.}}
 +
 
 +
 
 
===Restrict viewing of certain specific pages=== <!--T:19-->
 
===Restrict viewing of certain specific pages=== <!--T:19-->
</translate>
+
 
 
{{Page security extension disclaimer}}
 
{{Page security extension disclaimer}}
  
<translate><!--T:128--> To prevent anyone but sysops from viewing a page, it can simply be {{<tvar|1>ll|Help:Deletion and undeletion</>|deleted}}.</translate>
+
<!--T:128--> To prevent anyone but sysops from viewing a page, it can simply be {{<tvar|1>ll|Help:Deletion and undeletion</>|deleted}}.
<translate><!--T:129--> To prevent even sysops from viewing it, it can be removed more permanently using <tvar|1>{{ll|Manual:RevisionDelete}}</>.</translate>
+
<!--T:129--> To prevent even sysops from viewing it, it can be removed more permanently using <tvar|1>{{ll|Manual:RevisionDelete}}</>.
<translate><!--T:130--> To completely destroy the text of the page, it can be manually removed from the database.</translate>
+
<!--T:130--> To completely destroy the text of the page, it can be manually removed from the database.
<translate><!--T:131--> In any case, the page cannot be edited while in this state, and for most purposes no longer exists.</translate>
+
<!--T:131--> In any case, the page cannot be edited while in this state, and for most purposes no longer exists.
 +
 
 +
<!--T:132--> To have a page act normally for some users but be invisible to others, as is possible for instance in most forum software, is a very different matter.
 +
<!--T:133--> MediaWiki is designed for two basic access modes:
  
<translate><!--T:132--> To have a page act normally for some users but be invisible to others, as is possible for instance in most forum software, is a very different matter.</translate>
 
<translate><!--T:133--> MediaWiki is designed for two basic access modes:</translate>
 
  
<translate>
 
 
<!--T:134-->
 
<!--T:134-->
# Everyone can view every single page on the wiki (with the possible exception of a few special pages).</translate> <translate><!--T:135--> This is the mode used by Wikipedia and its sister projects.</translate>
+
# Everyone can view every single page on the wiki (with the possible exception of a few special pages). <!--T:135--> This is the mode used by Wikipedia and its sister projects.
<translate>
+
 
 
<!--T:136-->
 
<!--T:136-->
# Anonymous users can only view the Main Page and login page, and cannot edit any page.</translate> <translate><!--T:137--> This is basically the same as the above, in terms of technical implementation (just an extra check for every page view), which is why it exists.</translate> <translate><!--T:138--> This is the mode of operation used by certain private wikis such as those used by various Wikimedia committees.</translate>
+
# Anonymous users can only view the Main Page and login page, and cannot edit any page. <!--T:137--> This is basically the same as the above, in terms of technical implementation (just an extra check for every page view), which is why it exists. <!--T:138--> This is the mode of operation used by certain private wikis such as those used by various Wikimedia committees.
 +
 
 +
'''<!--T:139--> If you intend to have different view permissions than that, MediaWiki is not designed for your usage.'''
 +
(<!--T:140--> See <tvar|1>[[phab:T3924|T3924]]</>.)
 +
<!--T:141--> Data is not necessarily clearly delineated by namespace, page name, or other criteria, and there are a lot of leaks you'll have to plug if you want to make it so (see <tvar|1>''{{ll|security issues with authorization extensions}}''</> for a sample).
 +
<!--T:142--> Other wiki software may be more suitable for your purpose.
 +
<!--T:143--> You have been warned.
 +
<!--T:144--> If you must use MediaWiki, there are three basic possibilities:
  
'''<translate><!--T:139--> If you intend to have different view permissions than that, MediaWiki is not designed for your usage.</translate>'''
 
(<translate><!--T:140--> See <tvar|1>[[phab:T3924|T3924]]</>.</translate>)
 
<translate><!--T:141--> Data is not necessarily clearly delineated by namespace, page name, or other criteria, and there are a lot of leaks you'll have to plug if you want to make it so (see <tvar|1>''{{ll|security issues with authorization extensions}}''</> for a sample).</translate>
 
<translate><!--T:142--> Other wiki software may be more suitable for your purpose.</translate>
 
<translate><!--T:143--> You have been warned.</translate>
 
<translate><!--T:144--> If you must use MediaWiki, there are three basic possibilities:</translate>
 
  
<translate>
 
 
<!--T:145-->
 
<!--T:145-->
# Set your wiki up private and whitelist specific pages that will be public with <tvar|1><code>{{ll|Manual:$wgWhitelistRead|$wgWhitelistRead}}</code></> in the <tvar|2>LocalSetting.php</> file.</translate> <translate><!--T:146--> See the section above.</translate>
+
# Set your wiki up private and whitelist specific pages that will be public with <tvar|1><code>{{ll|Manual:$wgWhitelistRead|$wgWhitelistRead}}</code></> in the <tvar|2>LocalSetting.php</> file. <!--T:146--> See the section above.
<translate>
+
 
 
<!--T:147-->
 
<!--T:147-->
# Set up separate wikis with a {{<tvar|1>ll|Manual:$wgSharedDB</>|shared user database}}, configure one as viewable and one as unviewable ([[<tvar|2>#Disable anonymous reading</>|see above]]), and {{<tvar|3>ll|Help:Interwiki linking</>|make interwiki links}} between them.</translate>
+
# Set up separate wikis with a {{<tvar|1>ll|Manual:$wgSharedDB</>|shared user database}}, configure one as viewable and one as unviewable ([[<tvar|2>#Disable anonymous reading</>|see above]]), and {{<tvar|3>ll|Help:Interwiki linking</>|make interwiki links}} between them.
<translate>
+
 
 
<!--T:148-->
 
<!--T:148-->
# Install a third-party hack or extension.</translate> <translate><!--T:149--> You will have to reapply it every time you upgrade the software, and it may not be updated immediately when new security fixes or upgrades of MediaWiki are released.</translate> <translate><!--T:150--> Third-party hacks are, of course, not supported by MediaWiki developers, and if you're having problems you shouldn't ask on <tvar|1>MediaWiki-l</>, <tvar|2>#mediawiki</>, or other official support channels.</translate> <translate><!--T:151--> A number of hacks are listed in <tvar|1>{{ll|Category:Page specific user rights extensions}}</>.</translate> <translate><!--T:152--> Read about <tvar|1>{{ll|security issues with authorization extensions}}</> if you plan to use one of those.</translate>
+
# Install a third-party hack or extension. <!--T:149--> You will have to reapply it every time you upgrade the software, and it may not be updated immediately when new security fixes or upgrades of MediaWiki are released. <!--T:150--> Third-party hacks are, of course, not supported by MediaWiki developers, and if you're having problems you shouldn't ask on <tvar|1>MediaWiki-l</>, <tvar|2>#mediawiki</>, or other official support channels. <!--T:151--> A number of hacks are listed in <tvar|1>{{ll|Category:Page specific user rights extensions}}</>. <!--T:152--> Read about <tvar|1>{{ll|security issues with authorization extensions}}</> if you plan to use one of those.
 +
 
  
<translate>
 
 
==Restricting exporting== <!--T:20-->
 
==Restricting exporting== <!--T:20-->
</translate>
 
''<translate><!--T:153--> See also:</translate> {{ll|Manual:Parameters_to_Special:Export}}''
 
  
<translate>
+
''<!--T:153--> See also: {{ll|Manual:Parameters_to_Special:Export}}''
 +
 
 +
 
 
<!--T:154-->
 
<!--T:154-->
 
It is not possible to export the contents of a page that cannot be read since <tvar|1>{{rev|19935}}</>.
 
It is not possible to export the contents of a page that cannot be read since <tvar|1>{{rev|19935}}</>.
  
 
==Removing the Login link from all pages== <!--T:155-->
 
==Removing the Login link from all pages== <!--T:155-->
</translate>
+
 
<translate><!--T:156--> One can remove the login/create account link from the upper right corner of all pages,</translate>
+
<!--T:156--> One can remove the login/create account link from the upper right corner of all pages,
<translate><!--T:157--> as users can still go to <tvar|1>[[Special:SpecialPages]]</>><tvar|2>[[Special:UserLogin]]</> to login.</translate>
+
<!--T:157--> as users can still go to <tvar|1>[[Special:SpecialPages]]</>><tvar|2>[[Special:UserLogin]]</> to login.
<translate><!--T:158--> In LocalSettings.php use (tested with MediaWiki 1.16)</translate>
+
<!--T:158--> In LocalSettings.php use (tested with MediaWiki 1.16)
  
 
<syntaxhighlight lang="php">
 
<syntaxhighlight lang="php">
Line 371: Line 371:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
<translate>
+
 
 
==Removing accounts== <!--T:159-->
 
==Removing accounts== <!--T:159-->
</translate>
 
<translate><!--T:160--> If you want to completely remove access to a user, e.g. on a [[<tvar|1>#Simple private wiki</>|simple private wiki]], it's not possible to simply delete the account ({{<tvar|2>ll|Manual:removeUnusedAccounts.php</>|unless no edits have been made}}); you can {{<tvar|3>ll|Manual:Block and unblock</>|block}} it, but the user will still {{<tvar|4>ll|Manual:Block_and_unblock#Effects_of_being_blocked</>|be able}} to read pages.</translate>
 
<translate><!--T:161--> However, using <tvar|1>{{ll|Extension:User Merge and Delete|nsp=0}}</> extension you can merge the account in another one and delete the former; the original account will then "disappear".</translate>
 
<translate><!--T:162--> If you want to preserve history readability (i.e., to have edits from the user to be still shown under their name), you can create a new account e.g. with username "OriginalUserName (deactivated)" and then merge "OriginalUserName" into the former, or even use <tvar|1>{{ll|Extension:Renameuser|nsp=0}}</> extension to rename "OriginalUserName" into "AnotherUserName", then create an account under "OriginalUserName" and merge "AnotherUserName" into it: in this manner, "OriginalUserName" will be completely "usurped" (if you've set a non-null password).</translate>
 
  
<translate>
+
<!--T:160--> If you want to completely remove access to a user, e.g. on a [[<tvar|1>#Simple private wiki</>|simple private wiki]], it's not possible to simply delete the account ({{<tvar|2>ll|Manual:removeUnusedAccounts.php</>|unless no edits have been made}}); you can {{<tvar|3>ll|Manual:Block and unblock</>|block}} it, but the user will still {{<tvar|4>ll|Manual:Block_and_unblock#Effects_of_being_blocked</>|be able}} to read pages.
 +
<!--T:161--> However, using <tvar|1>{{ll|Extension:User Merge and Delete|nsp=0}}</> extension you can merge the account in another one and delete the former; the original account will then "disappear".
 +
<!--T:162--> If you want to preserve history readability (i.e., to have edits from the user to be still shown under their name), you can create a new account e.g. with username "OriginalUserName (deactivated)" and then merge "OriginalUserName" into the former, or even use <tvar|1>{{ll|Extension:Renameuser|nsp=0}}</> extension to rename "OriginalUserName" into "AnotherUserName", then create an account under "OriginalUserName" and merge "AnotherUserName" into it: in this manner, "OriginalUserName" will be completely "usurped" (if you've set a non-null password).
 +
 
 +
 
 
<!--T:163-->
 
<!--T:163-->
 
Since MediaWiki 1.16.0, it is possible to set <tvar|1>{{ll|Manual:$wgBlockDisablesLogin|$wgBlockDisablesLogin}}</> to true to prevent access and reading to blocked users.
 
Since MediaWiki 1.16.0, it is possible to set <tvar|1>{{ll|Manual:$wgBlockDisablesLogin|$wgBlockDisablesLogin}}</> to true to prevent access and reading to blocked users.
  
 
==Other restrictions== <!--T:164-->
 
==Other restrictions== <!--T:164-->
</translate>
+
 
<translate><!--T:165--> You may want to have pages editable only by their creator, or ban viewing of history, or any of a number of other things.</translate>
+
<!--T:165--> You may want to have pages editable only by their creator, or ban viewing of history, or any of a number of other things.
<translate><!--T:166--> None of these features are available in an unhacked version of MediaWiki.</translate>
+
<!--T:166--> None of these features are available in an unhacked version of MediaWiki.
<translate><!--T:167--> If you need more fine-grained permissions, see the [[<tvar|1>#See also</>|#See also]] section for links to other wiki packages that are designed for this, as well as hacks that attempt to contort MediaWiki into something it's not designed to be but may work anyway.</translate>
+
<!--T:167--> If you need more fine-grained permissions, see the [[<tvar|1>#See also</>|#See also]] section for links to other wiki packages that are designed for this, as well as hacks that attempt to contort MediaWiki into something it's not designed to be but may work anyway.
  
 
{{anchor|See also}}
 
{{anchor|See also}}
<translate>
+
 
 
==See also== <!--T:21-->
 
==See also== <!--T:21-->
  
 
<!--T:111-->
 
<!--T:111-->
 
There are some related manual/help pages that may be of interest:
 
There are some related manual/help pages that may be of interest:
</translate>
+
 
  
 
*{{ll|Manual:LocalSettings.php}}
 
*{{ll|Manual:LocalSettings.php}}
Line 406: Line 406:
 
*{{ll|Help:User rights and groups}}
 
*{{ll|Help:User rights and groups}}
  
<translate>
+
 
 
<!--T:112-->
 
<!--T:112-->
 
'''Other wiki software''' may have better support for fine-grained access control than MediaWiki:
 
'''Other wiki software''' may have better support for fine-grained access control than MediaWiki:
Line 413: Line 413:
 
*[http://moinmo.in/HelpOnAccessControlLists MoinMoin]
 
*[http://moinmo.in/HelpOnAccessControlLists MoinMoin]
 
*[http://twiki.org/ TWiki]
 
*[http://twiki.org/ TWiki]
*[http://tikiwiki.org/ TikiWiki] - <translate><!--T:114--> has fully configuable access control to features and permission levels.</translate>
+
*[http://tikiwiki.org/ TikiWiki] - <!--T:114--> has fully configuable access control to features and permission levels.
  
<!--T:115--> If you want better access control but want to use MediaWiki, this is a list of '''extensions''' and hacks to allow restrictions not possible in the software proper.</translate>
+
<!--T:115--> If you want better access control but want to use MediaWiki, this is a list of '''extensions''' and hacks to allow restrictions not possible in the software proper.
<translate><!--T:116--> These hacks may be out-of-date (check the version they're for).</translate>
+
<!--T:116--> These hacks may be out-of-date (check the version they're for).
<translate><!--T:117--> Please don't ask in official MediaWiki support channels if something goes wrong with a third-party hack.</translate>
+
<!--T:117--> Please don't ask in official MediaWiki support channels if something goes wrong with a third-party hack.
  
 
*{{ll|Extension:FlaggedRevs|Extension:Flagged Revisions}}
 
*{{ll|Extension:FlaggedRevs|Extension:Flagged Revisions}}
Line 425: Line 425:
 
*{{ll|Extension:AuthorProtect}}
 
*{{ll|Extension:AuthorProtect}}
 
*{{ll|Extension:ArticleProtection}}
 
*{{ll|Extension:ArticleProtection}}
*{{ll|Extension:EditSubpages}} -  <translate><!--T:119--> restricts anonymous users from editing most pages</translate>
+
*{{ll|Extension:EditSubpages}} -  <!--T:119--> restricts anonymous users from editing most pages
 
*{{ll|Extension:NSFileRepo}}
 
*{{ll|Extension:NSFileRepo}}
  

Revision as of 20:01, 19 April 2021

<languages />

For help customizing user rights, see <tvar|1>Manual:User rights</>.
This page contains examples useful for restricting access.
Most of the examples need changes to MediaWiki configuration file <tvar|1>Manual:LocalSettings.php</>.
Snippets of code with no accompanying instructions must be added to <tvar|1>LocalSettings.php</> to take effect.
To add one or more lines to the file, follow these steps:


  1. If there is a <tvar|1>?></> at the end of the file, remove it. It's unnecessary and may cause problems in certain situations.
  1. Add the line to the end of the file, using a text editor. It doesn't matter if there are some blank lines above or below the addition. Do not use Windows Notepad, which may add a "Byte Order Mark" (BOM) and prevent the file from being read correctly. Typical symptoms of BOMs include white pages and errors about headers already being sent. To remove a BOM, you'll have to edit the file in a hex editor. Windows WordPad seems to work fine, as does Notepad++. Removal of BOMs can also be accomplished using the Vim text editor by opening the file in Vim, typing :set nobomb, and resaving the file. If you're using a Mac, TextEdit will also do the job.


For more detailed information on editing <tvar|1>LocalSettings.php</>, read <tvar|2>Manual:LocalSettings.php</>.



Simple private wiki

For the common use case of "a private wiki, for oneself and approved others", you need to:


Template:Warning

<syntaxhighlight lang="php">

  1. Disable reading by anonymous users

$wgGroupPermissions['*']['read'] = false;

  1. Disable anonymous editing

$wgGroupPermissions['*']['edit'] = false;

  1. Prevent new user registrations except by sysops

$wgGroupPermissions['*']['createaccount'] = false; </syntaxhighlight>

Depending on what extensions you have installed, you may want to whitelist more pages.
For example if you are using the <tvar|1>Extension:ConfirmAccount</> extension, you probably want Special:RequestAccount whitelisted.
If the content language of your wiki is not English, you may have to use the translated name of the special pages in question.


Restrict account creation

To restrict account creation, you need to edit <tvar|1>LocalSettings.php</> in the root path of your MediaWiki installation.


<syntaxhighlight lang="php">

  1. Prevent new user registrations except by sysops

$wgGroupPermissions['*']['createaccount'] = false; </syntaxhighlight>

1>Extension:ConfirmAccount</> extension if you want to set up an account confirmation queue. ( If not you may still proceed as follows.)

New users will still be able to be created by sysops, in the following manner:


  1. Go to <tvar|1>Template:Blue</>, when logged in as a sysop.
  1. Click on "Create an account" link to get to the account creation form.
  1. Enter a username and an email address, and click the "by email" button. Note you need <tvar|1>Manual:$wgEnableEmail</> or else the sysop must pick a password and send it to the user.
  1. The account will be created with a random password which is then emailed to the given address (as with the "forgot password" feature). The user will be requested to change password at first login; when they do this, the email address will also be marked as confirmed.
    When you click the "create account" button instead, you have to manually send the user their password. If you've set <tvar|1>Manual:$wgMinimalPasswordLength</> (default configuration up to version 1.15) and you've left the password field blank, the user will be emailed an email address confirmation request but will be unable to access <tvar|2>Manual:Interface/Special pages summary</> to perform the confirmation. Instead, the user will get an error (unless you've added it to <tvar|1>Manual:$wgWhitelistRead</>); the user will be able to login with a blank password and then confirm email, but their password will not have been reset (it will have to be reset manually).
It may be appropriate to edit the text displayed when a non-user attempts to log in.
This can be done at <tvar|1>MediaWiki:Nosuchuser</>, when logged in as a sysop.
Use plain text without any special formatting, as the formatting is ignored and the text is literally rendered.
(Might have changed, see <tvar|1>bug 12952</>).


You may also modify the contents of the email sent to new users by editing the page <tvar|1>MediaWiki:Createaccount-text</>.

To prevent even sysops from creating accounts:


<syntaxhighlight lang="php">

  1. Prevent new user registrations by anyone

$wgGroupPermissions['*']['createaccount'] = false; $wgGroupPermissions['sysop']['createaccount'] = false; </syntaxhighlight>


To add a message on top of the login form, modify <tvar|1>MediaWiki:Loginprompt</>.

Restrict editing


Restrict editing of all pages

Users will still be able to read pages with these modifications, and they can view the source by using [[<tvar|1>Special:Export</>/Article name]] or other methods.
See also <tvar|1>bug 1859</>.
See <tvar|1>Help:User rights</> and <tvar|2>Manual:$wgGroupPermissions</>.
If you use <tvar|1>Extension:AbuseFilter</>, any wiki admin can also put various restrictions in place.


Some examples of how to protect all pages from editing (not reading) by certain classes of users:

Restrict anonymous editing

Requires that a user be registered before they can edit.


<syntaxhighlight lang="php"> $wgGroupPermissions['*']['edit'] = false; </syntaxhighlight>


Restrict editing by all non-sysop users

Requires that a user be a member of the administrators (sysop) usergroup.


<syntaxhighlight lang="php"> $wgGroupPermissions['*']['edit'] = false; $wgGroupPermissions['user']['edit'] = false; $wgGroupPermissions['sysop']['edit'] = true; </syntaxhighlight>


Restrict editing by absolutely everyone

<syntaxhighlight lang="php"> $wgGroupPermissions['*']['edit'] = false; $wgGroupPermissions['user']['edit'] = false; $wgGroupPermissions['sysop']['edit'] = false; </syntaxhighlight>


Restrict editing of an entire namespace

Template:MW 1.10

Starting from MediaWiki version 1.10, it is possible to protect entire namespaces using the <tvar|1>Manual:$wgNamespaceProtection</> variable.
Examples:

<syntaxhighlight lang="php">

  1. Only allow autoconfirmed users to edit Project namespace

$wgNamespaceProtection[NS_PROJECT] = array( 'autoconfirmed' );

  1. Don't allow anyone to edit non-talk pages until they've confirmed their
  2. email address (assuming we have no custom namespaces and allow edits
  3. from non-emailconfirmed users to start with)
  4. Note for 1.13: emailconfirmed group and right were removed from default
  5. setup, if you want to use it, you'll have to re-enable it manually

$wgNamespaceProtection[NS_MAIN] = $wgNamespaceProtection[NS_USER] = $wgNamespaceProtection[NS_PROJECT] = $wgNamespaceProtection[NS_IMAGE] = $wgNamespaceProtection[NS_TEMPLATE] = $wgNamespaceProtection[NS_HELP] = $wgNamespaceProtection[NS_CATEGORY] = array( 'emailconfirmed' );

  1. Only allow sysops to edit "Policy" namespace

$wgGroupPermissions['sysop']['editpolicy'] = true; $wgNamespaceProtection[NS_POLICY] = array( 'editpolicy' ); </syntaxhighlight>


Note that in the last case it's assumed that a custom namespace exists and that NS_POLICY is a defined constant equal to the namespace number. See Manual:Using custom namespaces and Manual:Namespace_constants for a list of MediaWiki's core namespaces.



Restrict editing of certain specific pages

Use the {{<tvar|1>ll|Manual:Administrators#Protection</>|Protect}} feature.
By default, any sysop can protect pages so only other sysops can edit them.
In 1.9 and higher, by default they can also protect pages so only "autoconfirmed" users (with accounts older than a configured period) can edit them.
This does not require editing configuration files.
If you want to restrict editing to groups with specific permissions, edit <tvar|1>Manual:$wgRestrictionLevels</>.
To prevent actions other than edit and move, use <tvar|1>Manual:$wgRestrictionTypes</>.


Restrict editing of all but a few pages

To impose a blanket restriction on editing for all pages, but allow a few (such as sandboxes, join request pages, etc.) to be more generously editable, you can use the <tvar|1>Extension:EditSubpages</> extension.
This may not fit too often, but you could also use the [[<tvar|1>#Restrict editing of certain specific pages</>|Restrict editing of certain specific pages]] method mentioned above, with all name spaces protected, and only a special one editable by everyone which has all the pages you want editable.


Restrict editing for certain IP address ranges

Schools and other institutions may want to block all edits not from a few specified IP address ranges.
To do so, see <tvar|1>Manual:Block and unblock</>.
The only way to do this at present  without modifying the code is to go to <tvar|1>Special:Blockip</> and systematically {{<tvar|2>ll|Help:Range blocks</>|rangeblock}} every one of the address ranges that you don't want to be able to edit.
This will work for all future versions of MediaWiki.
It will not work on a per-namespace basis.


Restrict editing by a particular user

Use the user {{<tvar|1>ll|Manual:Block and unblock</>|blocking}} functionality to deprive a user of all edit access.
MediaWiki does not include a possibility to give rights to separate users directly; instead rights are always given to a user group.
There is no way in the core software to change permissions of particular users in order to restrict or allow editing particular pages, except by changing their usergroup.


Restrict creating of all pages

Revoking the edit right already prevents affected users from creating new pages and talk pages.

<syntaxhighlight lang="php">

  1. Anonymous users can't create pages

$wgGroupPermissions['*']['createpage'] = false;

  1. Only users with accounts four days old or older can create pages
  2. Requires MW 1.6 or higher.

$wgGroupPermissions['*' ]['createpage'] = false; $wgGroupPermissions['user' ]['createpage'] = false; $wgGroupPermissions['autoconfirmed']['createpage'] = true; </syntaxhighlight>


Restrict creating pages in certain namespaces

There are separate rights for creating talk pages (<tvar|1>createtalk</>) and creating non-talk pages (<tvar|2>createpage</>).
If you need per-namespace control finer than that, it is not possible in core MediaWiki, and requires an extension such as <tvar|1>Extension:Lockdown</>.


Restrict access to uploaded files

Manual:Image authorization, Manual:img_auth.php, Manual:User rights#List of permissions
If you have enabled the ability to upload files, these will be served directly by the underlying web server.
As a result, {{<tvar|1>red</>|account-based access to the file is unrestricted by default}}.

Template:Uploaded-files-access-restriction-info


Example for access restriction to uploaded files in the server configuration

If sensitive files are uploaded to an internet-accessible wiki, you may wish to add restrictions on where these can be accessed from.
On Apache, if your local network were 10.1.2.*, you could restrict serving files to local addresses with:
  <Location /mediawiki/images>
    Order deny,allow
    Allow from 10.1.2.3
    Deny from all
  </Location>


Restrict viewing


Restrict viewing of all pages

Template:Warning

Template:Warning

Template:Warning

If anonymous users can't view your page, neither can search engines. Your site will not be indexed on Google.


Add this line to your LocalSettings.php file:


<syntaxhighlight lang="php">

  1. Disable reading by anonymous users

$wgGroupPermissions['*']['read'] = false;

  1. But allow them to read e.g., these pages:

$wgWhitelistRead = [ "Main Page", "Help:Contents" ];

  1. Allow Jobs to be run

$wgWhitelistRead = [ "Special:RunJobs" ]; </syntaxhighlight>

The <tvar|1>Manual:$wgWhitelistRead</> setting allows users to view the main page.
If page names have more than one word, use a space "<tvar|1> </>" between them, not an underscore "<tvar|2>_</>".


In addition to the main page of such a private site, you could give access to the Recentchanges page (if you think that its content isn't private) for feed readers by adding "Special:Recentchanges" to <tvar|1>Manual:$wgWhitelistRead</>.

If you need to protect even the sidebar, main page, or login screen for any reason, it's recommended that you use higher-level authentication such as <tvar|1>.htpasswd</> or equivalent.


1>Special:Listusers</> won't be available, it can be determined if a username is correct from Userlogin errors. You may want to give a common text for <tvar


Restrict viewing of certain specific pages

Template:Page security extension disclaimer

To prevent anyone but sysops from viewing a page, it can simply be {{<tvar|1>ll|Help:Deletion and undeletion</>|deleted}}.
To prevent even sysops from viewing it, it can be removed more permanently using <tvar|1>Manual:RevisionDelete</>.
To completely destroy the text of the page, it can be manually removed from the database.
In any case, the page cannot be edited while in this state, and for most purposes no longer exists.
To have a page act normally for some users but be invisible to others, as is possible for instance in most forum software, is a very different matter.
MediaWiki is designed for two basic access modes:


  1. Everyone can view every single page on the wiki (with the possible exception of a few special pages). This is the mode used by Wikipedia and its sister projects.
  1. Anonymous users can only view the Main Page and login page, and cannot edit any page. This is basically the same as the above, in terms of technical implementation (just an extra check for every page view), which is why it exists. This is the mode of operation used by certain private wikis such as those used by various Wikimedia committees.

If you intend to have different view permissions than that, MediaWiki is not designed for your usage. ( See <tvar|1>T3924</>.)

Data is not necessarily clearly delineated by namespace, page name, or other criteria, and there are a lot of leaks you'll have to plug if you want to make it so (see <tvar|1>security issues with authorization extensions</> for a sample).
Other wiki software may be more suitable for your purpose.
You have been warned.
If you must use MediaWiki, there are three basic possibilities:


  1. Set your wiki up private and whitelist specific pages that will be public with <tvar|1>Manual:$wgWhitelistRead</> in the <tvar|2>LocalSetting.php</> file. See the section above.
  1. Set up separate wikis with a {{<tvar|1>ll|Manual:$wgSharedDB</>|shared user database}}, configure one as viewable and one as unviewable ([[<tvar|2>#Disable anonymous reading</>|see above]]), and {{<tvar|3>ll|Help:Interwiki linking</>|make interwiki links}} between them.
  1. Install a third-party hack or extension. You will have to reapply it every time you upgrade the software, and it may not be updated immediately when new security fixes or upgrades of MediaWiki are released. Third-party hacks are, of course, not supported by MediaWiki developers, and if you're having problems you shouldn't ask on <tvar|1>MediaWiki-l</>, <tvar|2>#mediawiki</>, or other official support channels. A number of hacks are listed in <tvar|1></>. Read about <tvar|1>security issues with authorization extensions</> if you plan to use one of those.


Restricting exporting

See also: Manual:Parameters_to_Special:Export


It is not possible to export the contents of a page that cannot be read since <tvar|1>Template:Rev</>.

Removing the Login link from all pages

One can remove the login/create account link from the upper right corner of all pages,
as users can still go to <tvar|1>Special:SpecialPages</>><tvar|2>Special:UserLogin</> to login.
In LocalSettings.php use (tested with MediaWiki 1.16)

<syntaxhighlight lang="php"> function NoLoginLinkOnMainPage( &$personal_urls ){

   unset( $personal_urls['login'] );
   unset( $personal_urls['anonlogin'] );
   return true;

} $wgHooks['PersonalUrls'][]='NoLoginLinkOnMainPage'; </syntaxhighlight>


Removing accounts

If you want to completely remove access to a user, e.g. on a [[<tvar|1>#Simple private wiki</>|simple private wiki]], it's not possible to simply delete the account ({{<tvar|2>ll|Manual:removeUnusedAccounts.php</>|unless no edits have been made}}); you can {{<tvar|3>ll|Manual:Block and unblock</>|block}} it, but the user will still {{<tvar|4>ll|Manual:Block_and_unblock#Effects_of_being_blocked</>|be able}} to read pages.
However, using <tvar|1>Extension:User Merge and Delete</> extension you can merge the account in another one and delete the former; the original account will then "disappear".
If you want to preserve history readability (i.e., to have edits from the user to be still shown under their name), you can create a new account e.g. with username "OriginalUserName (deactivated)" and then merge "OriginalUserName" into the former, or even use <tvar|1>Extension:Renameuser</> extension to rename "OriginalUserName" into "AnotherUserName", then create an account under "OriginalUserName" and merge "AnotherUserName" into it: in this manner, "OriginalUserName" will be completely "usurped" (if you've set a non-null password).


Since MediaWiki 1.16.0, it is possible to set <tvar|1>Manual:$wgBlockDisablesLogin</> to true to prevent access and reading to blocked users.

Other restrictions

You may want to have pages editable only by their creator, or ban viewing of history, or any of a number of other things.
None of these features are available in an unhacked version of MediaWiki.
If you need more fine-grained permissions, see the [[<tvar|1>#See also</>|#See also]] section for links to other wiki packages that are designed for this, as well as hacks that attempt to contort MediaWiki into something it's not designed to be but may work anyway.


See also

There are some related manual/help pages that may be of interest:



Other wiki software may have better support for fine-grained access control than MediaWiki:


If you want better access control but want to use MediaWiki, this is a list of extensions and hacks to allow restrictions not possible in the software proper.
These hacks may be out-of-date (check the version they're for).
Please don't ask in official MediaWiki support channels if something goes wrong with a third-party hack.

[[Category:MediaWiki configuration{{#translation:}}]] [[Category:Configure{{#translation:}}]] [[Category:Permission{{#translation:}}]] [[Category:Namespace{{#translation:}}]]