Mediawiki Extension RightFunctions

From Micylou WIKI
This is the latest revision of this page; it has no approved revision.
Jump to navigation Jump to search
Source: DataSource
Language: English
Topic: Mediawiki
SubTopic: Mediawiki Extension
Last Edit By: DochyJP
LastEdit: 2021-04-14
Document type: Documentation
Status: Active
Access: free

Description

The RightFunctions extension tests various page or user permissions and displays text based off of them.

Please note that these parser functions may be used to superficially hide information from those with certain rights. Also note that all functions disable the cache on the page they are used in unless you set $wgRightFunctionsAllowCaching to true.

Installation

Download

Download and place the file(s) in a directory called RightFunctions in your extensions/ folder.

Version 1.35 LTS

Activation

Add the following code at the bottom of your LocalSettings.php:

require_once "$IP/extensions/RightFunctions/RightFunctions.php";

Configuration

These variables control how the various parser functions work. There are currently 4 variables.

  • $wgRightFunctionsUserGroups : Default value: array( '*', 'user', 'autoconfirmed', 'sysop', 'bureaucrat' ).
    An array of groups to test for in #Usergroup. They are arranged in order of least to greatest for group testing.
  • $wgRightFunctionsAllowCaching : Default value: false.
    If set to true, the functions do not disable the parser cache and they do not trigger the recache when getting a user's groups. It is recommended that you leave this as false.
  • $wgRightFunctionsAllowExpensiveQueries : Default value: true.
    If set to true, using ifpageright and ifpageallowed will check the rights more thoroughly (like through cascading protection), so it will produce more accurate results, but it will me more server-intensive to perform. It is recommended that you leave this as true.
  • $wgRightFunctionsDisableFunctions : Default value: array();
    Functions in this array will not get evaluated and will simply return nothing.

Usage

Ifright

Tests whether the current user has the given right, then displays the appropriate text. If the right doesn't exist, it simply returns else. If no right is specified, it returns then. This function ignores per-page restrictions on a user's rights, so use #Ifpageright if you need that functionality.
Usage: {{#ifright:right|then|else}}

Ifallowed

Tests whether the given user has the given right, then displays the appropriate text. This function will return nothing unless a user is defined. This function ignores per-page restrictions on a user's rights, so use #Ifpageallowed if you need that functionality.
Usage: {{#ifallowed:user|right|then|else}}

Switchright

A switch statement that tests whether the current user has the rights. This operates much like the ParserFunctions #switch statement.

Usage: {{#switchright:right1=result1|right2|right3=result2 and 3|right4=result4|default (or #default=default if the default text contains =)}}

Userrights

Lists all rights in an unordered list either of the current user or of the given user. If a user isn't defined, it triggers on the current user instead.

Usage: {{#userrights:}} (for current user) or {{#userrights:user}} (for other users)<//nowiki> === Usergroup === Returns the highest user group the user belongs to. The groups are defined in lowest-to-highest ranking in the array $wgRightFunctionsUserGroups. If a user isn't defined, it triggers on the current user instead.<br> Usage: <nowiki>{{#usergroup:}} (for current user) or {{#usergroup:user}} (for other users)

Ifgroup

Tests if the given user is in the specified group. If no user is specified, it tests the current user. If no group is specified, it returns else.

Usage: {{#ifgroup:group|then|else}} (for current user) or {{#ifgroup:group|then|else|user}} (for other users)

Switchgroup

A switch statement that tests whether the current user is in a group. This operates much like the ParserFunctions #switch statement.

Usage: {{#switchgroup:group1=result1|group2|group3=result2 and 3|group4=result4|default (or #default=default if the default text contains =)}}

Ifpageright

Tests whether the current user has the given right on the given page, then displays the appropriate text. If the right doesn't exist, it simply returns else. If no right is specified, it returns then. This function does not ignore per-page restrictions on a user's rights.

Usage: {{#ifpageright:right|then|else|page}} for testing other pages or {{#ifpageright:right|then|else}} for testing the current page.

Ifpageallowed

Tests whether the given user has the given right on the given page, then displays the appropriate text. If no user is specified, it returns nothing. If no page is specified, it checks the current page. If the right doesn't exist, it returns else and if no right is specified, it returns then. This function does not ignore per-page restrictions on a user's rights.

Usage: {{#ifpageallowed:user|right|then|else|page}} for testing other pages or {{#ifpageallowed:user|right|then|else}} for testing the current page.

Ifprotected

Tests whether the given page is protected, then displays the appropriate text. If no page is given, it tests the current page. It will return then if the page is either fully-protected, semi-protected, protected because it is included in a cascading-protected page, or if it is namespace-protected. You may control which of these are tested by adding the letters "f", "s", "c", and/or "n" (standing for fully-protected, semi-protected, cascading-protected, and namespace-protected, respectively) to the fourth parameter of the page (by default all 4 are tested).

Usage: {{#ifprotected:then|else|page}} for testing other pages, or {{#ifprotected:then|else}} for testing the current page or (for example) {{#ifprotected:then|else|page|fns}} for testing only certain types of protection.

Getrestrictions

Grabs what right is required to carry out the action on the given page. If no page is given, it checks the current page instead. If no right is given, it checks the 'edit' right. If there are no restrictions on that page for the particular right, it returns the empty string (""). If the page has cascading restrictions as well, it returns the highest restriction level for the page (from all cascading sources and the local page itself). If you would like all the restrictions to be listed instead, set the third parameter to "true". If you do, the output format changes to be more detailed, depending on what restrictions exist for the current page, cascading-protected sources, and namespace protection.

Usage: {{#getrestrictions:right|page}} for testing other pages, or {{#getrestrictions:right}} for testing the current page or {{#getrestrictions:right|page|true}} for listing all restrictions instead of just the highest one.



Back to top of page - Back to Welcome Page