29 $userrightsInterwikiDelimiter = $this->context->getConfig()
32 if ( !$this->plaintext ) {
34 ucfirst( $title->getDBkey() );
35 $parts = explode( $userrightsInterwikiDelimiter, $text, 2 );
37 if ( count( $parts ) === 2 ) {
39 $titleLink = WikiMap::foreignUserLink(
43 strtr( $parts[0],
'_',
' ' ) .
44 $userrightsInterwikiDelimiter .
49 if ( $titleLink !==
false ) {
55 return parent::makePageLink( $title, $parameters, $title ? $title->getText() : null );
60 $key = parent::getMessageKey();
62 if ( !isset( $params[3] ) && !isset( $params[4] ) ) {
72 $params = parent::getMessageParameters();
86 if ( count( $oldGroups ) ) {
89 $params[3] = $this->
msg(
'rightsnone' )->text();
91 if ( count( $newGroups ) ) {
94 $params[4] = $this->
msg(
'rightsnone' )->text();
97 $performerName = $params[1];
98 $userName = $this->entry->getTarget()->getText();
100 $params[5] = $userName;
113 $messagePrefix =
'logentry-rights-rights-';
114 if ( $this->entry->getSubtype() ===
'autopromote' ) {
115 $messagePrefix =
'logentry-rights-autopromote-';
134 return isset( $params[3] ) || isset( $params[4] );
147 if ( !isset( $params[3] ) ) {
151 $allParams = $this->entry->getParameters();
165 if ( !isset( $params[4] ) ) {
169 $allParams = $this->entry->getParameters();
186 $groupNames = $this->makeGroupArray( $groupNames );
187 if ( !$this->plaintext && count( $groupNames ) ) {
193 array_map(
null, $groupNames, $metadata )
194 as [ $groupName, $groupMetadata ]
196 if ( isset( $groupMetadata[
'expiry'] ) ) {
197 $expiry = $groupMetadata[
'expiry'];
201 $expiries[$groupName] = $expiry;
214 $lang = $this->context->getLanguage();
215 $userName = $this->entry->getTarget()->getText();
216 foreach ( $groupNames as &$group ) {
217 $group = $lang->getGroupMemberName( $group, $userName );
237 $granted = array_diff_key( $newGroups, $oldGroups );
238 $revoked = array_diff_key( $oldGroups, $newGroups );
239 $kept = array_intersect_key( $oldGroups, $newGroups );
244 foreach ( $kept as $group => $oldExpiry ) {
245 $newExpiry = $newGroups[$group];
246 if ( $oldExpiry !== $newExpiry ) {
247 $expiryChanged[$group] = [ $oldExpiry, $newExpiry ];
249 $noChange[$group] = $oldExpiry;
256 'granted' => $granted,
257 'revoked' => $revoked,
258 'expiry-changed' => $expiryChanged,
274 string $targetName,
string $messagePrefix =
'logentry-rights-rights-'
276 $formattedChanges = [];
278 foreach ( $groupChanges as $changeType => $groups ) {
279 if ( !count( $groups ) ) {
283 if ( $changeType ===
'expiry-changed' ) {
284 $formattedList = $this->formatRightsListExpiryChanged( $groups );
286 $formattedList = $this->formatRightsList( $groups );
289 $formattedChanges[] = $this->
msg(
290 $messagePrefix . $changeType,
297 $uiLanguage = $this->context->getLanguage();
298 return $uiLanguage->semicolonList( $formattedChanges );
301 private function formatRightsListExpiryChanged( array $groups ): string {
304 foreach ( $groups as $group => [ $oldExpiry, $newExpiry ] ) {
305 $oldExpiryFormatted = $oldExpiry ? $this->formatDate( $oldExpiry ) : false;
306 $newExpiryFormatted = $newExpiry ? $this->formatDate( $newExpiry ) : false;
308 if ( $oldExpiryFormatted && $newExpiryFormatted ) {
310 $list[] = $this->
msg(
'rightslogentry-expiry-changed' )->params(
312 $newExpiryFormatted[
'whole'],
313 $newExpiryFormatted[
'date'],
314 $newExpiryFormatted[
'time'],
315 $oldExpiryFormatted[
'whole'],
316 $oldExpiryFormatted[
'date'],
317 $oldExpiryFormatted[
'time']
319 } elseif ( $oldExpiryFormatted ) {
321 $list[] = $this->
msg(
'rightslogentry-expiry-removed' )->params(
323 $oldExpiryFormatted[
'whole'],
324 $oldExpiryFormatted[
'date'],
325 $oldExpiryFormatted[
'time']
327 } elseif ( $newExpiryFormatted ) {
329 $list[] = $this->
msg(
'rightslogentry-expiry-set' )->params(
331 $newExpiryFormatted[
'whole'],
332 $newExpiryFormatted[
'date'],
333 $newExpiryFormatted[
'time']
338 $list[] = htmlspecialchars( $group );
342 $uiLanguage = $this->context->getLanguage();
343 return $uiLanguage->listToText( $list );
346 private function formatRightsList( array $groups ): string {
347 $uiLanguage = $this->context->getLanguage();
349 $tempList = $permList = [];
351 foreach ( $groups as $group => $expiry ) {
354 $expiryFormatted = $this->formatDate( $expiry );
355 $tempList[] = $this->
msg(
'rightslogentry-temporary-group' )->params( $group,
356 $expiryFormatted[
'whole'], $expiryFormatted[
'date'], $expiryFormatted[
'time'] )
360 $permList[] = htmlspecialchars( $group );
366 return $uiLanguage->listToText( array_merge( $tempList, $permList ) );
369 private function formatDate(
string $date ): array {
370 $uiLanguage = $this->context->getLanguage();
371 $uiUser = $this->context->getUser();
374 'whole' => $uiLanguage->userTimeAndDate( $date, $uiUser ),
375 'date' => $uiLanguage->userDate( $date, $uiUser ),
376 'time' => $uiLanguage->userTime( $date, $uiUser ),
382 $entry = $this->entry;
383 $params = $entry->getParameters();
388 '4::oldgroups' =>
'4:array:oldgroups',
389 '5::newgroups' =>
'5:array:newgroups',
391 foreach ( $map as $index => $key ) {
392 if ( isset( $params[$index] ) ) {
393 $params[$key] = $params[$index];
394 unset( $params[$index] );
402 if ( isset( $params[
'4:array:oldgroups'] ) ) {
403 $params[
'4:array:oldgroups'] = $this->makeGroupArray( $params[
'4:array:oldgroups'] );
405 $oldmetadata =& $params[
'oldmetadata'];
407 unset( $params[
'oldmetadata'] );
408 $params[
'oldmetadata'] = array_map(
static function ( $index ) use ( $params, $oldmetadata ) {
409 $result = [
'group' => $params[
'4:array:oldgroups'][$index] ];
410 if ( isset( $oldmetadata[$index] ) ) {
411 $result += $oldmetadata[$index];
413 $result[
'expiry'] = ApiResult::formatExpiry( $result[
'expiry'] ??
null );
416 }, array_keys( $params[
'4:array:oldgroups'] ) );
419 if ( isset( $params[
'5:array:newgroups'] ) ) {
420 $params[
'5:array:newgroups'] = $this->makeGroupArray( $params[
'5:array:newgroups'] );
422 $newmetadata =& $params[
'newmetadata'];
424 unset( $params[
'newmetadata'] );
425 $params[
'newmetadata'] = array_map(
static function ( $index ) use ( $params, $newmetadata ) {
426 $result = [
'group' => $params[
'5:array:newgroups'][$index] ];
427 if ( isset( $newmetadata[$index] ) ) {
428 $result += $newmetadata[$index];
430 $result[
'expiry'] = ApiResult::formatExpiry( $result[
'expiry'] ??
null );
433 }, array_keys( $params[
'5:array:newgroups'] ) );
441 $ret = parent::formatParametersForApi();
442 if ( isset( $ret[
'oldgroups'] ) ) {
443 ApiResult::setIndexedTagName( $ret[
'oldgroups'],
'g' );
445 if ( isset( $ret[
'newgroups'] ) ) {
446 ApiResult::setIndexedTagName( $ret[
'newgroups'],
'g' );
448 if ( isset( $ret[
'oldmetadata'] ) ) {
449 ApiResult::setArrayType( $ret[
'oldmetadata'],
'array' );
450 ApiResult::setIndexedTagName( $ret[
'oldmetadata'],
'g' );
452 if ( isset( $ret[
'newmetadata'] ) ) {
453 ApiResult::setArrayType( $ret[
'newmetadata'],
'array' );
454 ApiResult::setIndexedTagName( $ret[
'newmetadata'],
'g' );
462 private function makeGroupArray( $group ): array {
464 if ( $group ===
'' ) {
466 } elseif ( is_string( $group ) ) {
467 $group = array_map(
'trim', explode(
',', $group ) );
474class_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()