None of this works and it's been long begging for a mercy kill.
All it does is waste contributor time on updating deprecations
in the dead code. I imagine we wouldn't reuse much of this
code if we're ever going to reimplement it.
Bug: T119336
Change-Id: Ibd26a4bea621857aac77823017e9be9b7dc52cca
auto-creation when 'createaccount' is not granted to all users.
* Deprecated AuthPluginAutoCreate hook in favor of LocalUserCreated.
* Most cookie-handling methods in User are deprecated.
+* $wgAllowAsyncCopyUploads and $CopyUploadAsyncTimeout were removed. This was an
+ experimental feature that has never worked.
=== New features in 1.27 ===
* $wgDataCenterId and $wgDataCenterRoles where added, which will serve as
* action=login transparently allows login using bot passwords. Clients should
merely need to change the username and password used after setting up a bot
password.
+* action=upload no longer understands statuskey, asyncdownload or leavemessage.
=== Action API internal changes in 1.27 ===
* ApiQueryORM removed.
'UploadFromFile' => __DIR__ . '/includes/upload/UploadFromFile.php',
'UploadFromStash' => __DIR__ . '/includes/upload/UploadFromStash.php',
'UploadFromUrl' => __DIR__ . '/includes/upload/UploadFromUrl.php',
- 'UploadFromUrlJob' => __DIR__ . '/includes/jobqueue/jobs/UploadFromUrlJob.php',
'UploadLogFormatter' => __DIR__ . '/includes/logging/UploadLogFormatter.php',
'UploadSourceAdapter' => __DIR__ . '/includes/import/UploadSourceAdapter.php',
'UploadSourceField' => __DIR__ . '/includes/specials/SpecialUpload.php',
*/
$wgAllowCopyUploads = false;
-/**
- * Allow asynchronous copy uploads.
- * This feature is experimental and broken as of r81612.
- */
-$wgAllowAsyncCopyUploads = false;
-
/**
* A list of domains copy uploads can come from
*
*/
$wgCopyUploadTimeout = false;
-/**
- * Different timeout for upload by url when run as a background job
- * This could be useful since when fetching large files via job queue,
- * you may want a different timeout, especially because there is no
- * http request being kept alive.
- *
- * false means fallback to $wgCopyUploadTimeout.
- * @since 1.22
- */
-$wgCopyUploadAsyncTimeout = false;
-
/**
* Max size for uploads, in bytes. If not set to an array, applies to all
* uploads. If set to an array, per upload type maximums can be set, using the
'sendMail' => 'EmaillingJob',
'enotifNotify' => 'EnotifNotifyJob',
'fixDoubleRedirect' => 'DoubleRedirectJob',
- 'uploadFromUrl' => 'UploadFromUrlJob',
'AssembleUploadChunks' => 'AssembleUploadChunksJob',
'PublishStashedFile' => 'PublishStashedFileJob',
'ThumbnailRender' => 'ThumbnailRenderJob',
// chunk or one and only one of the following parameters is needed
if ( !$this->mParams['chunk'] ) {
$this->requireOnlyOneParameter( $this->mParams,
- 'filekey', 'file', 'url', 'statuskey' );
+ 'filekey', 'file', 'url' );
}
// Status report for "upload to stash"/"upload from stash"
return false;
}
- if ( $this->mParams['statuskey'] ) {
- $this->checkAsyncDownloadEnabled();
-
- // Status request for an async upload
- $sessionData = UploadFromUrlJob::getSessionData( $this->mParams['statuskey'] );
- if ( !isset( $sessionData['result'] ) ) {
- $this->dieUsage( 'No result in session data', 'missingresult' );
- }
- if ( $sessionData['result'] == 'Warning' ) {
- $sessionData['warnings'] = $this->transformWarnings( $sessionData['warnings'] );
- $sessionData['sessionkey'] = $this->mParams['statuskey'];
- }
- $this->getResult()->addValue( null, $this->getModuleName(), $sessionData );
-
- return false;
- }
-
// The following modules all require the filename parameter to be set
if ( is_null( $this->mParams['filename'] ) ) {
$this->dieUsageMsg( array( 'missingparam', 'filename' ) );
$this->dieUsageMsg( 'copyuploadbadurl' );
}
- $async = false;
- if ( $this->mParams['asyncdownload'] ) {
- $this->checkAsyncDownloadEnabled();
-
- if ( $this->mParams['leavemessage'] && !$this->mParams['ignorewarnings'] ) {
- $this->dieUsage( 'Using leavemessage without ignorewarnings is not supported',
- 'missing-ignorewarnings' );
- }
-
- if ( $this->mParams['leavemessage'] ) {
- $async = 'async-leavemessage';
- } else {
- $async = 'async';
- }
- }
$this->mUpload = new UploadFromUrl;
$this->mUpload->initialize( $this->mParams['filename'],
- $this->mParams['url'], $async );
+ $this->mParams['url'] );
}
return true;
if ( !$status->isGood() ) {
$error = $status->getErrorsArray();
-
- if ( count( $error ) == 1 && $error[0][0] == 'async' ) {
- // The upload can not be performed right now, because the user
- // requested so
- return array(
- 'result' => 'Queued',
- 'statuskey' => $error[0][1],
- );
- }
-
ApiResult::setIndexedTagName( $error, 'error' );
$this->dieUsage( 'An internal error occurred', 'internal-error', 0, $error );
}
return $result;
}
- /**
- * Checks if asynchronous copy uploads are enabled and throws an error if they are not.
- */
- protected function checkAsyncDownloadEnabled() {
- if ( !$this->getConfig()->get( 'AllowAsyncCopyUploads' ) ) {
- $this->dieUsage( 'Asynchronous copy uploads disabled', 'asynccopyuploaddisabled' );
- }
- }
-
public function mustBePosted() {
return true;
}
),
'async' => false,
- 'asyncdownload' => false,
- 'leavemessage' => false,
- 'statuskey' => null,
'checkstatus' => false,
);
"apihelp-upload-param-offset": "Offset of chunk in bytes.",
"apihelp-upload-param-chunk": "Chunk contents.",
"apihelp-upload-param-async": "Make potentially large file operations asynchronous when possible.",
- "apihelp-upload-param-asyncdownload": "Make fetching a URL asynchronous.",
- "apihelp-upload-param-leavemessage": "If asyncdownload is used, leave a message on the user talk page if finished.",
- "apihelp-upload-param-statuskey": "Fetch the upload status for this file key (upload by URL).",
"apihelp-upload-param-checkstatus": "Only fetch the upload status for the given file key.",
"apihelp-upload-example-url": "Upload from a URL.",
"apihelp-upload-example-filekey": "Complete an upload that failed due to warnings.",
"apihelp-upload-param-offset": "{{doc-apihelp-param|upload|offset}}",
"apihelp-upload-param-chunk": "{{doc-apihelp-param|upload|chunk}}",
"apihelp-upload-param-async": "{{doc-apihelp-param|upload|async}}",
- "apihelp-upload-param-asyncdownload": "{{doc-apihelp-param|upload|asyncdownload}}",
- "apihelp-upload-param-leavemessage": "{{doc-apihelp-param|upload|leavemessage}}",
- "apihelp-upload-param-statuskey": "{{doc-apihelp-param|upload|statuskey}}",
"apihelp-upload-param-checkstatus": "{{doc-apihelp-param|upload|checkstatus}}",
"apihelp-upload-example-url": "{{doc-apihelp-example|upload}}",
"apihelp-upload-example-filekey": "{{doc-apihelp-example|upload}}",
+++ /dev/null
-<?php
-/**
- * Job for asynchronous upload-by-url.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- * http://www.gnu.org/copyleft/gpl.html
- *
- * @file
- * @ingroup JobQueue
- */
-
-/**
- * Job for asynchronous upload-by-url.
- *
- * This job is in fact an interface to UploadFromUrl, which is designed such
- * that it does not require any globals. If it does, fix it elsewhere, do not
- * add globals in here.
- *
- * @ingroup JobQueue
- */
-class UploadFromUrlJob extends Job {
- const SESSION_KEYNAME = 'wsUploadFromUrlJobData';
-
- /** @var UploadFromUrl */
- public $upload;
-
- /** @var User */
- protected $user;
-
- public function __construct( Title $title, array $params ) {
- parent::__construct( 'uploadFromUrl', $title, $params );
- }
-
- public function run() {
- global $wgCopyUploadAsyncTimeout;
- # Initialize this object and the upload object
- $this->upload = new UploadFromUrl();
- $this->upload->initialize(
- $this->title->getText(),
- $this->params['url'],
- false
- );
- $this->user = User::newFromName( $this->params['userName'] );
-
- # Fetch the file
- $opts = array();
- if ( $wgCopyUploadAsyncTimeout ) {
- $opts['timeout'] = $wgCopyUploadAsyncTimeout;
- }
- $status = $this->upload->fetchFile( $opts );
- if ( !$status->isOk() ) {
- $this->leaveMessage( $status );
-
- return true;
- }
-
- # Verify upload
- $result = $this->upload->verifyUpload();
- if ( $result['status'] != UploadBase::OK ) {
- $status = $this->upload->convertVerifyErrorToStatus( $result );
- $this->leaveMessage( $status );
-
- return true;
- }
-
- # Check warnings
- if ( !$this->params['ignoreWarnings'] ) {
- $warnings = $this->upload->checkWarnings();
- if ( $warnings ) {
-
- # Stash the upload
- $key = $this->upload->stashFile( $this->user );
-
- // @todo FIXME: This has been broken for a while.
- // User::leaveUserMessage() does not exist.
- if ( $this->params['leaveMessage'] ) {
- $this->user->leaveUserMessage(
- wfMessage( 'upload-warning-subj' )->text(),
- wfMessage( 'upload-warning-msg',
- $key,
- $this->params['url'] )->text()
- );
- } else {
- $session = MediaWiki\Session\SessionManager::singleton()
- ->getSessionById( $this->params['sessionId'] );
- $this->storeResultInSession( $session, 'Warning',
- 'warnings', $warnings );
- }
-
- return true;
- }
- }
-
- # Perform the upload
- $status = $this->upload->performUpload(
- $this->params['comment'],
- $this->params['pageText'],
- $this->params['watch'],
- $this->user
- );
- $this->leaveMessage( $status );
-
- return true;
- }
-
- /**
- * Leave a message on the user talk page or in the session according to
- * $params['leaveMessage'].
- *
- * @param Status $status
- */
- protected function leaveMessage( $status ) {
- if ( $this->params['leaveMessage'] ) {
- if ( $status->isGood() ) {
- // @todo FIXME: user->leaveUserMessage does not exist.
- $this->user->leaveUserMessage( wfMessage( 'upload-success-subj' )->text(),
- wfMessage( 'upload-success-msg',
- $this->upload->getTitle()->getText(),
- $this->params['url']
- )->text() );
- } else {
- // @todo FIXME: user->leaveUserMessage does not exist.
- $this->user->leaveUserMessage( wfMessage( 'upload-failure-subj' )->text(),
- wfMessage( 'upload-failure-msg',
- $status->getWikiText(),
- $this->params['url']
- )->text() );
- }
- } else {
- $session = MediaWiki\Session\SessionManager::singleton()
- ->getSessionById( $this->params['sessionId'] );
- if ( $status->isOk() ) {
- $this->storeResultInSession( $session, 'Success',
- 'filename', $this->upload->getLocalFile()->getName() );
- } else {
- $this->storeResultInSession( $session, 'Failure',
- 'errors', $status->getErrorsArray() );
- }
- }
- }
-
- /**
- * Store a result in the session data. Note that the caller is responsible
- * for appropriate session_start and session_write_close calls.
- *
- * @param MediaWiki\\Session\\Session|null $session Session to store result into
- * @param string $result The result (Success|Warning|Failure)
- * @param string $dataKey The key of the extra data
- * @param mixed $dataValue The extra data itself
- */
- protected function storeResultInSession(
- MediaWiki\Session\Session $session = null, $result, $dataKey, $dataValue
- ) {
- if ( $session ) {
- $data = self::getSessionData( $session, $this->params['sessionKey'] );
- $data['result'] = $result;
- $data[$dataKey] = $dataValue;
- self::setSessionData( $session, $this->params['sessionKey'], $data );
- } else {
- wfDebug( __METHOD__ . ': Cannot store result in session, session does not exist' );
- }
- }
-
- /**
- * Initialize the session data. Sets the initial result to queued.
- */
- public function initializeSessionData() {
- $session = MediaWiki\Session\SessionManager::getGlobalSession();
- $data = self::getSessionData( $session, $this->params['sessionKey'] );
- $data['result'] = 'Queued';
- self::setSessionData( $session, $this->params['sessionKey'], $data );
- }
-
- /**
- * @param MediaWiki\\Session\\Session $session
- * @param string $key
- * @return mixed
- */
- public static function getSessionData( MediaWiki\Session\Session $session, $key ) {
- $data = $session->get( self::SESSION_KEYNAME );
- if ( !is_array( $data ) || !isset( $data[$key] ) ) {
- self::setSessionData( $session, $key, array() );
- return array();
- }
- return $data[$key];
- }
-
- /**
- * @param MediaWiki\\Session\\Session $session
- * @param string $key
- * @param mixed $value
- */
- public static function setSessionData( MediaWiki\Session\Session $session, $key, $value ) {
- $data = $session->get( self::SESSION_KEYNAME, array() );
- if ( !is_array( $data ) ) {
- $data = array();
- }
- $data[$key] = $value;
- $session->set( self::SESSION_KEYNAME, $data );
- }
-}
* @author Michael Dale
*/
class UploadFromUrl extends UploadBase {
- protected $mAsync, $mUrl;
- protected $mIgnoreWarnings = true;
+ protected $mUrl;
protected $mTempPath, $mTmpHandle;
*
* @param string $name
* @param string $url
- * @param bool|string $async Whether the download should be performed
- * asynchronous. False for synchronous, async or async-leavemessage for
- * asynchronous download.
* @throws MWException
*/
- public function initialize( $name, $url, $async = false ) {
- global $wgAllowAsyncCopyUploads;
-
+ public function initialize( $name, $url ) {
$this->mUrl = $url;
- $this->mAsync = $wgAllowAsyncCopyUploads ? $async : false;
- if ( $async ) {
- throw new MWException( 'Asynchronous copy uploads are no longer possible as of r81612.' );
- }
- $tempPath = $this->mAsync ? null : $this->makeTemporaryFile();
+ $tempPath = $this->makeTemporaryFile();
# File size and removeTempFile will be filled in later
$this->initializePathInfo( $name, $tempPath, 0, false );
}
}
/**
- * Download the file (if not async)
+ * Download the file
*
- * @param array $httpOptions Array of options for MWHttpRequest. Ignored if async.
+ * @param array $httpOptions Array of options for MWHttpRequest.
* This could be used to override the timeout on the http request.
* @return Status
*/
if ( !self::isAllowedUrl( $this->mUrl ) ) {
return Status::newFatal( 'upload-copy-upload-invalid-url' );
}
- if ( !$this->mAsync ) {
- return $this->reallyFetchFile( $httpOptions );
- }
-
- return Status::newGood();
+ return $this->reallyFetchFile( $httpOptions );
}
/**
return $status;
}
-
- /**
- * Wrapper around the parent function in order to defer verifying the
- * upload until the file really has been fetched.
- * @return array|mixed
- */
- public function verifyUpload() {
- if ( $this->mAsync ) {
- return array( 'status' => UploadBase::OK );
- }
-
- return parent::verifyUpload();
- }
-
- /**
- * Wrapper around the parent function in order to defer checking warnings
- * until the file really has been fetched.
- * @return array
- */
- public function checkWarnings() {
- if ( $this->mAsync ) {
- $this->mIgnoreWarnings = false;
-
- return array();
- }
-
- return parent::checkWarnings();
- }
-
- /**
- * Wrapper around the parent function in order to defer checking protection
- * until we are sure that the file can actually be uploaded
- * @param User $user
- * @return bool|mixed
- */
- public function verifyTitlePermissions( $user ) {
- if ( $this->mAsync ) {
- return true;
- }
-
- return parent::verifyTitlePermissions( $user );
- }
-
- /**
- * Wrapper around the parent function in order to defer uploading to the
- * job queue for asynchronous uploads
- * @param string $comment
- * @param string $pageText
- * @param bool $watch
- * @param User $user
- * @return Status
- */
- public function performUpload( $comment, $pageText, $watch, $user ) {
- if ( $this->mAsync ) {
- $sessionKey = $this->insertJob( $comment, $pageText, $watch, $user );
-
- return Status::newFatal( 'async', $sessionKey );
- }
-
- return parent::performUpload( $comment, $pageText, $watch, $user );
- }
-
- /**
- * @param string $comment
- * @param string $pageText
- * @param bool $watch
- * @param User $user
- * @return string
- */
- protected function insertJob( $comment, $pageText, $watch, $user ) {
- $sessionKey = $this->stashSession();
- $job = new UploadFromUrlJob( $this->getTitle(), array(
- 'url' => $this->mUrl,
- 'comment' => $comment,
- 'pageText' => $pageText,
- 'watch' => $watch,
- 'userName' => $user->getName(),
- 'leaveMessage' => $this->mAsync == 'async-leavemessage',
- 'ignoreWarnings' => $this->mIgnoreWarnings,
- 'sessionId' => MediaWiki\Session\SessionManager::getGlobalSession()->getId(),
- 'sessionKey' => $sessionKey,
- ) );
- $job->initializeSessionData();
- JobQueueGroup::singleton()->push( $job );
-
- return $sessionKey;
- }
}
"filename-thumb-name": "This looks like a thumbnail title. Please do not upload thumbnails back to the same wiki. Otherwise, please fix the filename so it is more meaningful, and does not have the thumbnail prefix.",
"filename-bad-prefix": "The name of the file you are uploading begins with <strong>\"$1\"</strong>, which is a non-descriptive name typically assigned automatically by digital cameras.\nPlease choose a more descriptive name for your file.",
"filename-prefix-blacklist": " #<!-- leave this line exactly as it is --> <pre>\n# Syntax is as follows:\n# * Everything from a \"#\" character to the end of the line is a comment\n# * Every non-blank line is a prefix for typical filenames assigned automatically by digital cameras\nCIMG # Casio\nDSC_ # Nikon\nDSCF # Fuji\nDSCN # Nikon\nDUW # some mobile phones\nIMG # generic\nJD # Jenoptik\nMGP # Pentax\nPICT # misc.\n #</pre> <!-- leave this line exactly as it is -->",
- "upload-success-subj": "Successful upload",
- "upload-success-msg": "Your upload from [$2] was successful. It is available here: [[:{{ns:file}}:$1]]",
- "upload-failure-subj": "Upload problem",
- "upload-failure-msg": "There was a problem with your upload from [$2]:\n\n$1",
- "upload-warning-subj": "Upload warning",
- "upload-warning-msg": "There was a problem with your upload from [$2]. You may return to the [[Special:Upload/stash/$1|upload form]] to correct this problem.",
"upload-proto-error": "Incorrect protocol",
"upload-proto-error-text": "Remote upload requires URLs beginning with <code>http://</code> or <code>ftp://</code>.",
"upload-file-error": "Internal error",
"filename-thumb-name": "Appears when thumbnail title is similar to \"22px-Example.jpg\" - the prefix is what MW adds when downloading pictures as thumbnails.",
"filename-bad-prefix": "Used as warning in [[Special:Upload]]. Parameters:\n* $1 - prefix\nSee also:\n* {{msg-mw|fileexists}}\n* {{msg-mw|filepageexists}}\n* {{msg-mw|fileexists-extension}}\n* {{msg-mw|fileexists-thumbnail-yes}}\n* {{msg-mw|file-thumbnail-no}}\n* {{msg-mw|filewasdeleted}}",
"filename-prefix-blacklist": "{{optional}}\nDo not translate the file name prefixes before the hash mark (#). Leave all the wiki markup, including the spaces, as is. You can translate the text, including 'Leave this line exactly as it is'. The first line of this messages has one (1) leading space.",
- "upload-success-subj": "Used as message subject which is posted on the user talk page.\n\nSee also:\n* {{msg-mw|upload-success-subj|subject}}\n* {{msg-mw|upload-success-msg|message}}\n* {{msg-mw|upload-failure-subj|subject}}\n* {{msg-mw|upload-failure-msg|message}}",
- "upload-success-msg": "Used as message body which is posted on the user talk page. Parameters:\n* $1 - the local file name after uploading\n* $2 - the URL the file was uploaded from, when using upload-by-URL\nSee also:\n* {{msg-mw|upload-success-subj|subject}}\n* {{msg-mw|upload-success-msg|message}}\n* {{msg-mw|upload-failure-subj|subject}}\n* {{msg-mw|upload-failure-msg|message}}",
- "upload-failure-subj": "Used as message subject which is posted on the user talk page.\n\nI think this message should be translated as opposed to {{msg-mw|upload-success-subj}}.\n\nSee also:\n* {{msg-mw|upload-success-subj|subject}}\n* {{msg-mw|upload-success-msg|message}}\n* {{msg-mw|upload-failure-subj|subject}}\n* {{msg-mw|upload-failure-msg|message}}",
- "upload-failure-msg": "Used as message body which is posted on the user talk page. Parameters:\n* $1 - the specific error message\n* $2 - the URL the file tried to upload from, when using upload-by-URL.\nSee also:\n* {{msg-mw|upload-success-subj|subject}}\n* {{msg-mw|upload-success-msg|message}}\n* {{msg-mw|upload-failure-subj|subject}}\n* {{msg-mw|upload-failure-msg|message}}",
- "upload-warning-subj": "Used as warning subject which is posted on the user talk page.\n\nSee also:\n* {{msg-mw|upload-warning-subj|subject}}\n* {{msg-mw|upload-warning-msg|message}}",
- "upload-warning-msg": "Used as warning body which is posted on the user talk page. Parameters:\n* $1 - the URL the file was uploaded from, when using upload-by-URL\n* $2 - the session key for the upload\nSee also:\n* {{msg-mw|Upload-warning-subj|subject}}",
"upload-proto-error": "See also:\n* {{msg-mw|Upload-proto-error|title}}\n* {{msg-mw|Upload-proto-error-text|text}}",
"upload-proto-error-text": "\"Remote upload\" is explained on [[w:Uploading_and_downloading#Remote_upload|Wikipedia]].\n\nSee also:\n* {{msg-mw|Upload-proto-error|title}}\n* {{msg-mw|Upload-proto-error-text|text}}",
"upload-file-error": "Unused on core [[mw:Special:Code/MediaWiki/53282]].\n\nExtensions making use of it:\n*ImportFreeImages\n*SemanticForms\nSee also:\n* {{msg-mw|Upload-file-error|title}}\n* {{msg-mw|Upload-file-error-text|text}}\n{{Identical|Internal error}}",
astriks
asymp
async
-asynccopyuploaddisabled
-asyncdownload
at
atend
atext
lcrocker
ldquo
le
-leavemessage
len
length
leprop
), $session, self::$users['uploader']->getUser() );
} catch ( UsageException $e ) {
$exception = true;
- $this->assertEquals( "One of the parameters filekey, file, url, statuskey is required",
+ $this->assertEquals( "One of the parameters filekey, file, url is required",
$e->getMessage() );
}
$this->assertTrue( $exception, "Got exception" );
$this->setMwGlobals( array(
'wgEnableUploads' => true,
'wgAllowCopyUploads' => true,
- 'wgAllowAsyncCopyUploads' => true,
) );
if ( wfLocalFile( 'UploadFromUrlTest.png' )->exists() ) {
), $data );
} catch ( UsageException $e ) {
$exception = true;
- $this->assertEquals( "One of the parameters sessionkey, file, url, statuskey is required",
+ $this->assertEquals( "One of the parameters sessionkey, file, url is required",
$e->getMessage() );
}
$this->assertTrue( $exception, "Got exception" );
$this->assertEquals( "Permission denied", $e->getMessage() );
}
$this->assertTrue( $exception, "Got exception" );
-
- $this->user->addGroup( 'sysop' );
- $data = $this->doApiRequest( array(
- 'action' => 'upload',
- 'url' => 'http://upload.wikimedia.org/wikipedia/mediawiki/b/bc/Wiki.png',
- 'asyncdownload' => 1,
- 'filename' => 'UploadFromUrlTest.png',
- 'token' => $token,
- ), $data );
-
- $this->assertEquals( $data[0]['upload']['result'], 'Queued', 'Queued upload' );
-
- $job = JobQueueGroup::singleton()->pop();
- $this->assertThat( $job, $this->isInstanceOf( 'UploadFromUrlJob' ), 'Queued upload inserted' );
- }
-
- /**
- * @depends testClearQueue
- */
- public function testAsyncUpload( $data ) {
- $token = $this->user->getEditToken();
-
- $this->user->addGroup( 'users' );
-
- $data = $this->doAsyncUpload( $token, true );
- $this->assertEquals( $data[0]['upload']['result'], 'Success' );
- $this->assertEquals( $data[0]['upload']['filename'], 'UploadFromUrlTest.png' );
- $this->assertTrue( wfLocalFile( $data[0]['upload']['filename'] )->exists() );
-
- $this->deleteFile( 'UploadFromUrlTest.png' );
-
- return $data;
- }
-
- /**
- * @depends testClearQueue
- */
- public function testAsyncUploadWarning( $data ) {
- $token = $this->user->getEditToken();
-
- $this->user->addGroup( 'users' );
-
- $data = $this->doAsyncUpload( $token );
-
- $this->assertEquals( $data[0]['upload']['result'], 'Warning' );
- $this->assertTrue( isset( $data[0]['upload']['sessionkey'] ) );
-
- $data = $this->doApiRequest( array(
- 'action' => 'upload',
- 'sessionkey' => $data[0]['upload']['sessionkey'],
- 'filename' => 'UploadFromUrlTest.png',
- 'ignorewarnings' => 1,
- 'token' => $token,
- ) );
- $this->assertEquals( $data[0]['upload']['result'], 'Success' );
- $this->assertEquals( $data[0]['upload']['filename'], 'UploadFromUrlTest.png' );
- $this->assertTrue( wfLocalFile( $data[0]['upload']['filename'] )->exists() );
-
- $this->deleteFile( 'UploadFromUrlTest.png' );
-
- return $data;
}
/**
return $data;
}
- public function testLeaveMessage() {
- $token = $this->user->user->getEditToken();
-
- $talk = $this->user->user->getTalkPage();
- if ( $talk->exists() ) {
- $page = WikiPage::factory( $talk );
- $page->doDeleteArticle( '' );
- }
-
- $this->assertFalse(
- (bool)$talk->getArticleID( Title::GAID_FOR_UPDATE ),
- 'User talk does not exist'
- );
-
- $this->doApiRequest( array(
- 'action' => 'upload',
- 'filename' => 'UploadFromUrlTest.png',
- 'url' => 'http://upload.wikimedia.org/wikipedia/mediawiki/b/bc/Wiki.png',
- 'asyncdownload' => 1,
- 'token' => $token,
- 'leavemessage' => 1,
- 'ignorewarnings' => 1,
- ) );
-
- $job = JobQueueGroup::singleton()->pop();
- $this->assertEquals( 'UploadFromUrlJob', get_class( $job ) );
- $job->run();
-
- $this->assertTrue( wfLocalFile( 'UploadFromUrlTest.png' )->exists() );
- $this->assertTrue( (bool)$talk->getArticleID( Title::GAID_FOR_UPDATE ), 'User talk exists' );
-
- $this->deleteFile( 'UploadFromUrlTest.png' );
-
- $exception = false;
- try {
- $this->doApiRequest( array(
- 'action' => 'upload',
- 'filename' => 'UploadFromUrlTest.png',
- 'url' => 'http://upload.wikimedia.org/wikipedia/mediawiki/b/bc/Wiki.png',
- 'asyncdownload' => 1,
- 'token' => $token,
- 'leavemessage' => 1,
- ) );
- } catch ( UsageException $e ) {
- $exception = true;
- $this->assertEquals(
- 'Using leavemessage without ignorewarnings is not supported',
- $e->getMessage()
- );
- }
- $this->assertTrue( $exception );
-
- $job = JobQueueGroup::singleton()->pop();
- $this->assertFalse( $job );
-
- return;
- /*
- // Broken until using leavemessage with ignorewarnings is supported
- $talkRev = Revision::newFromTitle( $talk );
- $talkSize = $talkRev->getSize();
-
- $job->run();
-
- $this->assertFalse( wfLocalFile( 'UploadFromUrlTest.png' )->exists() );
-
- $talkRev = Revision::newFromTitle( $talk );
- $this->assertTrue( $talkRev->getSize() > $talkSize, 'New message left' );
- */
- }
-
- /**
- * Helper function to perform an async upload, execute the job and fetch
- * the status
- *
- * @param string $token
- * @param bool $ignoreWarnings
- * @param bool $leaveMessage
- * @return array The result of action=upload&statuskey=key
- */
- private function doAsyncUpload( $token, $ignoreWarnings = false, $leaveMessage = false ) {
- $params = array(
- 'action' => 'upload',
- 'filename' => 'UploadFromUrlTest.png',
- 'url' => 'http://upload.wikimedia.org/wikipedia/mediawiki/b/bc/Wiki.png',
- 'asyncdownload' => 1,
- 'token' => $token,
- );
- if ( $ignoreWarnings ) {
- $params['ignorewarnings'] = 1;
- }
- if ( $leaveMessage ) {
- $params['leavemessage'] = 1;
- }
-
- $data = $this->doApiRequest( $params );
- $this->assertEquals( $data[0]['upload']['result'], 'Queued' );
- $this->assertTrue( isset( $data[0]['upload']['statuskey'] ) );
- $statusKey = $data[0]['upload']['statuskey'];
-
- $job = JobQueueGroup::singleton()->pop();
- $this->assertEquals( 'UploadFromUrlJob', get_class( $job ) );
-
- $status = $job->run();
- $this->assertTrue( $status );
-
- $data = $this->doApiRequest( array(
- 'action' => 'upload',
- 'statuskey' => $statusKey,
- 'token' => $token,
- ) );
-
- return $data;
- }
-
protected function deleteFile( $name ) {
$t = Title::newFromText( $name, NS_FILE );
$this->assertTrue( $t->exists(), "File '$name' exists" );