| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
namespace MediaWiki\Specials; |
| 22 |
|
| 23 |
use LogEventsList; |
| 24 |
use LogPage; |
| 25 |
use ManualLogEntry; |
| 26 |
use MediaWiki\CommentStore\CommentStore; |
| 27 |
use MediaWiki\Html\Html; |
| 28 |
use MediaWiki\HTMLForm\Field\HTMLUserTextField; |
| 29 |
use MediaWiki\HTMLForm\HTMLForm; |
| 30 |
use MediaWiki\Linker\Linker; |
| 31 |
use MediaWiki\MainConfigNames; |
| 32 |
use MediaWiki\MediaWikiServices; |
| 33 |
use MediaWiki\Output\OutputPage; |
| 34 |
use MediaWiki\SpecialPage\SpecialPage; |
| 35 |
use MediaWiki\Status\Status; |
| 36 |
use MediaWiki\Title\Title; |
| 37 |
use MediaWiki\User\ActorStoreFactory; |
| 38 |
use MediaWiki\User\TempUser\TempUserConfig; |
| 39 |
use MediaWiki\User\UserFactory; |
| 40 |
use MediaWiki\User\UserGroupManager; |
| 41 |
use MediaWiki\User\UserGroupManagerFactory; |
| 42 |
use MediaWiki\User\UserGroupMembership; |
| 43 |
use MediaWiki\User\UserIdentity; |
| 44 |
use MediaWiki\User\UserNamePrefixSearch; |
| 45 |
use MediaWiki\User\UserNameUtils; |
| 46 |
use MediaWiki\Watchlist\WatchlistManager; |
| 47 |
use MediaWiki\WikiMap\WikiMap; |
| 48 |
use MediaWiki\Xml\Xml; |
| 49 |
use MediaWiki\Xml\XmlSelect; |
| 50 |
use PermissionsError; |
| 51 |
use UserBlockedError; |
| 52 |
use Wikimedia\Rdbms\IDBAccessObject; |
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
class SpecialUserRights extends SpecialPage { |
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
protected $mTarget; |
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
protected $mFetchedUser = null; |
| 71 |
|
| 72 |
protected $isself = false; |
| 73 |
|
| 74 |
private UserGroupManagerFactory $userGroupManagerFactory; |
| 75 |
|
| 76 |
|
| 77 |
private $userGroupManager = null; |
| 78 |
|
| 79 |
private UserNameUtils $userNameUtils; |
| 80 |
private UserNamePrefixSearch $userNamePrefixSearch; |
| 81 |
private UserFactory $userFactory; |
| 82 |
private ActorStoreFactory $actorStoreFactory; |
| 83 |
private WatchlistManager $watchlistManager; |
| 84 |
private TempUserConfig $tempUserConfig; |
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
public function __construct( |
| 96 |
?UserGroupManagerFactory $userGroupManagerFactory = null, |
| 97 |
?UserNameUtils $userNameUtils = null, |
| 98 |
?UserNamePrefixSearch $userNamePrefixSearch = null, |
| 99 |
?UserFactory $userFactory = null, |
| 100 |
?ActorStoreFactory $actorStoreFactory = null, |
| 101 |
?WatchlistManager $watchlistManager = null, |
| 102 |
?TempUserConfig $tempUserConfig = null |
| 103 |
) { |
| 104 |
parent::__construct( 'Userrights' ); |
| 105 |
$services = MediaWikiServices::getInstance(); |
| 106 |
|
| 107 |
$this->userNameUtils = $userNameUtils ?? $services->getUserNameUtils(); |
| 108 |
$this->userNamePrefixSearch = $userNamePrefixSearch ?? $services->getUserNamePrefixSearch(); |
| 109 |
$this->userFactory = $userFactory ?? $services->getUserFactory(); |
| 110 |
$this->userGroupManagerFactory = $userGroupManagerFactory ?? $services->getUserGroupManagerFactory(); |
| 111 |
$this->actorStoreFactory = $actorStoreFactory ?? $services->getActorStoreFactory(); |
| 112 |
$this->watchlistManager = $watchlistManager ?? $services->getWatchlistManager(); |
| 113 |
$this->tempUserConfig = $tempUserConfig ?? $services->getTempUserConfig(); |
| 114 |
} |
| 115 |
|
| 116 |
public function doesWrites() { |
| 117 |
return true; |
| 118 |
} |
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
public function userCanChangeRights( UserIdentity $targetUser, $checkIfSelf = true ) { |
| 132 |
if ( |
| 133 |
!$targetUser->isRegistered() || |
| 134 |
$this->userNameUtils->isTemp( $targetUser->getName() ) |
| 135 |
) { |
| 136 |
return false; |
| 137 |
} |
| 138 |
|
| 139 |
$userGroupManager = $this->userGroupManagerFactory |
| 140 |
->getUserGroupManager( $targetUser->getWikiId() ); |
| 141 |
$available = $userGroupManager->getGroupsChangeableBy( $this->getAuthority() ); |
| 142 |
if ( $available['add'] || $available['remove'] ) { |
| 143 |
|
| 144 |
return true; |
| 145 |
} |
| 146 |
|
| 147 |
$isself = $this->getUser()->equals( $targetUser ); |
| 148 |
if ( ( $available['add-self'] || $available['remove-self'] ) |
| 149 |
&& ( $isself || !$checkIfSelf ) |
| 150 |
) { |
| 151 |
|
| 152 |
return true; |
| 153 |
} |
| 154 |
|
| 155 |
return false; |
| 156 |
} |
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
public function execute( $par ) { |
| 166 |
$user = $this->getUser(); |
| 167 |
$request = $this->getRequest(); |
| 168 |
$session = $request->getSession(); |
| 169 |
$out = $this->getOutput(); |
| 170 |
|
| 171 |
$out->addModules( [ 'mediawiki.special.userrights' ] ); |
| 172 |
|
| 173 |
$this->mTarget = $par ?? $request->getVal( 'user' ); |
| 174 |
if ( $this->mTarget === null ) { |
| 175 |
$fetchedStatus = Status::newFatal( 'nouserspecified' ); |
| 176 |
|
| 177 |
} else { |
| 178 |
$this->mTarget = trim( $this->mTarget ); |
| 179 |
|
| 180 |
if ( $this->userNameUtils->getCanonical( $this->mTarget ) === $user->getName() ) { |
| 181 |
$this->isself = true; |
| 182 |
} |
| 183 |
|
| 184 |
$fetchedStatus = $this->fetchUser( $this->mTarget, true ); |
| 185 |
} |
| 186 |
|
| 187 |
if ( $fetchedStatus->isOK() ) { |
| 188 |
$this->mFetchedUser = $fetchedUser = $fetchedStatus->value; |
| 189 |
|
| 190 |
'@phan-var UserIdentity $fetchedUser'; |
| 191 |
$wikiId = $fetchedUser->getWikiId(); |
| 192 |
if ( $wikiId === UserIdentity::LOCAL ) { |
| 193 |
|
| 194 |
|
| 195 |
$this->getSkin()->setRelevantUser( $this->mFetchedUser ); |
| 196 |
} |
| 197 |
$this->userGroupManager = $this->userGroupManagerFactory |
| 198 |
->getUserGroupManager( $wikiId ); |
| 199 |
} |
| 200 |
|
| 201 |
|
| 202 |
if ( |
| 203 |
$session->get( 'specialUserrightsSaveSuccess' ) && |
| 204 |
$this->mFetchedUser !== null |
| 205 |
) { |
| 206 |
|
| 207 |
$session->remove( 'specialUserrightsSaveSuccess' ); |
| 208 |
|
| 209 |
$out->addModuleStyles( 'mediawiki.notification.convertmessagebox.styles' ); |
| 210 |
$out->addHTML( |
| 211 |
Html::successBox( |
| 212 |
Html::element( |
| 213 |
'p', |
| 214 |
[], |
| 215 |
$this->msg( 'savedrights', $this->getDisplayUsername( $this->mFetchedUser ) )->text() |
| 216 |
), |
| 217 |
'mw-notify-success' |
| 218 |
) |
| 219 |
); |
| 220 |
} |
| 221 |
|
| 222 |
$this->setHeaders(); |
| 223 |
$this->outputHeader(); |
| 224 |
|
| 225 |
$out->addModuleStyles( 'mediawiki.special' ); |
| 226 |
$this->addHelpLink( 'Help:Assigning permissions' ); |
| 227 |
|
| 228 |
$this->switchForm(); |
| 229 |
|
| 230 |
if ( $this->mTarget !== null && !$this->getAuthority()->isAllowed( 'userrights-interwiki' ) ) { |
| 231 |
$isRedirected = $this->redirectIfRemoteWikiForView( $this->mTarget ); |
| 232 |
if ( $isRedirected ) { |
| 233 |
return; |
| 234 |
} |
| 235 |
} |
| 236 |
|
| 237 |
if ( |
| 238 |
$request->wasPosted() && |
| 239 |
$request->getCheck( 'saveusergroups' ) && |
| 240 |
$this->mTarget !== null && |
| 241 |
$user->matchEditToken( $request->getVal( 'wpEditToken' ), $this->mTarget ) |
| 242 |
) { |
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
if ( !$this->getAuthority()->isAllowed( 'userrights' ) ) { |
| 249 |
$block = $user->getBlock(); |
| 250 |
if ( $block && $block->isSitewide() ) { |
| 251 |
throw new UserBlockedError( |
| 252 |
$block, |
| 253 |
$user, |
| 254 |
$this->getLanguage(), |
| 255 |
$request->getIP() |
| 256 |
); |
| 257 |
} |
| 258 |
} |
| 259 |
|
| 260 |
$this->checkReadOnly(); |
| 261 |
|
| 262 |
|
| 263 |
if ( !$fetchedStatus->isOK() ) { |
| 264 |
$this->getOutput()->addWikiTextAsInterface( |
| 265 |
$fetchedStatus->getWikiText( false, false, $this->getLanguage() ) |
| 266 |
); |
| 267 |
|
| 268 |
return; |
| 269 |
} |
| 270 |
|
| 271 |
$targetUser = $this->mFetchedUser; |
| 272 |
$conflictCheck = $request->getVal( 'conflictcheck-originalgroups' ); |
| 273 |
$conflictCheck = ( $conflictCheck === '' ) ? [] : explode( ',', $conflictCheck ); |
| 274 |
$userGroups = $this->userGroupManager->getUserGroups( $targetUser, IDBAccessObject::READ_LATEST ); |
| 275 |
|
| 276 |
if ( $userGroups !== $conflictCheck ) { |
| 277 |
$out->addHTML( Html::errorBox( |
| 278 |
$this->msg( 'userrights-conflict' )->parse() |
| 279 |
) ); |
| 280 |
} else { |
| 281 |
$status = $this->saveUserGroups( |
| 282 |
$request->getText( 'user-reason' ), |
| 283 |
$targetUser |
| 284 |
); |
| 285 |
|
| 286 |
if ( $status->isOK() ) { |
| 287 |
|
| 288 |
$session->set( 'specialUserrightsSaveSuccess', 1 ); |
| 289 |
|
| 290 |
$out->redirect( $this->getSuccessURL() ); |
| 291 |
return; |
| 292 |
} else { |
| 293 |
|
| 294 |
$out->wrapWikiTextAsInterface( |
| 295 |
'error', $status->getWikiText( false, false, $this->getLanguage() ) |
| 296 |
); |
| 297 |
} |
| 298 |
} |
| 299 |
} |
| 300 |
|
| 301 |
|
| 302 |
if ( $this->mTarget !== null ) { |
| 303 |
$this->editUserGroupsForm( $this->mTarget ); |
| 304 |
} |
| 305 |
} |
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
private function redirectIfRemoteWikiForView( string $target ): bool { |
| 318 |
$interwikiDelimiter = $this->getConfig()->get( MainConfigNames::UserrightsInterwikiDelimiter ); |
| 319 |
if ( !str_contains( $target, $interwikiDelimiter ) ) { |
| 320 |
return false; |
| 321 |
} |
| 322 |
|
| 323 |
$targetParts = explode( $interwikiDelimiter, $target ); |
| 324 |
[ $user, $remoteWikiId ] = $targetParts; |
| 325 |
|
| 326 |
if ( WikiMap::isCurrentWikiId( $remoteWikiId ) ) { |
| 327 |
|
| 328 |
return false; |
| 329 |
} |
| 330 |
|
| 331 |
$remoteWiki = WikiMap::getWiki( $remoteWikiId ); |
| 332 |
if ( !$remoteWiki ) { |
| 333 |
|
| 334 |
return false; |
| 335 |
} |
| 336 |
|
| 337 |
$remoteUrl = $remoteWiki->getUrl( 'Special:UserRights' ); |
| 338 |
$remoteUrl = wfAppendQuery( $remoteUrl, [ 'user' => $user ] ); |
| 339 |
$this->getOutput()->redirect( $remoteUrl ); |
| 340 |
return true; |
| 341 |
} |
| 342 |
|
| 343 |
private function getSuccessURL() { |
| 344 |
return $this->getPageTitle( $this->mTarget )->getFullURL(); |
| 345 |
} |
| 346 |
|
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
|
| 353 |
public function canProcessExpiries() { |
| 354 |
return true; |
| 355 |
} |
| 356 |
|
| 357 |
|
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
|
| 362 |
|
| 363 |
|
| 364 |
|
| 365 |
|
| 366 |
public static function expiryToTimestamp( $expiry ) { |
| 367 |
if ( wfIsInfinity( $expiry ) ) { |
| 368 |
return null; |
| 369 |
} |
| 370 |
|
| 371 |
$unix = strtotime( $expiry ); |
| 372 |
|
| 373 |
if ( !$unix || $unix === -1 ) { |
| 374 |
return false; |
| 375 |
} |
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
return wfTimestamp( TS_MW, $unix ); |
| 380 |
} |
| 381 |
|
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
protected function saveUserGroups( string $reason, UserIdentity $user ) { |
| 391 |
if ( $this->userNameUtils->isTemp( $user->getName() ) ) { |
| 392 |
return Status::newFatal( 'userrights-no-tempuser' ); |
| 393 |
} |
| 394 |
|
| 395 |
|
| 396 |
if ( |
| 397 |
$user->getWikiId() !== UserIdentity::LOCAL && |
| 398 |
!$this->tempUserConfig->isKnown() && |
| 399 |
$this->tempUserConfig->isReservedName( $user->getName() ) |
| 400 |
) { |
| 401 |
return Status::newFatal( 'userrights-cross-wiki-assignment-for-reserved-name' ); |
| 402 |
} |
| 403 |
|
| 404 |
$allgroups = $this->userGroupManager->listAllGroups(); |
| 405 |
$addgroup = []; |
| 406 |
$groupExpiries = []; |
| 407 |
$removegroup = []; |
| 408 |
$existingUGMs = $this->userGroupManager->getUserGroupMemberships( $user ); |
| 409 |
|
| 410 |
|
| 411 |
|
| 412 |
foreach ( $allgroups as $group ) { |
| 413 |
|
| 414 |
|
| 415 |
if ( $this->getRequest()->getCheck( "wpGroup-$group" ) ) { |
| 416 |
$addgroup[] = $group; |
| 417 |
|
| 418 |
if ( $this->canProcessExpiries() ) { |
| 419 |
|
| 420 |
$expiryDropdown = $this->getRequest()->getVal( "wpExpiry-$group" ); |
| 421 |
if ( $expiryDropdown === 'existing' ) { |
| 422 |
continue; |
| 423 |
} |
| 424 |
|
| 425 |
if ( $expiryDropdown === 'other' ) { |
| 426 |
$expiryValue = $this->getRequest()->getVal( "wpExpiry-$group-other" ); |
| 427 |
} else { |
| 428 |
$expiryValue = $expiryDropdown; |
| 429 |
} |
| 430 |
|
| 431 |
|
| 432 |
$groupExpiries[$group] = self::expiryToTimestamp( $expiryValue ); |
| 433 |
|
| 434 |
if ( $groupExpiries[$group] === false ) { |
| 435 |
return Status::newFatal( 'userrights-invalid-expiry', $group ); |
| 436 |
} |
| 437 |
|
| 438 |
|
| 439 |
if ( $groupExpiries[$group] && $groupExpiries[$group] < wfTimestampNow() ) { |
| 440 |
return Status::newFatal( 'userrights-expiry-in-past', $group ); |
| 441 |
} |
| 442 |
|
| 443 |
|
| 444 |
|
| 445 |
if ( !$this->canRemove( $group ) && |
| 446 |
isset( $existingUGMs[$group] ) && |
| 447 |
( $existingUGMs[$group]->getExpiry() ?: 'infinity' ) > |
| 448 |
( $groupExpiries[$group] ?: 'infinity' ) |
| 449 |
) { |
| 450 |
return Status::newFatal( 'userrights-cannot-shorten-expiry', $group ); |
| 451 |
} |
| 452 |
} |
| 453 |
} else { |
| 454 |
$removegroup[] = $group; |
| 455 |
} |
| 456 |
} |
| 457 |
|
| 458 |
$this->doSaveUserGroups( $user, $addgroup, $removegroup, $reason, [], $groupExpiries ); |
| 459 |
|
| 460 |
if ( $user->getWikiId() === UserIdentity::LOCAL && $this->getRequest()->getCheck( 'wpWatch' ) ) { |
| 461 |
$this->watchlistManager->addWatchIgnoringRights( |
| 462 |
$this->getUser(), |
| 463 |
Title::makeTitle( NS_USER, $user->getName() ) |
| 464 |
); |
| 465 |
} |
| 466 |
|
| 467 |
return Status::newGood(); |
| 468 |
} |
| 469 |
|
| 470 |
|
| 471 |
|
| 472 |
|
| 473 |
|
| 474 |
|
| 475 |
|
| 476 |
|
| 477 |
|
| 478 |
|
| 479 |
|
| 480 |
|
| 481 |
|
| 482 |
|
| 483 |
|
| 484 |
|
| 485 |
public function doSaveUserGroups( $user, array $add, array $remove, string $reason = '', |
| 486 |
array $tags = [], array $groupExpiries = [] |
| 487 |
) { |
| 488 |
|
| 489 |
$isself = $user->getName() == $this->getUser()->getName(); |
| 490 |
if ( $this->userGroupManager !== null ) { |
| 491 |
|
| 492 |
$userGroupManager = $this->userGroupManager; |
| 493 |
} else { |
| 494 |
|
| 495 |
$userGroupManager = $this->userGroupManagerFactory |
| 496 |
->getUserGroupManager( $user->getWikiId() ); |
| 497 |
} |
| 498 |
$groups = $userGroupManager->getUserGroups( $user ); |
| 499 |
$ugms = $userGroupManager->getUserGroupMemberships( $user ); |
| 500 |
$changeable = $userGroupManager->getGroupsChangeableBy( $this->getAuthority() ); |
| 501 |
$addable = array_merge( $changeable['add'], $isself ? $changeable['add-self'] : [] ); |
| 502 |
$removable = array_merge( $changeable['remove'], $isself ? $changeable['remove-self'] : [] ); |
| 503 |
|
| 504 |
$remove = array_unique( array_intersect( $remove, $removable, $groups ) ); |
| 505 |
$add = array_intersect( $add, $addable ); |
| 506 |
|
| 507 |
|
| 508 |
|
| 509 |
|
| 510 |
$add = array_filter( $add, |
| 511 |
static function ( $group ) use ( $groups, $groupExpiries, $removable, $ugms ) { |
| 512 |
if ( isset( $groupExpiries[$group] ) && |
| 513 |
!in_array( $group, $removable ) && |
| 514 |
isset( $ugms[$group] ) && |
| 515 |
( $ugms[$group]->getExpiry() ?: 'infinity' ) > |
| 516 |
( $groupExpiries[$group] ?: 'infinity' ) |
| 517 |
) { |
| 518 |
return false; |
| 519 |
} |
| 520 |
return !in_array( $group, $groups ) || array_key_exists( $group, $groupExpiries ); |
| 521 |
} ); |
| 522 |
|
| 523 |
if ( $user->getWikiId() === UserIdentity::LOCAL ) { |
| 524 |
|
| 525 |
$hookUser = $this->userFactory->newFromUserIdentity( $user ); |
| 526 |
} else { |
| 527 |
|
| 528 |
$hookUser = $user; |
| 529 |
} |
| 530 |
$this->getHookRunner()->onChangeUserGroups( $this->getUser(), $hookUser, $add, $remove ); |
| 531 |
|
| 532 |
$oldGroups = $groups; |
| 533 |
$oldUGMs = $userGroupManager->getUserGroupMemberships( $user ); |
| 534 |
$newGroups = $oldGroups; |
| 535 |
|
| 536 |
|
| 537 |
if ( $remove ) { |
| 538 |
foreach ( $remove as $index => $group ) { |
| 539 |
if ( !$userGroupManager->removeUserFromGroup( $user, $group ) ) { |
| 540 |
unset( $remove[$index] ); |
| 541 |
} |
| 542 |
} |
| 543 |
$newGroups = array_diff( $newGroups, $remove ); |
| 544 |
} |
| 545 |
if ( $add ) { |
| 546 |
foreach ( $add as $index => $group ) { |
| 547 |
$expiry = $groupExpiries[$group] ?? null; |
| 548 |
if ( !$userGroupManager->addUserToGroup( $user, $group, $expiry, true ) ) { |
| 549 |
unset( $add[$index] ); |
| 550 |
} |
| 551 |
} |
| 552 |
$newGroups = array_merge( $newGroups, $add ); |
| 553 |
} |
| 554 |
$newGroups = array_unique( $newGroups ); |
| 555 |
$newUGMs = $userGroupManager->getUserGroupMemberships( $user ); |
| 556 |
|
| 557 |
|
| 558 |
$this->userFactory->invalidateCache( $user ); |
| 559 |
|
| 560 |
|
| 561 |
$this->getHookRunner()->onUserGroupsChanged( $hookUser, $add, $remove, |
| 562 |
$this->getUser(), $reason, $oldUGMs, $newUGMs ); |
| 563 |
|
| 564 |
wfDebug( 'oldGroups: ' . print_r( $oldGroups, true ) ); |
| 565 |
wfDebug( 'newGroups: ' . print_r( $newGroups, true ) ); |
| 566 |
wfDebug( 'oldUGMs: ' . print_r( $oldUGMs, true ) ); |
| 567 |
wfDebug( 'newUGMs: ' . print_r( $newUGMs, true ) ); |
| 568 |
|
| 569 |
|
| 570 |
if ( $newGroups != $oldGroups || $newUGMs != $oldUGMs ) { |
| 571 |
$this->addLogEntry( $user, $oldGroups, $newGroups, $reason, $tags, $oldUGMs, $newUGMs ); |
| 572 |
} |
| 573 |
|
| 574 |
return [ $add, $remove ]; |
| 575 |
} |
| 576 |
|
| 577 |
|
| 578 |
|
| 579 |
|
| 580 |
|
| 581 |
|
| 582 |
|
| 583 |
|
| 584 |
protected static function serialiseUgmForLog( $ugm ) { |
| 585 |
if ( !$ugm instanceof UserGroupMembership ) { |
| 586 |
return null; |
| 587 |
} |
| 588 |
return [ 'expiry' => $ugm->getExpiry() ]; |
| 589 |
} |
| 590 |
|
| 591 |
|
| 592 |
|
| 593 |
|
| 594 |
|
| 595 |
|
| 596 |
|
| 597 |
|
| 598 |
|
| 599 |
|
| 600 |
|
| 601 |
protected function addLogEntry( $user, array $oldGroups, array $newGroups, string $reason, |
| 602 |
array $tags, array $oldUGMs, array $newUGMs |
| 603 |
) { |
| 604 |
|
| 605 |
|
| 606 |
$oldUGMs = array_map( static function ( $group ) use ( $oldUGMs ) { |
| 607 |
return isset( $oldUGMs[$group] ) ? |
| 608 |
self::serialiseUgmForLog( $oldUGMs[$group] ) : |
| 609 |
null; |
| 610 |
}, $oldGroups ); |
| 611 |
$newUGMs = array_map( static function ( $group ) use ( $newUGMs ) { |
| 612 |
return isset( $newUGMs[$group] ) ? |
| 613 |
self::serialiseUgmForLog( $newUGMs[$group] ) : |
| 614 |
null; |
| 615 |
}, $newGroups ); |
| 616 |
|
| 617 |
$logEntry = new ManualLogEntry( 'rights', 'rights' ); |
| 618 |
$logEntry->setPerformer( $this->getUser() ); |
| 619 |
$logEntry->setTarget( Title::makeTitle( NS_USER, $this->getDisplayUsername( $user ) ) ); |
| 620 |
$logEntry->setComment( $reason ); |
| 621 |
$logEntry->setParameters( [ |
| 622 |
'4::oldgroups' => $oldGroups, |
| 623 |
'5::newgroups' => $newGroups, |
| 624 |
'oldmetadata' => $oldUGMs, |
| 625 |
'newmetadata' => $newUGMs, |
| 626 |
] ); |
| 627 |
$logid = $logEntry->insert(); |
| 628 |
if ( count( $tags ) ) { |
| 629 |
$logEntry->addTags( $tags ); |
| 630 |
} |
| 631 |
$logEntry->publish( $logid ); |
| 632 |
} |
| 633 |
|
| 634 |
|
| 635 |
|
| 636 |
|
| 637 |
|
| 638 |
private function editUserGroupsForm( $username ) { |
| 639 |
$status = $this->fetchUser( $username, true ); |
| 640 |
if ( !$status->isOK() ) { |
| 641 |
$this->getOutput()->addWikiTextAsInterface( |
| 642 |
$status->getWikiText( false, false, $this->getLanguage() ) |
| 643 |
); |
| 644 |
|
| 645 |
return; |
| 646 |
} |
| 647 |
|
| 648 |
|
| 649 |
$user = $status->value; |
| 650 |
'@phan-var UserIdentity $user'; |
| 651 |
|
| 652 |
$groups = $this->userGroupManager->getUserGroups( $user ); |
| 653 |
$groupMemberships = $this->userGroupManager->getUserGroupMemberships( $user ); |
| 654 |
$this->showEditUserGroupsForm( $user, $groups, $groupMemberships ); |
| 655 |
|
| 656 |
|
| 657 |
|
| 658 |
$this->showLogFragment( $user, $this->getOutput() ); |
| 659 |
} |
| 660 |
|
| 661 |
|
| 662 |
|
| 663 |
|
| 664 |
|
| 665 |
|
| 666 |
|
| 667 |
|
| 668 |
|
| 669 |
|
| 670 |
public function fetchUser( $username, $writing = true ) { |
| 671 |
$parts = explode( $this->getConfig()->get( MainConfigNames::UserrightsInterwikiDelimiter ), |
| 672 |
$username ); |
| 673 |
if ( count( $parts ) < 2 ) { |
| 674 |
$name = trim( $username ); |
| 675 |
$wikiId = UserIdentity::LOCAL; |
| 676 |
} else { |
| 677 |
[ $name, $wikiId ] = array_map( 'trim', $parts ); |
| 678 |
|
| 679 |
if ( WikiMap::isCurrentWikiId( $wikiId ) ) { |
| 680 |
$wikiId = UserIdentity::LOCAL; |
| 681 |
} else { |
| 682 |
if ( $writing && |
| 683 |
!$this->getAuthority()->isAllowed( 'userrights-interwiki' ) |
| 684 |
) { |
| 685 |
return Status::newFatal( 'userrights-no-interwiki' ); |
| 686 |
} |
| 687 |
$localDatabases = $this->getConfig()->get( MainConfigNames::LocalDatabases ); |
| 688 |
if ( !in_array( $wikiId, $localDatabases ) ) { |
| 689 |
return Status::newFatal( 'userrights-nodatabase', $wikiId ); |
| 690 |
} |
| 691 |
} |
| 692 |
} |
| 693 |
|
| 694 |
if ( $name === '' ) { |
| 695 |
return Status::newFatal( 'nouserspecified' ); |
| 696 |
} |
| 697 |
|
| 698 |
$userIdentityLookup = $this->actorStoreFactory->getUserIdentityLookup( $wikiId ); |
| 699 |
if ( $name[0] == '#' ) { |
| 700 |
|
| 701 |
$id = intval( substr( $name, 1 ) ); |
| 702 |
|
| 703 |
$user = $userIdentityLookup->getUserIdentityByUserId( $id ); |
| 704 |
if ( !$user ) { |
| 705 |
|
| 706 |
return Status::newFatal( 'noname' ); |
| 707 |
} |
| 708 |
$name = $user->getName(); |
| 709 |
} else { |
| 710 |
$name = $this->userNameUtils->getCanonical( $name ); |
| 711 |
if ( $name === false ) { |
| 712 |
|
| 713 |
return Status::newFatal( 'nosuchusershort', $username ); |
| 714 |
} |
| 715 |
$user = $userIdentityLookup->getUserIdentityByName( $name ); |
| 716 |
} |
| 717 |
|
| 718 |
if ( $this->userNameUtils->isTemp( $name ) ) { |
| 719 |
return Status::newFatal( 'userrights-no-group' ); |
| 720 |
} |
| 721 |
|
| 722 |
if ( !$user || !$user->isRegistered() ) { |
| 723 |
return Status::newFatal( 'nosuchusershort', $username ); |
| 724 |
} |
| 725 |
|
| 726 |
|
| 727 |
|
| 728 |
if ( |
| 729 |
$user->getWikiId() !== UserIdentity::LOCAL && |
| 730 |
!$this->tempUserConfig->isKnown() && |
| 731 |
$this->tempUserConfig->isReservedName( $name ) |
| 732 |
) { |
| 733 |
return Status::newFatal( 'userrights-no-group' ); |
| 734 |
} |
| 735 |
|
| 736 |
if ( $user->getWikiId() === UserIdentity::LOCAL && |
| 737 |
$this->userFactory->newFromUserIdentity( $user )->isHidden() && |
| 738 |
!$this->getAuthority()->isAllowed( 'hideuser' ) |
| 739 |
) { |
| 740 |
|
| 741 |
return Status::newFatal( 'nosuchusershort', $username ); |
| 742 |
} |
| 743 |
|
| 744 |
return Status::newGood( $user ); |
| 745 |
} |
| 746 |
|
| 747 |
|
| 748 |
|
| 749 |
|
| 750 |
|
| 751 |
|
| 752 |
|
| 753 |
|
| 754 |
public function makeGroupNameList( $ids ) { |
| 755 |
if ( !$ids ) { |
| 756 |
return $this->msg( 'rightsnone' )->inContentLanguage()->text(); |
| 757 |
} else { |
| 758 |
return implode( ', ', $ids ); |
| 759 |
} |
| 760 |
} |
| 761 |
|
| 762 |
|
| 763 |
|
| 764 |
|
| 765 |
protected function switchForm() { |
| 766 |
$formDescriptor = [ |
| 767 |
'user' => [ |
| 768 |
'class' => HTMLUserTextField::class, |
| 769 |
'label-message' => 'userrights-user-editname', |
| 770 |
'name' => 'user', |
| 771 |
'ipallowed' => true, |
| 772 |
'iprange' => true, |
| 773 |
'excludetemp' => true, |
| 774 |
'autofocus' => $this->mFetchedUser === null, |
| 775 |
'default' => $this->mTarget, |
| 776 |
] |
| 777 |
]; |
| 778 |
|
| 779 |
$htmlForm = HTMLForm::factory( 'ooui', $formDescriptor, $this->getContext() ); |
| 780 |
$htmlForm |
| 781 |
->setMethod( 'GET' ) |
| 782 |
->setAction( wfScript() ) |
| 783 |
->setName( 'uluser' ) |
| 784 |
->setTitle( SpecialPage::getTitleFor( 'Userrights' ) ) |
| 785 |
->setWrapperLegendMsg( 'userrights-lookup-user' ) |
| 786 |
->setId( 'mw-userrights-form1' ) |
| 787 |
->setSubmitTextMsg( 'editusergroup' ) |
| 788 |
->prepareForm() |
| 789 |
->displayForm( true ); |
| 790 |
} |
| 791 |
|
| 792 |
|
| 793 |
|
| 794 |
|
| 795 |
|
| 796 |
|
| 797 |
|
| 798 |
|
| 799 |
|
| 800 |
|
| 801 |
protected function showEditUserGroupsForm( $user, $groups, $groupMemberships ) { |
| 802 |
$list = $membersList = $tempList = $tempMembersList = []; |
| 803 |
foreach ( $groupMemberships as $ugm ) { |
| 804 |
$linkG = UserGroupMembership::getLinkHTML( $ugm, $this->getContext() ); |
| 805 |
$linkM = UserGroupMembership::getLinkHTML( $ugm, $this->getContext(), $user->getName() ); |
| 806 |
if ( $ugm->getExpiry() ) { |
| 807 |
$tempList[] = $linkG; |
| 808 |
$tempMembersList[] = $linkM; |
| 809 |
} else { |
| 810 |
$list[] = $linkG; |
| 811 |
$membersList[] = $linkM; |
| 812 |
|
| 813 |
} |
| 814 |
} |
| 815 |
|
| 816 |
$autoList = []; |
| 817 |
$autoMembersList = []; |
| 818 |
|
| 819 |
if ( $user->getWikiId() === UserIdentity::LOCAL ) { |
| 820 |
|
| 821 |
foreach ( $this->userGroupManager->getUserAutopromoteGroups( $user ) as $group ) { |
| 822 |
$autoList[] = UserGroupMembership::getLinkHTML( $group, $this->getContext() ); |
| 823 |
$autoMembersList[] = UserGroupMembership::getLinkHTML( $group, $this->getContext(), $user->getName() ); |
| 824 |
} |
| 825 |
} |
| 826 |
|
| 827 |
$language = $this->getLanguage(); |
| 828 |
$displayedList = $this->msg( 'userrights-groupsmember-type' ) |
| 829 |
->rawParams( |
| 830 |
$language->commaList( array_merge( $tempList, $list ) ), |
| 831 |
$language->commaList( array_merge( $tempMembersList, $membersList ) ) |
| 832 |
)->escaped(); |
| 833 |
$displayedAutolist = $this->msg( 'userrights-groupsmember-type' ) |
| 834 |
->rawParams( |
| 835 |
$language->commaList( $autoList ), |
| 836 |
$language->commaList( $autoMembersList ) |
| 837 |
)->escaped(); |
| 838 |
|
| 839 |
$grouplist = ''; |
| 840 |
$count = count( $list ) + count( $tempList ); |
| 841 |
if ( $count > 0 ) { |
| 842 |
$grouplist = $this->msg( 'userrights-groupsmember' ) |
| 843 |
->numParams( $count ) |
| 844 |
->params( $user->getName() ) |
| 845 |
->parse(); |
| 846 |
$grouplist = '<p>' . $grouplist . ' ' . $displayedList . "</p>\n"; |
| 847 |
} |
| 848 |
|
| 849 |
$count = count( $autoList ); |
| 850 |
if ( $count > 0 ) { |
| 851 |
$autogrouplistintro = $this->msg( 'userrights-groupsmember-auto' ) |
| 852 |
->numParams( $count ) |
| 853 |
->params( $user->getName() ) |
| 854 |
->parse(); |
| 855 |
$grouplist .= '<p>' . $autogrouplistintro . ' ' . $displayedAutolist . "</p>\n"; |
| 856 |
} |
| 857 |
|
| 858 |
$systemUser = $user->getWikiId() === UserIdentity::LOCAL |
| 859 |
&& $this->userFactory->newFromUserIdentity( $user )->isSystemUser(); |
| 860 |
if ( $systemUser ) { |
| 861 |
$systemusernote = $this->msg( 'userrights-systemuser' ) |
| 862 |
->params( $user->getName() ) |
| 863 |
->parse(); |
| 864 |
$grouplist .= '<p>' . $systemusernote . "</p>\n"; |
| 865 |
} |
| 866 |
|
| 867 |
|
| 868 |
$flags = $systemUser ? 0 : Linker::TOOL_LINKS_EMAIL; |
| 869 |
$userToolLinks = Linker::userToolLinks( |
| 870 |
$user->getId( $user->getWikiId() ), |
| 871 |
$this->getDisplayUsername( $user ), |
| 872 |
false, |
| 873 |
$flags |
| 874 |
); |
| 875 |
|
| 876 |
[ $groupCheckboxes, $canChangeAny ] = |
| 877 |
$this->groupCheckboxes( $groupMemberships, $user ); |
| 878 |
$this->getOutput()->addHTML( |
| 879 |
Html::openElement( |
| 880 |
'form', |
| 881 |
[ |
| 882 |
'method' => 'post', |
| 883 |
'action' => $this->getPageTitle()->getLocalURL(), |
| 884 |
'name' => 'editGroup', |
| 885 |
'id' => 'mw-userrights-form2' |
| 886 |
] |
| 887 |
) . |
| 888 |
Html::hidden( 'user', $this->mTarget ) . |
| 889 |
Html::hidden( 'wpEditToken', $this->getUser()->getEditToken( $this->mTarget ) ) . |
| 890 |
Html::hidden( |
| 891 |
'conflictcheck-originalgroups', |
| 892 |
implode( ',', $this->userGroupManager->getUserGroups( $user ) ) |
| 893 |
) . |
| 894 |
Html::openElement( 'fieldset' ) . |
| 895 |
Html::element( |
| 896 |
'legend', |
| 897 |
[], |
| 898 |
$this->msg( |
| 899 |
$canChangeAny ? 'userrights-editusergroup' : 'userrights-viewusergroup', |
| 900 |
$user->getName() |
| 901 |
)->text() |
| 902 |
) . |
| 903 |
$this->msg( |
| 904 |
$canChangeAny ? 'editinguser' : 'viewinguserrights' |
| 905 |
)->params( wfEscapeWikiText( $this->getDisplayUsername( $user ) ) ) |
| 906 |
->rawParams( $userToolLinks )->parse() |
| 907 |
); |
| 908 |
if ( $canChangeAny ) { |
| 909 |
$this->getOutput()->addHTML( |
| 910 |
$this->msg( 'userrights-groups-help', $user->getName() )->parse() . |
| 911 |
$grouplist . |
| 912 |
$groupCheckboxes . |
| 913 |
Html::openElement( 'table', [ 'id' => 'mw-userrights-table-outer' ] ) . |
| 914 |
"<tr> |
| 915 |
<td class='mw-label'>" . |
| 916 |
Html::label( $this->msg( 'userrights-reason' )->text(), 'wpReason' ) . |
| 917 |
"</td> |
| 918 |
<td class='mw-input'>" . |
| 919 |
Xml::input( 'user-reason', 60, $this->getRequest()->getVal( 'user-reason' ) ?? false, [ |
| 920 |
'id' => 'wpReason', |
| 921 |
|
| 922 |
|
| 923 |
|
| 924 |
'maxlength' => CommentStore::COMMENT_CHARACTER_LIMIT, |
| 925 |
] ) . |
| 926 |
"</td> |
| 927 |
</tr> |
| 928 |
<tr> |
| 929 |
<td></td> |
| 930 |
<td class='mw-submit'>" . |
| 931 |
Html::submitButton( $this->msg( 'saveusergroups', $user->getName() )->text(), |
| 932 |
[ 'name' => 'saveusergroups' ] + |
| 933 |
Linker::tooltipAndAccesskeyAttribs( 'userrights-set' ) |
| 934 |
) . |
| 935 |
"</td> |
| 936 |
</tr> |
| 937 |
<tr> |
| 938 |
<td></td> |
| 939 |
<td class='mw-input'>" . |
| 940 |
Html::check( 'wpWatch', false, [ 'id' => 'wpWatch' ] ) . |
| 941 |
' ' . Html::label( $this->msg( 'userrights-watchuser' )->text(), 'wpWatch' ) . |
| 942 |
"</td> |
| 943 |
</tr>" . |
| 944 |
Xml::closeElement( 'table' ) . "\n" |
| 945 |
); |
| 946 |
} else { |
| 947 |
$this->getOutput()->addHTML( $grouplist ); |
| 948 |
} |
| 949 |
$this->getOutput()->addHTML( |
| 950 |
Xml::closeElement( 'fieldset' ) . |
| 951 |
Xml::closeElement( 'form' ) . "\n" |
| 952 |
); |
| 953 |
} |
| 954 |
|
| 955 |
|
| 956 |
|
| 957 |
|
| 958 |
|
| 959 |
|
| 960 |
|
| 961 |
|
| 962 |
|
| 963 |
|
| 964 |
private function groupCheckboxes( $usergroups, UserIdentity $user ) { |
| 965 |
$allgroups = $this->userGroupManager->listAllGroups(); |
| 966 |
$ret = ''; |
| 967 |
|
| 968 |
|
| 969 |
$expiryOptionsMsg = $this->msg( 'userrights-expiry-options' )->inContentLanguage(); |
| 970 |
$expiryOptions = $expiryOptionsMsg->isDisabled() |
| 971 |
? [] |
| 972 |
: XmlSelect::parseOptionsMessage( $expiryOptionsMsg->text() ); |
| 973 |
|
| 974 |
|
| 975 |
|
| 976 |
$columns = [ 'unchangeable' => [], 'changeable' => [] ]; |
| 977 |
|
| 978 |
foreach ( $allgroups as $group ) { |
| 979 |
$set = isset( $usergroups[$group] ); |
| 980 |
|
| 981 |
|
| 982 |
|
| 983 |
$canOnlyLengthenExpiry = ( $set && $this->canAdd( $group ) && |
| 984 |
!$this->canRemove( $group ) && $usergroups[$group]->getExpiry() ); |
| 985 |
|
| 986 |
$disabledCheckbox = !( |
| 987 |
( $set && $this->canRemove( $group ) ) || |
| 988 |
( !$set && $this->canAdd( $group ) ) ); |
| 989 |
|
| 990 |
$disabledExpiry = $disabledCheckbox && !$canOnlyLengthenExpiry; |
| 991 |
|
| 992 |
$irreversible = !$disabledCheckbox && ( |
| 993 |
( $set && !$this->canAdd( $group ) ) || |
| 994 |
( !$set && !$this->canRemove( $group ) ) ); |
| 995 |
|
| 996 |
$checkbox = [ |
| 997 |
'set' => $set, |
| 998 |
'disabled' => $disabledCheckbox, |
| 999 |
'disabled-expiry' => $disabledExpiry, |
| 1000 |
'irreversible' => $irreversible |
| 1001 |
]; |
| 1002 |
|
| 1003 |
if ( $disabledCheckbox && $disabledExpiry ) { |
| 1004 |
$columns['unchangeable'][$group] = $checkbox; |
| 1005 |
} else { |
| 1006 |
$columns['changeable'][$group] = $checkbox; |
| 1007 |
} |
| 1008 |
} |
| 1009 |
|
| 1010 |
|
| 1011 |
$ret .= Xml::openElement( 'table', [ 'class' => 'mw-userrights-groups' ] ) . |
| 1012 |
"<tr>\n"; |
| 1013 |
foreach ( $columns as $name => $column ) { |
| 1014 |
if ( $column === [] ) { |
| 1015 |
continue; |
| 1016 |
} |
| 1017 |
|
| 1018 |
$ret .= Xml::element( |
| 1019 |
'th', |
| 1020 |
null, |
| 1021 |
$this->msg( 'userrights-' . $name . '-col', count( $column ) )->text() |
| 1022 |
); |
| 1023 |
} |
| 1024 |
|
| 1025 |
$ret .= "</tr>\n<tr>\n"; |
| 1026 |
$uiLanguage = $this->getLanguage(); |
| 1027 |
$userName = $user->getName(); |
| 1028 |
foreach ( $columns as $column ) { |
| 1029 |
if ( $column === [] ) { |
| 1030 |
continue; |
| 1031 |
} |
| 1032 |
$ret .= "\t<td style='vertical-align:top;'>\n"; |
| 1033 |
foreach ( $column as $group => $checkbox ) { |
| 1034 |
$member = $uiLanguage->getGroupMemberName( $group, $userName ); |
| 1035 |
if ( $checkbox['irreversible'] ) { |
| 1036 |
$text = $this->msg( 'userrights-irreversible-marker', $member )->text(); |
| 1037 |
} elseif ( $checkbox['disabled'] && !$checkbox['disabled-expiry'] ) { |
| 1038 |
$text = $this->msg( 'userrights-no-shorten-expiry-marker', $member )->text(); |
| 1039 |
} else { |
| 1040 |
$text = $member; |
| 1041 |
} |
| 1042 |
$checkboxHtml = Html::element( 'input', [ |
| 1043 |
'type' => 'checkbox', 'name' => "wpGroup-$group", 'value' => '1', |
| 1044 |
'id' => "wpGroup-$group", 'checked' => $checkbox['set'], |
| 1045 |
'class' => 'mw-userrights-groupcheckbox', |
| 1046 |
'disabled' => $checkbox['disabled'], |
| 1047 |
] ) . ' ' . Html::label( $text, "wpGroup-$group" ); |
| 1048 |
|
| 1049 |
if ( $this->canProcessExpiries() ) { |
| 1050 |
$uiUser = $this->getUser(); |
| 1051 |
|
| 1052 |
$currentExpiry = isset( $usergroups[$group] ) ? |
| 1053 |
$usergroups[$group]->getExpiry() : |
| 1054 |
null; |
| 1055 |
|
| 1056 |
|
| 1057 |
|
| 1058 |
if ( $checkbox['set'] && |
| 1059 |
( $checkbox['irreversible'] || $checkbox['disabled-expiry'] ) |
| 1060 |
) { |
| 1061 |
if ( $currentExpiry ) { |
| 1062 |
$expiryFormatted = $uiLanguage->userTimeAndDate( $currentExpiry, $uiUser ); |
| 1063 |
$expiryFormattedD = $uiLanguage->userDate( $currentExpiry, $uiUser ); |
| 1064 |
$expiryFormattedT = $uiLanguage->userTime( $currentExpiry, $uiUser ); |
| 1065 |
$expiryHtml = Xml::element( 'span', null, |
| 1066 |
$this->msg( 'userrights-expiry-current' )->params( |
| 1067 |
$expiryFormatted, $expiryFormattedD, $expiryFormattedT )->text() ); |
| 1068 |
} else { |
| 1069 |
$expiryHtml = Xml::element( 'span', null, |
| 1070 |
$this->msg( 'userrights-expiry-none' )->text() ); |
| 1071 |
} |
| 1072 |
|
| 1073 |
|
| 1074 |
$expiryHtml .= Html::hidden( "wpExpiry-$group", |
| 1075 |
$currentExpiry ? 'existing' : 'infinite' ); |
| 1076 |
$expiryHtml .= "<br />\n"; |
| 1077 |
} else { |
| 1078 |
$expiryHtml = Html::element( 'span', [], |
| 1079 |
$this->msg( 'userrights-expiry' )->text() ); |
| 1080 |
$expiryHtml .= Html::openElement( 'span' ); |
| 1081 |
|
| 1082 |
|
| 1083 |
$expiryFormOptions = new XmlSelect( |
| 1084 |
"wpExpiry-$group", |
| 1085 |
"mw-input-wpExpiry-$group", |
| 1086 |
$currentExpiry ? 'existing' : 'infinite' |
| 1087 |
); |
| 1088 |
if ( $checkbox['disabled-expiry'] ) { |
| 1089 |
$expiryFormOptions->setAttribute( 'disabled', 'disabled' ); |
| 1090 |
} |
| 1091 |
|
| 1092 |
if ( $currentExpiry ) { |
| 1093 |
$timestamp = $uiLanguage->userTimeAndDate( $currentExpiry, $uiUser ); |
| 1094 |
$d = $uiLanguage->userDate( $currentExpiry, $uiUser ); |
| 1095 |
$t = $uiLanguage->userTime( $currentExpiry, $uiUser ); |
| 1096 |
$existingExpiryMessage = $this->msg( 'userrights-expiry-existing', |
| 1097 |
$timestamp, $d, $t ); |
| 1098 |
$expiryFormOptions->addOption( $existingExpiryMessage->text(), 'existing' ); |
| 1099 |
} |
| 1100 |
|
| 1101 |
$expiryFormOptions->addOption( |
| 1102 |
$this->msg( 'userrights-expiry-none' )->text(), |
| 1103 |
'infinite' |
| 1104 |
); |
| 1105 |
$expiryFormOptions->addOption( |
| 1106 |
$this->msg( 'userrights-expiry-othertime' )->text(), |
| 1107 |
'other' |
| 1108 |
); |
| 1109 |
|
| 1110 |
$expiryFormOptions->addOptions( $expiryOptions ); |
| 1111 |
|
| 1112 |
|
| 1113 |
$expiryHtml .= $expiryFormOptions->getHTML() . '<br />'; |
| 1114 |
|
| 1115 |
|
| 1116 |
$expiryHtml .= Html::element( 'input', [ |
| 1117 |
'name' => "wpExpiry-$group-other", 'size' => 30, 'value' => '', |
| 1118 |
'id' => "mw-input-wpExpiry-$group-other", |
| 1119 |
'class' => 'mw-userrights-expiryfield', |
| 1120 |
'disabled' => $checkbox['disabled-expiry'], |
| 1121 |
] ); |
| 1122 |
|
| 1123 |
|
| 1124 |
|
| 1125 |
if ( $checkbox['set'] && $checkbox['disabled'] ) { |
| 1126 |
$expiryHtml .= Html::hidden( "wpGroup-$group", 1 ); |
| 1127 |
} |
| 1128 |
|
| 1129 |
$expiryHtml .= Html::closeElement( 'span' ); |
| 1130 |
} |
| 1131 |
|
| 1132 |
$divAttribs = [ |
| 1133 |
'id' => "mw-userrights-nested-wpGroup-$group", |
| 1134 |
'class' => 'mw-userrights-nested', |
| 1135 |
]; |
| 1136 |
$checkboxHtml .= "\t\t\t" . Html::rawElement( 'div', $divAttribs, $expiryHtml ) . "\n"; |
| 1137 |
} |
| 1138 |
$ret .= "\t\t" . ( ( $checkbox['disabled'] && $checkbox['disabled-expiry'] ) |
| 1139 |
? Html::rawElement( 'div', [ 'class' => 'mw-userrights-disabled' ], $checkboxHtml ) |
| 1140 |
: Html::rawElement( 'div', [], $checkboxHtml ) |
| 1141 |
) . "\n"; |
| 1142 |
} |
| 1143 |
$ret .= "\t</td>\n"; |
| 1144 |
} |
| 1145 |
$ret .= Html::closeElement( 'tr' ) . Html::closeElement( 'table' ); |
| 1146 |
|
| 1147 |
return [ $ret, (bool)$columns['changeable'] ]; |
| 1148 |
} |
| 1149 |
|
| 1150 |
|
| 1151 |
|
| 1152 |
|
| 1153 |
|
| 1154 |
private function canRemove( $group ) { |
| 1155 |
$groups = $this->changeableGroups(); |
| 1156 |
|
| 1157 |
return in_array( |
| 1158 |
$group, |
| 1159 |
$groups['remove'] ) || ( $this->isself && in_array( $group, $groups['remove-self'] ) |
| 1160 |
); |
| 1161 |
} |
| 1162 |
|
| 1163 |
|
| 1164 |
|
| 1165 |
|
| 1166 |
|
| 1167 |
private function canAdd( $group ) { |
| 1168 |
$groups = $this->changeableGroups(); |
| 1169 |
|
| 1170 |
return in_array( |
| 1171 |
$group, |
| 1172 |
$groups['add'] ) || ( $this->isself && in_array( $group, $groups['add-self'] ) |
| 1173 |
); |
| 1174 |
} |
| 1175 |
|
| 1176 |
|
| 1177 |
|
| 1178 |
|
| 1179 |
|
| 1180 |
|
| 1181 |
|
| 1182 |
|
| 1183 |
|
| 1184 |
|
| 1185 |
protected function changeableGroups() { |
| 1186 |
return $this->userGroupManager->getGroupsChangeableBy( $this->getContext()->getAuthority() ); |
| 1187 |
} |
| 1188 |
|
| 1189 |
|
| 1190 |
|
| 1191 |
|
| 1192 |
|
| 1193 |
|
| 1194 |
|
| 1195 |
|
| 1196 |
|
| 1197 |
private function getDisplayUsername( UserIdentity $user ) { |
| 1198 |
$userName = $user->getName(); |
| 1199 |
if ( $user->getWikiId() !== UserIdentity::LOCAL ) { |
| 1200 |
$userName .= $this->getConfig()->get( MainConfigNames::UserrightsInterwikiDelimiter ) |
| 1201 |
. $user->getWikiId(); |
| 1202 |
} |
| 1203 |
return $userName; |
| 1204 |
} |
| 1205 |
|
| 1206 |
|
| 1207 |
|
| 1208 |
|
| 1209 |
|
| 1210 |
|
| 1211 |
|
| 1212 |
protected function showLogFragment( $user, $output ) { |
| 1213 |
$rightsLogPage = new LogPage( 'rights' ); |
| 1214 |
$output->addHTML( Html::element( 'h2', [], $rightsLogPage->getName()->text() ) ); |
| 1215 |
LogEventsList::showLogExtract( $output, 'rights', |
| 1216 |
Title::makeTitle( NS_USER, $this->getDisplayUsername( $user ) ) ); |
| 1217 |
} |
| 1218 |
|
| 1219 |
|
| 1220 |
|
| 1221 |
|
| 1222 |
|
| 1223 |
|
| 1224 |
|
| 1225 |
|
| 1226 |
|
| 1227 |
public function prefixSearchSubpages( $search, $limit, $offset ) { |
| 1228 |
$search = $this->userNameUtils->getCanonical( $search ); |
| 1229 |
if ( !$search ) { |
| 1230 |
|
| 1231 |
return []; |
| 1232 |
} |
| 1233 |
|
| 1234 |
return $this->userNamePrefixSearch |
| 1235 |
->search( UserNamePrefixSearch::AUDIENCE_PUBLIC, $search, $limit, $offset ); |
| 1236 |
} |
| 1237 |
|
| 1238 |
protected function getGroupName() { |
| 1239 |
return 'users'; |
| 1240 |
} |
| 1241 |
} |
| 1242 |
|
| 1243 |
|
| 1244 |
|
| 1245 |
|
| 1246 |
|
| 1247 |
class_alias( SpecialUserRights::class, 'UserrightsPage' ); |