loadRequest( is_null( $request ) ? $wgRequest : $request ); } /** Misc variables **/ protected $mRequest; // The WebRequest or FauxRequest this form is supposed to handle protected $mSourceType; protected $mUpload; protected $mLocalFile; protected $mUploadClicked; /** User input variables from the "description" section **/ protected $mDesiredDestName; // The requested target file name protected $mComment; protected $mLicense; /** User input variables from the root section **/ protected $mIgnoreWarning; protected $mWatchThis; protected $mCopyrightStatus; protected $mCopyrightSource; /** Hidden variables **/ protected $mForReUpload; // The user followed an "overwrite this file" link protected $mCancelUpload; // The user clicked "Cancel and return to upload form" button protected $mTokenOk; /** * Initialize instance variables from request and create an Upload handler * * @param WebRequest $request The request to extract variables from */ protected function loadRequest( $request ) { global $wgUser; $this->mRequest = $request; $this->mSourceType = $request->getVal( 'wpSourceType', 'file' ); $this->mUpload = UploadBase::createFromRequest( $request ); $this->mUploadClicked = $request->getCheck( 'wpUpload' ) && $request->wasPosted(); // Guess the desired name from the filename if not provided $this->mDesiredDestName = $request->getText( 'wpDestFile' ); if( !$this->mDesiredDestName ) $this->mDesiredDestName = $request->getText( 'wpUploadFile' ); $this->mComment = $request->getText( 'wpUploadDescription' ); $this->mLicense = $request->getText( 'wpLicense' ); $this->mIgnoreWarning = $request->getCheck( 'wpIgnoreWarning' ); $this->mWatchthis = $request->getBool( 'wpWatchthis' ); $this->mCopyrightStatus = $request->getText( 'wpUploadCopyStatus' ); $this->mCopyrightSource = $request->getText( 'wpUploadSource' ); $this->mForReUpload = $request->getBool( 'wpForReUpload' ); // updating a file $this->mCancelUpload = $request->getCheck( 'wpCancelUpload' ) || $request->getCheck( 'wpReUpload' ); // b/w compat // If it was posted check for the token (no remote POST'ing with user credentials) $token = $request->getVal( 'wpEditToken' ); if( $this->mSourceType == 'file' && $token == null ) { // Skip token check for file uploads as that can't be faked via JS... // Some client-side tools don't expect to need to send wpEditToken // with their submissions, as that's new in 1.16. $this->mTokenOk = true; } else { $this->mTokenOk = $wgUser->matchEditToken( $token ); } } /** * This page can be shown if uploading is enabled. * Handle permission checking elsewhere in order to be able to show * custom error messages. * * @param User $user * @return bool */ public function userCanExecute( $user ) { return UploadBase::isEnabled() && parent::userCanExecute( $user ); } /** * Special page entry point */ public function execute() { global $wgUser, $wgOut, $wgRequest; $this->setHeaders(); $this->outputHeader(); # Check uploading enabled if( !UploadBase::isEnabled() ) { $wgOut->showErrorPage( 'uploaddisabled', 'uploaddisabledtext' ); return; } # Check permissions global $wgGroupPermissions; if( !$wgUser->isAllowed( 'upload' ) ) { if( !$wgUser->isLoggedIn() && ( $wgGroupPermissions['user']['upload'] || $wgGroupPermissions['autoconfirmed']['upload'] ) ) { // Custom message if logged-in users without any special rights can upload $wgOut->showErrorPage( 'uploadnologin', 'uploadnologintext' ); } else { $wgOut->permissionRequired( 'upload' ); } return; } # Check blocks if( $wgUser->isBlocked() ) { $wgOut->blockedPage(); return; } # Check whether we actually want to allow changing stuff if( wfReadOnly() ) { $wgOut->readOnlyPage(); return; } # Unsave the temporary file in case this was a cancelled upload if ( $this->mCancelUpload ) { if ( !$this->unsaveUploadedFile() ) # Something went wrong, so unsaveUploadedFile showed a warning return; } # Process upload or show a form if ( $this->mTokenOk && !$this->mCancelUpload && ( $this->mUpload && $this->mUploadClicked ) ) { $this->processUpload(); } else { $this->showUploadForm( $this->getUploadForm() ); } # Cleanup if ( $this->mUpload ) $this->mUpload->cleanupTempFile(); } /** * Show the main upload form and optionally add the session key to the * output. This hides the source selection. * * @param string $message HTML message to be shown at top of form * @param string $sessionKey Session key of the stashed upload */ protected function showUploadForm( $form ) { # Add links if file was previously deleted if ( !$this->mDesiredDestName ) $this->showViewDeletedLinks(); $form->show(); } /** * Get an UploadForm instance with title and text properly set. * * @param string $message HTML string to add to the form * @param string $sessionKey Session key in case this is a stashed upload * @return UploadForm */ protected function getUploadForm( $message = '', $sessionKey = '' ) { # Initialize form $form = new UploadForm( $this->watchCheck(), $this->mForReUpload, $sessionKey ); $form->setTitle( $this->getTitle() ); # Check the token, but only if necessary if( !$this->mTokenOk && !$this->mCancelUpload && ( $this->mUpload && $this->mUploadClicked ) ) $form->addPreText( wfMsgExt( 'session_fail_preview', 'parseinline' ) ); # Add text to form $form->addPreText( '
' . wfMsgExt( 'uploadtext', 'parse' ) . '
'); # Add upload error message $form->addPreText( $message ); return $form; } /** * TODO: DOCUMENT */ protected function showViewDeletedLinks() { global $wgOut, $wgUser; $title = Title::makeTitleSafe( NS_FILE, $this->mDesiredDestName ); // Show a subtitle link to deleted revisions (to sysops et al only) if( $title instanceof Title && ( $count = $title->isDeleted() ) > 0 && $wgUser->isAllowed( 'deletedhistory' ) ) { $link = wfMsgExt( $wgUser->isAllowed( 'delete' ) ? 'thisisdeleted' : 'viewdeleted', array( 'parse', 'replaceafter' ), $wgUser->getSkin()->linkKnown( SpecialPage::getTitleFor( 'Undelete', $title->getPrefixedText() ), wfMsgExt( 'restorelink', array( 'parsemag', 'escape' ), $count ) ) ); $wgOut->addHTML( "
{$link}
" ); } // Show the relevant lines from deletion log (for still deleted files only) if( $title instanceof Title && $title->isDeletedQuick() && !$title->exists() ) { $this->showDeletionLog( $wgOut, $title->getPrefixedText() ); } } /** * Stashes the upload and shows the main upload form. * * Note: only errors that can be handled by changing the name or * description should be redirected here. It should be assumed that the * file itself is sane and has passed UploadBase::verifyFile. This * essentially means that UploadBase::VERIFICATION_ERROR and * UploadBase::EMPTY_FILE should not be passed here. * * @param string $message HTML message to be passed to mainUploadForm */ protected function recoverableUploadError( $message ) { $sessionKey = $this->mUpload->stashSession(); $message = '

' . wfMsgHtml( 'uploadwarning' ) . "

\n" . '
' . $message . "
\n"; $this->showUploadForm( $this->getUploadForm( $message, $sessionKey ) ); } /** * Stashes the upload, shows the main form, but adds an "continue anyway button" * * @param array $warnings */ protected function uploadWarning( $warnings ) { global $wgUser; $sessionKey = $this->mUpload->stashSession(); $sk = $wgUser->getSkin(); $warningHtml = '

' . wfMsgHtml( 'uploadwarning' ) . "

\n" . '