MediaWiki  master
GrantsLocalization.php
Go to the documentation of this file.
1 <?php
21 namespace MediaWiki\Permissions;
22 
23 use Language;
26 use SpecialPage;
27 
39  private $grantsInfo;
40 
42  private $linkRenderer;
43 
46 
49 
56  public function __construct(
61  ) {
62  $this->grantsInfo = $grantsInfo;
63  $this->linkRenderer = $linkRenderer;
64  $this->languageFactory = $languageFactory;
65  $this->contentLanguage = $contentLanguage;
66  }
67 
74  public function getGrantDescription( string $grant, $lang = null ): string {
75  // Give grep a chance to find the usages:
76  // grant-blockusers, grant-createeditmovepage, grant-delete,
77  // grant-editinterface, grant-editmycssjs, grant-editmywatchlist,
78  // grant-editsiteconfig, grant-editpage, grant-editprotected,
79  // grant-highvolume, grant-oversight, grant-patrol, grant-protect,
80  // grant-rollback, grant-sendemail, grant-uploadeditmovefile,
81  // grant-uploadfile, grant-basic, grant-viewdeleted,
82  // grant-viewmywatchlist, grant-createaccount, grant-mergehistory,
83  // grant-import
84 
85  // TODO: replace wfMessage with something that can be injected like TextFormatter
86  $msg = wfMessage( "grant-$grant" );
87 
88  if ( $lang ) {
89  $msg->inLanguage( $lang );
90  }
91 
92  if ( !$msg->exists() ) {
93  $msg = $lang
94  ? wfMessage( 'grant-generic', $grant )->inLanguage( $lang )
95  : wfMessage( 'grant-generic', $grant );
96  }
97 
98  return $msg->text();
99  }
100 
107  public function getGrantDescriptions( array $grants, $lang = null ): array {
108  $ret = [];
109 
110  foreach ( $grants as $grant ) {
111  $ret[] = $this->getGrantDescription( $grant, $lang );
112  }
113  return $ret;
114  }
115 
126  public function getGrantsLink( string $grant, $lang = null ): string {
127  return $this->linkRenderer->makeKnownLink(
128  SpecialPage::getTitleFor( 'Listgrants', false, $grant ),
129  $this->getGrantDescription( $grant, $lang )
130  );
131  }
132 
139  public function getGrantsWikiText( $grantsFilter, $lang = null ): string {
140  if ( is_string( $lang ) ) {
141  $lang = $this->languageFactory->getLanguage( $lang );
142  } elseif ( $lang === null ) {
144  }
145 
146  $s = '';
147  foreach ( $this->grantsInfo->getGrantGroups( $grantsFilter ) as $group => $grants ) {
148  if ( $group === 'hidden' ) {
149  continue; // implicitly granted
150  }
151  // Give grep a chance to find the usages:
152  // grant-group-page-interaction, grant-group-file-interaction
153  // grant-group-watchlist-interaction, grant-group-email,
154  // grant-group-high-volume, grant-group-customization,
155  // grant-group-administration, grant-group-private-information,
156  // grant-group-other
157  $s .= "*<span class=\"mw-grantgroup\">" .
158  // TODO: replace wfMessage with something that can be injected like TextFormatter
159  wfMessage( "grant-group-$group" )->inLanguage( $lang )->text() . "</span>\n";
160  $s .= ":" . $lang->semicolonList( $this->getGrantDescriptions( $grants, $lang ) ) . "\n";
161  }
162  return "$s\n";
163  }
164 }
MediaWiki\Permissions\GrantsLocalization\getGrantsLink
getGrantsLink(string $grant, $lang=null)
Generate a link to Special:ListGrants for a particular grant name.
Definition: GrantsLocalization.php:126
$lang
if(!isset( $args[0])) $lang
Definition: testCompression.php:37
MediaWiki\Permissions\GrantsLocalization\$contentLanguage
Language $contentLanguage
Definition: GrantsLocalization.php:48
MediaWiki\Languages\LanguageFactory
Internationalisation code See https://www.mediawiki.org/wiki/Special:MyLanguage/Localisation for more...
Definition: LanguageFactory.php:42
MediaWiki\Linker\LinkRenderer
Class that generates HTML links for pages.
Definition: LinkRenderer.php:43
wfMessage
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
Definition: GlobalFunctions.php:1183
SpecialPage\getTitleFor
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,...
Definition: SpecialPage.php:107
MediaWiki\Permissions\GrantsLocalization\getGrantDescription
getGrantDescription(string $grant, $lang=null)
Fetch the description of the grant.
Definition: GrantsLocalization.php:74
MediaWiki\Permissions\GrantsLocalization\getGrantDescriptions
getGrantDescriptions(array $grants, $lang=null)
Fetch the descriptions for the grants.
Definition: GrantsLocalization.php:107
MediaWiki\Permissions\GrantsLocalization\$grantsInfo
GrantsInfo $grantsInfo
Definition: GrantsLocalization.php:39
MediaWiki\Permissions\GrantsLocalization\__construct
__construct(GrantsInfo $grantsInfo, LinkRenderer $linkRenderer, LanguageFactory $languageFactory, Language $contentLanguage)
Definition: GrantsLocalization.php:56
MediaWiki\Permissions\GrantsLocalization\$languageFactory
LanguageFactory $languageFactory
Definition: GrantsLocalization.php:45
$s
foreach( $mmfl['setupFiles'] as $fileName) if( $queue) if(empty( $mmfl['quiet'])) $s
Definition: mergeMessageFileList.php:206
SpecialPage
Parent class for all special pages.
Definition: SpecialPage.php:43
MediaWiki\Permissions\GrantsLocalization\getGrantsWikiText
getGrantsWikiText( $grantsFilter, $lang=null)
Generate wikitext to display a list of grants.
Definition: GrantsLocalization.php:139
MediaWiki\Permissions\GrantsLocalization\$linkRenderer
LinkRenderer $linkRenderer
Definition: GrantsLocalization.php:42
MediaWiki\Permissions\GrantsInfo
Users can authorize applications to use their account via OAuth.
Definition: GrantsInfo.php:32
MediaWiki\Permissions\GrantsLocalization
This separate service is needed because the ::getGrantsLink method requires a LinkRenderer and if we ...
Definition: GrantsLocalization.php:37
Language
Internationalisation code See https://www.mediawiki.org/wiki/Special:MyLanguage/Localisation for more...
Definition: Language.php:42
MediaWiki\Permissions
Definition: Authority.php:21