| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
use MediaWiki\Context\IContextSource; |
| 22 |
use MediaWiki\Context\RequestContext; |
| 23 |
use MediaWiki\HookContainer\HookRunner; |
| 24 |
use MediaWiki\Html\Html; |
| 25 |
use MediaWiki\Language\Language; |
| 26 |
use MediaWiki\Language\RawMessage; |
| 27 |
use MediaWiki\MainConfigNames; |
| 28 |
use MediaWiki\MediaWikiServices; |
| 29 |
use MediaWiki\Message\Message; |
| 30 |
use MediaWiki\Parser\Sanitizer; |
| 31 |
use MediaWiki\Permissions\Authority; |
| 32 |
use MediaWiki\Permissions\PermissionStatus; |
| 33 |
use MediaWiki\SpecialPage\SpecialPage; |
| 34 |
use MediaWiki\Status\Status; |
| 35 |
use MediaWiki\Title\Title; |
| 36 |
use MediaWiki\User\UserIdentity; |
| 37 |
use MediaWiki\Xml\XmlSelect; |
| 38 |
use Wikimedia\ObjectCache\WANObjectCache; |
| 39 |
use Wikimedia\Rdbms\IReadableDatabase; |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
class ChangeTags { |
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
public const TAG_CONTENT_MODEL_CHANGE = 'mw-contentmodelchange'; |
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
public const TAG_NEW_REDIRECT = 'mw-new-redirect'; |
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
public const TAG_REMOVED_REDIRECT = 'mw-removed-redirect'; |
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
public const TAG_CHANGED_REDIRECT_TARGET = 'mw-changed-redirect-target'; |
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
public const TAG_BLANK = 'mw-blank'; |
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
public const TAG_REPLACE = 'mw-replace'; |
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
public const TAG_ROLLBACK = 'mw-rollback'; |
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
public const TAG_UNDO = 'mw-undo'; |
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
public const TAG_MANUAL_REVERT = 'mw-manual-revert'; |
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
public const TAG_REVERTED = 'mw-reverted'; |
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
public const TAG_SERVER_SIDE_UPLOAD = 'mw-server-side-upload'; |
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
public const REVERT_TAGS = [ self::TAG_ROLLBACK, self::TAG_UNDO, self::TAG_MANUAL_REVERT ]; |
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
public const BYPASS_MAX_USAGE_CHECK = 1; |
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
private const MAX_DELETE_USES = 5000; |
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
private const CHANGE_TAG = 'change_tag'; |
| 139 |
|
| 140 |
public const DISPLAY_TABLE_ALIAS = 'changetagdisplay'; |
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
public const TAG_SET_ACTIVE_ONLY = true; |
| 152 |
public const TAG_SET_ALL = false; |
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
public const USE_ALL_TAGS = true; |
| 163 |
public const USE_SOFTWARE_TAGS_ONLY = false; |
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
public static function getSoftwareTags( $all = false ) { |
| 174 |
return MediaWikiServices::getInstance()->getChangeTagsStore()->getSoftwareTags( $all ); |
| 175 |
} |
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
public static function formatSummaryRow( $tags, $unused, ?MessageLocalizer $localizer = null ) { |
| 191 |
if ( $tags === '' || $tags === null ) { |
| 192 |
return [ '', [] ]; |
| 193 |
} |
| 194 |
if ( !$localizer ) { |
| 195 |
$localizer = RequestContext::getMain(); |
| 196 |
} |
| 197 |
|
| 198 |
$classes = []; |
| 199 |
|
| 200 |
$tags = explode( ',', $tags ); |
| 201 |
$order = array_flip( MediaWikiServices::getInstance()->getChangeTagsStore()->listDefinedTags() ); |
| 202 |
usort( $tags, static function ( $a, $b ) use ( $order ) { |
| 203 |
return ( $order[ $a ] ?? INF ) <=> ( $order[ $b ] ?? INF ); |
| 204 |
} ); |
| 205 |
|
| 206 |
$displayTags = []; |
| 207 |
foreach ( $tags as $tag ) { |
| 208 |
if ( $tag === '' ) { |
| 209 |
continue; |
| 210 |
} |
| 211 |
$classes[] = Sanitizer::escapeClass( "mw-tag-$tag" ); |
| 212 |
$description = self::tagDescription( $tag, $localizer ); |
| 213 |
if ( $description === false ) { |
| 214 |
continue; |
| 215 |
} |
| 216 |
$displayTags[] = Html::rawElement( |
| 217 |
'span', |
| 218 |
[ 'class' => 'mw-tag-marker ' . |
| 219 |
Sanitizer::escapeClass( "mw-tag-marker-$tag" ) ], |
| 220 |
$description |
| 221 |
); |
| 222 |
} |
| 223 |
|
| 224 |
if ( !$displayTags ) { |
| 225 |
return [ '', $classes ]; |
| 226 |
} |
| 227 |
|
| 228 |
$markers = $localizer->msg( 'tag-list-wrapper' ) |
| 229 |
->numParams( count( $displayTags ) ) |
| 230 |
->rawParams( implode( ' ', $displayTags ) ) |
| 231 |
->parse(); |
| 232 |
$markers = Html::rawElement( 'span', [ 'class' => 'mw-tag-markers' ], $markers ); |
| 233 |
|
| 234 |
return [ $markers, $classes ]; |
| 235 |
} |
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
public static function tagShortDescriptionMessage( $tag, MessageLocalizer $context ) { |
| 251 |
$msg = $context->msg( "tag-$tag" ); |
| 252 |
if ( !$msg->exists() ) { |
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
return $context->msg( new RawMessage( '$1', [ Message::plaintextParam( $tag ) ] ) ); |
| 257 |
} |
| 258 |
if ( $msg->isDisabled() ) { |
| 259 |
|
| 260 |
return false; |
| 261 |
} |
| 262 |
|
| 263 |
|
| 264 |
return $msg; |
| 265 |
} |
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
public static function tagHelpLink( $tag, MessageLocalizer $context ) { |
| 280 |
$msg = $context->msg( "tag-$tag-helppage" )->inContentLanguage(); |
| 281 |
if ( $msg->exists() && !$msg->isDisabled() ) { |
| 282 |
$url = Skin::makeInternalOrExternalUrl( $msg->text() ); |
| 283 |
if ( $url ) { |
| 284 |
return $url; |
| 285 |
} |
| 286 |
} |
| 287 |
return null; |
| 288 |
} |
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
public static function tagDescription( $tag, MessageLocalizer $context ) { |
| 302 |
$msg = self::tagShortDescriptionMessage( $tag, $context ); |
| 303 |
$link = self::tagHelpLink( $tag, $context ); |
| 304 |
if ( $msg && $link ) { |
| 305 |
$label = $msg->parse(); |
| 306 |
|
| 307 |
if ( !str_contains( $label, '<a ' ) ) { |
| 308 |
return Html::rawElement( 'a', [ 'href' => $link ], $label ); |
| 309 |
} |
| 310 |
} |
| 311 |
return $msg ? $msg->parse() : false; |
| 312 |
} |
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
public static function tagLongDescriptionMessage( $tag, MessageLocalizer $context ) { |
| 327 |
$msg = $context->msg( "tag-$tag-description" ); |
| 328 |
if ( !$msg->exists() ) { |
| 329 |
return false; |
| 330 |
} |
| 331 |
if ( $msg->isDisabled() ) { |
| 332 |
|
| 333 |
return false; |
| 334 |
} |
| 335 |
|
| 336 |
|
| 337 |
return $msg; |
| 338 |
} |
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
|
| 343 |
|
| 344 |
|
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
public static function addTags( $tags, $rc_id = null, $rev_id = null, |
| 355 |
$log_id = null, $params = null, ?RecentChange $rc = null |
| 356 |
) { |
| 357 |
return MediaWikiServices::getInstance()->getChangeTagsStore()->addTags( |
| 358 |
$tags, $rc_id, $rev_id, $log_id, $params, $rc |
| 359 |
); |
| 360 |
} |
| 361 |
|
| 362 |
|
| 363 |
|
| 364 |
|
| 365 |
|
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
|
| 380 |
|
| 381 |
|
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
|
| 391 |
|
| 392 |
public static function updateTags( $tagsToAdd, $tagsToRemove, &$rc_id = null, |
| 393 |
&$rev_id = null, &$log_id = null, $params = null, ?RecentChange $rc = null, |
| 394 |
?UserIdentity $user = null |
| 395 |
) { |
| 396 |
return MediaWikiServices::getInstance()->getChangeTagsStore()->updateTags( |
| 397 |
$tagsToAdd, $tagsToRemove, $rc_id, $rev_id, $log_id, $params, $rc, $user |
| 398 |
); |
| 399 |
} |
| 400 |
|
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
|
| 405 |
|
| 406 |
|
| 407 |
|
| 408 |
|
| 409 |
|
| 410 |
|
| 411 |
|
| 412 |
|
| 413 |
public static function getTagsWithData( |
| 414 |
IReadableDatabase $db, $rc_id = null, $rev_id = null, $log_id = null |
| 415 |
) { |
| 416 |
return MediaWikiServices::getInstance()->getChangeTagsStore()->getTagsWithData( $db, $rc_id, $rev_id, $log_id ); |
| 417 |
} |
| 418 |
|
| 419 |
|
| 420 |
|
| 421 |
|
| 422 |
|
| 423 |
|
| 424 |
|
| 425 |
|
| 426 |
|
| 427 |
|
| 428 |
|
| 429 |
|
| 430 |
public static function getTags( IReadableDatabase $db, $rc_id = null, $rev_id = null, $log_id = null ) { |
| 431 |
return MediaWikiServices::getInstance()->getChangeTagsStore()->getTags( $db, $rc_id, $rev_id, $log_id ); |
| 432 |
} |
| 433 |
|
| 434 |
|
| 435 |
|
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
|
| 441 |
|
| 442 |
|
| 443 |
|
| 444 |
protected static function restrictedTagError( $msgOne, $msgMulti, $tags ) { |
| 445 |
$lang = RequestContext::getMain()->getLanguage(); |
| 446 |
$tags = array_values( $tags ); |
| 447 |
$count = count( $tags ); |
| 448 |
$status = Status::newFatal( ( $count > 1 ) ? $msgMulti : $msgOne, |
| 449 |
$lang->commaList( $tags ), $count ); |
| 450 |
$status->value = $tags; |
| 451 |
return $status; |
| 452 |
} |
| 453 |
|
| 454 |
|
| 455 |
|
| 456 |
|
| 457 |
|
| 458 |
|
| 459 |
|
| 460 |
|
| 461 |
|
| 462 |
|
| 463 |
|
| 464 |
|
| 465 |
|
| 466 |
|
| 467 |
|
| 468 |
public static function canAddTagsAccompanyingChange( |
| 469 |
array $tags, |
| 470 |
?Authority $performer = null, |
| 471 |
$checkBlock = true |
| 472 |
) { |
| 473 |
$user = null; |
| 474 |
$services = MediaWikiServices::getInstance(); |
| 475 |
if ( $performer !== null ) { |
| 476 |
if ( !$performer->isAllowed( 'applychangetags' ) ) { |
| 477 |
return Status::newFatal( 'tags-apply-no-permission' ); |
| 478 |
} |
| 479 |
|
| 480 |
if ( $checkBlock && $performer->getBlock() && $performer->getBlock()->isSitewide() ) { |
| 481 |
return Status::newFatal( |
| 482 |
'tags-apply-blocked', |
| 483 |
$performer->getUser()->getName() |
| 484 |
); |
| 485 |
} |
| 486 |
|
| 487 |
|
| 488 |
$user = $services->getUserFactory()->newFromAuthority( $performer ); |
| 489 |
} |
| 490 |
|
| 491 |
|
| 492 |
$allowedTags = $services->getChangeTagsStore()->listExplicitlyDefinedTags(); |
| 493 |
( new HookRunner( $services->getHookContainer() ) )->onChangeTagsAllowedAdd( $allowedTags, $tags, $user ); |
| 494 |
$disallowedTags = array_diff( $tags, $allowedTags ); |
| 495 |
if ( $disallowedTags ) { |
| 496 |
return self::restrictedTagError( 'tags-apply-not-allowed-one', |
| 497 |
'tags-apply-not-allowed-multi', $disallowedTags ); |
| 498 |
} |
| 499 |
|
| 500 |
return Status::newGood(); |
| 501 |
} |
| 502 |
|
| 503 |
|
| 504 |
|
| 505 |
|
| 506 |
|
| 507 |
|
| 508 |
|
| 509 |
|
| 510 |
|
| 511 |
|
| 512 |
|
| 513 |
|
| 514 |
|
| 515 |
|
| 516 |
|
| 517 |
public static function canUpdateTags( |
| 518 |
array $tagsToAdd, |
| 519 |
array $tagsToRemove, |
| 520 |
?Authority $performer = null |
| 521 |
) { |
| 522 |
if ( $performer !== null ) { |
| 523 |
if ( !$performer->isDefinitelyAllowed( 'changetags' ) ) { |
| 524 |
return Status::newFatal( 'tags-update-no-permission' ); |
| 525 |
} |
| 526 |
|
| 527 |
if ( $performer->getBlock() && $performer->getBlock()->isSitewide() ) { |
| 528 |
return Status::newFatal( |
| 529 |
'tags-update-blocked', |
| 530 |
$performer->getUser()->getName() |
| 531 |
); |
| 532 |
} |
| 533 |
} |
| 534 |
|
| 535 |
$changeTagStore = MediaWikiServices::getInstance()->getChangeTagsStore(); |
| 536 |
if ( $tagsToAdd ) { |
| 537 |
|
| 538 |
|
| 539 |
$explicitlyDefinedTags = $changeTagStore->listExplicitlyDefinedTags(); |
| 540 |
$diff = array_diff( $tagsToAdd, $explicitlyDefinedTags ); |
| 541 |
if ( $diff ) { |
| 542 |
return self::restrictedTagError( 'tags-update-add-not-allowed-one', |
| 543 |
'tags-update-add-not-allowed-multi', $diff ); |
| 544 |
} |
| 545 |
} |
| 546 |
|
| 547 |
if ( $tagsToRemove ) { |
| 548 |
|
| 549 |
|
| 550 |
|
| 551 |
$softwareDefinedTags = $changeTagStore->listSoftwareDefinedTags(); |
| 552 |
$intersect = array_intersect( $tagsToRemove, $softwareDefinedTags ); |
| 553 |
if ( $intersect ) { |
| 554 |
return self::restrictedTagError( 'tags-update-remove-not-allowed-one', |
| 555 |
'tags-update-remove-not-allowed-multi', $intersect ); |
| 556 |
} |
| 557 |
} |
| 558 |
|
| 559 |
return Status::newGood(); |
| 560 |
} |
| 561 |
|
| 562 |
|
| 563 |
|
| 564 |
|
| 565 |
|
| 566 |
|
| 567 |
|
| 568 |
|
| 569 |
|
| 570 |
|
| 571 |
|
| 572 |
|
| 573 |
|
| 574 |
|
| 575 |
|
| 576 |
|
| 577 |
|
| 578 |
|
| 579 |
|
| 580 |
|
| 581 |
|
| 582 |
|
| 583 |
|
| 584 |
|
| 585 |
|
| 586 |
|
| 587 |
|
| 588 |
|
| 589 |
|
| 590 |
|
| 591 |
|
| 592 |
public static function updateTagsWithChecks( $tagsToAdd, $tagsToRemove, |
| 593 |
$rc_id, $rev_id, $log_id, $params, string $reason, Authority $performer |
| 594 |
) { |
| 595 |
if ( !$tagsToAdd && !$tagsToRemove ) { |
| 596 |
|
| 597 |
return Status::newGood( (object)[ |
| 598 |
'logId' => null, |
| 599 |
'addedTags' => [], |
| 600 |
'removedTags' => [], |
| 601 |
] ); |
| 602 |
} |
| 603 |
|
| 604 |
$tagsToAdd ??= []; |
| 605 |
$tagsToRemove ??= []; |
| 606 |
|
| 607 |
|
| 608 |
$result = self::canUpdateTags( $tagsToAdd, $tagsToRemove, $performer ); |
| 609 |
if ( !$result->isOK() ) { |
| 610 |
$result->value = null; |
| 611 |
return $result; |
| 612 |
} |
| 613 |
|
| 614 |
|
| 615 |
$status = PermissionStatus::newEmpty(); |
| 616 |
if ( !$performer->authorizeAction( 'changetags', $status ) ) { |
| 617 |
return Status::wrap( $status ); |
| 618 |
} |
| 619 |
|
| 620 |
|
| 621 |
$changeTagStore = MediaWikiServices::getInstance()->getChangeTagsStore(); |
| 622 |
[ $tagsAdded, $tagsRemoved, $initialTags ] = $changeTagStore->updateTags( $tagsToAdd, |
| 623 |
$tagsToRemove, $rc_id, $rev_id, $log_id, $params, null, $performer->getUser() ); |
| 624 |
if ( !$tagsAdded && !$tagsRemoved ) { |
| 625 |
|
| 626 |
return Status::newGood( (object)[ |
| 627 |
'logId' => null, |
| 628 |
'addedTags' => [], |
| 629 |
'removedTags' => [], |
| 630 |
] ); |
| 631 |
} |
| 632 |
|
| 633 |
|
| 634 |
$logEntry = new ManualLogEntry( 'tag', 'update' ); |
| 635 |
$logEntry->setPerformer( $performer->getUser() ); |
| 636 |
$logEntry->setComment( $reason ); |
| 637 |
|
| 638 |
|
| 639 |
if ( $rev_id ) { |
| 640 |
$revisionRecord = MediaWikiServices::getInstance() |
| 641 |
->getRevisionLookup() |
| 642 |
->getRevisionById( $rev_id ); |
| 643 |
if ( $revisionRecord ) { |
| 644 |
$logEntry->setTarget( $revisionRecord->getPageAsLinkTarget() ); |
| 645 |
} |
| 646 |
} elseif ( $log_id ) { |
| 647 |
|
| 648 |
|
| 649 |
|
| 650 |
$logEntry->setTarget( RevDelLogList::suggestTarget( null, [ $log_id ] ) ); |
| 651 |
} |
| 652 |
|
| 653 |
if ( !$logEntry->getTarget() ) { |
| 654 |
|
| 655 |
$logEntry->setTarget( SpecialPage::getTitleFor( 'Tags' ) ); |
| 656 |
} |
| 657 |
|
| 658 |
$logParams = [ |
| 659 |
'4::revid' => $rev_id, |
| 660 |
'5::logid' => $log_id, |
| 661 |
'6:list:tagsAdded' => $tagsAdded, |
| 662 |
'7:number:tagsAddedCount' => count( $tagsAdded ), |
| 663 |
'8:list:tagsRemoved' => $tagsRemoved, |
| 664 |
'9:number:tagsRemovedCount' => count( $tagsRemoved ), |
| 665 |
'initialTags' => $initialTags, |
| 666 |
]; |
| 667 |
$logEntry->setParameters( $logParams ); |
| 668 |
$logEntry->setRelations( [ 'Tag' => array_merge( $tagsAdded, $tagsRemoved ) ] ); |
| 669 |
|
| 670 |
$dbw = MediaWikiServices::getInstance()->getConnectionProvider()->getPrimaryDatabase(); |
| 671 |
$logId = $logEntry->insert( $dbw ); |
| 672 |
|
| 673 |
$logEntry->publish( $logId, 'udp' ); |
| 674 |
|
| 675 |
return Status::newGood( (object)[ |
| 676 |
'logId' => $logId, |
| 677 |
'addedTags' => $tagsAdded, |
| 678 |
'removedTags' => $tagsRemoved, |
| 679 |
] ); |
| 680 |
} |
| 681 |
|
| 682 |
|
| 683 |
|
| 684 |
|
| 685 |
|
| 686 |
|
| 687 |
|
| 688 |
|
| 689 |
|
| 690 |
|
| 691 |
|
| 692 |
|
| 693 |
|
| 694 |
|
| 695 |
|
| 696 |
|
| 697 |
|
| 698 |
|
| 699 |
|
| 700 |
|
| 701 |
|
| 702 |
|
| 703 |
public static function modifyDisplayQuery( &$tables, &$fields, &$conds, |
| 704 |
&$join_conds, &$options, $filter_tag = '', bool $exclude = false |
| 705 |
) { |
| 706 |
MediaWikiServices::getInstance()->getChangeTagsStore()->modifyDisplayQuery( |
| 707 |
$tables, |
| 708 |
$fields, |
| 709 |
$conds, |
| 710 |
$join_conds, |
| 711 |
$options, |
| 712 |
$filter_tag, |
| 713 |
$exclude |
| 714 |
); |
| 715 |
} |
| 716 |
|
| 717 |
|
| 718 |
|
| 719 |
|
| 720 |
|
| 721 |
|
| 722 |
|
| 723 |
|
| 724 |
|
| 725 |
|
| 726 |
public static function getDisplayTableName() { |
| 727 |
return self::CHANGE_TAG; |
| 728 |
} |
| 729 |
|
| 730 |
|
| 731 |
|
| 732 |
|
| 733 |
|
| 734 |
|
| 735 |
|
| 736 |
|
| 737 |
|
| 738 |
public static function makeTagSummarySubquery( $tables ) { |
| 739 |
return MediaWikiServices::getInstance()->getChangeTagsStore()->makeTagSummarySubquery( $tables ); |
| 740 |
} |
| 741 |
|
| 742 |
|
| 743 |
|
| 744 |
|
| 745 |
|
| 746 |
|
| 747 |
|
| 748 |
|
| 749 |
|
| 750 |
|
| 751 |
|
| 752 |
|
| 753 |
|
| 754 |
|
| 755 |
|
| 756 |
|
| 757 |
public static function buildTagFilterSelector( |
| 758 |
$selected = '', $ooui = false, ?IContextSource $context = null, |
| 759 |
bool $activeOnly = self::TAG_SET_ACTIVE_ONLY, |
| 760 |
bool $useAllTags = self::USE_ALL_TAGS |
| 761 |
) { |
| 762 |
if ( !$context ) { |
| 763 |
$context = RequestContext::getMain(); |
| 764 |
} |
| 765 |
|
| 766 |
$config = $context->getConfig(); |
| 767 |
$changeTagStore = MediaWikiServices::getInstance()->getChangeTagsStore(); |
| 768 |
if ( !$config->get( MainConfigNames::UseTagFilter ) || |
| 769 |
!count( $changeTagStore->listDefinedTags() ) ) { |
| 770 |
return []; |
| 771 |
} |
| 772 |
|
| 773 |
$tags = self::getChangeTagList( |
| 774 |
$context, |
| 775 |
$context->getLanguage(), |
| 776 |
$activeOnly, |
| 777 |
$useAllTags, |
| 778 |
true |
| 779 |
); |
| 780 |
|
| 781 |
$autocomplete = []; |
| 782 |
foreach ( $tags as $tagInfo ) { |
| 783 |
$autocomplete[ $tagInfo['label'] ] = $tagInfo['name']; |
| 784 |
} |
| 785 |
|
| 786 |
$data = [ |
| 787 |
Html::rawElement( |
| 788 |
'label', |
| 789 |
[ 'for' => 'tagfilter' ], |
| 790 |
$context->msg( 'tag-filter' )->parse() |
| 791 |
) |
| 792 |
]; |
| 793 |
|
| 794 |
if ( $ooui ) { |
| 795 |
$options = Html::listDropdownOptionsOoui( $autocomplete ); |
| 796 |
|
| 797 |
$data[] = new OOUI\ComboBoxInputWidget( [ |
| 798 |
'id' => 'tagfilter', |
| 799 |
'name' => 'tagfilter', |
| 800 |
'value' => $selected, |
| 801 |
'classes' => 'mw-tagfilter-input', |
| 802 |
'options' => $options, |
| 803 |
] ); |
| 804 |
} else { |
| 805 |
$datalist = new XmlSelect( false, 'tagfilter-datalist' ); |
| 806 |
$datalist->setTagName( 'datalist' ); |
| 807 |
$datalist->addOptions( $autocomplete ); |
| 808 |
|
| 809 |
$data[] = Html::input( |
| 810 |
'tagfilter', |
| 811 |
$selected, |
| 812 |
'text', |
| 813 |
[ |
| 814 |
'class' => [ 'mw-tagfilter-input', 'mw-ui-input', 'mw-ui-input-inline' ], |
| 815 |
'size' => 20, |
| 816 |
'id' => 'tagfilter', |
| 817 |
'list' => 'tagfilter-datalist', |
| 818 |
] |
| 819 |
) . $datalist->getHTML(); |
| 820 |
} |
| 821 |
|
| 822 |
return $data; |
| 823 |
} |
| 824 |
|
| 825 |
|
| 826 |
|
| 827 |
|
| 828 |
|
| 829 |
|
| 830 |
|
| 831 |
|
| 832 |
|
| 833 |
|
| 834 |
public static function defineTag( $tag ) { |
| 835 |
MediaWikiServices::getInstance()->getChangeTagsStore()->defineTag( $tag ); |
| 836 |
} |
| 837 |
|
| 838 |
|
| 839 |
|
| 840 |
|
| 841 |
|
| 842 |
|
| 843 |
|
| 844 |
|
| 845 |
|
| 846 |
|
| 847 |
public static function canActivateTag( $tag, ?Authority $performer = null ) { |
| 848 |
if ( $performer !== null ) { |
| 849 |
if ( !$performer->isAllowed( 'managechangetags' ) ) { |
| 850 |
return Status::newFatal( 'tags-manage-no-permission' ); |
| 851 |
} |
| 852 |
if ( $performer->getBlock() && $performer->getBlock()->isSitewide() ) { |
| 853 |
return Status::newFatal( |
| 854 |
'tags-manage-blocked', |
| 855 |
$performer->getUser()->getName() |
| 856 |
); |
| 857 |
} |
| 858 |
} |
| 859 |
|
| 860 |
|
| 861 |
|
| 862 |
|
| 863 |
$changeTagStore = MediaWikiServices::getInstance()->getChangeTagsStore(); |
| 864 |
$definedTags = $changeTagStore->listDefinedTags(); |
| 865 |
if ( in_array( $tag, $definedTags ) ) { |
| 866 |
return Status::newFatal( 'tags-activate-not-allowed', $tag ); |
| 867 |
} |
| 868 |
|
| 869 |
|
| 870 |
if ( !isset( $changeTagStore->tagUsageStatistics()[$tag] ) ) { |
| 871 |
return Status::newFatal( 'tags-activate-not-found', $tag ); |
| 872 |
} |
| 873 |
|
| 874 |
return Status::newGood(); |
| 875 |
} |
| 876 |
|
| 877 |
|
| 878 |
|
| 879 |
|
| 880 |
|
| 881 |
|
| 882 |
|
| 883 |
|
| 884 |
|
| 885 |
|
| 886 |
|
| 887 |
|
| 888 |
|
| 889 |
|
| 890 |
|
| 891 |
|
| 892 |
|
| 893 |
|
| 894 |
public static function activateTagWithChecks( string $tag, string $reason, Authority $performer, |
| 895 |
bool $ignoreWarnings = false, array $logEntryTags = [] |
| 896 |
) { |
| 897 |
|
| 898 |
$result = self::canActivateTag( $tag, $performer ); |
| 899 |
if ( $ignoreWarnings ? !$result->isOK() : !$result->isGood() ) { |
| 900 |
$result->value = null; |
| 901 |
return $result; |
| 902 |
} |
| 903 |
$changeTagStore = MediaWikiServices::getInstance()->getChangeTagsStore(); |
| 904 |
|
| 905 |
$changeTagStore->defineTag( $tag ); |
| 906 |
|
| 907 |
$logId = $changeTagStore->logTagManagementAction( 'activate', $tag, $reason, $performer->getUser(), |
| 908 |
null, $logEntryTags ); |
| 909 |
|
| 910 |
return Status::newGood( $logId ); |
| 911 |
} |
| 912 |
|
| 913 |
|
| 914 |
|
| 915 |
|
| 916 |
|
| 917 |
|
| 918 |
|
| 919 |
|
| 920 |
|
| 921 |
|
| 922 |
public static function canDeactivateTag( $tag, ?Authority $performer = null ) { |
| 923 |
if ( $performer !== null ) { |
| 924 |
if ( !$performer->isAllowed( 'managechangetags' ) ) { |
| 925 |
return Status::newFatal( 'tags-manage-no-permission' ); |
| 926 |
} |
| 927 |
if ( $performer->getBlock() && $performer->getBlock()->isSitewide() ) { |
| 928 |
return Status::newFatal( |
| 929 |
'tags-manage-blocked', |
| 930 |
$performer->getUser()->getName() |
| 931 |
); |
| 932 |
} |
| 933 |
} |
| 934 |
|
| 935 |
|
| 936 |
$explicitlyDefinedTags = MediaWikiServices::getInstance()->getChangeTagsStore()->listExplicitlyDefinedTags(); |
| 937 |
if ( !in_array( $tag, $explicitlyDefinedTags ) ) { |
| 938 |
return Status::newFatal( 'tags-deactivate-not-allowed', $tag ); |
| 939 |
} |
| 940 |
return Status::newGood(); |
| 941 |
} |
| 942 |
|
| 943 |
|
| 944 |
|
| 945 |
|
| 946 |
|
| 947 |
|
| 948 |
|
| 949 |
|
| 950 |
|
| 951 |
|
| 952 |
|
| 953 |
|
| 954 |
|
| 955 |
|
| 956 |
|
| 957 |
|
| 958 |
|
| 959 |
|
| 960 |
public static function deactivateTagWithChecks( string $tag, string $reason, Authority $performer, |
| 961 |
bool $ignoreWarnings = false, array $logEntryTags = [] |
| 962 |
) { |
| 963 |
|
| 964 |
$result = self::canDeactivateTag( $tag, $performer ); |
| 965 |
if ( $ignoreWarnings ? !$result->isOK() : !$result->isGood() ) { |
| 966 |
$result->value = null; |
| 967 |
return $result; |
| 968 |
} |
| 969 |
$changeTagStore = MediaWikiServices::getInstance()->getChangeTagsStore(); |
| 970 |
|
| 971 |
$changeTagStore->undefineTag( $tag ); |
| 972 |
|
| 973 |
$logId = $changeTagStore->logTagManagementAction( 'deactivate', $tag, $reason, |
| 974 |
$performer->getUser(), null, $logEntryTags ); |
| 975 |
|
| 976 |
return Status::newGood( $logId ); |
| 977 |
} |
| 978 |
|
| 979 |
|
| 980 |
|
| 981 |
|
| 982 |
|
| 983 |
|
| 984 |
|
| 985 |
|
| 986 |
public static function isTagNameValid( $tag ) { |
| 987 |
|
| 988 |
if ( $tag === '' ) { |
| 989 |
return Status::newFatal( 'tags-create-no-name' ); |
| 990 |
} |
| 991 |
|
| 992 |
|
| 993 |
|
| 994 |
|
| 995 |
|
| 996 |
if ( strpos( $tag, ',' ) !== false || strpos( $tag, '|' ) !== false |
| 997 |
|| strpos( $tag, '/' ) !== false ) { |
| 998 |
return Status::newFatal( 'tags-create-invalid-chars' ); |
| 999 |
} |
| 1000 |
|
| 1001 |
|
| 1002 |
$title = Title::makeTitleSafe( NS_MEDIAWIKI, "Tag-$tag-description" ); |
| 1003 |
if ( $title === null ) { |
| 1004 |
return Status::newFatal( 'tags-create-invalid-title-chars' ); |
| 1005 |
} |
| 1006 |
|
| 1007 |
return Status::newGood(); |
| 1008 |
} |
| 1009 |
|
| 1010 |
|
| 1011 |
|
| 1012 |
|
| 1013 |
|
| 1014 |
|
| 1015 |
|
| 1016 |
|
| 1017 |
|
| 1018 |
|
| 1019 |
|
| 1020 |
|
| 1021 |
|
| 1022 |
public static function canCreateTag( $tag, ?Authority $performer = null ) { |
| 1023 |
$user = null; |
| 1024 |
$services = MediaWikiServices::getInstance(); |
| 1025 |
if ( $performer !== null ) { |
| 1026 |
if ( !$performer->isAllowed( 'managechangetags' ) ) { |
| 1027 |
return Status::newFatal( 'tags-manage-no-permission' ); |
| 1028 |
} |
| 1029 |
if ( $performer->getBlock() && $performer->getBlock()->isSitewide() ) { |
| 1030 |
return Status::newFatal( |
| 1031 |
'tags-manage-blocked', |
| 1032 |
$performer->getUser()->getName() |
| 1033 |
); |
| 1034 |
} |
| 1035 |
|
| 1036 |
$user = $services->getUserFactory()->newFromAuthority( $performer ); |
| 1037 |
} |
| 1038 |
|
| 1039 |
$status = self::isTagNameValid( $tag ); |
| 1040 |
if ( !$status->isGood() ) { |
| 1041 |
return $status; |
| 1042 |
} |
| 1043 |
|
| 1044 |
|
| 1045 |
$changeTagStore = $services->getChangeTagsStore(); |
| 1046 |
if ( |
| 1047 |
isset( $changeTagStore->tagUsageStatistics()[$tag] ) || |
| 1048 |
in_array( $tag, $changeTagStore->listDefinedTags() ) |
| 1049 |
) { |
| 1050 |
return Status::newFatal( 'tags-create-already-exists', $tag ); |
| 1051 |
} |
| 1052 |
|
| 1053 |
|
| 1054 |
$canCreateResult = Status::newGood(); |
| 1055 |
( new HookRunner( $services->getHookContainer() ) )->onChangeTagCanCreate( $tag, $user, $canCreateResult ); |
| 1056 |
return $canCreateResult; |
| 1057 |
} |
| 1058 |
|
| 1059 |
|
| 1060 |
|
| 1061 |
|
| 1062 |
|
| 1063 |
|
| 1064 |
|
| 1065 |
|
| 1066 |
|
| 1067 |
|
| 1068 |
|
| 1069 |
|
| 1070 |
|
| 1071 |
|
| 1072 |
|
| 1073 |
|
| 1074 |
|
| 1075 |
|
| 1076 |
|
| 1077 |
|
| 1078 |
public static function createTagWithChecks( string $tag, string $reason, Authority $performer, |
| 1079 |
bool $ignoreWarnings = false, array $logEntryTags = [] |
| 1080 |
) { |
| 1081 |
|
| 1082 |
$result = self::canCreateTag( $tag, $performer ); |
| 1083 |
if ( $ignoreWarnings ? !$result->isOK() : !$result->isGood() ) { |
| 1084 |
$result->value = null; |
| 1085 |
return $result; |
| 1086 |
} |
| 1087 |
|
| 1088 |
$changeTagStore = MediaWikiServices::getInstance()->getChangeTagsStore(); |
| 1089 |
$changeTagStore->defineTag( $tag ); |
| 1090 |
$logId = $changeTagStore->logTagManagementAction( 'create', $tag, $reason, |
| 1091 |
$performer->getUser(), null, $logEntryTags ); |
| 1092 |
|
| 1093 |
return Status::newGood( $logId ); |
| 1094 |
} |
| 1095 |
|
| 1096 |
|
| 1097 |
|
| 1098 |
|
| 1099 |
|
| 1100 |
|
| 1101 |
|
| 1102 |
|
| 1103 |
|
| 1104 |
|
| 1105 |
|
| 1106 |
|
| 1107 |
|
| 1108 |
|
| 1109 |
public static function deleteTagEverywhere( $tag ) { |
| 1110 |
return MediaWikiServices::getInstance()->getChangeTagsStore()->deleteTagEverywhere( $tag ); |
| 1111 |
} |
| 1112 |
|
| 1113 |
|
| 1114 |
|
| 1115 |
|
| 1116 |
|
| 1117 |
|
| 1118 |
|
| 1119 |
|
| 1120 |
|
| 1121 |
|
| 1122 |
|
| 1123 |
|
| 1124 |
|
| 1125 |
public static function canDeleteTag( $tag, ?Authority $performer = null, int $flags = 0 ) { |
| 1126 |
$user = null; |
| 1127 |
$services = MediaWikiServices::getInstance(); |
| 1128 |
if ( $performer !== null ) { |
| 1129 |
if ( !$performer->isAllowed( 'deletechangetags' ) ) { |
| 1130 |
return Status::newFatal( 'tags-delete-no-permission' ); |
| 1131 |
} |
| 1132 |
if ( $performer->getBlock() && $performer->getBlock()->isSitewide() ) { |
| 1133 |
return Status::newFatal( |
| 1134 |
'tags-manage-blocked', |
| 1135 |
$performer->getUser()->getName() |
| 1136 |
); |
| 1137 |
} |
| 1138 |
|
| 1139 |
$user = $services->getUserFactory()->newFromAuthority( $performer ); |
| 1140 |
} |
| 1141 |
|
| 1142 |
$changeTagStore = $services->getChangeTagsStore(); |
| 1143 |
$tagUsage = $changeTagStore->tagUsageStatistics(); |
| 1144 |
if ( |
| 1145 |
!isset( $tagUsage[$tag] ) && |
| 1146 |
!in_array( $tag, $changeTagStore->listDefinedTags() ) |
| 1147 |
) { |
| 1148 |
return Status::newFatal( 'tags-delete-not-found', $tag ); |
| 1149 |
} |
| 1150 |
|
| 1151 |
if ( $flags !== self::BYPASS_MAX_USAGE_CHECK && |
| 1152 |
isset( $tagUsage[$tag] ) && |
| 1153 |
$tagUsage[$tag] > self::MAX_DELETE_USES |
| 1154 |
) { |
| 1155 |
return Status::newFatal( 'tags-delete-too-many-uses', $tag, self::MAX_DELETE_USES ); |
| 1156 |
} |
| 1157 |
|
| 1158 |
$softwareDefined = $changeTagStore->listSoftwareDefinedTags(); |
| 1159 |
if ( in_array( $tag, $softwareDefined ) ) { |
| 1160 |
|
| 1161 |
|
| 1162 |
$status = Status::newFatal( 'tags-delete-not-allowed' ); |
| 1163 |
} else { |
| 1164 |
|
| 1165 |
$status = Status::newGood(); |
| 1166 |
} |
| 1167 |
|
| 1168 |
( new HookRunner( $services->getHookContainer() ) )->onChangeTagCanDelete( $tag, $user, $status ); |
| 1169 |
return $status; |
| 1170 |
} |
| 1171 |
|
| 1172 |
|
| 1173 |
|
| 1174 |
|
| 1175 |
|
| 1176 |
|
| 1177 |
|
| 1178 |
|
| 1179 |
|
| 1180 |
|
| 1181 |
|
| 1182 |
|
| 1183 |
|
| 1184 |
|
| 1185 |
|
| 1186 |
|
| 1187 |
|
| 1188 |
|
| 1189 |
public static function deleteTagWithChecks( string $tag, string $reason, Authority $performer, |
| 1190 |
bool $ignoreWarnings = false, array $logEntryTags = [] |
| 1191 |
) { |
| 1192 |
$changeTagStore = MediaWikiServices::getInstance()->getChangeTagsStore(); |
| 1193 |
|
| 1194 |
$result = self::canDeleteTag( $tag, $performer ); |
| 1195 |
if ( $ignoreWarnings ? !$result->isOK() : !$result->isGood() ) { |
| 1196 |
$result->value = null; |
| 1197 |
return $result; |
| 1198 |
} |
| 1199 |
|
| 1200 |
|
| 1201 |
$hitcount = $changeTagStore->tagUsageStatistics()[$tag] ?? 0; |
| 1202 |
|
| 1203 |
|
| 1204 |
$deleteResult = $changeTagStore->deleteTagEverywhere( $tag ); |
| 1205 |
if ( !$deleteResult->isOK() ) { |
| 1206 |
return $deleteResult; |
| 1207 |
} |
| 1208 |
|
| 1209 |
|
| 1210 |
$changeTagStore = MediaWikiServices::getInstance()->getChangeTagsStore(); |
| 1211 |
$logId = $changeTagStore->logTagManagementAction( 'delete', $tag, $reason, $performer->getUser(), |
| 1212 |
$hitcount, $logEntryTags ); |
| 1213 |
|
| 1214 |
$deleteResult->value = $logId; |
| 1215 |
return $deleteResult; |
| 1216 |
} |
| 1217 |
|
| 1218 |
|
| 1219 |
|
| 1220 |
|
| 1221 |
|
| 1222 |
|
| 1223 |
|
| 1224 |
|
| 1225 |
public static function listSoftwareActivatedTags() { |
| 1226 |
return MediaWikiServices::getInstance()->getChangeTagsStore()->listSoftwareActivatedTags(); |
| 1227 |
} |
| 1228 |
|
| 1229 |
|
| 1230 |
|
| 1231 |
|
| 1232 |
|
| 1233 |
|
| 1234 |
|
| 1235 |
|
| 1236 |
|
| 1237 |
public static function listDefinedTags() { |
| 1238 |
return MediaWikiServices::getInstance()->getChangeTagsStore()->listDefinedTags(); |
| 1239 |
} |
| 1240 |
|
| 1241 |
|
| 1242 |
|
| 1243 |
|
| 1244 |
|
| 1245 |
|
| 1246 |
|
| 1247 |
|
| 1248 |
|
| 1249 |
|
| 1250 |
public static function listExplicitlyDefinedTags() { |
| 1251 |
return MediaWikiServices::getInstance()->getChangeTagsStore()->listExplicitlyDefinedTags(); |
| 1252 |
} |
| 1253 |
|
| 1254 |
|
| 1255 |
|
| 1256 |
|
| 1257 |
|
| 1258 |
|
| 1259 |
|
| 1260 |
|
| 1261 |
|
| 1262 |
|
| 1263 |
|
| 1264 |
public static function listSoftwareDefinedTags() { |
| 1265 |
return MediaWikiServices::getInstance()->getChangeTagsStore()->listSoftwareDefinedTags(); |
| 1266 |
} |
| 1267 |
|
| 1268 |
|
| 1269 |
|
| 1270 |
|
| 1271 |
|
| 1272 |
|
| 1273 |
|
| 1274 |
public static function purgeTagCacheAll() { |
| 1275 |
MediaWikiServices::getInstance()->getChangeTagsStore()->purgeTagCacheAll(); |
| 1276 |
} |
| 1277 |
|
| 1278 |
|
| 1279 |
|
| 1280 |
|
| 1281 |
|
| 1282 |
|
| 1283 |
|
| 1284 |
|
| 1285 |
|
| 1286 |
public static function tagUsageStatistics() { |
| 1287 |
return MediaWikiServices::getInstance()->getChangeTagsStore()->tagUsageStatistics(); |
| 1288 |
} |
| 1289 |
|
| 1290 |
|
| 1291 |
|
| 1292 |
|
| 1293 |
|
| 1294 |
private const TAG_DESC_CHARACTER_LIMIT = 120; |
| 1295 |
|
| 1296 |
|
| 1297 |
|
| 1298 |
|
| 1299 |
|
| 1300 |
|
| 1301 |
|
| 1302 |
|
| 1303 |
|
| 1304 |
|
| 1305 |
|
| 1306 |
|
| 1307 |
|
| 1308 |
|
| 1309 |
|
| 1310 |
|
| 1311 |
|
| 1312 |
|
| 1313 |
|
| 1314 |
|
| 1315 |
|
| 1316 |
|
| 1317 |
|
| 1318 |
|
| 1319 |
|
| 1320 |
|
| 1321 |
|
| 1322 |
|
| 1323 |
|
| 1324 |
public static function getChangeTagListSummary( |
| 1325 |
MessageLocalizer $localizer, |
| 1326 |
Language $lang, |
| 1327 |
bool $activeOnly = self::TAG_SET_ACTIVE_ONLY, |
| 1328 |
bool $useAllTags = self::USE_ALL_TAGS |
| 1329 |
) { |
| 1330 |
$changeTagStore = MediaWikiServices::getInstance()->getChangeTagsStore(); |
| 1331 |
|
| 1332 |
if ( $useAllTags ) { |
| 1333 |
$tagKeys = $changeTagStore->listDefinedTags(); |
| 1334 |
$cacheKey = 'tags-list-summary'; |
| 1335 |
} else { |
| 1336 |
$tagKeys = $changeTagStore->getSoftwareTags( true ); |
| 1337 |
$cacheKey = 'core-software-tags-summary'; |
| 1338 |
} |
| 1339 |
|
| 1340 |
|
| 1341 |
$tagHitCounts = null; |
| 1342 |
if ( $activeOnly ) { |
| 1343 |
$tagHitCounts = $changeTagStore->tagUsageStatistics(); |
| 1344 |
} else { |
| 1345 |
|
| 1346 |
$cacheKey .= '-all'; |
| 1347 |
} |
| 1348 |
|
| 1349 |
$cache = MediaWikiServices::getInstance()->getMainWANObjectCache(); |
| 1350 |
return $cache->getWithSetCallback( |
| 1351 |
$cache->makeKey( $cacheKey, $lang->getCode() ), |
| 1352 |
WANObjectCache::TTL_DAY, |
| 1353 |
static function ( $oldValue, &$ttl, array &$setOpts ) use ( $localizer, $tagKeys, $tagHitCounts ) { |
| 1354 |
$result = []; |
| 1355 |
foreach ( $tagKeys as $tagName ) { |
| 1356 |
|
| 1357 |
if ( $tagHitCounts !== null ) { |
| 1358 |
|
| 1359 |
$hits = $tagHitCounts[$tagName] ?? 0; |
| 1360 |
if ( $hits <= 0 ) { |
| 1361 |
continue; |
| 1362 |
} |
| 1363 |
} |
| 1364 |
|
| 1365 |
$labelMsg = self::tagShortDescriptionMessage( $tagName, $localizer ); |
| 1366 |
$helpLink = self::tagHelpLink( $tagName, $localizer ); |
| 1367 |
$descriptionMsg = self::tagLongDescriptionMessage( $tagName, $localizer ); |
| 1368 |
|
| 1369 |
$result[] = [ |
| 1370 |
'name' => $tagName, |
| 1371 |
'labelMsg' => (bool)$labelMsg, |
| 1372 |
'label' => $labelMsg ? $labelMsg->plain() : $tagName, |
| 1373 |
'descriptionMsg' => (bool)$descriptionMsg, |
| 1374 |
'description' => $descriptionMsg ? $descriptionMsg->plain() : '', |
| 1375 |
'helpLink' => $helpLink, |
| 1376 |
'cssClass' => Sanitizer::escapeClass( 'mw-tag-' . $tagName ), |
| 1377 |
]; |
| 1378 |
} |
| 1379 |
return $result; |
| 1380 |
} |
| 1381 |
); |
| 1382 |
} |
| 1383 |
|
| 1384 |
|
| 1385 |
|
| 1386 |
|
| 1387 |
|
| 1388 |
|
| 1389 |
|
| 1390 |
|
| 1391 |
|
| 1392 |
|
| 1393 |
|
| 1394 |
|
| 1395 |
|
| 1396 |
|
| 1397 |
|
| 1398 |
|
| 1399 |
public static function getChangeTagList( |
| 1400 |
MessageLocalizer $localizer, Language $lang, |
| 1401 |
bool $activeOnly = self::TAG_SET_ACTIVE_ONLY, bool $useAllTags = self::USE_ALL_TAGS, |
| 1402 |
$labelsOnly = false |
| 1403 |
) { |
| 1404 |
$tags = self::getChangeTagListSummary( $localizer, $lang, $activeOnly, $useAllTags ); |
| 1405 |
|
| 1406 |
foreach ( $tags as &$tagInfo ) { |
| 1407 |
if ( $tagInfo['labelMsg'] ) { |
| 1408 |
|
| 1409 |
if ( wfEscapeWikiText( $tagInfo['label'] ) !== $tagInfo['label'] ) { |
| 1410 |
|
| 1411 |
$labelMsg = new RawMessage( $tagInfo['label'] ); |
| 1412 |
$tagInfo['label'] = Sanitizer::stripAllTags( $localizer->msg( $labelMsg )->parse() ); |
| 1413 |
} |
| 1414 |
} else { |
| 1415 |
$tagInfo['label'] = $localizer->msg( 'tag-hidden', $tagInfo['name'] )->text(); |
| 1416 |
} |
| 1417 |
|
| 1418 |
if ( $labelsOnly ) { |
| 1419 |
unset( $tagInfo['description'] ); |
| 1420 |
} elseif ( $tagInfo['descriptionMsg'] ) { |
| 1421 |
|
| 1422 |
if ( wfEscapeWikiText( $tagInfo['description'] ) !== $tagInfo['description'] ) { |
| 1423 |
$descriptionMsg = new RawMessage( $tagInfo['description'] ); |
| 1424 |
$tagInfo['description'] = Sanitizer::stripAllTags( $localizer->msg( $descriptionMsg )->parse() ); |
| 1425 |
} |
| 1426 |
$tagInfo['description'] = $lang->truncateForVisual( $tagInfo['description'], |
| 1427 |
self::TAG_DESC_CHARACTER_LIMIT ); |
| 1428 |
} |
| 1429 |
unset( $tagInfo['labelMsg'] ); |
| 1430 |
unset( $tagInfo['descriptionMsg'] ); |
| 1431 |
} |
| 1432 |
|
| 1433 |
|
| 1434 |
usort( $tags, static function ( $a, $b ) { |
| 1435 |
return strcasecmp( $a['label'], $b['label'] ); |
| 1436 |
} ); |
| 1437 |
return $tags; |
| 1438 |
} |
| 1439 |
|
| 1440 |
|
| 1441 |
|
| 1442 |
|
| 1443 |
|
| 1444 |
|
| 1445 |
|
| 1446 |
|
| 1447 |
|
| 1448 |
|
| 1449 |
|
| 1450 |
|
| 1451 |
|
| 1452 |
|
| 1453 |
|
| 1454 |
public static function showTagEditingUI( Authority $performer ) { |
| 1455 |
$changeTagStore = MediaWikiServices::getInstance()->getChangeTagsStore(); |
| 1456 |
return $performer->isAllowed( 'changetags' ) && (bool)$changeTagStore->listExplicitlyDefinedTags(); |
| 1457 |
} |
| 1458 |
} |