42 $userrightsInterwikiDelimiter = $this->context->getConfig()
45 if ( !$this->plaintext ) {
47 ucfirst( $title->getDBkey() );
48 $parts = explode( $userrightsInterwikiDelimiter, $text, 2 );
50 if ( count( $parts ) === 2 ) {
52 $titleLink = WikiMap::foreignUserLink(
56 strtr( $parts[0],
'_',
' ' ) .
57 $userrightsInterwikiDelimiter .
62 if ( $titleLink !==
false ) {
68 return parent::makePageLink( $title, $parameters, $title ? $title->getText() : null );
72 $key = parent::getMessageKey();
74 if ( !isset( $params[3] ) && !isset( $params[4] ) ) {
83 $params = parent::getMessageParameters();
97 if ( count( $oldGroups ) ) {
100 $params[3] = $this->
msg(
'rightsnone' )->text();
102 if ( count( $newGroups ) ) {
105 $params[4] = $this->
msg(
'rightsnone' )->text();
108 $performerName = $params[1];
109 $userName = $this->entry->getTarget()->getText();
111 $params[5] = $userName;
124 $messagePrefix =
'logentry-rights-rights-';
125 if ( $this->entry->getSubtype() ===
'autopromote' ) {
126 $messagePrefix =
'logentry-rights-autopromote-';
145 return isset( $params[3] ) || isset( $params[4] );
158 if ( !isset( $params[3] ) ) {
162 $allParams = $this->entry->getParameters();
176 if ( !isset( $params[4] ) ) {
180 $allParams = $this->entry->getParameters();
197 $groupNames = $this->makeGroupArray( $groupNames );
198 if ( !$this->plaintext && count( $groupNames ) ) {
204 array_map(
null, $groupNames, $metadata )
205 as [ $groupName, $groupMetadata ]
207 if ( isset( $groupMetadata[
'expiry'] ) ) {
208 $expiry = $groupMetadata[
'expiry'];
212 $expiries[$groupName] = $expiry;
225 $lang = $this->context->getLanguage();
226 $userName = $this->entry->getTarget()->getText();
227 foreach ( $groupNames as &$group ) {
228 $group = $lang->getGroupMemberName( $group, $userName );
248 $granted = array_diff_key( $newGroups, $oldGroups );
249 $revoked = array_diff_key( $oldGroups, $newGroups );
250 $kept = array_intersect_key( $oldGroups, $newGroups );
255 foreach ( $kept as $group => $oldExpiry ) {
256 $newExpiry = $newGroups[$group];
257 if ( $oldExpiry !== $newExpiry ) {
258 $expiryChanged[$group] = [ $oldExpiry, $newExpiry ];
260 $noChange[$group] = $oldExpiry;
267 'granted' => $granted,
268 'revoked' => $revoked,
269 'expiry-changed' => $expiryChanged,
285 string $targetName,
string $messagePrefix =
'logentry-rights-rights-'
287 $formattedChanges = [];
289 foreach ( $groupChanges as $changeType => $groups ) {
290 if ( !count( $groups ) ) {
294 if ( $changeType ===
'expiry-changed' ) {
295 $formattedList = $this->formatRightsListExpiryChanged( $groups );
297 $formattedList = $this->formatRightsList( $groups );
300 $formattedChanges[] = $this->
msg(
301 $messagePrefix . $changeType,
308 $uiLanguage = $this->context->getLanguage();
309 return $uiLanguage->semicolonList( $formattedChanges );
312 private function formatRightsListExpiryChanged( array $groups ): string {
315 foreach ( $groups as $group => [ $oldExpiry, $newExpiry ] ) {
316 $oldExpiryFormatted = $oldExpiry ? $this->formatDate( $oldExpiry ) : false;
317 $newExpiryFormatted = $newExpiry ? $this->formatDate( $newExpiry ) : false;
319 if ( $oldExpiryFormatted && $newExpiryFormatted ) {
321 $list[] = $this->
msg(
'rightslogentry-expiry-changed' )->params(
323 $newExpiryFormatted[
'whole'],
324 $newExpiryFormatted[
'date'],
325 $newExpiryFormatted[
'time'],
326 $oldExpiryFormatted[
'whole'],
327 $oldExpiryFormatted[
'date'],
328 $oldExpiryFormatted[
'time']
330 } elseif ( $oldExpiryFormatted ) {
332 $list[] = $this->
msg(
'rightslogentry-expiry-removed' )->params(
334 $oldExpiryFormatted[
'whole'],
335 $oldExpiryFormatted[
'date'],
336 $oldExpiryFormatted[
'time']
338 } elseif ( $newExpiryFormatted ) {
340 $list[] = $this->
msg(
'rightslogentry-expiry-set' )->params(
342 $newExpiryFormatted[
'whole'],
343 $newExpiryFormatted[
'date'],
344 $newExpiryFormatted[
'time']
349 $list[] = htmlspecialchars( $group );
353 $uiLanguage = $this->context->getLanguage();
354 return $uiLanguage->listToText( $list );
357 private function formatRightsList( array $groups ): string {
358 $uiLanguage = $this->context->getLanguage();
360 $tempList = $permList = [];
362 foreach ( $groups as $group => $expiry ) {
365 $expiryFormatted = $this->formatDate( $expiry );
366 $tempList[] = $this->msg(
'rightslogentry-temporary-group' )->params( $group,
367 $expiryFormatted[
'whole'], $expiryFormatted[
'date'], $expiryFormatted[
'time'] )
371 $permList[] = htmlspecialchars( $group );
377 return $uiLanguage->listToText( array_merge( $tempList, $permList ) );
380 private function formatDate(
string $date ): array {
381 $uiLanguage = $this->context->getLanguage();
382 $uiUser = $this->context->getUser();
385 'whole' => $uiLanguage->userTimeAndDate( $date, $uiUser ),
386 'date' => $uiLanguage->userDate( $date, $uiUser ),
387 'time' => $uiLanguage->userTime( $date, $uiUser ),
392 $entry = $this->entry;
393 $params = $entry->getParameters();
398 '4::oldgroups' =>
'4:array:oldgroups',
399 '5::newgroups' =>
'5:array:newgroups',
401 foreach ( $map as $index => $key ) {
402 if ( isset( $params[$index] ) ) {
403 $params[$key] = $params[$index];
404 unset( $params[$index] );
412 if ( isset( $params[
'4:array:oldgroups'] ) ) {
413 $params[
'4:array:oldgroups'] = $this->makeGroupArray( $params[
'4:array:oldgroups'] );
415 $oldmetadata =& $params[
'oldmetadata'];
417 unset( $params[
'oldmetadata'] );
418 $params[
'oldmetadata'] = array_map(
static function ( $index ) use ( $params, $oldmetadata ) {
419 $result = [
'group' => $params[
'4:array:oldgroups'][$index] ];
420 if ( isset( $oldmetadata[$index] ) ) {
421 $result += $oldmetadata[$index];
423 $result[
'expiry'] = ApiResult::formatExpiry( $result[
'expiry'] ??
null );
426 }, array_keys( $params[
'4:array:oldgroups'] ) );
429 if ( isset( $params[
'5:array:newgroups'] ) ) {
430 $params[
'5:array:newgroups'] = $this->makeGroupArray( $params[
'5:array:newgroups'] );
432 $newmetadata =& $params[
'newmetadata'];
434 unset( $params[
'newmetadata'] );
435 $params[
'newmetadata'] = array_map(
static function ( $index ) use ( $params, $newmetadata ) {
436 $result = [
'group' => $params[
'5:array:newgroups'][$index] ];
437 if ( isset( $newmetadata[$index] ) ) {
438 $result += $newmetadata[$index];
440 $result[
'expiry'] = ApiResult::formatExpiry( $result[
'expiry'] ??
null );
443 }, array_keys( $params[
'5:array:newgroups'] ) );
450 $ret = parent::formatParametersForApi();
451 if ( isset( $ret[
'oldgroups'] ) ) {
452 ApiResult::setIndexedTagName( $ret[
'oldgroups'],
'g' );
454 if ( isset( $ret[
'newgroups'] ) ) {
455 ApiResult::setIndexedTagName( $ret[
'newgroups'],
'g' );
457 if ( isset( $ret[
'oldmetadata'] ) ) {
458 ApiResult::setArrayType( $ret[
'oldmetadata'],
'array' );
459 ApiResult::setIndexedTagName( $ret[
'oldmetadata'],
'g' );
461 if ( isset( $ret[
'newmetadata'] ) ) {
462 ApiResult::setArrayType( $ret[
'newmetadata'],
'array' );
463 ApiResult::setIndexedTagName( $ret[
'newmetadata'],
'g' );
471 private function makeGroupArray( $group ): array {
473 if ( $group ===
'' ) {
475 } elseif ( is_string( $group ) ) {
476 $group = array_map(
'trim', explode(
',', $group ) );
483class_alias( RightsLogFormatter::class,
'RightsLogFormatter' );
if(!defined('MW_SETUP_CALLBACK'))
A class containing constants representing the names of configuration variables.
const UserrightsInterwikiDelimiter
Name constant for the UserrightsInterwikiDelimiter setting, for use with Config::get()