39 parent::__construct(
'Upload',
'upload' );
95 $this->mRequest = $request = $this->
getRequest();
96 $this->mSourceType = $request->getVal(
'wpSourceType',
'file' );
98 $this->mUploadClicked = $request->wasPosted()
99 && ( $request->getCheck(
'wpUpload' )
100 || $request->getCheck(
'wpUploadIgnoreWarning' ) );
103 $this->mDesiredDestName = $request->getText(
'wpDestFile' );
104 if ( !$this->mDesiredDestName && $request->getFileName(
'wpUploadFile' ) !== null ) {
105 $this->mDesiredDestName = $request->getFileName(
'wpUploadFile' );
107 $this->mLicense = $request->getText(
'wpLicense' );
109 $this->mDestWarningAck = $request->getText(
'wpDestFileWarningAck' );
110 $this->mIgnoreWarning = $request->getCheck(
'wpIgnoreWarning' )
111 || $request->getCheck(
'wpUploadIgnoreWarning' );
112 $this->mWatchthis = $request->getBool(
'wpWatchthis' ) && $this->
getUser()->isLoggedIn();
113 $this->mCopyrightStatus = $request->getText(
'wpUploadCopyStatus' );
114 $this->mCopyrightSource = $request->getText(
'wpUploadSource' );
116 $this->mForReUpload = $request->getBool(
'wpForReUpload' );
118 $commentDefault =
'';
119 $commentMsg = $this->
msg(
'upload-default-description' )->inContentLanguage();
120 if ( !$this->mForReUpload && !$commentMsg->isDisabled() ) {
121 $commentDefault = $commentMsg->plain();
123 $this->mComment = $request->getText(
'wpUploadDescription', $commentDefault );
125 $this->mCancelUpload = $request->getCheck(
'wpCancelUpload' )
126 || $request->getCheck(
'wpReUpload' );
129 $token = $request->getVal(
'wpEditToken' );
130 $this->mTokenOk = $this->
getUser()->matchEditToken( $token );
132 $this->uploadFormTextTop =
'';
133 $this->uploadFormTextAfterSummary =
'';
164 # Check uploading enabled
166 throw new ErrorPageError(
'uploaddisabled',
'uploaddisabledtext' );
174 if ( $permissionRequired !==
true ) {
179 if ( $user->isBlockedFromUpload() ) {
184 if ( $user->isBlockedGlobally() ) {
188 # Check whether we actually want to allow changing stuff
193 # Unsave the temporary file in case this was a cancelled upload
195 # Something went wrong, so unsaveUploadedFile showed a warning
199 # Process upload or show a form
201 $this->mTokenOk && !$this->mCancelUpload &&
202 ( $this->mUpload && $this->mUploadClicked )
206 # Backwards compatibility hook
209 if ( !Hooks::run(
'UploadForm:initial', [ &$upload ] ) ) {
210 wfDebug(
"Hook 'UploadForm:initial' broke output of the upload form\n" );
218 if ( $this->mUpload ) {
219 $this->mUpload->cleanupTempFile();
229 # Add links if file was previously deleted
230 if ( $this->mDesiredDestName ) {
249 protected function getUploadForm( $message =
'', $sessionKey =
'', $hideIgnoreWarning =
false ) {
255 'forreupload' => $this->mForReUpload,
256 'sessionkey' => $sessionKey,
257 'hideignorewarning' => $hideIgnoreWarning,
258 'destwarningack' => (
bool)$this->mDestWarningAck,
260 'description' => $this->mComment,
261 'texttop' => $this->uploadFormTextTop,
262 'textaftersummary' => $this->uploadFormTextAfterSummary,
263 'destfile' => $this->mDesiredDestName,
266 # Check the token, but only if necessary
268 !$this->mTokenOk && !$this->mCancelUpload &&
269 ( $this->mUpload && $this->mUploadClicked )
271 $form->addPreText( $this->
msg(
'session_fail_preview' )->parse() );
274 # Give a notice if the user is uploading a file that has been deleted or moved
275 # Note that this is independent from the message 'filewasdeleted'
276 $desiredTitleObj = Title::makeTitleSafe(
NS_FILE, $this->mDesiredDestName );
278 if ( $desiredTitleObj instanceof
Title && !$desiredTitleObj->
exists() ) {
284 'conds' => [
'log_action != ' .
$dbr->addQuotes(
'revision' ) ],
285 'showIfEmpty' =>
false,
286 'msgKey' => [
'upload-recreate-warning' ] ]
289 $form->addPreText( $delNotice );
292 $form->addPreText(
'<div id="uploadtext">' .
293 $this->
msg(
'uploadtext', [ $this->mDesiredDestName ] )->parseAsBlock() .
295 # Add upload error message
296 $form->addPreText( $message );
299 $uploadFooter = $this->
msg(
'uploadfooter' );
300 if ( !$uploadFooter->isDisabled() ) {
301 $form->addPostText(
'<div id="mw-upload-footer-message">'
302 . $uploadFooter->parseAsBlock() .
"</div>\n" );
312 $title = Title::makeTitleSafe(
NS_FILE, $this->mDesiredDestName );
314 $permissionManager = MediaWikiServices::getInstance()->getPermissionManager();
317 $count =
$title->isDeleted();
318 if ( $count > 0 && $permissionManager->userHasRight( $user,
'deletedhistory' ) ) {
321 $this->msg(
'restorelink' )->numParams( $count )->text()
324 $permissionManager->userHasRight( $user,
'delete' ) ?
'thisisdeleted' :
'viewdeleted'
325 )->rawParams( $restorelink )->parseAsBlock();
329 [
'id' =>
'contentSub2' ],
349 $stashStatus = $this->mUpload->tryStashFile( $this->
getUser() );
350 if ( $stashStatus->isGood() ) {
351 $sessionKey = $stashStatus->getValue()->getFileKey();
352 $uploadWarning =
'upload-tryagain';
355 $uploadWarning =
'upload-tryagain-nostash';
357 $message =
'<h2>' . $this->
msg(
'uploaderror' )->escaped() .
"</h2>\n" .
358 '<div class="error">' . $message .
"</div>\n";
361 $form->setSubmitText( $this->
msg( $uploadWarning )->escaped() );
374 # If there are no warnings, or warnings we can ignore, return early.
375 # mDestWarningAck is set when some javascript has shown the warning
376 # to the user. mForReUpload is set when the user clicks the "upload a
378 if ( !$warnings || ( count( $warnings ) == 1
379 && isset( $warnings[
'exists'] )
380 && ( $this->mDestWarningAck || $this->mForReUpload ) )
385 $stashStatus = $this->mUpload->tryStashFile( $this->
getUser() );
386 if ( $stashStatus->isGood() ) {
387 $sessionKey = $stashStatus->getValue()->getFileKey();
388 $uploadWarning =
'uploadwarning-text';
391 $uploadWarning =
'uploadwarning-text-nostash';
395 $this->
getOutput()->addModuleStyles(
'mediawiki.special' );
398 $warningHtml =
'<h2>' . $this->
msg(
'uploadwarning' )->escaped() .
"</h2>\n"
399 .
'<div class="mw-destfile-warning"><ul>';
400 foreach ( $warnings as $warning =>
$args ) {
401 if ( $warning ==
'badfilename' ) {
402 $this->mDesiredDestName = Title::makeTitle(
NS_FILE,
$args )->getText();
404 if ( $warning ==
'exists' ) {
406 } elseif ( $warning ==
'no-change' ) {
408 $filename =
$file->getTitle()->getPrefixedText();
409 $msg =
"\t<li>" . $this->
msg(
'fileexists-no-change', $filename )->parse() .
"</li>\n";
410 } elseif ( $warning ==
'duplicate-version' ) {
412 $count = count(
$args );
413 $filename =
$file->getTitle()->getPrefixedText();
414 $message = $this->
msg(
'fileexists-duplicate-version' )
415 ->params( $filename )
416 ->numParams( $count );
417 $msg =
"\t<li>" . $message->parse() .
"</li>\n";
418 } elseif ( $warning ==
'was-deleted' ) {
419 # If the file existed before and was deleted, warn the user of this
423 $this->
msg(
'deletionlog' )->text(),
427 'page' => Title::makeTitle(
NS_FILE,
$args )->getPrefixedText(),
430 $msg =
"\t<li>" . $this->
msg(
'filewasdeleted' )->rawParams( $llink )->parse() .
"</li>\n";
431 } elseif ( $warning ==
'duplicate' ) {
433 } elseif ( $warning ==
'duplicate-archive' ) {
434 if (
$args ===
'' ) {
435 $msg =
"\t<li>" . $this->
msg(
'file-deleted-duplicate-notitle' )->parse()
438 $msg =
"\t<li>" . $this->
msg(
'file-deleted-duplicate',
439 Title::makeTitle(
NS_FILE,
$args )->getPrefixedText() )->parse()
443 if (
$args ===
true ) {
445 } elseif ( !is_array(
$args ) ) {
448 $msg =
"\t<li>" . $this->
msg( $warning,
$args )->parse() .
"</li>\n";
450 $warningHtml .= $msg;
452 $warningHtml .=
"</ul></div>\n";
453 $warningHtml .= $this->
msg( $uploadWarning )->parseAsBlock();
455 $form = $this->
getUploadForm( $warningHtml, $sessionKey,
true );
456 $form->setSubmitText( $this->
msg(
'upload-tryagain' )->text() );
458 'name' =>
'wpUploadIgnoreWarning',
459 'value' => $this->
msg(
'ignorewarning' )->text()
462 'name' =>
'wpCancelUpload',
463 'value' => $this->
msg(
'reuploaddesc' )->text()
468 # Indicate that we showed a form
478 $message =
'<h2>' . $this->
msg(
'uploadwarning' )->escaped() .
"</h2>\n" .
479 '<div class="error">' . $message .
"</div>\n";
489 $status = $this->mUpload->fetchFile();
490 if ( !$status->isOK() ) {
492 $status->getWikiText(
false,
false, $this->getLanguage() )
499 if ( !Hooks::run(
'UploadForm:BeforeProcessing', [ &$upload ] ) ) {
500 wfDebug(
"Hook 'UploadForm:BeforeProcessing' broke processing the file.\n" );
510 $details = $this->mUpload->verifyUpload();
518 $permErrors = $this->mUpload->verifyTitlePermissions( $this->
getUser() );
519 if ( $permErrors !==
true ) {
520 $code = array_shift( $permErrors[0] );
526 $this->mLocalFile = $this->mUpload->getLocalFile();
529 if ( !$this->mIgnoreWarning ) {
530 $warnings = $this->mUpload->checkWarnings();
539 $this->
msg(
'actionthrottledtext' )->escaped()
545 if ( !$this->mForReUpload ) {
547 $this->mCopyrightStatus, $this->mCopyrightSource, $this->
getConfig() );
552 $changeTags = $this->
getRequest()->getVal(
'wpChangeTags' );
553 if ( is_null( $changeTags ) || $changeTags ===
'' ) {
556 $changeTags = array_filter( array_map(
'trim', explode(
',', $changeTags ) ) );
561 $changeTags, $this->
getUser() );
562 if ( !$changeTagsStatus->isOK() ) {
564 $changeTagsStatus->getWikiText(
false,
false, $this->getLanguage() )
571 $status = $this->mUpload->performUpload(
579 if ( !$status->isGood() ) {
582 $status->getWikiText(
false,
false, $this->getLanguage() )
590 $this->mUploadSuccessful =
true;
593 Hooks::run(
'SpecialUploadComplete', [ &$upload ] );
594 $this->
getOutput()->redirect( $this->mLocalFile->getTitle()->getFullURL() );
609 if ( $config ===
null ) {
610 wfDebug( __METHOD__ .
' called without a Config instance passed to it' );
611 $config = MediaWikiServices::getInstance()->getMainConfig();
615 $forceUIMsgAsContentMsg = (array)$config->get(
'ForceUIMsgAsContentMsg' );
620 foreach ( [
'license-header',
'filedesc',
'filestatus',
'filesource' ] as $msgName ) {
621 if ( in_array( $msgName, $forceUIMsgAsContentMsg ) ) {
622 $msg[$msgName] =
"{{int:$msgName}}";
624 $msg[$msgName] =
wfMessage( $msgName )->inContentLanguage()->text();
629 if ( $license !==
'' ) {
630 $licenseText =
'== ' . $msg[
'license-header'] .
" ==\n{{" . $license .
"}}\n";
633 $pageText = $comment .
"\n";
634 $headerText =
'== ' . $msg[
'filedesc'] .
' ==';
635 if ( $comment !==
'' && strpos( $comment, $headerText ) ===
false ) {
637 $pageText = $headerText .
"\n" . $pageText;
640 if ( $config->get(
'UseCopyrightUpload' ) ) {
641 $pageText .=
'== ' . $msg[
'filestatus'] .
" ==\n" . $copyStatus .
"\n";
642 $pageText .= $licenseText;
643 $pageText .=
'== ' . $msg[
'filesource'] .
" ==\n" .
$source;
645 $pageText .= $licenseText;
649 Hooks::run(
'UploadForm:getInitialPageText', [ &$pageText, $msg, $config ] );
667 if ( $this->
getUser()->getOption(
'watchdefault' ) ) {
672 $desiredTitleObj = Title::makeTitleSafe(
NS_FILE, $this->mDesiredDestName );
673 if ( $desiredTitleObj instanceof
Title && $this->
getUser()->isWatched( $desiredTitleObj ) ) {
678 $local = MediaWikiServices::getInstance()->getRepoGroup()->getLocalRepo()
679 ->newFile( $this->mDesiredDestName );
680 if ( $local && $local->exists() ) {
686 return $this->
getUser()->getOption(
'watchcreations' ) ||
687 $this->
getUser()->getOption(
'watchuploads' );
698 switch ( $details[
'status'] ) {
705 $details[
'filtered'] )->parse() );
725 $msg = $this->
msg(
'filetype-banned-type' );
726 if ( isset( $details[
'blacklistedExt'] ) ) {
727 $msg->params( $this->
getLanguage()->commaList( $details[
'blacklistedExt'] ) );
729 $msg->params( $details[
'finalExt'] );
731 $extensions = array_unique( $this->
getConfig()->
get(
'FileExtensions' ) );
732 $msg->params( $this->
getLanguage()->commaList( $extensions ),
733 count( $extensions ) );
738 if ( isset( $details[
'blacklistedExt'] ) ) {
739 $msg->params( count( $details[
'blacklistedExt'] ) );
747 unset( $details[
'status'] );
748 $code = array_shift( $details[
'details'] );
752 if ( is_array( $details[
'error'] ) ) { # allow hooks to
return error details in an array
753 $args = $details[
'error'];
754 $error = array_shift(
$args );
756 $error = $details[
'error'];
763 throw new MWException( __METHOD__ .
": Unknown value `{$details['status']}`" );
776 $success = $this->mUpload->unsaveUploadedFile();
779 $this->
msg(
'filedeleteerror' )
780 ->params( $this->mUpload->getTempPath() )
804 $file = $exists[
'file'];
805 $filename =
$file->getTitle()->getPrefixedText();
808 if ( $exists[
'warning'] ==
'exists' ) {
810 $warnMsg =
wfMessage(
'fileexists', $filename );
811 } elseif ( $exists[
'warning'] ==
'page-exists' ) {
813 $warnMsg =
wfMessage(
'filepageexists', $filename );
814 } elseif ( $exists[
'warning'] ==
'exists-normalized' ) {
815 $warnMsg =
wfMessage(
'fileexists-extension', $filename,
816 $exists[
'normalizedFile']->
getTitle()->getPrefixedText() );
817 } elseif ( $exists[
'warning'] ==
'thumb' ) {
819 $warnMsg =
wfMessage(
'fileexists-thumbnail-yes',
820 $exists[
'thumbFile']->
getTitle()->getPrefixedText(), $filename );
821 } elseif ( $exists[
'warning'] ==
'thumb-name' ) {
823 $name =
$file->getName();
824 $badPart = substr( $name, 0, strpos( $name,
'-' ) + 1 );
825 $warnMsg =
wfMessage(
'file-thumbnail-no', $badPart );
826 } elseif ( $exists[
'warning'] ==
'bad-prefix' ) {
827 $warnMsg =
wfMessage(
'filename-bad-prefix', $exists[
'prefix'] );
830 return $warnMsg ? $warnMsg->title(
$file->getTitle() )->parse() :
'';
844 $gallery->setShowBytes(
false );
845 $gallery->setShowDimensions(
false );
846 foreach ( $dupes as
$file ) {
847 $gallery->add(
$file->getTitle() );
851 $this->
msg(
'file-exists-duplicate' )->numParams( count( $dupes ) )->parse() .
852 $gallery->toHTML() .
"</li>\n";
869 return $bitmapHandler->autoRotateEnabled();
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
Generic handler for bitmap images.
An IContextSource implementation which will inherit context from another source but allow individual ...
An error page which can definitely be safely rendered using the OutputPage.
WebRequest clone which takes values from a provided array.
static factory( $mode=false, IContextSource $context=null)
Get a new image gallery.
Class to represent a local file in the wiki's own database.
static showLogExtract(&$out, $types=[], $page='', $user='', $param=[])
Show log extract.
Show an error when a user tries to do something they do not have the necessary permissions for.
Parent class for all special pages.
outputHeader( $summaryMessageKey='')
Outputs a summary message on top of special pages Per default the message key is the canonical name o...
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!
getOutput()
Get the OutputPage being used for this instance.
getUser()
Shortcut to get the User executing this instance.
static getTitleFor( $name, $subpage=false, $fragment='')
Get a localised Title object for a specified special page name If you don't need a full Title object,...
getContext()
Gets the context this SpecialPage is executed in.
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
getConfig()
Shortcut to get main config object.
getRequest()
Get the WebRequest being used for this instance.
checkReadOnly()
If the wiki is currently in readonly mode, throws a ReadOnlyError.
getPageTitle( $subpage=false)
Get a self-referential title object.
useTransactionalTimeLimit()
Call wfTransactionalTimeLimit() if this request was POSTed.
getLanguage()
Shortcut to get user's language.
addHelpLink( $to, $overrideBaseUrl=false)
Adds help link with an icon via page indicators.
MediaWiki Linker LinkRenderer null $linkRenderer
Form for handling uploads and special page.
processVerificationError( $details)
Provides output to the user for a result of UploadBase::verifyUpload.
showViewDeletedLinks()
Shows the "view X deleted revivions link"".
getWatchCheck()
See if we should check the 'watch this page' checkbox on the form based on the user's preferences and...
loadRequest()
Initialize instance variables from request and create an Upload handler.
static getInitialPageText( $comment='', $license='', $copyStatus='', $source='', Config $config=null)
Get the initial image page text based on a comment and optional file status information.
showUploadWarning( $warnings)
Stashes the upload, shows the main form, but adds a "continue anyway button".
$uploadFormTextTop
Text injection points for hooks not using HTMLForm.
bool $mCancelUpload
The user clicked "Cancel and return to upload form" button.
unsaveUploadedFile()
Remove a temporarily kept file stashed by saveTempUploadedFile().
userCanExecute(User $user)
This page can be shown if uploading is enabled.
static getExistsWarning( $exists)
Functions for formatting warnings.
string $mDesiredDestName
User input variables from the "description" section.
showRecoverableUploadError( $message)
Stashes the upload and shows the main upload form.
$mDestWarningAck
Hidden variables.
getDupeWarning( $dupes)
Construct a warning and a gallery from an array of duplicate files.
showUploadForm( $form)
Show the main upload form.
__construct( $request=null)
Get data POSTed through the form and assign them to the object.
WebRequest FauxRequest $mRequest
Misc variables.
processUpload()
Do the upload.
bool $mUploadSuccessful
Subclasses can use this to determine whether a file was uploaded.
$uploadFormTextAfterSummary
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
getUploadForm( $message='', $sessionKey='', $hideIgnoreWarning=false)
Get an UploadForm instance with title and text properly set.
doesWrites()
Indicates whether this special page may perform database writes.
bool $mForReUpload
The user followed an "overwrite this file" link.
$mIgnoreWarning
User input variables from the root section.
showUploadError( $message)
Show the upload form with error message, but do not stash the file.
static rotationEnabled()
Should we rotate images in the preview on Special:Upload.
Represents a title within MediaWiki.
exists( $flags=0)
Check if page exists.
UploadBase and subclasses are the backend of MediaWiki's file uploads.
static createFromRequest(&$request, $type=null)
Create a form of UploadBase depending on wpSourceType and initializes it.
static isEnabled()
Returns true if uploads are enabled.
static isAllowed(UserIdentity $user)
Returns true if the user can use this upload module or else a string identifying the missing permissi...
const WINDOWS_NONASCII_FILENAME
static isThrottled( $user)
Returns true if the user has surpassed the upload rate limit, false otherwise.
const MIN_LENGTH_PARTNAME
Implements uploading from previously stored file.
Show an error when the user tries to do something whilst blocked.
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
The WebRequest class encapsulates getting at data passed in the URL or via a POSTed form stripping il...
Interface for configuration instances.
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.