From d9022f63880ce039446fba8364f68e656b7bf4cb Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Thu, 3 May 2012 13:01:35 +0200 Subject: Update to MediaWiki 1.19.0 --- includes/specials/SpecialUpload.php | 176 ++++++++++++++++-------------------- 1 file changed, 78 insertions(+), 98 deletions(-) (limited to 'includes/specials/SpecialUpload.php') diff --git a/includes/specials/SpecialUpload.php b/includes/specials/SpecialUpload.php index 33013e08..d6a76d02 100644 --- a/includes/specials/SpecialUpload.php +++ b/includes/specials/SpecialUpload.php @@ -35,11 +35,7 @@ class SpecialUpload extends SpecialPage { * @param $request WebRequest : data posted. */ public function __construct( $request = null ) { - global $wgRequest; - parent::__construct( 'Upload', 'upload' ); - - $this->loadRequest( is_null( $request ) ? $wgRequest : $request ); } /** Misc variables **/ @@ -83,13 +79,9 @@ class SpecialUpload extends SpecialPage { /** * Initialize instance variables from request and create an Upload handler - * - * @param $request WebRequest: the request to extract variables from */ - protected function loadRequest( $request ) { - global $wgUser; - - $this->mRequest = $request; + protected function loadRequest() { + $this->mRequest = $request = $this->getRequest(); $this->mSourceType = $request->getVal( 'wpSourceType', 'file' ); $this->mUpload = UploadBase::createFromRequest( $request ); $this->mUploadClicked = $request->wasPosted() @@ -108,7 +100,7 @@ class SpecialUpload extends SpecialPage { $this->mDestWarningAck = $request->getText( 'wpDestFileWarningAck' ); $this->mIgnoreWarning = $request->getCheck( 'wpIgnoreWarning' ) || $request->getCheck( 'wpUploadIgnoreWarning' ); - $this->mWatchthis = $request->getBool( 'wpWatchthis' ) && $wgUser->isLoggedIn(); + $this->mWatchthis = $request->getBool( 'wpWatchthis' ) && $this->getUser()->isLoggedIn(); $this->mCopyrightStatus = $request->getText( 'wpUploadCopyStatus' ); $this->mCopyrightSource = $request->getText( 'wpUploadSource' ); @@ -119,7 +111,7 @@ class SpecialUpload extends SpecialPage { // If it was posted check for the token (no remote POST'ing with user credentials) $token = $request->getVal( 'wpEditToken' ); - $this->mTokenOk = $wgUser->matchEditToken( $token ); + $this->mTokenOk = $this->getUser()->matchEditToken( $token ); $this->uploadFormTextTop = ''; $this->uploadFormTextAfterSummary = ''; @@ -141,42 +133,30 @@ class SpecialUpload extends SpecialPage { * Special page entry point */ public function execute( $par ) { - global $wgUser, $wgOut; - $this->setHeaders(); $this->outputHeader(); # Check uploading enabled if( !UploadBase::isEnabled() ) { - $wgOut->showErrorPage( 'uploaddisabled', 'uploaddisabledtext' ); - return; + throw new ErrorPageError( 'uploaddisabled', 'uploaddisabledtext' ); } # Check permissions - global $wgGroupPermissions; - $permissionRequired = UploadBase::isAllowed( $wgUser ); + $user = $this->getUser(); + $permissionRequired = UploadBase::isAllowed( $user ); if( $permissionRequired !== true ) { - 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( $permissionRequired ); - } - return; + throw new PermissionsError( $permissionRequired ); } # Check blocks - if( $wgUser->isBlocked() ) { - $wgOut->blockedPage(); - return; + if( $user->isBlocked() ) { + throw new UserBlockedError( $user->mBlock ); } # Check whether we actually want to allow changing stuff - if( wfReadOnly() ) { - $wgOut->readOnlyPage(); - return; - } + $this->checkReadOnly(); + + $this->loadRequest(); # Unsave the temporary file in case this was a cancelled upload if ( $this->mCancelUpload ) { @@ -190,8 +170,7 @@ class SpecialUpload extends SpecialPage { if ( $this->mTokenOk && !$this->mCancelUpload && ( $this->mUpload && $this->mUploadClicked ) - ) - { + ) { $this->processUpload(); } else { # Backwards compatibility hook @@ -199,8 +178,6 @@ class SpecialUpload extends SpecialPage { wfDebug( "Hook 'UploadForm:initial' broke output of the upload form" ); return; } - - $this->showUploadForm( $this->getUploadForm() ); } @@ -224,8 +201,7 @@ class SpecialUpload extends SpecialPage { if ( $form instanceof HTMLForm ) { $form->show(); } else { - global $wgOut; - $wgOut->addHTML( $form ); + $this->getOutput()->addHTML( $form ); } } @@ -239,8 +215,6 @@ class SpecialUpload extends SpecialPage { * @return UploadForm */ protected function getUploadForm( $message = '', $sessionKey = '', $hideIgnoreWarning = false ) { - global $wgOut; - # Initialize form $form = new UploadForm( array( 'watch' => $this->getWatchCheck(), @@ -253,15 +227,14 @@ class SpecialUpload extends SpecialPage { 'texttop' => $this->uploadFormTextTop, 'textaftersummary' => $this->uploadFormTextAfterSummary, 'destfile' => $this->mDesiredDestName, - ) ); + ), $this->getContext() ); $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' ) ); } @@ -271,7 +244,7 @@ class SpecialUpload extends SpecialPage { $delNotice = ''; // empty by default if ( $desiredTitleObj instanceof Title && !$desiredTitleObj->exists() ) { LogEventsList::showLogExtract( $delNotice, array( 'delete', 'move' ), - $desiredTitleObj->getPrefixedText(), + $desiredTitleObj, '', array( 'lim' => 10, 'conds' => array( "log_action != 'revision'" ), 'showIfEmpty' => false, @@ -291,33 +264,31 @@ class SpecialUpload extends SpecialPage { $uploadFooter = wfMessage( 'uploadfooter' ); if ( !$uploadFooter->isDisabled() ) { $form->addPostText( '\n" ); + . $this->getOutput()->parse( $uploadFooter->plain() ) . "\n" ); } return $form; - } /** * Shows the "view X deleted revivions link"" */ protected function showViewDeletedLinks() { - global $wgOut, $wgUser; - $title = Title::makeTitleSafe( NS_FILE, $this->mDesiredDestName ); + $user = $this->getUser(); // Show a subtitle link to deleted revisions (to sysops et al only) if( $title instanceof Title ) { $count = $title->isDeleted(); - if ( $count > 0 && $wgUser->isAllowed( 'deletedhistory' ) ) { + if ( $count > 0 && $user->isAllowed( 'deletedhistory' ) ) { $link = wfMsgExt( - $wgUser->isAllowed( 'delete' ) ? 'thisisdeleted' : 'viewdeleted', + $user->isAllowed( 'delete' ) ? 'thisisdeleted' : 'viewdeleted', array( 'parse', 'replaceafter' ), - $this->getSkin()->linkKnown( + Linker::linkKnown( SpecialPage::getTitleFor( 'Undelete', $title->getPrefixedText() ), wfMsgExt( 'restorelink', array( 'parsemag', 'escape' ), $count ) ) ); - $wgOut->addHTML( "
{$link}
" ); + $this->getOutput()->addHTML( "
{$link}
" ); } } } @@ -402,7 +373,7 @@ class SpecialUpload extends SpecialPage { /** * Show the upload form with error message, but do not stash the file. * - * @param $message HTML string + * @param $message string HTML string */ protected function showUploadError( $message ) { $message = '

' . wfMsgHtml( 'uploadwarning' ) . "

\n" . @@ -415,12 +386,10 @@ class SpecialUpload extends SpecialPage { * Checks are made in SpecialUpload::execute() */ protected function processUpload() { - global $wgUser, $wgOut; - // Fetch the file if required $status = $this->mUpload->fetchFile(); if( !$status->isOK() ) { - $this->showUploadError( $wgOut->parse( $status->getWikiText() ) ); + $this->showUploadError( $this->getOutput()->parse( $status->getWikiText() ) ); return; } @@ -442,7 +411,7 @@ class SpecialUpload extends SpecialPage { } // Verify permissions for this title - $permErrors = $this->mUpload->verifyTitlePermissions( $wgUser ); + $permErrors = $this->mUpload->verifyTitlePermissions( $this->getUser() ); if( $permErrors !== true ) { $code = array_shift( $permErrors[0] ); $this->showRecoverableUploadError( wfMsgExt( $code, @@ -467,25 +436,31 @@ class SpecialUpload extends SpecialPage { } else { $pageText = false; } - $status = $this->mUpload->performUpload( $this->mComment, $pageText, $this->mWatchthis, $wgUser ); + $status = $this->mUpload->performUpload( $this->mComment, $pageText, $this->mWatchthis, $this->getUser() ); if ( !$status->isGood() ) { - $this->showUploadError( $wgOut->parse( $status->getWikiText() ) ); + $this->showUploadError( $this->getOutput()->parse( $status->getWikiText() ) ); return; } // Success, redirect to description page $this->mUploadSuccessful = true; wfRunHooks( 'SpecialUploadComplete', array( &$this ) ); - $wgOut->redirect( $this->mLocalFile->getTitle()->getFullURL() ); + $this->getOutput()->redirect( $this->mLocalFile->getTitle()->getFullURL() ); } /** * Get the initial image page text based on a comment and optional file status information + * @param $comment string + * @param $license string + * @param $copyStatus string + * @param $source string + * @return string */ public static function getInitialPageText( $comment = '', $license = '', $copyStatus = '', $source = '' ) { global $wgUseCopyrightUpload, $wgForceUIMsgAsContentMsg; $wgForceUIMsgAsContentMsg = (array) $wgForceUIMsgAsContentMsg; + $msg = array(); /* These messages are transcluded into the actual text of the description page. * Thus, forcing them as content messages makes the upload to produce an int: template * instead of hardcoding it there in the uploader language. @@ -529,10 +504,10 @@ class SpecialUpload extends SpecialPage { * * Note that the page target can be changed *on the form*, so our check * state can get out of sync. + * @return Bool|String */ protected function getWatchCheck() { - global $wgUser; - if( $wgUser->getOption( 'watchdefault' ) ) { + if( $this->getUser()->getOption( 'watchdefault' ) ) { // Watch all edits! return true; } @@ -544,7 +519,7 @@ class SpecialUpload extends SpecialPage { return $local->getTitle()->userIsWatching(); } else { // New page should get watched if that's our option. - return $wgUser->getOption( 'watchcreations' ); + return $this->getUser()->getOption( 'watchcreations' ); } } @@ -555,7 +530,7 @@ class SpecialUpload extends SpecialPage { * @param $details Array: result of UploadBase::verifyUpload */ protected function processVerificationError( $details ) { - global $wgFileExtensions, $wgLang; + global $wgFileExtensions; switch( $details['status'] ) { @@ -567,6 +542,9 @@ class SpecialUpload extends SpecialPage { $this->showRecoverableUploadError( wfMsgExt( 'illegalfilename', 'parseinline', $details['filtered'] ) ); break; + case UploadBase::FILENAME_TOO_LONG: + $this->showRecoverableUploadError( wfMsgHtml( 'filename-toolong' ) ); + break; case UploadBase::FILETYPE_MISSING: $this->showRecoverableUploadError( wfMsgExt( 'filetype-missing', 'parseinline' ) ); @@ -586,11 +564,11 @@ class SpecialUpload extends SpecialPage { case UploadBase::FILETYPE_BADTYPE: $msg = wfMessage( 'filetype-banned-type' ); if ( isset( $details['blacklistedExt'] ) ) { - $msg->params( $wgLang->commaList( $details['blacklistedExt'] ) ); + $msg->params( $this->getLanguage()->commaList( $details['blacklistedExt'] ) ); } else { $msg->params( $details['finalExt'] ); } - $msg->params( $wgLang->commaList( $wgFileExtensions ), + $msg->params( $this->getLanguage()->commaList( $wgFileExtensions ), count( $wgFileExtensions ) ); // Add PLURAL support for the first parameter. This results @@ -631,13 +609,12 @@ class SpecialUpload extends SpecialPage { * @return Boolean: success */ protected function unsaveUploadedFile() { - global $wgOut; if ( !( $this->mUpload instanceof UploadFromStash ) ) { return true; } $success = $this->mUpload->unsaveUploadedFile(); if ( !$success ) { - $wgOut->showFileDeleteError( $this->mUpload->getTempPath() ); + $this->getOutput()->showFileDeleteError( $this->mUpload->getTempPath() ); return false; } else { return true; @@ -654,8 +631,6 @@ class SpecialUpload extends SpecialPage { * @return String: empty string if there is no warning or an HTML fragment */ public static function getExistsWarning( $exists ) { - global $wgUser; - if ( !$exists ) { return ''; } @@ -664,8 +639,6 @@ class SpecialUpload extends SpecialPage { $filename = $file->getTitle()->getPrefixedText(); $warning = ''; - $sk = $wgUser->getSkin(); - if( $exists['warning'] == 'exists' ) { // Exact match $warning = wfMsgExt( 'fileexists', 'parseinline', $filename ); @@ -689,7 +662,7 @@ class SpecialUpload extends SpecialPage { } elseif ( $exists['warning'] == 'was-deleted' ) { # If the file existed before and was deleted, warn the user of this $ltitle = SpecialPage::getTitleFor( 'Log' ); - $llink = $sk->linkKnown( + $llink = Linker::linkKnown( $ltitle, wfMsgHtml( 'deletionlog' ), array(), @@ -730,10 +703,12 @@ class SpecialUpload extends SpecialPage { /** * Construct a warning and a gallery from an array of duplicate files. + * @param $dupes array + * @return string */ public static function getDupeWarning( $dupes ) { + global $wgOut; if( $dupes ) { - global $wgOut; $msg = ''; foreach( $dupes as $file ) { $title = $file->getTitle(); @@ -771,7 +746,9 @@ class UploadForm extends HTMLForm { protected $mMaxFileSize = array(); - public function __construct( $options = array() ) { + protected $mMaxUploadSize = array(); + + public function __construct( array $options = array(), IContextSource $context = null ) { $this->mWatch = !empty( $options['watch'] ); $this->mForReUpload = !empty( $options['forreupload'] ); $this->mSessionKey = isset( $options['sessionkey'] ) @@ -795,7 +772,7 @@ class UploadForm extends HTMLForm { + $this->getOptionsSection(); wfRunHooks( 'UploadFormInitDescriptor', array( &$descriptor ) ); - parent::__construct( $descriptor, 'upload' ); + parent::__construct( $descriptor, $context, 'upload' ); # Set some form properties $this->setSubmitText( wfMsg( 'uploadbtn' ) ); @@ -821,8 +798,6 @@ class UploadForm extends HTMLForm { * @return Array: descriptor array */ protected function getSourceSection() { - global $wgLang, $wgUser, $wgRequest; - if ( $this->mSessionKey ) { return array( 'SessionKey' => array( @@ -836,9 +811,9 @@ class UploadForm extends HTMLForm { ); } - $canUploadByUrl = UploadFromUrl::isEnabled() && $wgUser->isAllowed( 'upload_by_url' ); + $canUploadByUrl = UploadFromUrl::isEnabled() && UploadFromUrl::isAllowed( $this->getUser() ); $radio = $canUploadByUrl; - $selectedSourceType = strtolower( $wgRequest->getText( 'wpSourceType', 'File' ) ); + $selectedSourceType = strtolower( $this->getRequest()->getText( 'wpSourceType', 'File' ) ); $descriptor = array(); if ( $this->mTextTop ) { @@ -868,7 +843,7 @@ class UploadForm extends HTMLForm { 'radio' => &$radio, 'help' => wfMsgExt( 'upload-maxfilesize', array( 'parseinline', 'escapenoentities' ), - $wgLang->formatSize( $this->mMaxUploadSize['file'] ) + $this->getContext()->getLanguage()->formatSize( $this->mMaxUploadSize['file'] ) ) . ' ' . wfMsgHtml( 'upload_source_file' ), 'checked' => $selectedSourceType == 'file', ); @@ -883,7 +858,7 @@ class UploadForm extends HTMLForm { 'radio' => &$radio, 'help' => wfMsgExt( 'upload-maxfilesize', array( 'parseinline', 'escapenoentities' ), - $wgLang->formatSize( $this->mMaxUploadSize['url'] ) + $this->getContext()->getLanguage()->formatSize( $this->mMaxUploadSize['url'] ) ) . ' ' . wfMsgHtml( 'upload_source_url' ), 'checked' => $selectedSourceType == 'url', ); @@ -907,7 +882,7 @@ class UploadForm extends HTMLForm { protected function getExtensionsMessage() { # Print a list of allowed file extensions, if so configured. We ignore # MIME type here, it's incomprehensible to most people and too long. - global $wgLang, $wgCheckFileExtensions, $wgStrictFileExtensions, + global $wgCheckFileExtensions, $wgStrictFileExtensions, $wgFileExtensions, $wgFileBlacklist; if( $wgCheckFileExtensions ) { @@ -915,16 +890,16 @@ class UploadForm extends HTMLForm { # Everything not permitted is banned $extensionsList = '
' . - wfMsgExt( 'upload-permitted', 'parse', $wgLang->commaList( $wgFileExtensions ) ) . + wfMsgExt( 'upload-permitted', 'parse', $this->getContext()->getLanguage()->commaList( $wgFileExtensions ) ) . "
\n"; } else { # We have to list both preferred and prohibited $extensionsList = '
' . - wfMsgExt( 'upload-preferred', 'parse', $wgLang->commaList( $wgFileExtensions ) ) . + wfMsgExt( 'upload-preferred', 'parse', $this->getContext()->getLanguage()->commaList( $wgFileExtensions ) ) . "
\n" . '
' . - wfMsgExt( 'upload-prohibited', 'parse', $wgLang->commaList( $wgFileBlacklist ) ) . + wfMsgExt( 'upload-prohibited', 'parse', $this->getContext()->getLanguage()->commaList( $wgFileBlacklist ) ) . "
\n"; } } else { @@ -941,8 +916,6 @@ class UploadForm extends HTMLForm { * @return Array: descriptor array */ protected function getDescriptionSection() { - global $wgUser; - if ( $this->mSessionKey ) { $stash = RepoGroup::singleton()->getLocalRepo()->getUploadStash(); try { @@ -982,7 +955,7 @@ class UploadForm extends HTMLForm { ? 'filereuploadsummary' : 'fileuploadsummary', 'default' => $this->mComment, - 'cols' => intval( $wgUser->getOption( 'cols' ) ), + 'cols' => intval( $this->getUser()->getOption( 'cols' ) ), 'rows' => 8, ) ); @@ -1041,16 +1014,15 @@ class UploadForm extends HTMLForm { * @return Array: descriptor array */ protected function getOptionsSection() { - global $wgUser; - - if ( $wgUser->isLoggedIn() ) { + $user = $this->getUser(); + if ( $user->isLoggedIn() ) { $descriptor = array( 'Watchthis' => array( 'type' => 'check', 'id' => 'wpWatchthis', 'label-message' => 'watchthisupload', 'section' => 'options', - 'default' => $wgUser->getOption( 'watchcreations' ), + 'default' => $user->getOption( 'watchcreations' ), ) ); } @@ -1089,11 +1061,10 @@ class UploadForm extends HTMLForm { } /** - * Add upload JS to $wgOut + * Add upload JS to the OutputPage */ protected function addUploadJS() { global $wgUseAjax, $wgAjaxUploadDestCheck, $wgAjaxLicensePreview, $wgEnableAPI, $wgStrictFileExtensions; - global $wgOut; $useAjaxDestCheck = $wgUseAjax && $wgAjaxUploadDestCheck; $useAjaxLicensePreview = $wgUseAjax && $wgAjaxLicensePreview && $wgEnableAPI; @@ -1112,10 +1083,11 @@ class UploadForm extends HTMLForm { 'wgMaxUploadSize' => $this->mMaxUploadSize, ); - $wgOut->addScript( Skin::makeVariablesScript( $scriptVars ) ); + $out = $this->getOutput(); + $out->addJsConfigVars( $scriptVars ); - $wgOut->addModules( array( + $out->addModules( array( 'mediawiki.action.edit', // For support 'mediawiki.legacy.upload', // Old form stuff... 'mediawiki.special.upload', // Newer extras for thumbnail preview. @@ -1137,6 +1109,11 @@ class UploadForm extends HTMLForm { * A form field that contains a radio box in the label */ class UploadSourceField extends HTMLTextField { + + /** + * @param $cellAttributes array + * @return string + */ function getLabelHtml( $cellAttributes = array() ) { $id = "wpSourceType{$this->mParams['upload-type']}"; $label = Html::rawElement( 'label', array( 'for' => $id ), $this->mLabel ); @@ -1157,6 +1134,9 @@ class UploadSourceField extends HTMLTextField { return Html::rawElement( 'td', array( 'class' => 'mw-label' ) + $cellAttributes, $label ); } + /** + * @return int + */ function getSize() { return isset( $this->mParams['size'] ) ? $this->mParams['size'] -- cgit v1.2.3-54-g00ecf