| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
namespace MediaWiki\Specials; |
| 22 |
|
| 23 |
use BitmapHandler; |
| 24 |
use ChangeTags; |
| 25 |
use ErrorPageError; |
| 26 |
use ImageGalleryBase; |
| 27 |
use JobQueueGroup; |
| 28 |
use LocalFile; |
| 29 |
use LocalRepo; |
| 30 |
use LogEventsList; |
| 31 |
use MediaWiki\Config\Config; |
| 32 |
use MediaWiki\HookContainer\HookRunner; |
| 33 |
use MediaWiki\Html\Html; |
| 34 |
use MediaWiki\HTMLForm\HTMLForm; |
| 35 |
use MediaWiki\Logger\LoggerFactory; |
| 36 |
use MediaWiki\MainConfigNames; |
| 37 |
use MediaWiki\MediaWikiServices; |
| 38 |
use MediaWiki\Request\FauxRequest; |
| 39 |
use MediaWiki\Request\WebRequest; |
| 40 |
use MediaWiki\SpecialPage\SpecialPage; |
| 41 |
use MediaWiki\Status\Status; |
| 42 |
use MediaWiki\Title\NamespaceInfo; |
| 43 |
use MediaWiki\Title\Title; |
| 44 |
use MediaWiki\User\Options\UserOptionsLookup; |
| 45 |
use MediaWiki\User\User; |
| 46 |
use MediaWiki\Watchlist\WatchlistManager; |
| 47 |
use PermissionsError; |
| 48 |
use Psr\Log\LoggerInterface; |
| 49 |
use RepoGroup; |
| 50 |
use UnexpectedValueException; |
| 51 |
use UploadBase; |
| 52 |
use UploadForm; |
| 53 |
use UploadFromStash; |
| 54 |
use UserBlockedError; |
| 55 |
use WikiFilePage; |
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
class SpecialUpload extends SpecialPage { |
| 64 |
|
| 65 |
private LocalRepo $localRepo; |
| 66 |
private UserOptionsLookup $userOptionsLookup; |
| 67 |
private NamespaceInfo $nsInfo; |
| 68 |
private WatchlistManager $watchlistManager; |
| 69 |
|
| 70 |
public bool $allowAsync; |
| 71 |
private JobQueueGroup $jobQueueGroup; |
| 72 |
private LoggerInterface $log; |
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
public function __construct( |
| 81 |
?RepoGroup $repoGroup = null, |
| 82 |
?UserOptionsLookup $userOptionsLookup = null, |
| 83 |
?NamespaceInfo $nsInfo = null, |
| 84 |
?WatchlistManager $watchlistManager = null |
| 85 |
) { |
| 86 |
parent::__construct( 'Upload', 'upload' ); |
| 87 |
|
| 88 |
$services = MediaWikiServices::getInstance(); |
| 89 |
$this->jobQueueGroup = $services->getJobQueueGroup(); |
| 90 |
$repoGroup ??= $services->getRepoGroup(); |
| 91 |
$this->localRepo = $repoGroup->getLocalRepo(); |
| 92 |
$this->userOptionsLookup = $userOptionsLookup ?? $services->getUserOptionsLookup(); |
| 93 |
$this->nsInfo = $nsInfo ?? $services->getNamespaceInfo(); |
| 94 |
$this->watchlistManager = $watchlistManager ?? $services->getWatchlistManager(); |
| 95 |
$this->allowAsync = ( |
| 96 |
$this->getConfig()->get( MainConfigNames::EnableAsyncUploads ) && |
| 97 |
$this->getConfig()->get( MainConfigNames::EnableAsyncUploadsByURL ) |
| 98 |
); |
| 99 |
$this->log = LoggerFactory::getInstance( 'SpecialUpload' ); |
| 100 |
} |
| 101 |
|
| 102 |
public function doesWrites() { |
| 103 |
return true; |
| 104 |
} |
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
public $mRequest; |
| 110 |
|
| 111 |
public $mSourceType; |
| 112 |
|
| 113 |
|
| 114 |
public $mCacheKey; |
| 115 |
|
| 116 |
|
| 117 |
public $mUpload; |
| 118 |
|
| 119 |
|
| 120 |
public $mLocalFile; |
| 121 |
|
| 122 |
public $mUploadClicked; |
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
public $mDesiredDestName; |
| 128 |
|
| 129 |
public $mComment; |
| 130 |
|
| 131 |
public $mLicense; |
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
public $mIgnoreWarning; |
| 137 |
|
| 138 |
public $mWatchthis; |
| 139 |
|
| 140 |
public $mCopyrightStatus; |
| 141 |
|
| 142 |
public $mCopyrightSource; |
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
public $mDestWarningAck; |
| 148 |
|
| 149 |
|
| 150 |
public $mForReUpload; |
| 151 |
|
| 152 |
|
| 153 |
public $mCancelUpload; |
| 154 |
|
| 155 |
public $mTokenOk; |
| 156 |
|
| 157 |
|
| 158 |
public $mUploadSuccessful = false; |
| 159 |
|
| 160 |
|
| 161 |
public $uploadFormTextTop; |
| 162 |
|
| 163 |
public $uploadFormTextAfterSummary; |
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
protected function loadRequest() { |
| 169 |
$this->mRequest = $request = $this->getRequest(); |
| 170 |
$this->mSourceType = $request->getVal( 'wpSourceType', 'file' ); |
| 171 |
$this->mUpload = UploadBase::createFromRequest( $request ); |
| 172 |
$this->mUploadClicked = $request->wasPosted() |
| 173 |
&& ( $request->getCheck( 'wpUpload' ) |
| 174 |
|| $request->getCheck( 'wpUploadIgnoreWarning' ) ); |
| 175 |
|
| 176 |
|
| 177 |
$this->mDesiredDestName = $request->getText( 'wpDestFile' ); |
| 178 |
if ( !$this->mDesiredDestName && $request->getFileName( 'wpUploadFile' ) !== null ) { |
| 179 |
$this->mDesiredDestName = $request->getFileName( 'wpUploadFile' ); |
| 180 |
} |
| 181 |
$this->mLicense = $request->getText( 'wpLicense' ); |
| 182 |
|
| 183 |
$this->mDestWarningAck = $request->getText( 'wpDestFileWarningAck' ); |
| 184 |
$this->mIgnoreWarning = $request->getCheck( 'wpIgnoreWarning' ) |
| 185 |
|| $request->getCheck( 'wpUploadIgnoreWarning' ); |
| 186 |
$this->mWatchthis = $request->getBool( 'wpWatchthis' ) && $this->getUser()->isRegistered(); |
| 187 |
$this->mCopyrightStatus = $request->getText( 'wpUploadCopyStatus' ); |
| 188 |
$this->mCopyrightSource = $request->getText( 'wpUploadSource' ); |
| 189 |
|
| 190 |
$this->mForReUpload = $request->getBool( 'wpForReUpload' ); |
| 191 |
|
| 192 |
$commentDefault = ''; |
| 193 |
$commentMsg = $this->msg( 'upload-default-description' )->inContentLanguage(); |
| 194 |
if ( !$this->mForReUpload && !$commentMsg->isDisabled() ) { |
| 195 |
$commentDefault = $commentMsg->plain(); |
| 196 |
} |
| 197 |
$this->mComment = $request->getText( 'wpUploadDescription', $commentDefault ); |
| 198 |
|
| 199 |
$this->mCancelUpload = $request->getCheck( 'wpCancelUpload' ) |
| 200 |
|| $request->getCheck( 'wpReUpload' ); |
| 201 |
|
| 202 |
|
| 203 |
$token = $request->getVal( 'wpEditToken' ); |
| 204 |
$this->mTokenOk = $this->getUser()->matchEditToken( $token ); |
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
if ( $this->isAsyncUpload() ) { |
| 209 |
$this->mCacheKey = \UploadFromUrl::getCacheKeyFromRequest( $request ); |
| 210 |
} else { |
| 211 |
$this->mCacheKey = ''; |
| 212 |
} |
| 213 |
|
| 214 |
$this->uploadFormTextTop = ''; |
| 215 |
$this->uploadFormTextAfterSummary = ''; |
| 216 |
} |
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
protected function isAsyncUpload() { |
| 224 |
return ( $this->mSourceType === 'url' && $this->allowAsync ); |
| 225 |
} |
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
public function userCanExecute( User $user ) { |
| 236 |
return UploadBase::isEnabled() && parent::userCanExecute( $user ); |
| 237 |
} |
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
public function execute( $par ) { |
| 243 |
$this->useTransactionalTimeLimit(); |
| 244 |
|
| 245 |
$this->setHeaders(); |
| 246 |
$this->outputHeader(); |
| 247 |
|
| 248 |
|
| 249 |
if ( !UploadBase::isEnabled() ) { |
| 250 |
throw new ErrorPageError( 'uploaddisabled', 'uploaddisabledtext' ); |
| 251 |
} |
| 252 |
|
| 253 |
$this->addHelpLink( 'Help:Managing files' ); |
| 254 |
|
| 255 |
|
| 256 |
$user = $this->getUser(); |
| 257 |
$permissionRequired = UploadBase::isAllowed( $user ); |
| 258 |
if ( $permissionRequired !== true ) { |
| 259 |
throw new PermissionsError( $permissionRequired ); |
| 260 |
} |
| 261 |
|
| 262 |
|
| 263 |
if ( $user->isBlockedFromUpload() ) { |
| 264 |
throw new UserBlockedError( |
| 265 |
|
| 266 |
$user->getBlock(), |
| 267 |
$user, |
| 268 |
$this->getLanguage(), |
| 269 |
$this->getRequest()->getIP() |
| 270 |
); |
| 271 |
} |
| 272 |
|
| 273 |
|
| 274 |
$this->checkReadOnly(); |
| 275 |
|
| 276 |
$this->loadRequest(); |
| 277 |
|
| 278 |
|
| 279 |
if ( $this->mCancelUpload && !$this->unsaveUploadedFile() ) { |
| 280 |
|
| 281 |
return; |
| 282 |
} |
| 283 |
|
| 284 |
|
| 285 |
if ( $this->mTokenOk && $this->mCacheKey !== '' ) { |
| 286 |
if ( $this->mUpload && $this->mUploadClicked && !$this->mCancelUpload ) { |
| 287 |
|
| 288 |
$this->processAsyncUpload(); |
| 289 |
} else { |
| 290 |
|
| 291 |
$this->showUploadStatus( $user ); |
| 292 |
} |
| 293 |
} elseif ( |
| 294 |
|
| 295 |
$this->mTokenOk && !$this->mCancelUpload && |
| 296 |
( $this->mUpload && $this->mUploadClicked ) |
| 297 |
) { |
| 298 |
$this->processUpload(); |
| 299 |
} else { |
| 300 |
|
| 301 |
if ( !$this->getHookRunner()->onUploadForm_initial( $this ) ) { |
| 302 |
wfDebug( "Hook 'UploadForm:initial' broke output of the upload form" ); |
| 303 |
|
| 304 |
return; |
| 305 |
} |
| 306 |
$this->showUploadForm( $this->getUploadForm() ); |
| 307 |
} |
| 308 |
|
| 309 |
|
| 310 |
if ( $this->mUpload ) { |
| 311 |
$this->mUpload->cleanupTempFile(); |
| 312 |
} |
| 313 |
} |
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
protected function showUploadStatus( $user ) { |
| 321 |
|
| 322 |
$progress = UploadBase::getSessionStatus( $user, $this->mCacheKey ); |
| 323 |
if ( !$progress ) { |
| 324 |
$progress = [ 'status' => Status::newFatal( 'invalid-cache-key' ) ]; |
| 325 |
} |
| 326 |
$this->log->debug( 'Upload status: stage {stage}, result {result}', $progress ); |
| 327 |
|
| 328 |
$status = $progress['status'] ?? Status::newFatal( 'invalid-cache-key' ); |
| 329 |
$stage = $progress['stage'] ?? 'unknown'; |
| 330 |
$result = $progress['result'] ?? 'unknown'; |
| 331 |
switch ( $stage ) { |
| 332 |
case 'publish': |
| 333 |
switch ( $result ) { |
| 334 |
case 'Success': |
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
$this->mUploadSuccessful = true; |
| 339 |
$this->getHookRunner()->onSpecialUploadComplete( $this ); |
| 340 |
|
| 341 |
|
| 342 |
$title = Title::makeTitleSafe( NS_FILE, $this->mRequest->getText( 'wpDestFile' ) ); |
| 343 |
if ( $title ) { |
| 344 |
$this->log->debug( 'Purging page', [ 'title' => $title->getText() ] ); |
| 345 |
$page = new WikiFilePage( $title ); |
| 346 |
$page->doPurge(); |
| 347 |
} |
| 348 |
$this->getOutput()->redirect( $this->mRequest->getText( 'wpDestUrl' ) ); |
| 349 |
break; |
| 350 |
case 'Warning': |
| 351 |
$this->showUploadWarning( UploadBase::unserializeWarnings( $progress['warnings'] ) ); |
| 352 |
break; |
| 353 |
case 'Failure': |
| 354 |
$details = $status->getValue(); |
| 355 |
|
| 356 |
if ( is_array( $details ) && isset( $details['verification'] ) ) { |
| 357 |
$this->processVerificationError( $details['verification'] ); |
| 358 |
} else { |
| 359 |
$this->showUploadError( $this->getOutput()->parseAsInterface( |
| 360 |
$status->getWikiText( false, false, $this->getLanguage() ) ) |
| 361 |
); |
| 362 |
} |
| 363 |
break; |
| 364 |
case 'Poll': |
| 365 |
$this->showUploadProgress( |
| 366 |
[ 'active' => true, 'msg' => 'upload-progress-processing' ] |
| 367 |
); |
| 368 |
break; |
| 369 |
default: |
| 370 |
|
| 371 |
$this->showUploadError( $this->getOutput()->parseAsInterface( |
| 372 |
$status->getWikiText( false, false, $this->getLanguage() ) ) |
| 373 |
); |
| 374 |
break; |
| 375 |
} |
| 376 |
break; |
| 377 |
case 'queued': |
| 378 |
|
| 379 |
$this->showUploadProgress( [ 'active' => false, 'msg' => 'upload-progress-queued' ] ); |
| 380 |
break; |
| 381 |
case 'fetching': |
| 382 |
switch ( $result ) { |
| 383 |
case 'Success': |
| 384 |
|
| 385 |
|
| 386 |
$this->showUploadProgress( [ 'active' => true, 'msg' => 'upload-progress-downloading' ] ); |
| 387 |
break; |
| 388 |
case 'Failure': |
| 389 |
|
| 390 |
$this->showUploadError( $this->getOutput()->parseAsInterface( |
| 391 |
$status->getWikiText( false, false, $this->getLanguage() ) ) |
| 392 |
); |
| 393 |
break; |
| 394 |
default: |
| 395 |
|
| 396 |
$this->showUploadError( $this->getOutput()->parseAsInterface( |
| 397 |
$status->getWikiText( false, false, $this->getLanguage() ) ) |
| 398 |
); |
| 399 |
break; |
| 400 |
} |
| 401 |
break; |
| 402 |
default: |
| 403 |
|
| 404 |
if ( $status->isOK() ) { |
| 405 |
$status = Status::newFatal( 'upload-progress-unknown' ); |
| 406 |
} |
| 407 |
$statusmsg = $this->getOutput()->parseAsInterface( |
| 408 |
$status->getWikiText( false, false, $this->getLanguage() ) |
| 409 |
); |
| 410 |
$message = '<h2>' . $this->msg( 'uploaderror' )->escaped() . '</h2>' . HTML::errorBox( $statusmsg ); |
| 411 |
$this->showUploadForm( $this->getUploadForm( $message ) ); |
| 412 |
break; |
| 413 |
} |
| 414 |
} |
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
|
| 419 |
|
| 420 |
|
| 421 |
|
| 422 |
|
| 423 |
|
| 424 |
|
| 425 |
|
| 426 |
private function showUploadProgress( $options ) { |
| 427 |
|
| 428 |
|
| 429 |
$message = $this->msg( $options['msg'] )->escaped(); |
| 430 |
$destUrl = $this->mRequest->getText( 'wpDestUrl', '' ); |
| 431 |
if ( !$destUrl && $this->mUpload ) { |
| 432 |
if ( !$this->mLocalFile ) { |
| 433 |
$this->mLocalFile = $this->mUpload->getLocalFile(); |
| 434 |
} |
| 435 |
|
| 436 |
|
| 437 |
if ( $this->mLocalFile === null ) { |
| 438 |
$destUrl = ''; |
| 439 |
} else { |
| 440 |
$destUrl = $this->mLocalFile->getTitle()->getFullURL(); |
| 441 |
} |
| 442 |
} |
| 443 |
|
| 444 |
$destName = $this->mDesiredDestName; |
| 445 |
if ( !$destName ) { |
| 446 |
$destName = $this->mRequest->getText( 'wpDestFile' ); |
| 447 |
} |
| 448 |
|
| 449 |
|
| 450 |
$sourceURL = $this->mRequest->getText( 'wpUploadFileURL' ); |
| 451 |
|
| 452 |
$form = new HTMLForm( [ |
| 453 |
'CacheKey' => [ |
| 454 |
'type' => 'hidden', |
| 455 |
'default' => $this->mCacheKey, |
| 456 |
], |
| 457 |
'SourceType' => [ |
| 458 |
'type' => 'hidden', |
| 459 |
'default' => $this->mSourceType, |
| 460 |
], |
| 461 |
'DestUrl' => [ |
| 462 |
'type' => 'hidden', |
| 463 |
'default' => $destUrl, |
| 464 |
], |
| 465 |
'DestFile' => [ |
| 466 |
'type' => 'hidden', |
| 467 |
'default' => $destName, |
| 468 |
], |
| 469 |
'UploadFileURL' => [ |
| 470 |
'type' => 'hidden', |
| 471 |
'default' => $sourceURL, |
| 472 |
], |
| 473 |
], $this->getContext(), 'uploadProgress' ); |
| 474 |
$form->setSubmitText( $this->msg( 'upload-refresh' )->escaped() ); |
| 475 |
|
| 476 |
|
| 477 |
$preHtml = "<div id='upload-progress-message'>$message</div>"; |
| 478 |
$form->addPreHtml( $preHtml ); |
| 479 |
$form->setSubmitCallback( |
| 480 |
static function ( $formData ) { |
| 481 |
return true; |
| 482 |
} |
| 483 |
); |
| 484 |
$form->prepareForm(); |
| 485 |
$this->getOutput()->addHTML( $form->getHTML( false ) ); |
| 486 |
} |
| 487 |
|
| 488 |
|
| 489 |
|
| 490 |
|
| 491 |
|
| 492 |
|
| 493 |
protected function showUploadForm( $form ) { |
| 494 |
if ( $form instanceof HTMLForm ) { |
| 495 |
$form->show(); |
| 496 |
} else { |
| 497 |
$this->getOutput()->addHTML( $form ); |
| 498 |
} |
| 499 |
} |
| 500 |
|
| 501 |
|
| 502 |
|
| 503 |
|
| 504 |
|
| 505 |
|
| 506 |
|
| 507 |
|
| 508 |
|
| 509 |
protected function getUploadForm( $message = '', $sessionKey = '', $hideIgnoreWarning = false ) { |
| 510 |
|
| 511 |
$form = new UploadForm( |
| 512 |
[ |
| 513 |
'watch' => $this->getWatchCheck(), |
| 514 |
'forreupload' => $this->mForReUpload, |
| 515 |
'sessionkey' => $sessionKey, |
| 516 |
'hideignorewarning' => $hideIgnoreWarning, |
| 517 |
'destwarningack' => (bool)$this->mDestWarningAck, |
| 518 |
|
| 519 |
'description' => $this->mComment, |
| 520 |
'texttop' => $this->uploadFormTextTop, |
| 521 |
'textaftersummary' => $this->uploadFormTextAfterSummary, |
| 522 |
'destfile' => $this->mDesiredDestName, |
| 523 |
], |
| 524 |
$this->getContext(), |
| 525 |
$this->getLinkRenderer(), |
| 526 |
$this->localRepo, |
| 527 |
$this->getContentLanguage(), |
| 528 |
$this->nsInfo, |
| 529 |
$this->getHookContainer() |
| 530 |
); |
| 531 |
$form->setTitle( $this->getPageTitle() ); |
| 532 |
|
| 533 |
|
| 534 |
if ( |
| 535 |
!$this->mTokenOk && !$this->mCancelUpload && |
| 536 |
( $this->mUpload && $this->mUploadClicked ) |
| 537 |
) { |
| 538 |
$form->addPreHtml( $this->msg( 'session_fail_preview' )->parse() ); |
| 539 |
} |
| 540 |
|
| 541 |
|
| 542 |
|
| 543 |
$desiredTitleObj = Title::makeTitleSafe( NS_FILE, $this->mDesiredDestName ); |
| 544 |
$delNotice = ''; |
| 545 |
if ( $desiredTitleObj instanceof Title && !$desiredTitleObj->exists() ) { |
| 546 |
LogEventsList::showLogExtract( $delNotice, [ 'delete', 'move' ], |
| 547 |
$desiredTitleObj, |
| 548 |
'', [ 'lim' => 10, |
| 549 |
'conds' => [ $this->localRepo->getReplicaDB()->expr( 'log_action', '!=', 'revision' ) ], |
| 550 |
'showIfEmpty' => false, |
| 551 |
'msgKey' => [ 'upload-recreate-warning' ] ] |
| 552 |
); |
| 553 |
} |
| 554 |
$form->addPreHtml( $delNotice ); |
| 555 |
|
| 556 |
|
| 557 |
$form->addPreHtml( '<div id="uploadtext">' . |
| 558 |
$this->msg( 'uploadtext', [ $this->mDesiredDestName ] )->parseAsBlock() . |
| 559 |
'</div>' ); |
| 560 |
|
| 561 |
$form->addPreHtml( $message ); |
| 562 |
|
| 563 |
|
| 564 |
$uploadFooter = $this->msg( 'uploadfooter' ); |
| 565 |
if ( !$uploadFooter->isDisabled() ) { |
| 566 |
$form->addPostHtml( '<div id="mw-upload-footer-message">' |
| 567 |
. $uploadFooter->parseAsBlock() . "</div>\n" ); |
| 568 |
} |
| 569 |
|
| 570 |
return $form; |
| 571 |
} |
| 572 |
|
| 573 |
|
| 574 |
|
| 575 |
|
| 576 |
|
| 577 |
|
| 578 |
|
| 579 |
|
| 580 |
|
| 581 |
|
| 582 |
|
| 583 |
|
| 584 |
protected function showRecoverableUploadError( $message ) { |
| 585 |
$stashStatus = $this->mUpload->tryStashFile( $this->getUser() ); |
| 586 |
if ( $stashStatus->isGood() ) { |
| 587 |
$sessionKey = $stashStatus->getValue()->getFileKey(); |
| 588 |
$uploadWarning = 'upload-tryagain'; |
| 589 |
} else { |
| 590 |
$sessionKey = null; |
| 591 |
$uploadWarning = 'upload-tryagain-nostash'; |
| 592 |
} |
| 593 |
$message = '<h2>' . $this->msg( 'uploaderror' )->escaped() . '</h2>' . |
| 594 |
Html::errorBox( $message ); |
| 595 |
|
| 596 |
$form = $this->getUploadForm( $message, $sessionKey ); |
| 597 |
$form->setSubmitText( $this->msg( $uploadWarning )->escaped() ); |
| 598 |
$this->showUploadForm( $form ); |
| 599 |
} |
| 600 |
|
| 601 |
|
| 602 |
|
| 603 |
|
| 604 |
|
| 605 |
|
| 606 |
|
| 607 |
|
| 608 |
|
| 609 |
protected function showUploadWarning( $warnings ) { |
| 610 |
|
| 611 |
|
| 612 |
|
| 613 |
|
| 614 |
if ( !$warnings || ( count( $warnings ) == 1 |
| 615 |
&& isset( $warnings['exists'] ) |
| 616 |
&& ( $this->mDestWarningAck || $this->mForReUpload ) ) |
| 617 |
) { |
| 618 |
return false; |
| 619 |
} |
| 620 |
|
| 621 |
if ( $this->mUpload ) { |
| 622 |
$stashStatus = $this->mUpload->tryStashFile( $this->getUser() ); |
| 623 |
if ( $stashStatus->isGood() ) { |
| 624 |
$sessionKey = $stashStatus->getValue()->getFileKey(); |
| 625 |
$uploadWarning = 'uploadwarning-text'; |
| 626 |
} else { |
| 627 |
$sessionKey = null; |
| 628 |
$uploadWarning = 'uploadwarning-text-nostash'; |
| 629 |
} |
| 630 |
} else { |
| 631 |
$sessionKey = null; |
| 632 |
$uploadWarning = 'uploadwarning-text-nostash'; |
| 633 |
} |
| 634 |
|
| 635 |
|
| 636 |
$this->getOutput()->addModuleStyles( 'mediawiki.special' ); |
| 637 |
|
| 638 |
$linkRenderer = $this->getLinkRenderer(); |
| 639 |
$warningHtml = '<h2>' . $this->msg( 'uploadwarning' )->escaped() . "</h2>\n" |
| 640 |
. '<div class="mw-destfile-warning"><ul>'; |
| 641 |
foreach ( $warnings as $warning => $args ) { |
| 642 |
if ( $warning == 'badfilename' ) { |
| 643 |
$this->mDesiredDestName = Title::makeTitle( NS_FILE, $args )->getText(); |
| 644 |
} |
| 645 |
if ( $warning == 'exists' ) { |
| 646 |
$msg = "\t<li>" . self::getExistsWarning( $args ) . "</li>\n"; |
| 647 |
} elseif ( $warning == 'no-change' ) { |
| 648 |
$file = $args; |
| 649 |
$filename = $file->getTitle()->getPrefixedText(); |
| 650 |
$msg = "\t<li>" . $this->msg( 'fileexists-no-change', $filename )->parse() . "</li>\n"; |
| 651 |
} elseif ( $warning == 'duplicate-version' ) { |
| 652 |
$file = $args[0]; |
| 653 |
$count = count( $args ); |
| 654 |
$filename = $file->getTitle()->getPrefixedText(); |
| 655 |
$message = $this->msg( 'fileexists-duplicate-version' ) |
| 656 |
->params( $filename ) |
| 657 |
->numParams( $count ); |
| 658 |
$msg = "\t<li>" . $message->parse() . "</li>\n"; |
| 659 |
} elseif ( $warning == 'was-deleted' ) { |
| 660 |
|
| 661 |
$ltitle = SpecialPage::getTitleFor( 'Log' ); |
| 662 |
$llink = $linkRenderer->makeKnownLink( |
| 663 |
$ltitle, |
| 664 |
$this->msg( 'deletionlog' )->text(), |
| 665 |
[], |
| 666 |
[ |
| 667 |
'type' => 'delete', |
| 668 |
'page' => Title::makeTitle( NS_FILE, $args )->getPrefixedText(), |
| 669 |
] |
| 670 |
); |
| 671 |
$msg = "\t<li>" . $this->msg( 'filewasdeleted' )->rawParams( $llink )->parse() . "</li>\n"; |
| 672 |
} elseif ( $warning == 'duplicate' ) { |
| 673 |
$msg = $this->getDupeWarning( $args ); |
| 674 |
} elseif ( $warning == 'duplicate-archive' ) { |
| 675 |
if ( $args === '' ) { |
| 676 |
$msg = "\t<li>" . $this->msg( 'file-deleted-duplicate-notitle' )->parse() |
| 677 |
. "</li>\n"; |
| 678 |
} else { |
| 679 |
$msg = "\t<li>" . $this->msg( 'file-deleted-duplicate', |
| 680 |
Title::makeTitle( NS_FILE, $args )->getPrefixedText() )->parse() |
| 681 |
. "</li>\n"; |
| 682 |
} |
| 683 |
} else { |
| 684 |
if ( $args === true ) { |
| 685 |
$args = []; |
| 686 |
} elseif ( !is_array( $args ) ) { |
| 687 |
$args = [ $args ]; |
| 688 |
} |
| 689 |
$msg = "\t<li>" . $this->msg( $warning, $args )->parse() . "</li>\n"; |
| 690 |
} |
| 691 |
$warningHtml .= $msg; |
| 692 |
} |
| 693 |
$warningHtml .= "</ul></div>\n"; |
| 694 |
$warningHtml .= $this->msg( $uploadWarning )->parseAsBlock(); |
| 695 |
|
| 696 |
$form = $this->getUploadForm( $warningHtml, $sessionKey, true ); |
| 697 |
$form->setSubmitTextMsg( 'upload-tryagain' ); |
| 698 |
$form->addButton( [ |
| 699 |
'name' => 'wpUploadIgnoreWarning', |
| 700 |
'value' => $this->msg( 'ignorewarning' )->text() |
| 701 |
] ); |
| 702 |
$form->addButton( [ |
| 703 |
'name' => 'wpCancelUpload', |
| 704 |
'value' => $this->msg( 'reuploaddesc' )->text() |
| 705 |
] ); |
| 706 |
|
| 707 |
$this->showUploadForm( $form ); |
| 708 |
|
| 709 |
|
| 710 |
return true; |
| 711 |
} |
| 712 |
|
| 713 |
|
| 714 |
|
| 715 |
|
| 716 |
|
| 717 |
|
| 718 |
protected function showUploadError( $message ) { |
| 719 |
$message = '<h2>' . $this->msg( 'uploadwarning' )->escaped() . '</h2>' . |
| 720 |
Html::errorBox( $message ); |
| 721 |
$this->showUploadForm( $this->getUploadForm( $message ) ); |
| 722 |
} |
| 723 |
|
| 724 |
|
| 725 |
|
| 726 |
|
| 727 |
|
| 728 |
|
| 729 |
|
| 730 |
protected function performUploadChecks( $fetchFileStatus ): bool { |
| 731 |
if ( !$fetchFileStatus->isOK() ) { |
| 732 |
$this->showUploadError( $this->getOutput()->parseAsInterface( |
| 733 |
$fetchFileStatus->getWikiText( false, false, $this->getLanguage() ) |
| 734 |
) ); |
| 735 |
|
| 736 |
return false; |
| 737 |
} |
| 738 |
if ( !$this->getHookRunner()->onUploadForm_BeforeProcessing( $this ) ) { |
| 739 |
wfDebug( "Hook 'UploadForm:BeforeProcessing' broke processing the file." ); |
| 740 |
|
| 741 |
|
| 742 |
|
| 743 |
|
| 744 |
|
| 745 |
return false; |
| 746 |
} |
| 747 |
|
| 748 |
|
| 749 |
|
| 750 |
if ( $this->isAsyncUpload() ) { |
| 751 |
return true; |
| 752 |
} |
| 753 |
$details = $this->mUpload->verifyUpload(); |
| 754 |
if ( $details['status'] != UploadBase::OK ) { |
| 755 |
$this->processVerificationError( $details ); |
| 756 |
|
| 757 |
return false; |
| 758 |
} |
| 759 |
|
| 760 |
|
| 761 |
$user = $this->getUser(); |
| 762 |
$permErrors = $this->mUpload->verifyTitlePermissions( $user ); |
| 763 |
if ( $permErrors !== true ) { |
| 764 |
$code = array_shift( $permErrors[0] ); |
| 765 |
$this->showRecoverableUploadError( $this->msg( $code, $permErrors[0] )->parse() ); |
| 766 |
|
| 767 |
return false; |
| 768 |
} |
| 769 |
|
| 770 |
$this->mLocalFile = $this->mUpload->getLocalFile(); |
| 771 |
|
| 772 |
|
| 773 |
if ( !$this->mIgnoreWarning ) { |
| 774 |
$warnings = $this->mUpload->checkWarnings( $user ); |
| 775 |
if ( $this->showUploadWarning( $warnings ) ) { |
| 776 |
return false; |
| 777 |
} |
| 778 |
} |
| 779 |
|
| 780 |
return true; |
| 781 |
} |
| 782 |
|
| 783 |
|
| 784 |
|
| 785 |
|
| 786 |
|
| 787 |
|
| 788 |
protected function getPageTextAndTags() { |
| 789 |
|
| 790 |
if ( !$this->mForReUpload ) { |
| 791 |
$pageText = self::getInitialPageText( $this->mComment, $this->mLicense, |
| 792 |
$this->mCopyrightStatus, $this->mCopyrightSource, |
| 793 |
$this->getConfig() ); |
| 794 |
} else { |
| 795 |
$pageText = false; |
| 796 |
} |
| 797 |
$changeTags = $this->getRequest()->getVal( 'wpChangeTags' ); |
| 798 |
if ( $changeTags === null || $changeTags === '' ) { |
| 799 |
$changeTags = []; |
| 800 |
} else { |
| 801 |
$changeTags = array_filter( array_map( 'trim', explode( ',', $changeTags ) ) ); |
| 802 |
} |
| 803 |
if ( $changeTags ) { |
| 804 |
$changeTagsStatus = ChangeTags::canAddTagsAccompanyingChange( |
| 805 |
$changeTags, $this->getUser() ); |
| 806 |
if ( !$changeTagsStatus->isOK() ) { |
| 807 |
$this->showUploadError( $this->getOutput()->parseAsInterface( |
| 808 |
$changeTagsStatus->getWikiText( false, false, $this->getLanguage() ) |
| 809 |
) ); |
| 810 |
|
| 811 |
return null; |
| 812 |
} |
| 813 |
} |
| 814 |
return [ $pageText, $changeTags ]; |
| 815 |
} |
| 816 |
|
| 817 |
|
| 818 |
|
| 819 |
|
| 820 |
|
| 821 |
protected function processUpload() { |
| 822 |
|
| 823 |
$status = $this->mUpload->fetchFile(); |
| 824 |
if ( !$this->performUploadChecks( $status ) ) { |
| 825 |
return; |
| 826 |
} |
| 827 |
$user = $this->getUser(); |
| 828 |
$pageAndTags = $this->getPageTextAndTags(); |
| 829 |
if ( $pageAndTags === null ) { |
| 830 |
return; |
| 831 |
} |
| 832 |
[ $pageText, $changeTags ] = $pageAndTags; |
| 833 |
|
| 834 |
$status = $this->mUpload->performUpload( |
| 835 |
$this->mComment, |
| 836 |
$pageText, |
| 837 |
$this->mWatchthis, |
| 838 |
$user, |
| 839 |
$changeTags |
| 840 |
); |
| 841 |
|
| 842 |
if ( !$status->isGood() ) { |
| 843 |
$this->showRecoverableUploadError( |
| 844 |
$this->getOutput()->parseAsInterface( |
| 845 |
$status->getWikiText( false, false, $this->getLanguage() ) |
| 846 |
) |
| 847 |
); |
| 848 |
|
| 849 |
return; |
| 850 |
} |
| 851 |
|
| 852 |
|
| 853 |
$this->mUploadSuccessful = true; |
| 854 |
$this->getHookRunner()->onSpecialUploadComplete( $this ); |
| 855 |
$this->getOutput()->redirect( $this->mLocalFile->getTitle()->getFullURL() ); |
| 856 |
} |
| 857 |
|
| 858 |
|
| 859 |
|
| 860 |
|
| 861 |
protected function processAsyncUpload() { |
| 862 |
|
| 863 |
if ( !$this->mUpload instanceof \UploadFromUrl ) { |
| 864 |
$this->showUploadError( $this->msg( 'uploaderror' )->escaped() ); |
| 865 |
|
| 866 |
return; |
| 867 |
} |
| 868 |
|
| 869 |
$status = $this->mUpload->canFetchFile(); |
| 870 |
if ( !$this->performUploadChecks( $status ) ) { |
| 871 |
$this->log->debug( 'Upload failed verification: {error}', [ 'error' => $status ] ); |
| 872 |
return; |
| 873 |
} |
| 874 |
|
| 875 |
$pageAndTags = $this->getPageTextAndTags(); |
| 876 |
if ( $pageAndTags === null ) { |
| 877 |
return; |
| 878 |
} |
| 879 |
[ $pageText, $changeTags ] = $pageAndTags; |
| 880 |
|
| 881 |
|
| 882 |
$job = new \UploadFromUrlJob( |
| 883 |
[ |
| 884 |
'filename' => $this->mUpload->getDesiredDestName(), |
| 885 |
'url' => $this->mUpload->getUrl(), |
| 886 |
'comment' => $this->mComment, |
| 887 |
'tags' => $changeTags, |
| 888 |
'text' => $pageText, |
| 889 |
'watch' => $this->mWatchthis, |
| 890 |
'watchlistexpiry' => null, |
| 891 |
'session' => $this->getContext()->exportSession(), |
| 892 |
'reupload' => $this->mForReUpload, |
| 893 |
'ignorewarnings' => $this->mIgnoreWarning, |
| 894 |
] |
| 895 |
); |
| 896 |
|
| 897 |
$cacheKey = $job->getCacheKey(); |
| 898 |
UploadBase::setSessionStatus( $this->getUser(), $cacheKey, [ |
| 899 |
'status' => Status::newGood(), |
| 900 |
'stage' => 'queued', |
| 901 |
'result' => 'Poll' |
| 902 |
] ); |
| 903 |
$this->log->info( "Submitting UploadFromUrlJob for {filename}", |
| 904 |
[ 'filename' => $this->mUpload->getDesiredDestName() ] |
| 905 |
); |
| 906 |
|
| 907 |
$this->jobQueueGroup->push( $job ); |
| 908 |
|
| 909 |
$this->showUploadStatus( $this->getUser() ); |
| 910 |
} |
| 911 |
|
| 912 |
|
| 913 |
|
| 914 |
|
| 915 |
|
| 916 |
|
| 917 |
|
| 918 |
|
| 919 |
|
| 920 |
|
| 921 |
public static function getInitialPageText( $comment = '', $license = '', |
| 922 |
$copyStatus = '', $source = '', ?Config $config = null |
| 923 |
) { |
| 924 |
if ( $config === null ) { |
| 925 |
wfDebug( __METHOD__ . ' called without a Config instance passed to it' ); |
| 926 |
$config = MediaWikiServices::getInstance()->getMainConfig(); |
| 927 |
} |
| 928 |
|
| 929 |
$msg = []; |
| 930 |
$forceUIMsgAsContentMsg = (array)$config->get( MainConfigNames::ForceUIMsgAsContentMsg ); |
| 931 |
|
| 932 |
|
| 933 |
|
| 934 |
|
| 935 |
foreach ( [ 'license-header', 'filedesc', 'filestatus', 'filesource' ] as $msgName ) { |
| 936 |
if ( in_array( $msgName, $forceUIMsgAsContentMsg ) ) { |
| 937 |
$msg[$msgName] = "{{int:$msgName}}"; |
| 938 |
} else { |
| 939 |
$msg[$msgName] = wfMessage( $msgName )->inContentLanguage()->text(); |
| 940 |
} |
| 941 |
} |
| 942 |
|
| 943 |
$licenseText = ''; |
| 944 |
if ( $license !== '' ) { |
| 945 |
$licenseText = '== ' . $msg['license-header'] . " ==\n{{" . $license . "}}\n"; |
| 946 |
} |
| 947 |
|
| 948 |
$pageText = $comment . "\n"; |
| 949 |
$headerText = '== ' . $msg['filedesc'] . ' =='; |
| 950 |
if ( $comment !== '' && !str_contains( $comment, $headerText ) ) { |
| 951 |
|
| 952 |
$pageText = $headerText . "\n" . $pageText; |
| 953 |
} |
| 954 |
|
| 955 |
if ( $config->get( MainConfigNames::UseCopyrightUpload ) ) { |
| 956 |
$pageText .= '== ' . $msg['filestatus'] . " ==\n" . $copyStatus . "\n"; |
| 957 |
$pageText .= $licenseText; |
| 958 |
$pageText .= '== ' . $msg['filesource'] . " ==\n" . $source; |
| 959 |
} else { |
| 960 |
$pageText .= $licenseText; |
| 961 |
} |
| 962 |
|
| 963 |
|
| 964 |
( new HookRunner( MediaWikiServices::getInstance()->getHookContainer() ) ) |
| 965 |
->onUploadForm_getInitialPageText( $pageText, $msg, $config ); |
| 966 |
|
| 967 |
return $pageText; |
| 968 |
} |
| 969 |
|
| 970 |
|
| 971 |
|
| 972 |
|
| 973 |
|
| 974 |
|
| 975 |
|
| 976 |
|
| 977 |
|
| 978 |
|
| 979 |
|
| 980 |
|
| 981 |
|
| 982 |
protected function getWatchCheck() { |
| 983 |
$user = $this->getUser(); |
| 984 |
if ( $this->userOptionsLookup->getBoolOption( $user, 'watchdefault' ) ) { |
| 985 |
|
| 986 |
return true; |
| 987 |
} |
| 988 |
|
| 989 |
$desiredTitleObj = Title::makeTitleSafe( NS_FILE, $this->mDesiredDestName ); |
| 990 |
if ( $desiredTitleObj instanceof Title && |
| 991 |
$this->watchlistManager->isWatched( $user, $desiredTitleObj ) ) { |
| 992 |
|
| 993 |
return true; |
| 994 |
} |
| 995 |
|
| 996 |
$local = $this->localRepo->newFile( $this->mDesiredDestName ); |
| 997 |
if ( $local && $local->exists() ) { |
| 998 |
|
| 999 |
|
| 1000 |
return false; |
| 1001 |
} else { |
| 1002 |
|
| 1003 |
return $this->userOptionsLookup->getBoolOption( $user, 'watchcreations' ) || |
| 1004 |
$this->userOptionsLookup->getBoolOption( $user, 'watchuploads' ); |
| 1005 |
} |
| 1006 |
} |
| 1007 |
|
| 1008 |
|
| 1009 |
|
| 1010 |
|
| 1011 |
|
| 1012 |
|
| 1013 |
protected function processVerificationError( $details ) { |
| 1014 |
switch ( $details['status'] ) { |
| 1015 |
|
| 1016 |
case UploadBase::MIN_LENGTH_PARTNAME: |
| 1017 |
$this->showRecoverableUploadError( $this->msg( 'minlength1' )->escaped() ); |
| 1018 |
break; |
| 1019 |
case UploadBase::ILLEGAL_FILENAME: |
| 1020 |
$this->showRecoverableUploadError( $this->msg( 'illegalfilename', |
| 1021 |
$details['filtered'] )->parse() ); |
| 1022 |
break; |
| 1023 |
case UploadBase::FILENAME_TOO_LONG: |
| 1024 |
$this->showRecoverableUploadError( $this->msg( 'filename-toolong' )->escaped() ); |
| 1025 |
break; |
| 1026 |
case UploadBase::FILETYPE_MISSING: |
| 1027 |
$this->showRecoverableUploadError( $this->msg( 'filetype-missing' )->parse() ); |
| 1028 |
break; |
| 1029 |
case UploadBase::WINDOWS_NONASCII_FILENAME: |
| 1030 |
$this->showRecoverableUploadError( $this->msg( 'windows-nonascii-filename' )->parse() ); |
| 1031 |
break; |
| 1032 |
|
| 1033 |
|
| 1034 |
case UploadBase::EMPTY_FILE: |
| 1035 |
$this->showUploadError( $this->msg( 'emptyfile' )->escaped() ); |
| 1036 |
break; |
| 1037 |
case UploadBase::FILE_TOO_LARGE: |
| 1038 |
$this->showUploadError( $this->msg( 'largefileserver' )->escaped() ); |
| 1039 |
break; |
| 1040 |
case UploadBase::FILETYPE_BADTYPE: |
| 1041 |
$msg = $this->msg( 'filetype-banned-type' ); |
| 1042 |
if ( isset( $details['blacklistedExt'] ) ) { |
| 1043 |
$msg->params( $this->getLanguage()->commaList( $details['blacklistedExt'] ) ); |
| 1044 |
} else { |
| 1045 |
$msg->params( $details['finalExt'] ); |
| 1046 |
} |
| 1047 |
$extensions = |
| 1048 |
array_unique( $this->getConfig()->get( MainConfigNames::FileExtensions ) ); |
| 1049 |
$msg->params( $this->getLanguage()->commaList( $extensions ), |
| 1050 |
count( $extensions ) ); |
| 1051 |
|
| 1052 |
|
| 1053 |
|
| 1054 |
|
| 1055 |
if ( isset( $details['blacklistedExt'] ) ) { |
| 1056 |
$msg->params( count( $details['blacklistedExt'] ) ); |
| 1057 |
} else { |
| 1058 |
$msg->params( 1 ); |
| 1059 |
} |
| 1060 |
|
| 1061 |
$this->showUploadError( $msg->parse() ); |
| 1062 |
break; |
| 1063 |
case UploadBase::VERIFICATION_ERROR: |
| 1064 |
unset( $details['status'] ); |
| 1065 |
$code = array_shift( $details['details'] ); |
| 1066 |
$this->showUploadError( $this->msg( $code, $details['details'] )->parse() ); |
| 1067 |
break; |
| 1068 |
case UploadBase::HOOK_ABORTED: |
| 1069 |
if ( is_array( $details['error'] ) ) { |
| 1070 |
$args = $details['error']; |
| 1071 |
$error = array_shift( $args ); |
| 1072 |
} else { |
| 1073 |
$error = $details['error']; |
| 1074 |
$args = null; |
| 1075 |
} |
| 1076 |
|
| 1077 |
$this->showUploadError( $this->msg( $error, $args )->parse() ); |
| 1078 |
break; |
| 1079 |
default: |
| 1080 |
throw new UnexpectedValueException( __METHOD__ . ": Unknown value `{$details['status']}`" ); |
| 1081 |
} |
| 1082 |
} |
| 1083 |
|
| 1084 |
|
| 1085 |
|
| 1086 |
|
| 1087 |
|
| 1088 |
|
| 1089 |
protected function unsaveUploadedFile() { |
| 1090 |
if ( !( $this->mUpload instanceof UploadFromStash ) ) { |
| 1091 |
return true; |
| 1092 |
} |
| 1093 |
$success = $this->mUpload->unsaveUploadedFile(); |
| 1094 |
if ( !$success ) { |
| 1095 |
$this->getOutput()->showErrorPage( |
| 1096 |
'internalerror', |
| 1097 |
'filedeleteerror', |
| 1098 |
[ $this->mUpload->getTempPath() ] |
| 1099 |
); |
| 1100 |
|
| 1101 |
return false; |
| 1102 |
} else { |
| 1103 |
return true; |
| 1104 |
} |
| 1105 |
} |
| 1106 |
|
| 1107 |
|
| 1108 |
|
| 1109 |
|
| 1110 |
|
| 1111 |
|
| 1112 |
|
| 1113 |
|
| 1114 |
|
| 1115 |
|
| 1116 |
public static function getExistsWarning( $exists ) { |
| 1117 |
if ( !$exists ) { |
| 1118 |
return ''; |
| 1119 |
} |
| 1120 |
|
| 1121 |
$file = $exists['file']; |
| 1122 |
$filename = $file->getTitle()->getPrefixedText(); |
| 1123 |
$warnMsg = null; |
| 1124 |
|
| 1125 |
if ( $exists['warning'] == 'exists' ) { |
| 1126 |
|
| 1127 |
$warnMsg = wfMessage( 'fileexists', $filename ); |
| 1128 |
} elseif ( $exists['warning'] == 'page-exists' ) { |
| 1129 |
|
| 1130 |
$warnMsg = wfMessage( 'filepageexists', $filename ); |
| 1131 |
} elseif ( $exists['warning'] == 'exists-normalized' ) { |
| 1132 |
$warnMsg = wfMessage( 'fileexists-extension', $filename, |
| 1133 |
$exists['normalizedFile']->getTitle()->getPrefixedText() ); |
| 1134 |
} elseif ( $exists['warning'] == 'thumb' ) { |
| 1135 |
|
| 1136 |
$warnMsg = wfMessage( 'fileexists-thumbnail-yes', |
| 1137 |
$exists['thumbFile']->getTitle()->getPrefixedText(), $filename ); |
| 1138 |
} elseif ( $exists['warning'] == 'thumb-name' ) { |
| 1139 |
|
| 1140 |
$name = $file->getName(); |
| 1141 |
$badPart = substr( $name, 0, strpos( $name, '-' ) + 1 ); |
| 1142 |
$warnMsg = wfMessage( 'file-thumbnail-no', $badPart ); |
| 1143 |
} elseif ( $exists['warning'] == 'bad-prefix' ) { |
| 1144 |
$warnMsg = wfMessage( 'filename-bad-prefix', $exists['prefix'] ); |
| 1145 |
} |
| 1146 |
|
| 1147 |
return $warnMsg ? $warnMsg->page( $file->getTitle() )->parse() : ''; |
| 1148 |
} |
| 1149 |
|
| 1150 |
|
| 1151 |
|
| 1152 |
|
| 1153 |
|
| 1154 |
|
| 1155 |
public function getDupeWarning( $dupes ) { |
| 1156 |
if ( !$dupes ) { |
| 1157 |
return ''; |
| 1158 |
} |
| 1159 |
|
| 1160 |
$gallery = ImageGalleryBase::factory( false, $this->getContext() ); |
| 1161 |
$gallery->setShowBytes( false ); |
| 1162 |
$gallery->setShowDimensions( false ); |
| 1163 |
foreach ( $dupes as $file ) { |
| 1164 |
$gallery->add( $file->getTitle() ); |
| 1165 |
} |
| 1166 |
|
| 1167 |
return '<li>' . |
| 1168 |
$this->msg( 'file-exists-duplicate' )->numParams( count( $dupes ) )->parse() . |
| 1169 |
$gallery->toHTML() . "</li>\n"; |
| 1170 |
} |
| 1171 |
|
| 1172 |
protected function getGroupName() { |
| 1173 |
return 'media'; |
| 1174 |
} |
| 1175 |
|
| 1176 |
|
| 1177 |
|
| 1178 |
|
| 1179 |
|
| 1180 |
|
| 1181 |
|
| 1182 |
|
| 1183 |
|
| 1184 |
public static function rotationEnabled() { |
| 1185 |
$bitmapHandler = new BitmapHandler(); |
| 1186 |
return $bitmapHandler->autoRotateEnabled(); |
| 1187 |
} |
| 1188 |
} |
| 1189 |
|
| 1190 |
|
| 1191 |
|
| 1192 |
|
| 1193 |
|
| 1194 |
class_alias( SpecialUpload::class, 'SpecialUpload' ); |