MediaWiki REL1_33
MWGrants.php
Go to the documentation of this file.
1<?php
21
25class MWGrants {
26
31 public static function getValidGrants() {
33
34 return array_keys( $wgGrantPermissions );
35 }
36
41 public static function getRightsByGrant() {
43
44 $res = [];
45 foreach ( $wgGrantPermissions as $grant => $rights ) {
46 $res[$grant] = array_keys( array_filter( $rights ) );
47 }
48 return $res;
49 }
50
57 public static function grantName( $grant, $lang = null ) {
58 // Give grep a chance to find the usages:
59 // grant-blockusers, grant-createeditmovepage, grant-delete,
60 // grant-editinterface, grant-editmycssjs, grant-editmywatchlist,
61 // grant-editsiteconfig, grant-editpage, grant-editprotected,
62 // grant-highvolume, grant-oversight, grant-patrol, grant-protect,
63 // grant-rollback, grant-sendemail, grant-uploadeditmovefile,
64 // grant-uploadfile, grant-basic, grant-viewdeleted,
65 // grant-viewmywatchlist, grant-createaccount
66 $msg = wfMessage( "grant-$grant" );
67 if ( $lang !== null ) {
68 if ( is_string( $lang ) ) {
69 $lang = Language::factory( $lang );
70 }
71 $msg->inLanguage( $lang );
72 }
73 if ( !$msg->exists() ) {
74 $msg = wfMessage( 'grant-generic', $grant );
75 if ( $lang ) {
76 $msg->inLanguage( $lang );
77 }
78 }
79 return $msg->text();
80 }
81
88 public static function grantNames( array $grants, $lang = null ) {
89 if ( $lang !== null && is_string( $lang ) ) {
90 $lang = Language::factory( $lang );
91 }
92
93 $ret = [];
94 foreach ( $grants as $grant ) {
95 $ret[] = self::grantName( $grant, $lang );
96 }
97 return $ret;
98 }
99
105 public static function getGrantRights( $grants ) {
106 global $wgGrantPermissions;
107
108 $rights = [];
109 foreach ( (array)$grants as $grant ) {
110 if ( isset( $wgGrantPermissions[$grant] ) ) {
111 $rights = array_merge( $rights, array_keys( array_filter( $wgGrantPermissions[$grant] ) ) );
112 }
113 }
114 return array_unique( $rights );
115 }
116
122 public static function grantsAreValid( array $grants ) {
123 return array_diff( $grants, self::getValidGrants() ) === [];
124 }
125
131 public static function getGrantGroups( $grantsFilter = null ) {
133
134 if ( is_array( $grantsFilter ) ) {
135 $grantsFilter = array_flip( $grantsFilter );
136 }
137
138 $groups = [];
139 foreach ( $wgGrantPermissions as $grant => $rights ) {
140 if ( $grantsFilter !== null && !isset( $grantsFilter[$grant] ) ) {
141 continue;
142 }
143 if ( isset( $wgGrantPermissionGroups[$grant] ) ) {
144 $groups[$wgGrantPermissionGroups[$grant]][] = $grant;
145 } else {
146 $groups['other'][] = $grant;
147 }
148 }
149
150 return $groups;
151 }
152
157 public static function getHiddenGrants() {
159
160 $grants = [];
161 foreach ( $wgGrantPermissionGroups as $grant => $group ) {
162 if ( $group === 'hidden' ) {
163 $grants[] = $grant;
164 }
165 }
166 return $grants;
167 }
168
179 public static function getGrantsLink( $grant, $lang = null ) {
180 $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
181 return $linkRenderer->makeKnownLink(
182 \SpecialPage::getTitleFor( 'Listgrants', false, $grant ),
183 self::grantName( $grant, $lang )
184 );
185 }
186
193 public static function getGrantsWikiText( $grantsFilter, $lang = null ) {
194 if ( is_string( $lang ) ) {
195 $lang = Language::factory( $lang );
196 } elseif ( $lang === null ) {
197 $lang = MediaWikiServices::getInstance()->getContentLanguage();
198 }
199
200 $s = '';
201 foreach ( self::getGrantGroups( $grantsFilter ) as $group => $grants ) {
202 if ( $group === 'hidden' ) {
203 continue; // implicitly granted
204 }
205 $s .= "*<span class=\"mw-grantgroup\">" .
206 wfMessage( "grant-group-$group" )->inLanguage( $lang )->text() . "</span>\n";
207 $s .= ":" . $lang->semicolonList( self::grantNames( $grants, $lang ) ) . "\n";
208 }
209 return "$s\n";
210 }
211
212}
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
array $wgGrantPermissions
Map of (grant => right => boolean) Users authorize consumers (like Apps) to act on their behalf but o...
array $wgGrantPermissionGroups
Map of grants to their UI grouping.
A collection of public static functions to deal with grants.
Definition MWGrants.php:25
static getGrantsWikiText( $grantsFilter, $lang=null)
Generate wikitext to display a list of grants.
Definition MWGrants.php:193
static grantName( $grant, $lang=null)
Fetch the display name of the grant.
Definition MWGrants.php:57
static getHiddenGrants()
Get the list of grants that are hidden and should always be granted.
Definition MWGrants.php:157
static grantNames(array $grants, $lang=null)
Fetch the display names for the grants.
Definition MWGrants.php:88
static getGrantsLink( $grant, $lang=null)
Generate a link to Special:ListGrants for a particular grant name.
Definition MWGrants.php:179
static getRightsByGrant()
Map all grants to corresponding user rights.
Definition MWGrants.php:41
static grantsAreValid(array $grants)
Test that all grants in the list are known.
Definition MWGrants.php:122
static getGrantRights( $grants)
Fetch the rights allowed by a set of grants.
Definition MWGrants.php:105
static getGrantGroups( $grantsFilter=null)
Divide the grants into groups.
Definition MWGrants.php:131
static getValidGrants()
List all known grants.
Definition MWGrants.php:31
MediaWikiServices is the service locator for the application scope of MediaWiki.
$res
Definition database.txt:21
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses & $ret
Definition hooks.txt:2003
either a unescaped string or a HtmlArmor object after in associative array form externallinks including delete and has completed for all link tables whether this was an auto creation use $formDescriptor instead default is conds Array Extra conditions for the No matching items in log is displayed if loglist is empty msgKey Array If you want a nice box with a set this to the key of the message First element is the message additional optional elements are parameters for the key that are processed with wfMessage() -> params() ->parseAsBlock() - offset Set to overwrite offset parameter in $wgRequest set to '' to unset offset - wrap String Wrap the message in html(usually something like "&lt;div ...>$1&lt;/div>"). - flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException':Called before an exception(or PHP error) is logged. This is meant for integration with external error aggregation services
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned and may include noclasses after processing after in associative array form before processing starts Return false to skip default processing and return $ret $linkRenderer
Definition hooks.txt:2054
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition injection.txt:37
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))
if(!isset( $args[0])) $lang