| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
use MediaWiki\Config\ConfigException; |
| 10 |
use MediaWiki\Context\IContextSource; |
| 11 |
use MediaWiki\HookContainer\ProtectedHookAccessorTrait; |
| 12 |
use MediaWiki\Language\Language; |
| 13 |
use MediaWiki\Linker\LinkTarget; |
| 14 |
use MediaWiki\Logger\LoggerFactory; |
| 15 |
use MediaWiki\MainConfigNames; |
| 16 |
use MediaWiki\MediaWikiServices; |
| 17 |
use MediaWiki\Page\PageIdentity; |
| 18 |
use MediaWiki\Permissions\Authority; |
| 19 |
use MediaWiki\PoolCounter\PoolCounterWorkViaCallback; |
| 20 |
use MediaWiki\Status\Status; |
| 21 |
use MediaWiki\Title\Title; |
| 22 |
use MediaWiki\User\UserIdentity; |
| 23 |
use Shellbox\Command\BoxedCommand; |
| 24 |
use Wikimedia\FileBackend\FileBackend; |
| 25 |
use Wikimedia\FileBackend\FSFile\FSFile; |
| 26 |
use Wikimedia\FileBackend\FSFile\TempFSFile; |
| 27 |
use Wikimedia\ObjectCache\WANObjectCache; |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
abstract class File implements MediaHandlerState { |
| 80 |
use ProtectedHookAccessorTrait; |
| 81 |
|
| 82 |
|
| 83 |
public const DELETED_FILE = 1; |
| 84 |
public const DELETED_COMMENT = 2; |
| 85 |
public const DELETED_USER = 4; |
| 86 |
public const DELETED_RESTRICTED = 8; |
| 87 |
|
| 88 |
|
| 89 |
public const RENDER_NOW = 1; |
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
public const RENDER_FORCE = 2; |
| 95 |
|
| 96 |
public const DELETE_SOURCE = 1; |
| 97 |
|
| 98 |
|
| 99 |
public const FOR_PUBLIC = 1; |
| 100 |
public const FOR_THIS_USER = 2; |
| 101 |
public const RAW = 3; |
| 102 |
|
| 103 |
|
| 104 |
public const THUMB_FULL_NAME = 1; |
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
public $repo; |
| 127 |
|
| 128 |
|
| 129 |
protected $title; |
| 130 |
|
| 131 |
|
| 132 |
protected $lastError; |
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
protected $redirected; |
| 139 |
|
| 140 |
|
| 141 |
protected $redirectedTitle; |
| 142 |
|
| 143 |
|
| 144 |
protected $fsFile; |
| 145 |
|
| 146 |
|
| 147 |
protected $handler; |
| 148 |
|
| 149 |
|
| 150 |
protected $url; |
| 151 |
|
| 152 |
|
| 153 |
protected $extension; |
| 154 |
|
| 155 |
|
| 156 |
protected $name; |
| 157 |
|
| 158 |
|
| 159 |
protected $path; |
| 160 |
|
| 161 |
|
| 162 |
protected $hashPath; |
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
protected $pageCount; |
| 168 |
|
| 169 |
|
| 170 |
protected $transformScript; |
| 171 |
|
| 172 |
|
| 173 |
protected $redirectTitle; |
| 174 |
|
| 175 |
|
| 176 |
protected $canRender; |
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
protected $isSafeFile; |
| 182 |
|
| 183 |
|
| 184 |
protected $repoClass = FileRepo::class; |
| 185 |
|
| 186 |
|
| 187 |
protected $tmpBucketedThumbCache = []; |
| 188 |
|
| 189 |
|
| 190 |
private $handlerState = []; |
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
public function __construct( $title, $repo ) { |
| 204 |
|
| 205 |
if ( $title !== false ) { |
| 206 |
$title = self::normalizeTitle( $title, 'exception' ); |
| 207 |
} |
| 208 |
$this->title = $title; |
| 209 |
$this->repo = $repo; |
| 210 |
} |
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
public static function normalizeTitle( $title, $exception = false ) { |
| 221 |
$ret = $title; |
| 222 |
|
| 223 |
if ( !$ret instanceof Title ) { |
| 224 |
if ( $ret instanceof PageIdentity ) { |
| 225 |
$ret = Title::castFromPageIdentity( $ret ); |
| 226 |
} elseif ( $ret instanceof LinkTarget ) { |
| 227 |
$ret = Title::castFromLinkTarget( $ret ); |
| 228 |
} |
| 229 |
} |
| 230 |
|
| 231 |
if ( $ret instanceof Title ) { |
| 232 |
|
| 233 |
if ( $ret->getNamespace() === NS_MEDIA ) { |
| 234 |
$ret = Title::makeTitleSafe( NS_FILE, $ret->getDBkey() ); |
| 235 |
|
| 236 |
} elseif ( $ret->getNamespace() !== NS_FILE ) { |
| 237 |
$ret = null; |
| 238 |
} |
| 239 |
} else { |
| 240 |
|
| 241 |
$ret = Title::makeTitleSafe( NS_FILE, (string)$ret ); |
| 242 |
} |
| 243 |
if ( !$ret && $exception !== false ) { |
| 244 |
throw new RuntimeException( "`$title` is not a valid file title." ); |
| 245 |
} |
| 246 |
|
| 247 |
return $ret; |
| 248 |
} |
| 249 |
|
| 250 |
public function __get( $name ) { |
| 251 |
$function = [ $this, 'get' . ucfirst( $name ) ]; |
| 252 |
if ( !is_callable( $function ) ) { |
| 253 |
return null; |
| 254 |
} else { |
| 255 |
$this->$name = $function(); |
| 256 |
|
| 257 |
return $this->$name; |
| 258 |
} |
| 259 |
} |
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
public static function normalizeExtension( $extension ) { |
| 270 |
$lower = strtolower( $extension ); |
| 271 |
$squish = [ |
| 272 |
'htm' => 'html', |
| 273 |
'jpeg' => 'jpg', |
| 274 |
'mpeg' => 'mpg', |
| 275 |
'tiff' => 'tif', |
| 276 |
'ogv' => 'ogg' ]; |
| 277 |
if ( isset( $squish[$lower] ) ) { |
| 278 |
return $squish[$lower]; |
| 279 |
} elseif ( preg_match( '/^[0-9a-z]+$/', $lower ) ) { |
| 280 |
return $lower; |
| 281 |
} else { |
| 282 |
return ''; |
| 283 |
} |
| 284 |
} |
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
public static function checkExtensionCompatibility( File $old, $new ) { |
| 295 |
$oldMime = $old->getMimeType(); |
| 296 |
$n = strrpos( $new, '.' ); |
| 297 |
$newExt = self::normalizeExtension( $n ? substr( $new, $n + 1 ) : '' ); |
| 298 |
$mimeMagic = MediaWikiServices::getInstance()->getMimeAnalyzer(); |
| 299 |
|
| 300 |
return $mimeMagic->isMatchingExtension( $newExt, $oldMime ); |
| 301 |
} |
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
public function upgradeRow() { |
| 311 |
} |
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
public static function splitMime( ?string $mime ) { |
| 321 |
if ( $mime === null ) { |
| 322 |
return [ 'unknown', 'unknown' ]; |
| 323 |
} elseif ( str_contains( $mime, '/' ) ) { |
| 324 |
return explode( '/', $mime, 2 ); |
| 325 |
} else { |
| 326 |
return [ $mime, 'unknown' ]; |
| 327 |
} |
| 328 |
} |
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
public static function compare( File $a, File $b ) { |
| 338 |
return strcmp( $a->getName(), $b->getName() ); |
| 339 |
} |
| 340 |
|
| 341 |
|
| 342 |
|
| 343 |
|
| 344 |
|
| 345 |
|
| 346 |
|
| 347 |
public function getName() { |
| 348 |
if ( $this->name === null ) { |
| 349 |
$this->assertRepoDefined(); |
| 350 |
$this->name = $this->repo->getNameFromTitle( $this->title ); |
| 351 |
} |
| 352 |
|
| 353 |
return $this->name; |
| 354 |
} |
| 355 |
|
| 356 |
|
| 357 |
|
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
|
| 362 |
public function getExtension() { |
| 363 |
if ( !isset( $this->extension ) ) { |
| 364 |
$n = strrpos( $this->getName(), '.' ); |
| 365 |
$this->extension = self::normalizeExtension( |
| 366 |
$n ? substr( $this->getName(), $n + 1 ) : '' ); |
| 367 |
} |
| 368 |
|
| 369 |
return $this->extension; |
| 370 |
} |
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
public function getTitle() { |
| 378 |
return $this->title; |
| 379 |
} |
| 380 |
|
| 381 |
|
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
public function getOriginalTitle() { |
| 387 |
if ( $this->redirected !== null ) { |
| 388 |
return $this->getRedirectedTitle(); |
| 389 |
} |
| 390 |
|
| 391 |
return $this->title; |
| 392 |
} |
| 393 |
|
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
public function getUrl() { |
| 401 |
if ( !isset( $this->url ) ) { |
| 402 |
$this->assertRepoDefined(); |
| 403 |
$ext = $this->getExtension(); |
| 404 |
$this->url = $this->repo->getZoneUrl( 'public', $ext ) . '/' . $this->getUrlRel(); |
| 405 |
} |
| 406 |
|
| 407 |
return $this->url; |
| 408 |
} |
| 409 |
|
| 410 |
|
| 411 |
|
| 412 |
|
| 413 |
|
| 414 |
|
| 415 |
|
| 416 |
|
| 417 |
public function getDescriptionShortUrl() { |
| 418 |
return null; |
| 419 |
} |
| 420 |
|
| 421 |
|
| 422 |
|
| 423 |
|
| 424 |
|
| 425 |
|
| 426 |
|
| 427 |
|
| 428 |
|
| 429 |
public function getFullUrl() { |
| 430 |
return (string)MediaWikiServices::getInstance()->getUrlUtils() |
| 431 |
->expand( $this->getUrl(), PROTO_RELATIVE ); |
| 432 |
} |
| 433 |
|
| 434 |
|
| 435 |
|
| 436 |
|
| 437 |
|
| 438 |
public function getCanonicalUrl() { |
| 439 |
return (string)MediaWikiServices::getInstance()->getUrlUtils() |
| 440 |
->expand( $this->getUrl(), PROTO_CANONICAL ); |
| 441 |
} |
| 442 |
|
| 443 |
|
| 444 |
|
| 445 |
|
| 446 |
public function getViewURL() { |
| 447 |
if ( $this->mustRender() ) { |
| 448 |
if ( $this->canRender() ) { |
| 449 |
return $this->createThumb( $this->getWidth() ); |
| 450 |
} else { |
| 451 |
wfDebug( __METHOD__ . ': supposed to render ' . $this->getName() . |
| 452 |
' (' . $this->getMimeType() . "), but can't!" ); |
| 453 |
|
| 454 |
return $this->getUrl(); |
| 455 |
} |
| 456 |
} else { |
| 457 |
return $this->getUrl(); |
| 458 |
} |
| 459 |
} |
| 460 |
|
| 461 |
|
| 462 |
|
| 463 |
|
| 464 |
|
| 465 |
|
| 466 |
|
| 467 |
|
| 468 |
|
| 469 |
|
| 470 |
|
| 471 |
|
| 472 |
|
| 473 |
|
| 474 |
|
| 475 |
public function getPath() { |
| 476 |
if ( !isset( $this->path ) ) { |
| 477 |
$this->assertRepoDefined(); |
| 478 |
$this->path = $this->repo->getZonePath( 'public' ) . '/' . $this->getRel(); |
| 479 |
} |
| 480 |
|
| 481 |
return $this->path; |
| 482 |
} |
| 483 |
|
| 484 |
|
| 485 |
|
| 486 |
|
| 487 |
|
| 488 |
|
| 489 |
|
| 490 |
|
| 491 |
public function getLocalRefPath() { |
| 492 |
$this->assertRepoDefined(); |
| 493 |
if ( !isset( $this->fsFile ) ) { |
| 494 |
$timer = MediaWikiServices::getInstance()->getStatsFactory() |
| 495 |
->getTiming( 'media_thumbnail_generate_fetchoriginal_seconds' ) |
| 496 |
->copyToStatsdAt( 'media.thumbnail.generate.fetchoriginal' ); |
| 497 |
$timer->start(); |
| 498 |
|
| 499 |
$this->fsFile = $this->repo->getLocalReference( $this->getPath() ); |
| 500 |
|
| 501 |
$timer->stop(); |
| 502 |
|
| 503 |
if ( !$this->fsFile ) { |
| 504 |
$this->fsFile = false; |
| 505 |
} |
| 506 |
} |
| 507 |
|
| 508 |
return ( $this->fsFile ) |
| 509 |
? $this->fsFile->getPath() |
| 510 |
: false; |
| 511 |
} |
| 512 |
|
| 513 |
|
| 514 |
|
| 515 |
|
| 516 |
|
| 517 |
|
| 518 |
|
| 519 |
|
| 520 |
|
| 521 |
public function addToShellboxCommand( BoxedCommand $command, string $boxedName ) { |
| 522 |
return $this->repo->addShellboxInputFile( $command, $boxedName, $this->getVirtualUrl() ); |
| 523 |
} |
| 524 |
|
| 525 |
|
| 526 |
|
| 527 |
|
| 528 |
|
| 529 |
|
| 530 |
|
| 531 |
|
| 532 |
|
| 533 |
|
| 534 |
|
| 535 |
|
| 536 |
public function getWidth( $page = 1 ) { |
| 537 |
return false; |
| 538 |
} |
| 539 |
|
| 540 |
|
| 541 |
|
| 542 |
|
| 543 |
|
| 544 |
|
| 545 |
|
| 546 |
|
| 547 |
|
| 548 |
|
| 549 |
|
| 550 |
|
| 551 |
public function getHeight( $page = 1 ) { |
| 552 |
return false; |
| 553 |
} |
| 554 |
|
| 555 |
|
| 556 |
|
| 557 |
|
| 558 |
|
| 559 |
|
| 560 |
|
| 561 |
|
| 562 |
|
| 563 |
|
| 564 |
public function getThumbnailBucket( $desiredWidth, $page = 1 ) { |
| 565 |
$thumbnailBuckets = MediaWikiServices::getInstance() |
| 566 |
->getMainConfig()->get( MainConfigNames::ThumbnailBuckets ); |
| 567 |
$thumbnailMinimumBucketDistance = MediaWikiServices::getInstance() |
| 568 |
->getMainConfig()->get( MainConfigNames::ThumbnailMinimumBucketDistance ); |
| 569 |
$imageWidth = $this->getWidth( $page ); |
| 570 |
|
| 571 |
if ( $imageWidth === false ) { |
| 572 |
return false; |
| 573 |
} |
| 574 |
|
| 575 |
if ( $desiredWidth > $imageWidth ) { |
| 576 |
return false; |
| 577 |
} |
| 578 |
|
| 579 |
if ( !$thumbnailBuckets ) { |
| 580 |
return false; |
| 581 |
} |
| 582 |
|
| 583 |
$sortedBuckets = $thumbnailBuckets; |
| 584 |
|
| 585 |
sort( $sortedBuckets ); |
| 586 |
|
| 587 |
foreach ( $sortedBuckets as $bucket ) { |
| 588 |
if ( $bucket >= $imageWidth ) { |
| 589 |
return false; |
| 590 |
} |
| 591 |
|
| 592 |
if ( $bucket - $thumbnailMinimumBucketDistance > $desiredWidth ) { |
| 593 |
return $bucket; |
| 594 |
} |
| 595 |
} |
| 596 |
|
| 597 |
|
| 598 |
return false; |
| 599 |
} |
| 600 |
|
| 601 |
|
| 602 |
|
| 603 |
|
| 604 |
|
| 605 |
|
| 606 |
|
| 607 |
|
| 608 |
|
| 609 |
|
| 610 |
public function getDisplayWidthHeight( $maxWidth, $maxHeight, $page = 1 ) { |
| 611 |
if ( !$maxWidth || !$maxHeight ) { |
| 612 |
|
| 613 |
throw new ConfigException( 'Using a choice from $wgImageLimits that is 0x0' ); |
| 614 |
} |
| 615 |
|
| 616 |
$width = $this->getWidth( $page ); |
| 617 |
$height = $this->getHeight( $page ); |
| 618 |
if ( !$width || !$height ) { |
| 619 |
return [ 0, 0 ]; |
| 620 |
} |
| 621 |
|
| 622 |
|
| 623 |
if ( $width <= $maxWidth && $height <= $maxHeight ) { |
| 624 |
|
| 625 |
} elseif ( $width / $height >= $maxWidth / $maxHeight ) { |
| 626 |
|
| 627 |
$height = round( $height * $maxWidth / $width ); |
| 628 |
$width = $maxWidth; |
| 629 |
|
| 630 |
} else { |
| 631 |
$newwidth = floor( $width * $maxHeight / $height ); |
| 632 |
$height = round( $height * $newwidth / $width ); |
| 633 |
$width = $newwidth; |
| 634 |
|
| 635 |
|
| 636 |
} |
| 637 |
return [ $width, $height ]; |
| 638 |
} |
| 639 |
|
| 640 |
|
| 641 |
|
| 642 |
|
| 643 |
|
| 644 |
|
| 645 |
|
| 646 |
public function getLength() { |
| 647 |
$handler = $this->getHandler(); |
| 648 |
if ( $handler ) { |
| 649 |
return $handler->getLength( $this ); |
| 650 |
} else { |
| 651 |
return 0; |
| 652 |
} |
| 653 |
} |
| 654 |
|
| 655 |
|
| 656 |
|
| 657 |
|
| 658 |
|
| 659 |
|
| 660 |
public function isVectorized() { |
| 661 |
$handler = $this->getHandler(); |
| 662 |
if ( $handler ) { |
| 663 |
return $handler->isVectorized( $this ); |
| 664 |
} else { |
| 665 |
return false; |
| 666 |
} |
| 667 |
} |
| 668 |
|
| 669 |
|
| 670 |
|
| 671 |
|
| 672 |
|
| 673 |
|
| 674 |
|
| 675 |
|
| 676 |
|
| 677 |
|
| 678 |
|
| 679 |
|
| 680 |
public function getAvailableLanguages() { |
| 681 |
$handler = $this->getHandler(); |
| 682 |
if ( $handler ) { |
| 683 |
return $handler->getAvailableLanguages( $this ); |
| 684 |
} else { |
| 685 |
return []; |
| 686 |
} |
| 687 |
} |
| 688 |
|
| 689 |
|
| 690 |
|
| 691 |
|
| 692 |
|
| 693 |
|
| 694 |
|
| 695 |
|
| 696 |
public function getMatchedLanguage( $userPreferredLanguage ) { |
| 697 |
$handler = $this->getHandler(); |
| 698 |
if ( $handler ) { |
| 699 |
return $handler->getMatchedLanguage( |
| 700 |
$userPreferredLanguage, |
| 701 |
$handler->getAvailableLanguages( $this ) |
| 702 |
); |
| 703 |
} |
| 704 |
|
| 705 |
return null; |
| 706 |
} |
| 707 |
|
| 708 |
|
| 709 |
|
| 710 |
|
| 711 |
|
| 712 |
|
| 713 |
|
| 714 |
|
| 715 |
public function getDefaultRenderLanguage() { |
| 716 |
$handler = $this->getHandler(); |
| 717 |
if ( $handler ) { |
| 718 |
return $handler->getDefaultRenderLanguage( $this ); |
| 719 |
} else { |
| 720 |
return null; |
| 721 |
} |
| 722 |
} |
| 723 |
|
| 724 |
|
| 725 |
|
| 726 |
|
| 727 |
|
| 728 |
|
| 729 |
|
| 730 |
|
| 731 |
|
| 732 |
|
| 733 |
|
| 734 |
public function canAnimateThumbIfAppropriate() { |
| 735 |
$handler = $this->getHandler(); |
| 736 |
if ( !$handler ) { |
| 737 |
|
| 738 |
|
| 739 |
|
| 740 |
return true; |
| 741 |
} |
| 742 |
|
| 743 |
return !$this->allowInlineDisplay() |
| 744 |
|
| 745 |
|
| 746 |
|| !$handler->isAnimatedImage( $this ) |
| 747 |
|
| 748 |
|
| 749 |
|| $handler->canAnimateThumbnail( $this ); |
| 750 |
} |
| 751 |
|
| 752 |
|
| 753 |
|
| 754 |
|
| 755 |
|
| 756 |
|
| 757 |
|
| 758 |
|
| 759 |
public function getMetadata() { |
| 760 |
return false; |
| 761 |
} |
| 762 |
|
| 763 |
public function getHandlerState( string $key ) { |
| 764 |
return $this->handlerState[$key] ?? null; |
| 765 |
} |
| 766 |
|
| 767 |
public function setHandlerState( string $key, $value ) { |
| 768 |
$this->handlerState[$key] = $value; |
| 769 |
} |
| 770 |
|
| 771 |
|
| 772 |
|
| 773 |
|
| 774 |
|
| 775 |
|
| 776 |
|
| 777 |
public function getMetadataArray(): array { |
| 778 |
return []; |
| 779 |
} |
| 780 |
|
| 781 |
|
| 782 |
|
| 783 |
|
| 784 |
|
| 785 |
|
| 786 |
|
| 787 |
|
| 788 |
public function getMetadataItem( string $itemName ) { |
| 789 |
$items = $this->getMetadataItems( [ $itemName ] ); |
| 790 |
return $items[$itemName] ?? null; |
| 791 |
} |
| 792 |
|
| 793 |
|
| 794 |
|
| 795 |
|
| 796 |
|
| 797 |
|
| 798 |
|
| 799 |
|
| 800 |
public function getMetadataItems( array $itemNames ): array { |
| 801 |
return array_intersect_key( |
| 802 |
$this->getMetadataArray(), |
| 803 |
array_fill_keys( $itemNames, true ) ); |
| 804 |
} |
| 805 |
|
| 806 |
|
| 807 |
|
| 808 |
|
| 809 |
|
| 810 |
|
| 811 |
|
| 812 |
public function getCommonMetaArray() { |
| 813 |
$handler = $this->getHandler(); |
| 814 |
return $handler ? $handler->getCommonMetaArray( $this ) : false; |
| 815 |
} |
| 816 |
|
| 817 |
|
| 818 |
|
| 819 |
|
| 820 |
|
| 821 |
|
| 822 |
|
| 823 |
|
| 824 |
public function convertMetadataVersion( $metadata, $version ) { |
| 825 |
$handler = $this->getHandler(); |
| 826 |
if ( $handler ) { |
| 827 |
return $handler->convertMetadataVersion( $metadata, $version ); |
| 828 |
} else { |
| 829 |
return $metadata; |
| 830 |
} |
| 831 |
} |
| 832 |
|
| 833 |
|
| 834 |
|
| 835 |
|
| 836 |
|
| 837 |
|
| 838 |
|
| 839 |
|
| 840 |
public function getBitDepth() { |
| 841 |
return 0; |
| 842 |
} |
| 843 |
|
| 844 |
|
| 845 |
|
| 846 |
|
| 847 |
|
| 848 |
|
| 849 |
|
| 850 |
|
| 851 |
public function getSize() { |
| 852 |
return false; |
| 853 |
} |
| 854 |
|
| 855 |
|
| 856 |
|
| 857 |
|
| 858 |
|
| 859 |
|
| 860 |
|
| 861 |
|
| 862 |
|
| 863 |
public function getMimeType() { |
| 864 |
return 'unknown/unknown'; |
| 865 |
} |
| 866 |
|
| 867 |
|
| 868 |
|
| 869 |
|
| 870 |
|
| 871 |
|
| 872 |
|
| 873 |
|
| 874 |
|
| 875 |
public function getMediaType() { |
| 876 |
return MEDIATYPE_UNKNOWN; |
| 877 |
} |
| 878 |
|
| 879 |
|
| 880 |
|
| 881 |
|
| 882 |
|
| 883 |
|
| 884 |
|
| 885 |
|
| 886 |
|
| 887 |
|
| 888 |
|
| 889 |
public function canRender() { |
| 890 |
if ( !isset( $this->canRender ) ) { |
| 891 |
$this->canRender = $this->getHandler() && $this->handler->canRender( $this ) && $this->exists(); |
| 892 |
} |
| 893 |
|
| 894 |
return $this->canRender; |
| 895 |
} |
| 896 |
|
| 897 |
|
| 898 |
|
| 899 |
|
| 900 |
|
| 901 |
protected function getCanRender() { |
| 902 |
return $this->canRender(); |
| 903 |
} |
| 904 |
|
| 905 |
|
| 906 |
|
| 907 |
|
| 908 |
|
| 909 |
|
| 910 |
|
| 911 |
|
| 912 |
|
| 913 |
|
| 914 |
|
| 915 |
|
| 916 |
public function mustRender() { |
| 917 |
return $this->getHandler() && $this->handler->mustRender( $this ); |
| 918 |
} |
| 919 |
|
| 920 |
|
| 921 |
|
| 922 |
|
| 923 |
|
| 924 |
|
| 925 |
public function allowInlineDisplay() { |
| 926 |
return $this->canRender(); |
| 927 |
} |
| 928 |
|
| 929 |
|
| 930 |
|
| 931 |
|
| 932 |
|
| 933 |
|
| 934 |
|
| 935 |
|
| 936 |
|
| 937 |
|
| 938 |
|
| 939 |
|
| 940 |
|
| 941 |
|
| 942 |
public function isSafeFile() { |
| 943 |
if ( !isset( $this->isSafeFile ) ) { |
| 944 |
$this->isSafeFile = $this->getIsSafeFileUncached(); |
| 945 |
} |
| 946 |
|
| 947 |
return $this->isSafeFile; |
| 948 |
} |
| 949 |
|
| 950 |
|
| 951 |
|
| 952 |
|
| 953 |
|
| 954 |
|
| 955 |
protected function getIsSafeFile() { |
| 956 |
return $this->isSafeFile(); |
| 957 |
} |
| 958 |
|
| 959 |
|
| 960 |
|
| 961 |
|
| 962 |
|
| 963 |
|
| 964 |
protected function getIsSafeFileUncached() { |
| 965 |
$trustedMediaFormats = MediaWikiServices::getInstance()->getMainConfig() |
| 966 |
->get( MainConfigNames::TrustedMediaFormats ); |
| 967 |
|
| 968 |
if ( $this->allowInlineDisplay() ) { |
| 969 |
return true; |
| 970 |
} |
| 971 |
if ( $this->isTrustedFile() ) { |
| 972 |
return true; |
| 973 |
} |
| 974 |
|
| 975 |
$type = $this->getMediaType(); |
| 976 |
$mime = $this->getMimeType(); |
| 977 |
|
| 978 |
if ( !$type || $type === MEDIATYPE_UNKNOWN ) { |
| 979 |
return false; |
| 980 |
} |
| 981 |
if ( in_array( $type, $trustedMediaFormats ) ) { |
| 982 |
return true; |
| 983 |
} |
| 984 |
|
| 985 |
if ( $mime === "unknown/unknown" ) { |
| 986 |
return false; |
| 987 |
} |
| 988 |
if ( in_array( $mime, $trustedMediaFormats ) ) { |
| 989 |
return true; |
| 990 |
} |
| 991 |
|
| 992 |
return false; |
| 993 |
} |
| 994 |
|
| 995 |
|
| 996 |
|
| 997 |
|
| 998 |
|
| 999 |
|
| 1000 |
|
| 1001 |
|
| 1002 |
|
| 1003 |
|
| 1004 |
|
| 1005 |
|
| 1006 |
|
| 1007 |
|
| 1008 |
protected function isTrustedFile() { |
| 1009 |
|
| 1010 |
|
| 1011 |
return false; |
| 1012 |
} |
| 1013 |
|
| 1014 |
|
| 1015 |
|
| 1016 |
|
| 1017 |
|
| 1018 |
|
| 1019 |
|
| 1020 |
|
| 1021 |
|
| 1022 |
|
| 1023 |
|
| 1024 |
public function load( $flags = 0 ) { |
| 1025 |
} |
| 1026 |
|
| 1027 |
|
| 1028 |
|
| 1029 |
|
| 1030 |
|
| 1031 |
|
| 1032 |
|
| 1033 |
|
| 1034 |
|
| 1035 |
public function exists() { |
| 1036 |
return $this->getPath() && $this->repo->fileExists( $this->path ); |
| 1037 |
} |
| 1038 |
|
| 1039 |
|
| 1040 |
|
| 1041 |
|
| 1042 |
|
| 1043 |
|
| 1044 |
|
| 1045 |
|
| 1046 |
public function isVisible() { |
| 1047 |
return $this->exists(); |
| 1048 |
} |
| 1049 |
|
| 1050 |
|
| 1051 |
|
| 1052 |
|
| 1053 |
private function getTransformScript() { |
| 1054 |
if ( !isset( $this->transformScript ) ) { |
| 1055 |
$this->transformScript = false; |
| 1056 |
if ( $this->repo ) { |
| 1057 |
$script = $this->repo->getThumbScriptUrl(); |
| 1058 |
if ( $script ) { |
| 1059 |
$this->transformScript = wfAppendQuery( $script, [ 'f' => $this->getName() ] ); |
| 1060 |
} |
| 1061 |
} |
| 1062 |
} |
| 1063 |
|
| 1064 |
return $this->transformScript; |
| 1065 |
} |
| 1066 |
|
| 1067 |
|
| 1068 |
|
| 1069 |
|
| 1070 |
|
| 1071 |
|
| 1072 |
|
| 1073 |
|
| 1074 |
public function getUnscaledThumb( $handlerParams = [] ) { |
| 1075 |
$hp =& $handlerParams; |
| 1076 |
$page = $hp['page'] ?? false; |
| 1077 |
$width = $this->getWidth( $page ); |
| 1078 |
if ( !$width ) { |
| 1079 |
return $this->iconThumb(); |
| 1080 |
} |
| 1081 |
$hp['width'] = $width; |
| 1082 |
|
| 1083 |
unset( $hp['height'] ); |
| 1084 |
|
| 1085 |
return $this->transform( $hp ); |
| 1086 |
} |
| 1087 |
|
| 1088 |
|
| 1089 |
|
| 1090 |
|
| 1091 |
|
| 1092 |
|
| 1093 |
|
| 1094 |
|
| 1095 |
|
| 1096 |
|
| 1097 |
|
| 1098 |
|
| 1099 |
|
| 1100 |
|
| 1101 |
|
| 1102 |
|
| 1103 |
public function thumbName( $params, $flags = 0 ) { |
| 1104 |
$name = ( $this->repo && !( $flags & self::THUMB_FULL_NAME ) ) |
| 1105 |
? $this->repo->nameForThumb( $this->getName() ) |
| 1106 |
: $this->getName(); |
| 1107 |
|
| 1108 |
return $this->generateThumbName( $name, $params ); |
| 1109 |
} |
| 1110 |
|
| 1111 |
|
| 1112 |
|
| 1113 |
|
| 1114 |
|
| 1115 |
|
| 1116 |
|
| 1117 |
|
| 1118 |
|
| 1119 |
public function generateThumbName( $name, $params ) { |
| 1120 |
if ( !$this->getHandler() ) { |
| 1121 |
return null; |
| 1122 |
} |
| 1123 |
$extension = $this->getExtension(); |
| 1124 |
[ $thumbExt, ] = $this->getHandler()->getThumbType( |
| 1125 |
$extension, $this->getMimeType(), $params ); |
| 1126 |
$thumbName = $this->getHandler()->makeParamString( $params ); |
| 1127 |
|
| 1128 |
if ( $this->repo->supportsSha1URLs() ) { |
| 1129 |
$thumbName .= '-' . $this->getSha1() . '.' . $thumbExt; |
| 1130 |
} else { |
| 1131 |
$thumbName .= '-' . $name; |
| 1132 |
|
| 1133 |
if ( $thumbExt != $extension ) { |
| 1134 |
$thumbName .= ".$thumbExt"; |
| 1135 |
} |
| 1136 |
} |
| 1137 |
|
| 1138 |
return $thumbName; |
| 1139 |
} |
| 1140 |
|
| 1141 |
|
| 1142 |
|
| 1143 |
|
| 1144 |
|
| 1145 |
|
| 1146 |
|
| 1147 |
|
| 1148 |
|
| 1149 |
|
| 1150 |
|
| 1151 |
|
| 1152 |
|
| 1153 |
|
| 1154 |
|
| 1155 |
|
| 1156 |
|
| 1157 |
|
| 1158 |
public function createThumb( $width, $height = -1 ) { |
| 1159 |
$params = [ 'width' => $width ]; |
| 1160 |
if ( $height != -1 ) { |
| 1161 |
$params['height'] = $height; |
| 1162 |
} |
| 1163 |
$thumb = $this->transform( $params ); |
| 1164 |
if ( !$thumb || $thumb->isError() ) { |
| 1165 |
return ''; |
| 1166 |
} |
| 1167 |
|
| 1168 |
return $thumb->getUrl(); |
| 1169 |
} |
| 1170 |
|
| 1171 |
|
| 1172 |
|
| 1173 |
|
| 1174 |
|
| 1175 |
|
| 1176 |
|
| 1177 |
|
| 1178 |
|
| 1179 |
|
| 1180 |
protected function transformErrorOutput( $thumbPath, $thumbUrl, $params, $flags ) { |
| 1181 |
$ignoreImageErrors = MediaWikiServices::getInstance()->getMainConfig() |
| 1182 |
->get( MainConfigNames::IgnoreImageErrors ); |
| 1183 |
|
| 1184 |
$handler = $this->getHandler(); |
| 1185 |
if ( $handler && $ignoreImageErrors && !( $flags & self::RENDER_NOW ) ) { |
| 1186 |
return $handler->getTransform( $this, $thumbPath, $thumbUrl, $params ); |
| 1187 |
} else { |
| 1188 |
return new MediaTransformError( 'thumbnail_error', |
| 1189 |
$params['width'], 0, wfMessage( 'thumbnail-dest-create' ) ); |
| 1190 |
} |
| 1191 |
} |
| 1192 |
|
| 1193 |
|
| 1194 |
|
| 1195 |
|
| 1196 |
|
| 1197 |
|
| 1198 |
|
| 1199 |
|
| 1200 |
|
| 1201 |
|
| 1202 |
public function transform( $params, $flags = 0 ) { |
| 1203 |
$thumbnailEpoch = MediaWikiServices::getInstance()->getMainConfig() |
| 1204 |
->get( MainConfigNames::ThumbnailEpoch ); |
| 1205 |
|
| 1206 |
do { |
| 1207 |
if ( !$this->canRender() ) { |
| 1208 |
$thumb = $this->iconThumb(); |
| 1209 |
break; |
| 1210 |
} |
| 1211 |
|
| 1212 |
|
| 1213 |
$descriptionUrl = $this->getDescriptionUrl(); |
| 1214 |
if ( $descriptionUrl ) { |
| 1215 |
$params['descriptionUrl'] = MediaWikiServices::getInstance()->getUrlUtils() |
| 1216 |
->expand( $descriptionUrl, PROTO_CANONICAL ); |
| 1217 |
} |
| 1218 |
|
| 1219 |
$handler = $this->getHandler(); |
| 1220 |
$script = $this->getTransformScript(); |
| 1221 |
if ( $script && !( $flags & self::RENDER_NOW ) ) { |
| 1222 |
|
| 1223 |
$thumb = $handler->getScriptedTransform( $this, $script, $params ); |
| 1224 |
if ( $thumb ) { |
| 1225 |
break; |
| 1226 |
} |
| 1227 |
} |
| 1228 |
|
| 1229 |
$normalisedParams = $params; |
| 1230 |
$handler->normaliseParams( $this, $normalisedParams ); |
| 1231 |
|
| 1232 |
$thumbName = $this->thumbName( $normalisedParams ); |
| 1233 |
$thumbUrl = $this->getThumbUrl( $thumbName ); |
| 1234 |
|
| 1235 |
$thumbPath = $this->getThumbPath( $thumbName ); |
| 1236 |
if ( isset( $normalisedParams['isFilePageThumb'] ) && $normalisedParams['isFilePageThumb'] ) { |
| 1237 |
|
| 1238 |
$thumbUrl = $this->getFilePageThumbUrl( $thumbUrl ); |
| 1239 |
} |
| 1240 |
|
| 1241 |
if ( $this->repo ) { |
| 1242 |
|
| 1243 |
if ( $this->repo->canTransformVia404() && !( $flags & self::RENDER_NOW ) ) { |
| 1244 |
|
| 1245 |
|
| 1246 |
|
| 1247 |
$thumb = $handler->getTransform( $this, $thumbPath, $thumbUrl, $params ); |
| 1248 |
break; |
| 1249 |
} |
| 1250 |
|
| 1251 |
wfDebug( __METHOD__ . ": Doing stat for $thumbPath" ); |
| 1252 |
if ( !( $flags & self::RENDER_FORCE ) && $this->repo->fileExists( $thumbPath ) ) { |
| 1253 |
$timestamp = $this->repo->getFileTimestamp( $thumbPath ); |
| 1254 |
if ( $timestamp !== false && $timestamp >= $thumbnailEpoch ) { |
| 1255 |
|
| 1256 |
|
| 1257 |
|
| 1258 |
$thumb = $handler->getTransform( $this, $thumbPath, $thumbUrl, $params ); |
| 1259 |
$thumb->setStoragePath( $thumbPath ); |
| 1260 |
break; |
| 1261 |
} |
| 1262 |
} elseif ( $flags & self::RENDER_FORCE ) { |
| 1263 |
wfDebug( __METHOD__ . " forcing rendering per flag File::RENDER_FORCE" ); |
| 1264 |
} |
| 1265 |
|
| 1266 |
|
| 1267 |
|
| 1268 |
if ( $this->repo->getReadOnlyReason() !== false ) { |
| 1269 |
$thumb = $this->transformErrorOutput( $thumbPath, $thumbUrl, $params, $flags ); |
| 1270 |
break; |
| 1271 |
} |
| 1272 |
|
| 1273 |
|
| 1274 |
if ( !$this->repo->canTransformLocally() ) { |
| 1275 |
LoggerFactory::getInstance( 'thumbnail' ) |
| 1276 |
->error( 'Local transform denied by configuration' ); |
| 1277 |
$thumb = new MediaTransformError( |
| 1278 |
wfMessage( |
| 1279 |
'thumbnail_error', |
| 1280 |
'MediaWiki is configured to disallow local image scaling' |
| 1281 |
), |
| 1282 |
$params['width'], |
| 1283 |
0 |
| 1284 |
); |
| 1285 |
break; |
| 1286 |
} |
| 1287 |
} |
| 1288 |
|
| 1289 |
$tmpFile = $this->makeTransformTmpFile( $thumbPath ); |
| 1290 |
|
| 1291 |
if ( !$tmpFile ) { |
| 1292 |
$thumb = $this->transformErrorOutput( $thumbPath, $thumbUrl, $params, $flags ); |
| 1293 |
} else { |
| 1294 |
$thumb = $this->generateAndSaveThumb( $tmpFile, $params, $flags ); |
| 1295 |
} |
| 1296 |
} while ( false ); |
| 1297 |
|
| 1298 |
return is_object( $thumb ) ? $thumb : false; |
| 1299 |
} |
| 1300 |
|
| 1301 |
|
| 1302 |
|
| 1303 |
|
| 1304 |
|
| 1305 |
|
| 1306 |
|
| 1307 |
|
| 1308 |
public function generateAndSaveThumb( $tmpFile, $transformParams, $flags ) { |
| 1309 |
$ignoreImageErrors = MediaWikiServices::getInstance()->getMainConfig() |
| 1310 |
->get( MainConfigNames::IgnoreImageErrors ); |
| 1311 |
|
| 1312 |
if ( !$this->repo->canTransformLocally() ) { |
| 1313 |
LoggerFactory::getInstance( 'thumbnail' ) |
| 1314 |
->error( 'Local transform denied by configuration' ); |
| 1315 |
return new MediaTransformError( |
| 1316 |
wfMessage( |
| 1317 |
'thumbnail_error', |
| 1318 |
'MediaWiki is configured to disallow local image scaling' |
| 1319 |
), |
| 1320 |
$transformParams['width'], |
| 1321 |
0 |
| 1322 |
); |
| 1323 |
} |
| 1324 |
|
| 1325 |
$statsFactory = MediaWikiServices::getInstance()->getStatsFactory(); |
| 1326 |
|
| 1327 |
$handler = $this->getHandler(); |
| 1328 |
|
| 1329 |
$normalisedParams = $transformParams; |
| 1330 |
$handler->normaliseParams( $this, $normalisedParams ); |
| 1331 |
|
| 1332 |
$thumbName = $this->thumbName( $normalisedParams ); |
| 1333 |
$thumbUrl = $this->getThumbUrl( $thumbName ); |
| 1334 |
|
| 1335 |
$thumbPath = $this->getThumbPath( $thumbName ); |
| 1336 |
if ( isset( $normalisedParams['isFilePageThumb'] ) && $normalisedParams['isFilePageThumb'] ) { |
| 1337 |
|
| 1338 |
$thumbUrl = $this->getFilePageThumbUrl( $thumbUrl ); |
| 1339 |
} |
| 1340 |
|
| 1341 |
$tmpThumbPath = $tmpFile->getPath(); |
| 1342 |
|
| 1343 |
if ( $handler->supportsBucketing() ) { |
| 1344 |
$this->generateBucketsIfNeeded( $normalisedParams, $flags ); |
| 1345 |
} |
| 1346 |
|
| 1347 |
|
| 1348 |
|
| 1349 |
|
| 1350 |
|
| 1351 |
|
| 1352 |
$starttime = microtime( true ); |
| 1353 |
|
| 1354 |
|
| 1355 |
$thumb = $handler->doTransform( $this, $tmpThumbPath, $thumbUrl, $transformParams ); |
| 1356 |
$tmpFile->bind( $thumb ); |
| 1357 |
|
| 1358 |
$statsFactory->getTiming( 'media_thumbnail_generate_transform_seconds' ) |
| 1359 |
->copyToStatsdAt( 'media.thumbnail.generate.transform' ) |
| 1360 |
->observe( ( microtime( true ) - $starttime ) * 1000 ); |
| 1361 |
|
| 1362 |
if ( !$thumb ) { |
| 1363 |
$thumb = false; |
| 1364 |
} elseif ( $thumb->isError() ) { |
| 1365 |
|
| 1366 |
'@phan-var MediaTransformError $thumb'; |
| 1367 |
$this->lastError = $thumb->toText(); |
| 1368 |
|
| 1369 |
if ( $ignoreImageErrors && !( $flags & self::RENDER_NOW ) ) { |
| 1370 |
$thumb = $handler->getTransform( $this, $tmpThumbPath, $thumbUrl, $transformParams ); |
| 1371 |
} |
| 1372 |
} elseif ( $this->repo && $thumb->hasFile() && !$thumb->fileIsSource() ) { |
| 1373 |
|
| 1374 |
|
| 1375 |
$timer = $statsFactory->getTiming( 'media_thumbnail_generate_store_seconds' ) |
| 1376 |
->copyToStatsdAt( 'media.thumbnail.generate.store' ); |
| 1377 |
$timer->start(); |
| 1378 |
|
| 1379 |
$disposition = $this->getThumbDisposition( $thumbName ); |
| 1380 |
$status = $this->repo->quickImport( $tmpThumbPath, $thumbPath, $disposition ); |
| 1381 |
if ( $status->isOK() ) { |
| 1382 |
$thumb->setStoragePath( $thumbPath ); |
| 1383 |
} else { |
| 1384 |
$thumb = $this->transformErrorOutput( $thumbPath, $thumbUrl, $transformParams, $flags ); |
| 1385 |
} |
| 1386 |
|
| 1387 |
$timer->stop(); |
| 1388 |
|
| 1389 |
|
| 1390 |
$this->getHookRunner()->onFileTransformed( $this, $thumb, $tmpThumbPath, $thumbPath ); |
| 1391 |
} |
| 1392 |
|
| 1393 |
return $thumb; |
| 1394 |
} |
| 1395 |
|
| 1396 |
|
| 1397 |
|
| 1398 |
|
| 1399 |
|
| 1400 |
|
| 1401 |
|
| 1402 |
protected function generateBucketsIfNeeded( $params, $flags = 0 ) { |
| 1403 |
if ( !$this->repo |
| 1404 |
|| !isset( $params['physicalWidth'] ) |
| 1405 |
|| !isset( $params['physicalHeight'] ) |
| 1406 |
) { |
| 1407 |
return false; |
| 1408 |
} |
| 1409 |
|
| 1410 |
$bucket = $this->getThumbnailBucket( $params['physicalWidth'] ); |
| 1411 |
|
| 1412 |
if ( !$bucket || $bucket == $params['physicalWidth'] ) { |
| 1413 |
return false; |
| 1414 |
} |
| 1415 |
|
| 1416 |
$bucketPath = $this->getBucketThumbPath( $bucket ); |
| 1417 |
|
| 1418 |
if ( $this->repo->fileExists( $bucketPath ) ) { |
| 1419 |
return false; |
| 1420 |
} |
| 1421 |
|
| 1422 |
$timer = MediaWikiServices::getInstance()->getStatsFactory() |
| 1423 |
->getTiming( 'media_thumbnail_generate_bucket_seconds' ) |
| 1424 |
->copyToStatsdAt( 'media.thumbnail.generate.bucket' ); |
| 1425 |
$timer->start(); |
| 1426 |
|
| 1427 |
$params['physicalWidth'] = $bucket; |
| 1428 |
$params['width'] = $bucket; |
| 1429 |
|
| 1430 |
$params = $this->getHandler()->sanitizeParamsForBucketing( $params ); |
| 1431 |
|
| 1432 |
$tmpFile = $this->makeTransformTmpFile( $bucketPath ); |
| 1433 |
|
| 1434 |
if ( !$tmpFile ) { |
| 1435 |
return false; |
| 1436 |
} |
| 1437 |
|
| 1438 |
$thumb = $this->generateAndSaveThumb( $tmpFile, $params, $flags ); |
| 1439 |
|
| 1440 |
if ( !$thumb || $thumb->isError() ) { |
| 1441 |
return false; |
| 1442 |
} |
| 1443 |
|
| 1444 |
$timer->stop(); |
| 1445 |
|
| 1446 |
$this->tmpBucketedThumbCache[$bucket] = $tmpFile->getPath(); |
| 1447 |
|
| 1448 |
|
| 1449 |
$tmpFile->bind( $this ); |
| 1450 |
|
| 1451 |
return true; |
| 1452 |
} |
| 1453 |
|
| 1454 |
|
| 1455 |
|
| 1456 |
|
| 1457 |
|
| 1458 |
|
| 1459 |
public function getThumbnailSource( $params ) { |
| 1460 |
if ( $this->repo |
| 1461 |
&& $this->getHandler()->supportsBucketing() |
| 1462 |
&& isset( $params['physicalWidth'] ) |
| 1463 |
) { |
| 1464 |
$bucket = $this->getThumbnailBucket( $params['physicalWidth'] ); |
| 1465 |
if ( $bucket ) { |
| 1466 |
if ( $this->getWidth() != 0 ) { |
| 1467 |
$bucketHeight = round( $this->getHeight() * ( $bucket / $this->getWidth() ) ); |
| 1468 |
} else { |
| 1469 |
$bucketHeight = 0; |
| 1470 |
} |
| 1471 |
|
| 1472 |
|
| 1473 |
if ( isset( $this->tmpBucketedThumbCache[$bucket] ) ) { |
| 1474 |
$tmpPath = $this->tmpBucketedThumbCache[$bucket]; |
| 1475 |
|
| 1476 |
if ( file_exists( $tmpPath ) ) { |
| 1477 |
return [ |
| 1478 |
'path' => $tmpPath, |
| 1479 |
'width' => $bucket, |
| 1480 |
'height' => $bucketHeight |
| 1481 |
]; |
| 1482 |
} |
| 1483 |
} |
| 1484 |
|
| 1485 |
$bucketPath = $this->getBucketThumbPath( $bucket ); |
| 1486 |
|
| 1487 |
if ( $this->repo->fileExists( $bucketPath ) ) { |
| 1488 |
$fsFile = $this->repo->getLocalReference( $bucketPath ); |
| 1489 |
|
| 1490 |
if ( $fsFile ) { |
| 1491 |
return [ |
| 1492 |
'path' => $fsFile->getPath(), |
| 1493 |
'width' => $bucket, |
| 1494 |
'height' => $bucketHeight |
| 1495 |
]; |
| 1496 |
} |
| 1497 |
} |
| 1498 |
} |
| 1499 |
} |
| 1500 |
|
| 1501 |
|
| 1502 |
|
| 1503 |
if ( $this->getSize() >= 1e7 ) { |
| 1504 |
$work = new PoolCounterWorkViaCallback( 'GetLocalFileCopy', sha1( $this->getName() ), |
| 1505 |
[ |
| 1506 |
'doWork' => function () { |
| 1507 |
return $this->getLocalRefPath(); |
| 1508 |
} |
| 1509 |
] |
| 1510 |
); |
| 1511 |
$srcPath = $work->execute(); |
| 1512 |
} else { |
| 1513 |
$srcPath = $this->getLocalRefPath(); |
| 1514 |
} |
| 1515 |
|
| 1516 |
|
| 1517 |
return [ |
| 1518 |
'path' => $srcPath, |
| 1519 |
'width' => $this->getWidth(), |
| 1520 |
'height' => $this->getHeight() |
| 1521 |
]; |
| 1522 |
} |
| 1523 |
|
| 1524 |
|
| 1525 |
|
| 1526 |
|
| 1527 |
|
| 1528 |
|
| 1529 |
protected function getBucketThumbPath( $bucket ) { |
| 1530 |
$thumbName = $this->getBucketThumbName( $bucket ); |
| 1531 |
return $this->getThumbPath( $thumbName ); |
| 1532 |
} |
| 1533 |
|
| 1534 |
|
| 1535 |
|
| 1536 |
|
| 1537 |
|
| 1538 |
|
| 1539 |
protected function getBucketThumbName( $bucket ) { |
| 1540 |
return $this->thumbName( [ 'physicalWidth' => $bucket ] ); |
| 1541 |
} |
| 1542 |
|
| 1543 |
|
| 1544 |
|
| 1545 |
|
| 1546 |
|
| 1547 |
|
| 1548 |
protected function makeTransformTmpFile( $thumbPath ) { |
| 1549 |
$thumbExt = FileBackend::extensionFromPath( $thumbPath ); |
| 1550 |
return MediaWikiServices::getInstance()->getTempFSFileFactory() |
| 1551 |
->newTempFSFile( 'transform_', $thumbExt ); |
| 1552 |
} |
| 1553 |
|
| 1554 |
|
| 1555 |
|
| 1556 |
|
| 1557 |
|
| 1558 |
|
| 1559 |
public function getThumbDisposition( $thumbName, $dispositionType = 'inline' ) { |
| 1560 |
$fileName = $this->getName(); |
| 1561 |
$thumbExt = FileBackend::extensionFromPath( $thumbName ); |
| 1562 |
if ( $thumbExt != '' && $thumbExt !== $this->getExtension() ) { |
| 1563 |
$fileName .= ".$thumbExt"; |
| 1564 |
} |
| 1565 |
|
| 1566 |
return FileBackend::makeContentDisposition( $dispositionType, $fileName ); |
| 1567 |
} |
| 1568 |
|
| 1569 |
|
| 1570 |
|
| 1571 |
|
| 1572 |
|
| 1573 |
|
| 1574 |
|
| 1575 |
public function getHandler() { |
| 1576 |
if ( !isset( $this->handler ) ) { |
| 1577 |
$this->handler = MediaHandler::getHandler( $this->getMimeType() ); |
| 1578 |
} |
| 1579 |
|
| 1580 |
return $this->handler; |
| 1581 |
} |
| 1582 |
|
| 1583 |
|
| 1584 |
|
| 1585 |
|
| 1586 |
|
| 1587 |
|
| 1588 |
public function iconThumb() { |
| 1589 |
global $IP; |
| 1590 |
$resourceBasePath = MediaWikiServices::getInstance()->getMainConfig() |
| 1591 |
->get( MainConfigNames::ResourceBasePath ); |
| 1592 |
$assetsPath = "{$resourceBasePath}/resources/assets/file-type-icons/"; |
| 1593 |
$assetsDirectory = "$IP/resources/assets/file-type-icons/"; |
| 1594 |
|
| 1595 |
$try = [ 'fileicon-' . $this->getExtension() . '.png', 'fileicon.png' ]; |
| 1596 |
foreach ( $try as $icon ) { |
| 1597 |
if ( file_exists( $assetsDirectory . $icon ) ) { |
| 1598 |
$params = [ 'width' => 120, 'height' => 120 ]; |
| 1599 |
|
| 1600 |
return new ThumbnailImage( $this, $assetsPath . $icon, false, $params ); |
| 1601 |
} |
| 1602 |
} |
| 1603 |
|
| 1604 |
return null; |
| 1605 |
} |
| 1606 |
|
| 1607 |
|
| 1608 |
|
| 1609 |
|
| 1610 |
|
| 1611 |
|
| 1612 |
public function getLastError() { |
| 1613 |
return $this->lastError; |
| 1614 |
} |
| 1615 |
|
| 1616 |
|
| 1617 |
|
| 1618 |
|
| 1619 |
|
| 1620 |
|
| 1621 |
|
| 1622 |
|
| 1623 |
protected function getThumbnails() { |
| 1624 |
return []; |
| 1625 |
} |
| 1626 |
|
| 1627 |
|
| 1628 |
|
| 1629 |
|
| 1630 |
|
| 1631 |
|
| 1632 |
|
| 1633 |
|
| 1634 |
|
| 1635 |
public function purgeCache( $options = [] ) { |
| 1636 |
} |
| 1637 |
|
| 1638 |
|
| 1639 |
|
| 1640 |
|
| 1641 |
|
| 1642 |
|
| 1643 |
public function purgeDescription() { |
| 1644 |
$title = $this->getTitle(); |
| 1645 |
if ( $title ) { |
| 1646 |
$title->invalidateCache(); |
| 1647 |
$hcu = MediaWikiServices::getInstance()->getHtmlCacheUpdater(); |
| 1648 |
$hcu->purgeTitleUrls( $title, $hcu::PURGE_INTENT_TXROUND_REFLECTED ); |
| 1649 |
} |
| 1650 |
} |
| 1651 |
|
| 1652 |
|
| 1653 |
|
| 1654 |
|
| 1655 |
|
| 1656 |
public function purgeEverything() { |
| 1657 |
|
| 1658 |
$this->purgeCache(); |
| 1659 |
$this->purgeDescription(); |
| 1660 |
|
| 1661 |
$title = $this->getTitle(); |
| 1662 |
if ( $title ) { |
| 1663 |
$job = HTMLCacheUpdateJob::newForBacklinks( |
| 1664 |
$title, |
| 1665 |
'imagelinks', |
| 1666 |
[ 'causeAction' => 'file-purge' ] |
| 1667 |
); |
| 1668 |
MediaWikiServices::getInstance()->getJobQueueGroup()->lazyPush( $job ); |
| 1669 |
} |
| 1670 |
} |
| 1671 |
|
| 1672 |
|
| 1673 |
|
| 1674 |
|
| 1675 |
|
| 1676 |
|
| 1677 |
|
| 1678 |
|
| 1679 |
|
| 1680 |
|
| 1681 |
|
| 1682 |
|
| 1683 |
|
| 1684 |
public function getHistory( $limit = null, $start = null, $end = null, $inc = true ) { |
| 1685 |
return []; |
| 1686 |
} |
| 1687 |
|
| 1688 |
|
| 1689 |
|
| 1690 |
|
| 1691 |
|
| 1692 |
|
| 1693 |
|
| 1694 |
|
| 1695 |
|
| 1696 |
|
| 1697 |
|
| 1698 |
public function nextHistoryLine() { |
| 1699 |
return false; |
| 1700 |
} |
| 1701 |
|
| 1702 |
|
| 1703 |
|
| 1704 |
|
| 1705 |
|
| 1706 |
|
| 1707 |
|
| 1708 |
|
| 1709 |
public function resetHistory() { |
| 1710 |
} |
| 1711 |
|
| 1712 |
|
| 1713 |
|
| 1714 |
|
| 1715 |
|
| 1716 |
|
| 1717 |
|
| 1718 |
|
| 1719 |
public function getHashPath() { |
| 1720 |
if ( $this->hashPath === null ) { |
| 1721 |
$this->assertRepoDefined(); |
| 1722 |
$this->hashPath = $this->repo->getHashPath( $this->getName() ); |
| 1723 |
} |
| 1724 |
|
| 1725 |
return $this->hashPath; |
| 1726 |
} |
| 1727 |
|
| 1728 |
|
| 1729 |
|
| 1730 |
|
| 1731 |
|
| 1732 |
|
| 1733 |
|
| 1734 |
|
| 1735 |
public function getRel() { |
| 1736 |
return $this->getHashPath() . $this->getName(); |
| 1737 |
} |
| 1738 |
|
| 1739 |
|
| 1740 |
|
| 1741 |
|
| 1742 |
|
| 1743 |
|
| 1744 |
|
| 1745 |
|
| 1746 |
|
| 1747 |
public function getArchiveRel( $suffix = false ) { |
| 1748 |
$path = 'archive/' . $this->getHashPath(); |
| 1749 |
if ( $suffix === false ) { |
| 1750 |
$path = rtrim( $path, '/' ); |
| 1751 |
} else { |
| 1752 |
$path .= $suffix; |
| 1753 |
} |
| 1754 |
|
| 1755 |
return $path; |
| 1756 |
} |
| 1757 |
|
| 1758 |
|
| 1759 |
|
| 1760 |
|
| 1761 |
|
| 1762 |
|
| 1763 |
|
| 1764 |
|
| 1765 |
|
| 1766 |
public function getThumbRel( $suffix = false ) { |
| 1767 |
$path = $this->getRel(); |
| 1768 |
if ( $suffix !== false ) { |
| 1769 |
$path .= '/' . $suffix; |
| 1770 |
} |
| 1771 |
|
| 1772 |
return $path; |
| 1773 |
} |
| 1774 |
|
| 1775 |
|
| 1776 |
|
| 1777 |
|
| 1778 |
|
| 1779 |
|
| 1780 |
|
| 1781 |
|
| 1782 |
public function getUrlRel() { |
| 1783 |
return $this->getHashPath() . rawurlencode( $this->getName() ); |
| 1784 |
} |
| 1785 |
|
| 1786 |
|
| 1787 |
|
| 1788 |
|
| 1789 |
|
| 1790 |
|
| 1791 |
|
| 1792 |
|
| 1793 |
|
| 1794 |
private function getArchiveThumbRel( $archiveName, $suffix = false ) { |
| 1795 |
$path = $this->getArchiveRel( $archiveName ); |
| 1796 |
if ( $suffix !== false ) { |
| 1797 |
$path .= '/' . $suffix; |
| 1798 |
} |
| 1799 |
|
| 1800 |
return $path; |
| 1801 |
} |
| 1802 |
|
| 1803 |
|
| 1804 |
|
| 1805 |
|
| 1806 |
|
| 1807 |
|
| 1808 |
|
| 1809 |
public function getArchivePath( $suffix = false ) { |
| 1810 |
$this->assertRepoDefined(); |
| 1811 |
|
| 1812 |
return $this->repo->getZonePath( 'public' ) . '/' . $this->getArchiveRel( $suffix ); |
| 1813 |
} |
| 1814 |
|
| 1815 |
|
| 1816 |
|
| 1817 |
|
| 1818 |
|
| 1819 |
|
| 1820 |
|
| 1821 |
|
| 1822 |
public function getArchiveThumbPath( $archiveName, $suffix = false ) { |
| 1823 |
$this->assertRepoDefined(); |
| 1824 |
|
| 1825 |
return $this->repo->getZonePath( 'thumb' ) . '/' . |
| 1826 |
$this->getArchiveThumbRel( $archiveName, $suffix ); |
| 1827 |
} |
| 1828 |
|
| 1829 |
|
| 1830 |
|
| 1831 |
|
| 1832 |
|
| 1833 |
|
| 1834 |
|
| 1835 |
|
| 1836 |
public function getThumbPath( $suffix = false ) { |
| 1837 |
$this->assertRepoDefined(); |
| 1838 |
|
| 1839 |
return $this->repo->getZonePath( 'thumb' ) . '/' . $this->getThumbRel( $suffix ); |
| 1840 |
} |
| 1841 |
|
| 1842 |
|
| 1843 |
|
| 1844 |
|
| 1845 |
|
| 1846 |
|
| 1847 |
|
| 1848 |
public function getTranscodedPath( $suffix = false ) { |
| 1849 |
$this->assertRepoDefined(); |
| 1850 |
|
| 1851 |
return $this->repo->getZonePath( 'transcoded' ) . '/' . $this->getThumbRel( $suffix ); |
| 1852 |
} |
| 1853 |
|
| 1854 |
|
| 1855 |
|
| 1856 |
|
| 1857 |
|
| 1858 |
|
| 1859 |
|
| 1860 |
|
| 1861 |
public function getArchiveUrl( $suffix = false ) { |
| 1862 |
$this->assertRepoDefined(); |
| 1863 |
$ext = $this->getExtension(); |
| 1864 |
$path = $this->repo->getZoneUrl( 'public', $ext ) . '/archive/' . $this->getHashPath(); |
| 1865 |
if ( $suffix === false ) { |
| 1866 |
$path = rtrim( $path, '/' ); |
| 1867 |
} else { |
| 1868 |
$path .= rawurlencode( $suffix ); |
| 1869 |
} |
| 1870 |
|
| 1871 |
return $path; |
| 1872 |
} |
| 1873 |
|
| 1874 |
|
| 1875 |
|
| 1876 |
|
| 1877 |
|
| 1878 |
|
| 1879 |
|
| 1880 |
|
| 1881 |
|
| 1882 |
public function getArchiveThumbUrl( $archiveName, $suffix = false ) { |
| 1883 |
$this->assertRepoDefined(); |
| 1884 |
$ext = $this->getExtension(); |
| 1885 |
$path = $this->repo->getZoneUrl( 'thumb', $ext ) . '/archive/' . |
| 1886 |
$this->getHashPath() . rawurlencode( $archiveName ); |
| 1887 |
if ( $suffix !== false ) { |
| 1888 |
$path .= '/' . rawurlencode( $suffix ); |
| 1889 |
} |
| 1890 |
|
| 1891 |
return $path; |
| 1892 |
} |
| 1893 |
|
| 1894 |
|
| 1895 |
|
| 1896 |
|
| 1897 |
|
| 1898 |
|
| 1899 |
|
| 1900 |
|
| 1901 |
private function getZoneUrl( $zone, $suffix = false ) { |
| 1902 |
$this->assertRepoDefined(); |
| 1903 |
$ext = $this->getExtension(); |
| 1904 |
$path = $this->repo->getZoneUrl( $zone, $ext ) . '/' . $this->getUrlRel(); |
| 1905 |
if ( $suffix !== false ) { |
| 1906 |
$path .= '/' . rawurlencode( $suffix ); |
| 1907 |
} |
| 1908 |
|
| 1909 |
return $path; |
| 1910 |
} |
| 1911 |
|
| 1912 |
|
| 1913 |
|
| 1914 |
|
| 1915 |
|
| 1916 |
|
| 1917 |
|
| 1918 |
|
| 1919 |
public function getThumbUrl( $suffix = false ) { |
| 1920 |
return $this->getZoneUrl( 'thumb', $suffix ); |
| 1921 |
} |
| 1922 |
|
| 1923 |
|
| 1924 |
|
| 1925 |
|
| 1926 |
|
| 1927 |
|
| 1928 |
|
| 1929 |
|
| 1930 |
|
| 1931 |
public function getFilePageThumbUrl( $url ) { |
| 1932 |
if ( $this->repo->isLocal() ) { |
| 1933 |
return wfAppendQuery( $url, urlencode( $this->getTimestamp() ) ); |
| 1934 |
} else { |
| 1935 |
return $url; |
| 1936 |
} |
| 1937 |
} |
| 1938 |
|
| 1939 |
|
| 1940 |
|
| 1941 |
|
| 1942 |
|
| 1943 |
|
| 1944 |
|
| 1945 |
public function getTranscodedUrl( $suffix = false ) { |
| 1946 |
return $this->getZoneUrl( 'transcoded', $suffix ); |
| 1947 |
} |
| 1948 |
|
| 1949 |
|
| 1950 |
|
| 1951 |
|
| 1952 |
|
| 1953 |
|
| 1954 |
|
| 1955 |
|
| 1956 |
public function getVirtualUrl( $suffix = false ) { |
| 1957 |
$this->assertRepoDefined(); |
| 1958 |
$path = $this->repo->getVirtualUrl() . '/public/' . $this->getUrlRel(); |
| 1959 |
if ( $suffix !== false ) { |
| 1960 |
$path .= '/' . rawurlencode( $suffix ); |
| 1961 |
} |
| 1962 |
|
| 1963 |
return $path; |
| 1964 |
} |
| 1965 |
|
| 1966 |
|
| 1967 |
|
| 1968 |
|
| 1969 |
|
| 1970 |
|
| 1971 |
|
| 1972 |
|
| 1973 |
public function getArchiveVirtualUrl( $suffix = false ) { |
| 1974 |
$this->assertRepoDefined(); |
| 1975 |
$path = $this->repo->getVirtualUrl() . '/public/archive/' . $this->getHashPath(); |
| 1976 |
if ( $suffix === false ) { |
| 1977 |
$path = rtrim( $path, '/' ); |
| 1978 |
} else { |
| 1979 |
$path .= rawurlencode( $suffix ); |
| 1980 |
} |
| 1981 |
|
| 1982 |
return $path; |
| 1983 |
} |
| 1984 |
|
| 1985 |
|
| 1986 |
|
| 1987 |
|
| 1988 |
|
| 1989 |
|
| 1990 |
|
| 1991 |
|
| 1992 |
public function getThumbVirtualUrl( $suffix = false ) { |
| 1993 |
$this->assertRepoDefined(); |
| 1994 |
$path = $this->repo->getVirtualUrl() . '/thumb/' . $this->getUrlRel(); |
| 1995 |
if ( $suffix !== false ) { |
| 1996 |
$path .= '/' . rawurlencode( $suffix ); |
| 1997 |
} |
| 1998 |
|
| 1999 |
return $path; |
| 2000 |
} |
| 2001 |
|
| 2002 |
|
| 2003 |
|
| 2004 |
|
| 2005 |
protected function isHashed() { |
| 2006 |
$this->assertRepoDefined(); |
| 2007 |
|
| 2008 |
return (bool)$this->repo->getHashLevels(); |
| 2009 |
} |
| 2010 |
|
| 2011 |
|
| 2012 |
|
| 2013 |
|
| 2014 |
protected function readOnlyError() { |
| 2015 |
throw new LogicException( static::class . ': write operations are not supported' ); |
| 2016 |
} |
| 2017 |
|
| 2018 |
|
| 2019 |
|
| 2020 |
|
| 2021 |
|
| 2022 |
|
| 2023 |
|
| 2024 |
|
| 2025 |
|
| 2026 |
|
| 2027 |
|
| 2028 |
|
| 2029 |
|
| 2030 |
|
| 2031 |
|
| 2032 |
|
| 2033 |
|
| 2034 |
|
| 2035 |
|
| 2036 |
|
| 2037 |
|
| 2038 |
|
| 2039 |
|
| 2040 |
public function publish( $src, $flags = 0, array $options = [] ) { |
| 2041 |
$this->readOnlyError(); |
| 2042 |
} |
| 2043 |
|
| 2044 |
|
| 2045 |
|
| 2046 |
|
| 2047 |
|
| 2048 |
public function formatMetadata( $context = false ) { |
| 2049 |
$handler = $this->getHandler(); |
| 2050 |
return $handler ? $handler->formatMetadata( $this, $context ) : false; |
| 2051 |
} |
| 2052 |
|
| 2053 |
|
| 2054 |
|
| 2055 |
|
| 2056 |
|
| 2057 |
|
| 2058 |
public function isLocal() { |
| 2059 |
return $this->repo && $this->repo->isLocal(); |
| 2060 |
} |
| 2061 |
|
| 2062 |
|
| 2063 |
|
| 2064 |
|
| 2065 |
|
| 2066 |
|
| 2067 |
public function getRepoName() { |
| 2068 |
return $this->repo ? $this->repo->getName() : 'unknown'; |
| 2069 |
} |
| 2070 |
|
| 2071 |
|
| 2072 |
|
| 2073 |
|
| 2074 |
|
| 2075 |
|
| 2076 |
|
| 2077 |
public function getRepo() { |
| 2078 |
return $this->repo; |
| 2079 |
} |
| 2080 |
|
| 2081 |
|
| 2082 |
|
| 2083 |
|
| 2084 |
|
| 2085 |
|
| 2086 |
|
| 2087 |
|
| 2088 |
public function isOld() { |
| 2089 |
return false; |
| 2090 |
} |
| 2091 |
|
| 2092 |
|
| 2093 |
|
| 2094 |
|
| 2095 |
|
| 2096 |
|
| 2097 |
|
| 2098 |
|
| 2099 |
|
| 2100 |
public function isDeleted( $field ) { |
| 2101 |
return false; |
| 2102 |
} |
| 2103 |
|
| 2104 |
|
| 2105 |
|
| 2106 |
|
| 2107 |
|
| 2108 |
|
| 2109 |
|
| 2110 |
public function getVisibility() { |
| 2111 |
return 0; |
| 2112 |
} |
| 2113 |
|
| 2114 |
|
| 2115 |
|
| 2116 |
|
| 2117 |
|
| 2118 |
|
| 2119 |
public function wasDeleted() { |
| 2120 |
$title = $this->getTitle(); |
| 2121 |
|
| 2122 |
return $title && $title->hasDeletedEdits(); |
| 2123 |
} |
| 2124 |
|
| 2125 |
|
| 2126 |
|
| 2127 |
|
| 2128 |
|
| 2129 |
|
| 2130 |
|
| 2131 |
|
| 2132 |
|
| 2133 |
|
| 2134 |
|
| 2135 |
|
| 2136 |
|
| 2137 |
|
| 2138 |
public function move( $target ) { |
| 2139 |
$this->readOnlyError(); |
| 2140 |
} |
| 2141 |
|
| 2142 |
|
| 2143 |
|
| 2144 |
|
| 2145 |
|
| 2146 |
|
| 2147 |
|
| 2148 |
|
| 2149 |
|
| 2150 |
|
| 2151 |
|
| 2152 |
|
| 2153 |
|
| 2154 |
|
| 2155 |
|
| 2156 |
|
| 2157 |
|
| 2158 |
|
| 2159 |
|
| 2160 |
public function deleteFile( $reason, UserIdentity $user, $suppress = false ) { |
| 2161 |
$this->readOnlyError(); |
| 2162 |
} |
| 2163 |
|
| 2164 |
|
| 2165 |
|
| 2166 |
|
| 2167 |
|
| 2168 |
|
| 2169 |
|
| 2170 |
|
| 2171 |
|
| 2172 |
|
| 2173 |
|
| 2174 |
|
| 2175 |
|
| 2176 |
|
| 2177 |
|
| 2178 |
public function restore( $versions = [], $unsuppress = false ) { |
| 2179 |
$this->readOnlyError(); |
| 2180 |
} |
| 2181 |
|
| 2182 |
|
| 2183 |
|
| 2184 |
|
| 2185 |
|
| 2186 |
|
| 2187 |
|
| 2188 |
|
| 2189 |
|
| 2190 |
public function isMultipage() { |
| 2191 |
return $this->getHandler() && $this->handler->isMultiPage( $this ); |
| 2192 |
} |
| 2193 |
|
| 2194 |
|
| 2195 |
|
| 2196 |
|
| 2197 |
|
| 2198 |
|
| 2199 |
|
| 2200 |
|
| 2201 |
public function pageCount() { |
| 2202 |
if ( !isset( $this->pageCount ) ) { |
| 2203 |
if ( $this->getHandler() && $this->handler->isMultiPage( $this ) ) { |
| 2204 |
$this->pageCount = $this->handler->pageCount( $this ); |
| 2205 |
} else { |
| 2206 |
$this->pageCount = false; |
| 2207 |
} |
| 2208 |
} |
| 2209 |
|
| 2210 |
return $this->pageCount; |
| 2211 |
} |
| 2212 |
|
| 2213 |
|
| 2214 |
|
| 2215 |
|
| 2216 |
|
| 2217 |
|
| 2218 |
|
| 2219 |
|
| 2220 |
|
| 2221 |
|
| 2222 |
public static function scaleHeight( $srcWidth, $srcHeight, $dstWidth ) { |
| 2223 |
|
| 2224 |
if ( $srcWidth == 0 ) { |
| 2225 |
return 0; |
| 2226 |
} else { |
| 2227 |
return (int)round( $srcHeight * $dstWidth / $srcWidth ); |
| 2228 |
} |
| 2229 |
} |
| 2230 |
|
| 2231 |
|
| 2232 |
|
| 2233 |
|
| 2234 |
|
| 2235 |
|
| 2236 |
|
| 2237 |
|
| 2238 |
public function getDescriptionUrl() { |
| 2239 |
if ( $this->repo ) { |
| 2240 |
return $this->repo->getDescriptionUrl( $this->getName() ); |
| 2241 |
} else { |
| 2242 |
return false; |
| 2243 |
} |
| 2244 |
} |
| 2245 |
|
| 2246 |
|
| 2247 |
|
| 2248 |
|
| 2249 |
|
| 2250 |
|
| 2251 |
|
| 2252 |
|
| 2253 |
|
| 2254 |
public function getDescriptionText( ?Language $lang = null ) { |
| 2255 |
global $wgLang; |
| 2256 |
|
| 2257 |
if ( !$this->repo || !$this->repo->fetchDescription ) { |
| 2258 |
return false; |
| 2259 |
} |
| 2260 |
|
| 2261 |
$lang ??= $wgLang; |
| 2262 |
|
| 2263 |
$renderUrl = $this->repo->getDescriptionRenderUrl( $this->getName(), $lang->getCode() ); |
| 2264 |
if ( $renderUrl ) { |
| 2265 |
$cache = MediaWikiServices::getInstance()->getMainWANObjectCache(); |
| 2266 |
$key = $this->repo->getLocalCacheKey( |
| 2267 |
'file-remote-description', |
| 2268 |
$lang->getCode(), |
| 2269 |
md5( $this->getName() ) |
| 2270 |
); |
| 2271 |
$fname = __METHOD__; |
| 2272 |
|
| 2273 |
return $cache->getWithSetCallback( |
| 2274 |
$key, |
| 2275 |
$this->repo->descriptionCacheExpiry ?: $cache::TTL_UNCACHEABLE, |
| 2276 |
static function ( $oldValue, &$ttl, array &$setOpts ) use ( $renderUrl, $fname ) { |
| 2277 |
wfDebug( "Fetching shared description from $renderUrl" ); |
| 2278 |
$res = MediaWikiServices::getInstance()->getHttpRequestFactory()-> |
| 2279 |
get( $renderUrl, [], $fname ); |
| 2280 |
if ( !$res ) { |
| 2281 |
$ttl = WANObjectCache::TTL_UNCACHEABLE; |
| 2282 |
} |
| 2283 |
|
| 2284 |
return $res; |
| 2285 |
} |
| 2286 |
); |
| 2287 |
} |
| 2288 |
|
| 2289 |
return false; |
| 2290 |
} |
| 2291 |
|
| 2292 |
|
| 2293 |
|
| 2294 |
|
| 2295 |
|
| 2296 |
|
| 2297 |
|
| 2298 |
|
| 2299 |
|
| 2300 |
|
| 2301 |
|
| 2302 |
|
| 2303 |
|
| 2304 |
|
| 2305 |
|
| 2306 |
|
| 2307 |
public function getUploader( int $audience = self::FOR_PUBLIC, ?Authority $performer = null ): ?UserIdentity { |
| 2308 |
return null; |
| 2309 |
} |
| 2310 |
|
| 2311 |
|
| 2312 |
|
| 2313 |
|
| 2314 |
|
| 2315 |
|
| 2316 |
|
| 2317 |
|
| 2318 |
|
| 2319 |
|
| 2320 |
|
| 2321 |
|
| 2322 |
|
| 2323 |
|
| 2324 |
public function getDescription( $audience = self::FOR_PUBLIC, ?Authority $performer = null ) { |
| 2325 |
return null; |
| 2326 |
} |
| 2327 |
|
| 2328 |
|
| 2329 |
|
| 2330 |
|
| 2331 |
|
| 2332 |
|
| 2333 |
|
| 2334 |
public function getTimestamp() { |
| 2335 |
$this->assertRepoDefined(); |
| 2336 |
|
| 2337 |
return $this->repo->getFileTimestamp( $this->getPath() ); |
| 2338 |
} |
| 2339 |
|
| 2340 |
|
| 2341 |
|
| 2342 |
|
| 2343 |
|
| 2344 |
|
| 2345 |
|
| 2346 |
|
| 2347 |
|
| 2348 |
public function getDescriptionTouched() { |
| 2349 |
return false; |
| 2350 |
} |
| 2351 |
|
| 2352 |
|
| 2353 |
|
| 2354 |
|
| 2355 |
|
| 2356 |
|
| 2357 |
|
| 2358 |
public function getSha1() { |
| 2359 |
$this->assertRepoDefined(); |
| 2360 |
|
| 2361 |
return $this->repo->getFileSha1( $this->getPath() ); |
| 2362 |
} |
| 2363 |
|
| 2364 |
|
| 2365 |
|
| 2366 |
|
| 2367 |
|
| 2368 |
|
| 2369 |
public function getStorageKey() { |
| 2370 |
$hash = $this->getSha1(); |
| 2371 |
if ( !$hash ) { |
| 2372 |
return false; |
| 2373 |
} |
| 2374 |
$ext = $this->getExtension(); |
| 2375 |
$dotExt = $ext === '' ? '' : ".$ext"; |
| 2376 |
|
| 2377 |
return $hash . $dotExt; |
| 2378 |
} |
| 2379 |
|
| 2380 |
|
| 2381 |
|
| 2382 |
|
| 2383 |
|
| 2384 |
|
| 2385 |
|
| 2386 |
|
| 2387 |
|
| 2388 |
|
| 2389 |
public function userCan( $field, Authority $performer ) { |
| 2390 |
return true; |
| 2391 |
} |
| 2392 |
|
| 2393 |
|
| 2394 |
|
| 2395 |
|
| 2396 |
|
| 2397 |
public function getContentHeaders() { |
| 2398 |
$handler = $this->getHandler(); |
| 2399 |
if ( $handler ) { |
| 2400 |
return $handler->getContentHeaders( $this->getMetadataArray() ); |
| 2401 |
} |
| 2402 |
|
| 2403 |
return []; |
| 2404 |
} |
| 2405 |
|
| 2406 |
|
| 2407 |
|
| 2408 |
|
| 2409 |
public function getLongDesc() { |
| 2410 |
$handler = $this->getHandler(); |
| 2411 |
if ( $handler ) { |
| 2412 |
return $handler->getLongDesc( $this ); |
| 2413 |
} else { |
| 2414 |
return MediaHandler::getGeneralLongDesc( $this ); |
| 2415 |
} |
| 2416 |
} |
| 2417 |
|
| 2418 |
|
| 2419 |
|
| 2420 |
|
| 2421 |
public function getShortDesc() { |
| 2422 |
$handler = $this->getHandler(); |
| 2423 |
if ( $handler ) { |
| 2424 |
return $handler->getShortDesc( $this ); |
| 2425 |
} else { |
| 2426 |
return MediaHandler::getGeneralShortDesc( $this ); |
| 2427 |
} |
| 2428 |
} |
| 2429 |
|
| 2430 |
|
| 2431 |
|
| 2432 |
|
| 2433 |
public function getDimensionsString() { |
| 2434 |
$handler = $this->getHandler(); |
| 2435 |
if ( $handler ) { |
| 2436 |
return $handler->getDimensionsString( $this ); |
| 2437 |
} else { |
| 2438 |
return ''; |
| 2439 |
} |
| 2440 |
} |
| 2441 |
|
| 2442 |
|
| 2443 |
|
| 2444 |
|
| 2445 |
|
| 2446 |
public function getRedirected(): ?string { |
| 2447 |
return $this->redirected; |
| 2448 |
} |
| 2449 |
|
| 2450 |
|
| 2451 |
|
| 2452 |
|
| 2453 |
protected function getRedirectedTitle() { |
| 2454 |
if ( $this->redirected !== null ) { |
| 2455 |
if ( !$this->redirectTitle ) { |
| 2456 |
$this->redirectTitle = Title::makeTitle( NS_FILE, $this->redirected ); |
| 2457 |
} |
| 2458 |
|
| 2459 |
return $this->redirectTitle; |
| 2460 |
} |
| 2461 |
|
| 2462 |
return null; |
| 2463 |
} |
| 2464 |
|
| 2465 |
|
| 2466 |
|
| 2467 |
|
| 2468 |
|
| 2469 |
public function redirectedFrom( string $from ) { |
| 2470 |
$this->redirected = $from; |
| 2471 |
} |
| 2472 |
|
| 2473 |
|
| 2474 |
|
| 2475 |
|
| 2476 |
|
| 2477 |
public function isMissing() { |
| 2478 |
return false; |
| 2479 |
} |
| 2480 |
|
| 2481 |
|
| 2482 |
|
| 2483 |
|
| 2484 |
|
| 2485 |
|
| 2486 |
public function isCacheable() { |
| 2487 |
return true; |
| 2488 |
} |
| 2489 |
|
| 2490 |
|
| 2491 |
|
| 2492 |
|
| 2493 |
protected function assertRepoDefined() { |
| 2494 |
if ( !( $this->repo instanceof $this->repoClass ) ) { |
| 2495 |
throw new LogicException( "A {$this->repoClass} object is not set for this File.\n" ); |
| 2496 |
} |
| 2497 |
} |
| 2498 |
|
| 2499 |
|
| 2500 |
|
| 2501 |
|
| 2502 |
protected function assertTitleDefined() { |
| 2503 |
if ( !( $this->title instanceof Title ) ) { |
| 2504 |
throw new LogicException( "A Title object is not set for this File.\n" ); |
| 2505 |
} |
| 2506 |
} |
| 2507 |
|
| 2508 |
|
| 2509 |
|
| 2510 |
|
| 2511 |
|
| 2512 |
public function isExpensiveToThumbnail() { |
| 2513 |
$handler = $this->getHandler(); |
| 2514 |
return $handler && $handler->isExpensiveToThumbnail( $this ); |
| 2515 |
} |
| 2516 |
|
| 2517 |
|
| 2518 |
|
| 2519 |
|
| 2520 |
|
| 2521 |
|
| 2522 |
|
| 2523 |
public function isTransformedLocally() { |
| 2524 |
return true; |
| 2525 |
} |
| 2526 |
} |