| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
use MediaWiki\FileRepo\File\FileSelectQueryBuilder; |
| 22 |
use MediaWiki\MediaWikiServices; |
| 23 |
use MediaWiki\Permissions\Authority; |
| 24 |
use MediaWiki\Revision\RevisionRecord; |
| 25 |
use MediaWiki\Title\Title; |
| 26 |
use MediaWiki\User\UserIdentity; |
| 27 |
use Wikimedia\Rdbms\Blob; |
| 28 |
use Wikimedia\Rdbms\IReadableDatabase; |
| 29 |
use Wikimedia\Rdbms\SelectQueryBuilder; |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
class ArchivedFile { |
| 38 |
|
| 39 |
|
| 40 |
public const FOR_PUBLIC = 1; |
| 41 |
public const FOR_THIS_USER = 2; |
| 42 |
public const RAW = 3; |
| 43 |
|
| 44 |
|
| 45 |
private const MDS_EMPTY = 'empty'; |
| 46 |
|
| 47 |
|
| 48 |
private const MDS_LEGACY = 'legacy'; |
| 49 |
|
| 50 |
|
| 51 |
private const MDS_PHP = 'php'; |
| 52 |
|
| 53 |
|
| 54 |
private const MDS_JSON = 'json'; |
| 55 |
|
| 56 |
|
| 57 |
private $id; |
| 58 |
|
| 59 |
|
| 60 |
private $name; |
| 61 |
|
| 62 |
|
| 63 |
private $group; |
| 64 |
|
| 65 |
|
| 66 |
private $key; |
| 67 |
|
| 68 |
|
| 69 |
private $size; |
| 70 |
|
| 71 |
|
| 72 |
private $bits; |
| 73 |
|
| 74 |
|
| 75 |
private $width; |
| 76 |
|
| 77 |
|
| 78 |
private $height; |
| 79 |
|
| 80 |
|
| 81 |
protected $metadataArray = []; |
| 82 |
|
| 83 |
|
| 84 |
protected $extraDataLoaded = false; |
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
protected $metadataSerializationFormat; |
| 93 |
|
| 94 |
|
| 95 |
protected $metadataBlobs = []; |
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
protected $unloadedMetadataBlobs = []; |
| 104 |
|
| 105 |
|
| 106 |
private $mime; |
| 107 |
|
| 108 |
|
| 109 |
private $media_type; |
| 110 |
|
| 111 |
|
| 112 |
private $description; |
| 113 |
|
| 114 |
|
| 115 |
private $user; |
| 116 |
|
| 117 |
|
| 118 |
private $timestamp; |
| 119 |
|
| 120 |
|
| 121 |
private $dataLoaded; |
| 122 |
|
| 123 |
|
| 124 |
private $deleted; |
| 125 |
|
| 126 |
|
| 127 |
private $sha1; |
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
private $pageCount; |
| 133 |
|
| 134 |
|
| 135 |
private $archive_name; |
| 136 |
|
| 137 |
|
| 138 |
protected $handler; |
| 139 |
|
| 140 |
|
| 141 |
protected $title; |
| 142 |
|
| 143 |
|
| 144 |
protected $exists; |
| 145 |
|
| 146 |
|
| 147 |
private $repo; |
| 148 |
|
| 149 |
|
| 150 |
private $metadataStorageHelper; |
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
public function __construct( $title, $id = 0, $key = '', $sha1 = '' ) { |
| 160 |
$this->id = -1; |
| 161 |
$this->title = null; |
| 162 |
$this->name = false; |
| 163 |
$this->group = 'deleted'; |
| 164 |
$this->key = ''; |
| 165 |
$this->size = 0; |
| 166 |
$this->bits = 0; |
| 167 |
$this->width = 0; |
| 168 |
$this->height = 0; |
| 169 |
$this->mime = "unknown/unknown"; |
| 170 |
$this->media_type = ''; |
| 171 |
$this->description = ''; |
| 172 |
$this->user = null; |
| 173 |
$this->timestamp = null; |
| 174 |
$this->deleted = 0; |
| 175 |
$this->dataLoaded = false; |
| 176 |
$this->exists = false; |
| 177 |
$this->sha1 = ''; |
| 178 |
|
| 179 |
if ( $title instanceof Title ) { |
| 180 |
$this->title = File::normalizeTitle( $title, 'exception' ); |
| 181 |
$this->name = $title->getDBkey(); |
| 182 |
} |
| 183 |
|
| 184 |
if ( $id ) { |
| 185 |
$this->id = $id; |
| 186 |
} |
| 187 |
|
| 188 |
if ( $key ) { |
| 189 |
$this->key = $key; |
| 190 |
} |
| 191 |
|
| 192 |
if ( $sha1 ) { |
| 193 |
$this->sha1 = $sha1; |
| 194 |
} |
| 195 |
|
| 196 |
if ( !$id && !$key && !( $title instanceof Title ) && !$sha1 ) { |
| 197 |
throw new BadMethodCallException( "No specifications provided to ArchivedFile constructor." ); |
| 198 |
} |
| 199 |
|
| 200 |
$this->repo = MediaWikiServices::getInstance()->getRepoGroup()->getLocalRepo(); |
| 201 |
$this->metadataStorageHelper = new MetadataStorageHelper( $this->repo ); |
| 202 |
} |
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
public function load() { |
| 210 |
if ( $this->dataLoaded ) { |
| 211 |
return true; |
| 212 |
} |
| 213 |
$conds = []; |
| 214 |
|
| 215 |
if ( $this->id > 0 ) { |
| 216 |
$conds['fa_id'] = $this->id; |
| 217 |
} |
| 218 |
if ( $this->key ) { |
| 219 |
$conds['fa_storage_group'] = $this->group; |
| 220 |
$conds['fa_storage_key'] = $this->key; |
| 221 |
} |
| 222 |
if ( $this->title ) { |
| 223 |
$conds['fa_name'] = $this->title->getDBkey(); |
| 224 |
} |
| 225 |
if ( $this->sha1 ) { |
| 226 |
$conds['fa_sha1'] = $this->sha1; |
| 227 |
} |
| 228 |
|
| 229 |
if ( $conds === [] ) { |
| 230 |
throw new RuntimeException( "No specific information for retrieving archived file" ); |
| 231 |
} |
| 232 |
|
| 233 |
if ( !$this->title || $this->title->getNamespace() === NS_FILE ) { |
| 234 |
$this->dataLoaded = true; |
| 235 |
$dbr = $this->repo->getReplicaDB(); |
| 236 |
$queryBuilder = FileSelectQueryBuilder::newForArchivedFile( $dbr ); |
| 237 |
$row = $queryBuilder->where( $conds ) |
| 238 |
->orderBy( 'fa_timestamp', SelectQueryBuilder::SORT_DESC ) |
| 239 |
->caller( __METHOD__ )->fetchRow(); |
| 240 |
if ( !$row ) { |
| 241 |
|
| 242 |
return null; |
| 243 |
} |
| 244 |
|
| 245 |
|
| 246 |
$this->loadFromRow( $row ); |
| 247 |
} else { |
| 248 |
throw new UnexpectedValueException( 'This title does not correspond to an image page.' ); |
| 249 |
} |
| 250 |
|
| 251 |
return true; |
| 252 |
} |
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
public static function newFromRow( $row ) { |
| 262 |
$file = new ArchivedFile( Title::makeTitle( NS_FILE, $row->fa_name ) ); |
| 263 |
$file->loadFromRow( $row ); |
| 264 |
|
| 265 |
return $file; |
| 266 |
} |
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
public static function getQueryInfo() { |
| 286 |
$dbr = MediaWikiServices::getInstance()->getConnectionProvider()->getReplicaDatabase(); |
| 287 |
$queryInfo = ( FileSelectQueryBuilder::newForArchivedFile( $dbr ) )->getQueryInfo(); |
| 288 |
return [ |
| 289 |
'tables' => $queryInfo['tables'], |
| 290 |
'fields' => $queryInfo['fields'], |
| 291 |
'joins' => $queryInfo['join_conds'], |
| 292 |
]; |
| 293 |
} |
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
public function loadFromRow( $row ) { |
| 303 |
$this->id = intval( $row->fa_id ); |
| 304 |
$this->name = $row->fa_name; |
| 305 |
$this->archive_name = $row->fa_archive_name; |
| 306 |
$this->group = $row->fa_storage_group; |
| 307 |
$this->key = $row->fa_storage_key; |
| 308 |
$this->size = $row->fa_size; |
| 309 |
$this->bits = $row->fa_bits; |
| 310 |
$this->width = $row->fa_width; |
| 311 |
$this->height = $row->fa_height; |
| 312 |
$this->loadMetadataFromDbFieldValue( |
| 313 |
$this->repo->getReplicaDB(), $row->fa_metadata ); |
| 314 |
$this->mime = "$row->fa_major_mime/$row->fa_minor_mime"; |
| 315 |
$this->media_type = $row->fa_media_type; |
| 316 |
$services = MediaWikiServices::getInstance(); |
| 317 |
$this->description = $services->getCommentStore() |
| 318 |
|
| 319 |
->getCommentLegacy( $this->repo->getReplicaDB(), 'fa_description', $row )->text; |
| 320 |
$this->user = $services->getUserFactory() |
| 321 |
->newFromAnyId( $row->fa_user, $row->fa_user_text, $row->fa_actor ); |
| 322 |
$this->timestamp = $row->fa_timestamp; |
| 323 |
$this->deleted = $row->fa_deleted; |
| 324 |
if ( isset( $row->fa_sha1 ) ) { |
| 325 |
$this->sha1 = $row->fa_sha1; |
| 326 |
} else { |
| 327 |
|
| 328 |
$this->sha1 = LocalRepo::getHashFromKey( $this->key ); |
| 329 |
} |
| 330 |
if ( !$this->title ) { |
| 331 |
$this->title = Title::makeTitleSafe( NS_FILE, $row->fa_name ); |
| 332 |
} |
| 333 |
$this->exists = $row->fa_archive_name !== ''; |
| 334 |
} |
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
public function getTitle() { |
| 342 |
if ( !$this->title ) { |
| 343 |
$this->load(); |
| 344 |
} |
| 345 |
return $this->title; |
| 346 |
} |
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
|
| 353 |
public function getName() { |
| 354 |
if ( $this->name === false ) { |
| 355 |
$this->load(); |
| 356 |
} |
| 357 |
|
| 358 |
return $this->name; |
| 359 |
} |
| 360 |
|
| 361 |
|
| 362 |
|
| 363 |
|
| 364 |
public function getID() { |
| 365 |
$this->load(); |
| 366 |
|
| 367 |
return $this->id; |
| 368 |
} |
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
public function exists() { |
| 374 |
$this->load(); |
| 375 |
|
| 376 |
return $this->exists; |
| 377 |
} |
| 378 |
|
| 379 |
|
| 380 |
|
| 381 |
|
| 382 |
|
| 383 |
public function getKey() { |
| 384 |
$this->load(); |
| 385 |
|
| 386 |
return $this->key; |
| 387 |
} |
| 388 |
|
| 389 |
|
| 390 |
|
| 391 |
|
| 392 |
|
| 393 |
public function getStorageKey() { |
| 394 |
return $this->getKey(); |
| 395 |
} |
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
|
| 401 |
public function getGroup() { |
| 402 |
return $this->group; |
| 403 |
} |
| 404 |
|
| 405 |
|
| 406 |
|
| 407 |
|
| 408 |
|
| 409 |
public function getWidth() { |
| 410 |
$this->load(); |
| 411 |
|
| 412 |
return $this->width; |
| 413 |
} |
| 414 |
|
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
|
| 419 |
public function getHeight() { |
| 420 |
$this->load(); |
| 421 |
|
| 422 |
return $this->height; |
| 423 |
} |
| 424 |
|
| 425 |
|
| 426 |
|
| 427 |
|
| 428 |
|
| 429 |
|
| 430 |
|
| 431 |
public function getMetadata() { |
| 432 |
$data = $this->getMetadataArray(); |
| 433 |
if ( !$data ) { |
| 434 |
return ''; |
| 435 |
} elseif ( array_keys( $data ) === [ '_error' ] ) { |
| 436 |
|
| 437 |
return $data['_error']; |
| 438 |
} else { |
| 439 |
return serialize( $this->getMetadataArray() ); |
| 440 |
} |
| 441 |
} |
| 442 |
|
| 443 |
|
| 444 |
|
| 445 |
|
| 446 |
|
| 447 |
|
| 448 |
|
| 449 |
public function getMetadataArray(): array { |
| 450 |
$this->load(); |
| 451 |
if ( $this->unloadedMetadataBlobs ) { |
| 452 |
return $this->getMetadataItems( |
| 453 |
array_unique( array_merge( |
| 454 |
array_keys( $this->metadataArray ), |
| 455 |
array_keys( $this->unloadedMetadataBlobs ) |
| 456 |
) ) |
| 457 |
); |
| 458 |
} |
| 459 |
return $this->metadataArray; |
| 460 |
} |
| 461 |
|
| 462 |
public function getMetadataItems( array $itemNames ): array { |
| 463 |
$this->load(); |
| 464 |
$result = []; |
| 465 |
$addresses = []; |
| 466 |
foreach ( $itemNames as $itemName ) { |
| 467 |
if ( array_key_exists( $itemName, $this->metadataArray ) ) { |
| 468 |
$result[$itemName] = $this->metadataArray[$itemName]; |
| 469 |
} elseif ( isset( $this->unloadedMetadataBlobs[$itemName] ) ) { |
| 470 |
$addresses[$itemName] = $this->unloadedMetadataBlobs[$itemName]; |
| 471 |
} |
| 472 |
} |
| 473 |
|
| 474 |
if ( $addresses ) { |
| 475 |
$resultFromBlob = $this->metadataStorageHelper->getMetadataFromBlobStore( $addresses ); |
| 476 |
foreach ( $addresses as $itemName => $address ) { |
| 477 |
unset( $this->unloadedMetadataBlobs[$itemName] ); |
| 478 |
$value = $resultFromBlob[$itemName] ?? null; |
| 479 |
if ( $value !== null ) { |
| 480 |
$result[$itemName] = $value; |
| 481 |
$this->metadataArray[$itemName] = $value; |
| 482 |
} |
| 483 |
} |
| 484 |
} |
| 485 |
return $result; |
| 486 |
} |
| 487 |
|
| 488 |
|
| 489 |
|
| 490 |
|
| 491 |
|
| 492 |
|
| 493 |
|
| 494 |
|
| 495 |
|
| 496 |
|
| 497 |
|
| 498 |
|
| 499 |
public function getMetadataForDb( IReadableDatabase $db ) { |
| 500 |
$this->load(); |
| 501 |
if ( !$this->metadataArray && !$this->metadataBlobs ) { |
| 502 |
$s = ''; |
| 503 |
} elseif ( $this->repo->isJsonMetadataEnabled() ) { |
| 504 |
$s = $this->getJsonMetadata(); |
| 505 |
} else { |
| 506 |
$s = serialize( $this->getMetadataArray() ); |
| 507 |
} |
| 508 |
if ( !is_string( $s ) ) { |
| 509 |
throw new RuntimeException( 'Could not serialize image metadata value for DB' ); |
| 510 |
} |
| 511 |
return $db->encodeBlob( $s ); |
| 512 |
} |
| 513 |
|
| 514 |
|
| 515 |
|
| 516 |
|
| 517 |
|
| 518 |
|
| 519 |
|
| 520 |
private function getJsonMetadata() { |
| 521 |
|
| 522 |
$envelope = [ |
| 523 |
'data' => array_diff_key( $this->metadataArray, $this->metadataBlobs ) |
| 524 |
]; |
| 525 |
|
| 526 |
|
| 527 |
if ( $this->metadataBlobs ) { |
| 528 |
$envelope['blobs'] = $this->metadataBlobs; |
| 529 |
} |
| 530 |
|
| 531 |
[ $s, $blobAddresses ] = $this->metadataStorageHelper->getJsonMetadata( $this, $envelope ); |
| 532 |
|
| 533 |
|
| 534 |
$this->metadataBlobs += $blobAddresses; |
| 535 |
|
| 536 |
return $s; |
| 537 |
} |
| 538 |
|
| 539 |
|
| 540 |
|
| 541 |
|
| 542 |
|
| 543 |
|
| 544 |
|
| 545 |
|
| 546 |
|
| 547 |
protected function loadMetadataFromDbFieldValue( IReadableDatabase $db, $metadataBlob ) { |
| 548 |
$this->loadMetadataFromString( $db->decodeBlob( $metadataBlob ) ); |
| 549 |
} |
| 550 |
|
| 551 |
|
| 552 |
|
| 553 |
|
| 554 |
|
| 555 |
|
| 556 |
|
| 557 |
|
| 558 |
protected function loadMetadataFromString( $metadataString ) { |
| 559 |
$this->extraDataLoaded = true; |
| 560 |
$this->metadataArray = []; |
| 561 |
$this->metadataBlobs = []; |
| 562 |
$this->unloadedMetadataBlobs = []; |
| 563 |
$metadataString = (string)$metadataString; |
| 564 |
if ( $metadataString === '' ) { |
| 565 |
$this->metadataSerializationFormat = self::MDS_EMPTY; |
| 566 |
return; |
| 567 |
} |
| 568 |
if ( $metadataString[0] === '{' ) { |
| 569 |
$envelope = $this->metadataStorageHelper->jsonDecode( $metadataString ); |
| 570 |
if ( !$envelope ) { |
| 571 |
|
| 572 |
$this->metadataArray = [ '_error' => $metadataString ]; |
| 573 |
$this->metadataSerializationFormat = self::MDS_LEGACY; |
| 574 |
} else { |
| 575 |
$this->metadataSerializationFormat = self::MDS_JSON; |
| 576 |
if ( isset( $envelope['data'] ) ) { |
| 577 |
$this->metadataArray = $envelope['data']; |
| 578 |
} |
| 579 |
if ( isset( $envelope['blobs'] ) ) { |
| 580 |
$this->metadataBlobs = $this->unloadedMetadataBlobs = $envelope['blobs']; |
| 581 |
} |
| 582 |
} |
| 583 |
} else { |
| 584 |
|
| 585 |
$data = @unserialize( $metadataString ); |
| 586 |
if ( !is_array( $data ) ) { |
| 587 |
|
| 588 |
$data = [ '_error' => $metadataString ]; |
| 589 |
$this->metadataSerializationFormat = self::MDS_LEGACY; |
| 590 |
} else { |
| 591 |
$this->metadataSerializationFormat = self::MDS_PHP; |
| 592 |
} |
| 593 |
$this->metadataArray = $data; |
| 594 |
} |
| 595 |
} |
| 596 |
|
| 597 |
|
| 598 |
|
| 599 |
|
| 600 |
|
| 601 |
public function getSize() { |
| 602 |
$this->load(); |
| 603 |
|
| 604 |
return $this->size; |
| 605 |
} |
| 606 |
|
| 607 |
|
| 608 |
|
| 609 |
|
| 610 |
|
| 611 |
public function getBits() { |
| 612 |
$this->load(); |
| 613 |
|
| 614 |
return $this->bits; |
| 615 |
} |
| 616 |
|
| 617 |
|
| 618 |
|
| 619 |
|
| 620 |
|
| 621 |
public function getMimeType() { |
| 622 |
$this->load(); |
| 623 |
|
| 624 |
return $this->mime; |
| 625 |
} |
| 626 |
|
| 627 |
|
| 628 |
|
| 629 |
|
| 630 |
|
| 631 |
private function getHandler() { |
| 632 |
if ( !isset( $this->handler ) ) { |
| 633 |
$this->handler = MediaHandler::getHandler( $this->getMimeType() ); |
| 634 |
} |
| 635 |
|
| 636 |
return $this->handler; |
| 637 |
} |
| 638 |
|
| 639 |
|
| 640 |
|
| 641 |
|
| 642 |
|
| 643 |
|
| 644 |
|
| 645 |
public function pageCount() { |
| 646 |
if ( !isset( $this->pageCount ) ) { |
| 647 |
|
| 648 |
|
| 649 |
if ( $this->getHandler() && $this->handler->isMultiPage( $this ) ) { |
| 650 |
|
| 651 |
$this->pageCount = $this->handler->pageCount( $this ); |
| 652 |
} else { |
| 653 |
$this->pageCount = false; |
| 654 |
} |
| 655 |
} |
| 656 |
|
| 657 |
return $this->pageCount; |
| 658 |
} |
| 659 |
|
| 660 |
|
| 661 |
|
| 662 |
|
| 663 |
|
| 664 |
|
| 665 |
public function getMediaType() { |
| 666 |
$this->load(); |
| 667 |
|
| 668 |
return $this->media_type; |
| 669 |
} |
| 670 |
|
| 671 |
|
| 672 |
|
| 673 |
|
| 674 |
|
| 675 |
|
| 676 |
public function getTimestamp() { |
| 677 |
$this->load(); |
| 678 |
|
| 679 |
return wfTimestamp( TS_MW, $this->timestamp ); |
| 680 |
} |
| 681 |
|
| 682 |
|
| 683 |
|
| 684 |
|
| 685 |
|
| 686 |
|
| 687 |
|
| 688 |
public function getSha1() { |
| 689 |
$this->load(); |
| 690 |
|
| 691 |
return $this->sha1; |
| 692 |
} |
| 693 |
|
| 694 |
|
| 695 |
|
| 696 |
|
| 697 |
|
| 698 |
|
| 699 |
|
| 700 |
|
| 701 |
|
| 702 |
|
| 703 |
|
| 704 |
|
| 705 |
public function getUploader( int $audience = self::FOR_PUBLIC, ?Authority $performer = null ): ?UserIdentity { |
| 706 |
$this->load(); |
| 707 |
if ( $audience === self::FOR_PUBLIC && $this->isDeleted( File::DELETED_USER ) ) { |
| 708 |
return null; |
| 709 |
} elseif ( $audience === self::FOR_THIS_USER && !$this->userCan( File::DELETED_USER, $performer ) ) { |
| 710 |
return null; |
| 711 |
} else { |
| 712 |
return $this->user; |
| 713 |
} |
| 714 |
} |
| 715 |
|
| 716 |
|
| 717 |
|
| 718 |
|
| 719 |
|
| 720 |
|
| 721 |
|
| 722 |
|
| 723 |
|
| 724 |
|
| 725 |
|
| 726 |
|
| 727 |
|
| 728 |
public function getDescription( int $audience = self::FOR_PUBLIC, ?Authority $performer = null ): string { |
| 729 |
$this->load(); |
| 730 |
if ( $audience === self::FOR_PUBLIC && $this->isDeleted( File::DELETED_COMMENT ) ) { |
| 731 |
return ''; |
| 732 |
} elseif ( $audience === self::FOR_THIS_USER && !$this->userCan( File::DELETED_COMMENT, $performer ) ) { |
| 733 |
return ''; |
| 734 |
} else { |
| 735 |
return $this->description; |
| 736 |
} |
| 737 |
} |
| 738 |
|
| 739 |
|
| 740 |
|
| 741 |
|
| 742 |
|
| 743 |
public function getVisibility() { |
| 744 |
$this->load(); |
| 745 |
|
| 746 |
return $this->deleted; |
| 747 |
} |
| 748 |
|
| 749 |
|
| 750 |
|
| 751 |
|
| 752 |
|
| 753 |
|
| 754 |
|
| 755 |
public function isDeleted( $field ) { |
| 756 |
$this->load(); |
| 757 |
|
| 758 |
return ( $this->deleted & $field ) == $field; |
| 759 |
} |
| 760 |
|
| 761 |
|
| 762 |
|
| 763 |
|
| 764 |
|
| 765 |
|
| 766 |
|
| 767 |
|
| 768 |
public function userCan( $field, Authority $performer ) { |
| 769 |
$this->load(); |
| 770 |
$title = $this->getTitle(); |
| 771 |
|
| 772 |
return RevisionRecord::userCanBitfield( |
| 773 |
$this->deleted, |
| 774 |
$field, |
| 775 |
$performer, |
| 776 |
$title ?: null |
| 777 |
); |
| 778 |
} |
| 779 |
} |