35 $performerName = $this->entry->getPerformerIdentity()->getName();
39 return ExternalUserNames::getPrefix( $performerName );
44 $userrightsInterwikiDelimiter = $this->context->getConfig()
47 if ( !$this->plaintext ) {
49 ucfirst( $title->getDBkey() );
50 $parts = explode( $userrightsInterwikiDelimiter, $text, 2 );
52 if ( count( $parts ) === 2 ) {
54 $titleLink = WikiMap::foreignUserLink(
58 strtr( $parts[0],
'_',
' ' ) .
59 $userrightsInterwikiDelimiter .
64 if ( $titleLink !==
false ) {
70 return parent::makePageLink( $title, $parameters, $title ? $title->getText() : null );
75 $key = parent::getMessageKey();
77 if ( !isset( $params[3] ) && !isset( $params[4] ) ) {
87 $params = parent::getMessageParameters();
101 if ( count( $oldGroups ) ) {
104 $params[3] = $this->
msg(
'rightsnone' )->text();
106 if ( count( $newGroups ) ) {
109 $params[4] = $this->
msg(
'rightsnone' )->text();
112 $performerName = $params[1];
113 $userName = $this->entry->getTarget()->getText();
115 $params[5] = $userName;
128 $messagePrefix =
'logentry-rights-rights-';
129 if ( $this->entry->getSubtype() ===
'autopromote' ) {
130 $messagePrefix =
'logentry-rights-autopromote-';
149 return isset( $params[3] ) || isset( $params[4] );
162 if ( !isset( $params[3] ) ) {
166 $allParams = $this->entry->getParameters();
180 if ( !isset( $params[4] ) ) {
184 $allParams = $this->entry->getParameters();
201 $groupNames = $this->makeGroupArray( $groupNames );
202 if ( !$this->plaintext && count( $groupNames ) ) {
208 array_map(
null, $groupNames, $metadata )
209 as [ $groupName, $groupMetadata ]
211 if ( isset( $groupMetadata[
'expiry'] ) ) {
212 $expiry = $groupMetadata[
'expiry'];
216 $expiries[$groupName] = $expiry;
229 $lang = $this->context->getLanguage();
230 $userName = $this->entry->getTarget()->getText();
231 foreach ( $groupNames as &$group ) {
232 $group = $lang->getGroupMemberName( $group, $userName );
252 $granted = array_diff_key( $newGroups, $oldGroups );
253 $revoked = array_diff_key( $oldGroups, $newGroups );
254 $kept = array_intersect_key( $oldGroups, $newGroups );
259 foreach ( $kept as $group => $oldExpiry ) {
260 $newExpiry = $newGroups[$group];
261 if ( $oldExpiry !== $newExpiry ) {
262 $expiryChanged[$group] = [ $oldExpiry, $newExpiry ];
264 $noChange[$group] = $oldExpiry;
271 'granted' => $granted,
272 'revoked' => $revoked,
273 'expiry-changed' => $expiryChanged,
289 string $targetName,
string $messagePrefix =
'logentry-rights-rights-'
291 $formattedChanges = [];
293 foreach ( $groupChanges as $changeType => $groups ) {
294 if ( !count( $groups ) ) {
298 if ( $changeType ===
'expiry-changed' ) {
299 $formattedList = $this->formatRightsListExpiryChanged( $groups );
301 $formattedList = $this->formatRightsList( $groups );
304 $formattedChanges[] = $this->
msg(
305 $messagePrefix . $changeType,
312 $uiLanguage = $this->context->getLanguage();
313 return $uiLanguage->semicolonList( $formattedChanges );
316 private function formatRightsListExpiryChanged( array $groups ): string {
319 foreach ( $groups as $group => [ $oldExpiry, $newExpiry ] ) {
320 $oldExpiryFormatted = $oldExpiry ? $this->formatDate( $oldExpiry ) : false;
321 $newExpiryFormatted = $newExpiry ? $this->formatDate( $newExpiry ) : false;
323 if ( $oldExpiryFormatted && $newExpiryFormatted ) {
325 $list[] = $this->
msg(
'rightslogentry-expiry-changed' )->params(
327 $newExpiryFormatted[
'whole'],
328 $newExpiryFormatted[
'date'],
329 $newExpiryFormatted[
'time'],
330 $oldExpiryFormatted[
'whole'],
331 $oldExpiryFormatted[
'date'],
332 $oldExpiryFormatted[
'time']
334 } elseif ( $oldExpiryFormatted ) {
336 $list[] = $this->
msg(
'rightslogentry-expiry-removed' )->params(
338 $oldExpiryFormatted[
'whole'],
339 $oldExpiryFormatted[
'date'],
340 $oldExpiryFormatted[
'time']
342 } elseif ( $newExpiryFormatted ) {
344 $list[] = $this->
msg(
'rightslogentry-expiry-set' )->params(
346 $newExpiryFormatted[
'whole'],
347 $newExpiryFormatted[
'date'],
348 $newExpiryFormatted[
'time']
353 $list[] = htmlspecialchars( $group );
357 $uiLanguage = $this->context->getLanguage();
358 return $uiLanguage->listToText( $list );
361 private function formatRightsList( array $groups ): string {
364 $tempList = $permList = [];
366 foreach ( $groups as $group => $expiry ) {
369 $expiryFormatted = $this->formatDate( $expiry );
370 $tempList[] = $this->
msg(
'rightslogentry-temporary-group' )->params( $group,
371 $expiryFormatted[
'whole'], $expiryFormatted[
'date'], $expiryFormatted[
'time'] )
375 $permList[] = htmlspecialchars( $group );
381 return $uiLanguage->listToText( array_merge( $tempList, $permList ) );
384 private function formatDate(
string $date ): array {
386 $uiUser = $this->context->getUser();
389 'whole' => $uiLanguage->userTimeAndDate( $date, $uiUser ),
390 'date' => $uiLanguage->userDate( $date, $uiUser ),
391 'time' => $uiLanguage->userTime( $date, $uiUser ),
397 $entry = $this->entry;
398 $params = $entry->getParameters();
403 '4::oldgroups' =>
'4:array:oldgroups',
404 '5::newgroups' =>
'5:array:newgroups',
406 foreach ( $map as $index => $key ) {
407 if ( isset( $params[$index] ) ) {
408 $params[$key] = $params[$index];
409 unset( $params[$index] );
417 if ( isset( $params[
'4:array:oldgroups'] ) ) {
418 $params[
'4:array:oldgroups'] = $this->makeGroupArray( $params[
'4:array:oldgroups'] );
420 $oldmetadata =& $params[
'oldmetadata'];
422 unset( $params[
'oldmetadata'] );
423 $params[
'oldmetadata'] = array_map(
static function ( $index ) use ( $params, $oldmetadata ) {
424 $result = [
'group' => $params[
'4:array:oldgroups'][$index] ];
425 if ( isset( $oldmetadata[$index] ) ) {
426 $result += $oldmetadata[$index];
428 $result[
'expiry'] = ApiResult::formatExpiry( $result[
'expiry'] ??
null );
431 }, array_keys( $params[
'4:array:oldgroups'] ) );
434 if ( isset( $params[
'5:array:newgroups'] ) ) {
435 $params[
'5:array:newgroups'] = $this->makeGroupArray( $params[
'5:array:newgroups'] );
437 $newmetadata =& $params[
'newmetadata'];
439 unset( $params[
'newmetadata'] );
440 $params[
'newmetadata'] = array_map(
static function ( $index ) use ( $params, $newmetadata ) {
441 $result = [
'group' => $params[
'5:array:newgroups'][$index] ];
442 if ( isset( $newmetadata[$index] ) ) {
443 $result += $newmetadata[$index];
445 $result[
'expiry'] = ApiResult::formatExpiry( $result[
'expiry'] ??
null );
448 }, array_keys( $params[
'5:array:newgroups'] ) );
456 $ret = parent::formatParametersForApi();
457 if ( isset( $ret[
'oldgroups'] ) ) {
458 ApiResult::setIndexedTagName( $ret[
'oldgroups'],
'g' );
460 if ( isset( $ret[
'newgroups'] ) ) {
461 ApiResult::setIndexedTagName( $ret[
'newgroups'],
'g' );
463 if ( isset( $ret[
'oldmetadata'] ) ) {
464 ApiResult::setArrayType( $ret[
'oldmetadata'],
'array' );
465 ApiResult::setIndexedTagName( $ret[
'oldmetadata'],
'g' );
467 if ( isset( $ret[
'newmetadata'] ) ) {
468 ApiResult::setArrayType( $ret[
'newmetadata'],
'array' );
469 ApiResult::setIndexedTagName( $ret[
'newmetadata'],
'g' );
477 private function makeGroupArray( $group ): array {
480 if ( $group ===
'' || $group === [
'' ] ) {
482 } elseif ( is_string( $group ) ) {
483 $group = array_map(
'trim', explode(
',', $group ) );
490class_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()