MediaWiki REL1_37
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, grant-mergehistory,
66 // grant-import
67 $msg = wfMessage( "grant-$grant" );
68
69 if ( $lang ) {
70 $msg->inLanguage( $lang );
71 }
72
73 if ( !$msg->exists() ) {
74 $msg = $lang
75 ? wfMessage( 'grant-generic', $grant )->inLanguage( $lang )
76 : wfMessage( 'grant-generic', $grant );
77 }
78
79 return $msg->text();
80 }
81
88 public static function grantNames( array $grants, $lang = null ) {
89 $ret = [];
90
91 foreach ( $grants as $grant ) {
92 $ret[] = self::grantName( $grant, $lang );
93 }
94 return $ret;
95 }
96
102 public static function getGrantRights( $grants ) {
103 global $wgGrantPermissions;
104
105 $rights = [];
106 foreach ( (array)$grants as $grant ) {
107 if ( isset( $wgGrantPermissions[$grant] ) ) {
108 $rights = array_merge( $rights, array_keys( array_filter( $wgGrantPermissions[$grant] ) ) );
109 }
110 }
111 return array_unique( $rights );
112 }
113
119 public static function grantsAreValid( array $grants ) {
120 return array_diff( $grants, self::getValidGrants() ) === [];
121 }
122
128 public static function getGrantGroups( $grantsFilter = null ) {
130
131 if ( is_array( $grantsFilter ) ) {
132 $grantsFilter = array_fill_keys( $grantsFilter, true );
133 }
134
135 $groups = [];
136 foreach ( $wgGrantPermissions as $grant => $rights ) {
137 if ( $grantsFilter !== null && !isset( $grantsFilter[$grant] ) ) {
138 continue;
139 }
140 if ( isset( $wgGrantPermissionGroups[$grant] ) ) {
141 $groups[$wgGrantPermissionGroups[$grant]][] = $grant;
142 } else {
143 $groups['other'][] = $grant;
144 }
145 }
146
147 return $groups;
148 }
149
154 public static function getHiddenGrants() {
156
157 $grants = [];
158 foreach ( $wgGrantPermissionGroups as $grant => $group ) {
159 if ( $group === 'hidden' ) {
160 $grants[] = $grant;
161 }
162 }
163 return $grants;
164 }
165
176 public static function getGrantsLink( $grant, $lang = null ) {
177 $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
178 return $linkRenderer->makeKnownLink(
179 \SpecialPage::getTitleFor( 'Listgrants', false, $grant ),
180 self::grantName( $grant, $lang )
181 );
182 }
183
190 public static function getGrantsWikiText( $grantsFilter, $lang = null ) {
191 if ( is_string( $lang ) ) {
192 $lang = MediaWikiServices::getInstance()->getLanguageFactory()->getLanguage( $lang );
193 } elseif ( $lang === null ) {
194 $lang = MediaWikiServices::getInstance()->getContentLanguage();
195 }
196
197 $s = '';
198 foreach ( self::getGrantGroups( $grantsFilter ) as $group => $grants ) {
199 if ( $group === 'hidden' ) {
200 continue; // implicitly granted
201 }
202 $s .= "*<span class=\"mw-grantgroup\">" .
203 wfMessage( "grant-group-$group" )->inLanguage( $lang )->text() . "</span>\n";
204 $s .= ":" . $lang->semicolonList( self::grantNames( $grants, $lang ) ) . "\n";
205 }
206 return "$s\n";
207 }
208
209}
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.
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
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:190
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:154
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:176
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:119
static getGrantRights( $grants)
Fetch the rights allowed by a set of grants.
Definition MWGrants.php:102
static getGrantGroups( $grantsFilter=null)
Divide the grants into groups.
Definition MWGrants.php:128
static getValidGrants()
List all known grants.
Definition MWGrants.php:31
MediaWikiServices is the service locator for the application scope of MediaWiki.
static getTitleFor( $name, $subpage=false, $fragment='')
Get a localised Title object for a specified special page name If you don't need a full Title object,...
foreach( $mmfl['setupFiles'] as $fileName) if($queue) if(empty( $mmfl['quiet'])) $s
if(!isset( $args[0])) $lang