r64425 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r64424‎ | r64425 | r64426 >
Date:06:29, 31 March 2010
Author:mah
Status:deferred
Tags:
Comment:
initial backport 1.16
Modified paths:
  • /branches/REL1_16/extensions/FirefoggChunkedUpload/ApiFirefoggChunkedUpload.php (modified) (history)
  • /branches/REL1_16/extensions/FirefoggChunkedUpload/FirefoggChunkedUpload.php (modified) (history)
  • /branches/REL1_16/extensions/FirefoggChunkedUpload/FirefoggChunkedUploadHandler.php (modified) (history)
  • /branches/REL1_16/extensions/FirefoggChunkedUpload/tests/UploadFromChunksTest.php (modified) (history)
  • /branches/REL1_16/extensions/FirefoggChunkedUpload/tests/bootstrap.php (modified) (history)

Diff [purge]

Index: branches/REL1_16/extensions/FirefoggChunkedUpload/ApiFirefoggChunkedUpload.php
@@ -31,7 +31,7 @@
3232 $request->getVal( 'chunksession', null ),
3333 $request->getFileTempName( 'chunk' ),
3434 $request->getFileSize( 'chunk' ),
35 - $request->getSessionData( UploadBase::getSessionKeyname() )
 35+ $request->getSessionData( 'wsUploadData' )
3636 );
3737
3838 if ( $status !== true ) {
@@ -110,6 +110,56 @@
111111 return $ret;
112112 }
113113
 114+ /**
 115+ * Produce the usage error
 116+ * After 1.16, this function is in UploadBase
 117+ *
 118+ * @param $verification array an associative array with the status
 119+ * key
 120+ */
 121+ public function getVerificationError( $verification ) {
 122+ // TODO: Move them to ApiBase's message map
 123+ switch( $verification['status'] ) {
 124+ case UploadBase::EMPTY_FILE:
 125+ $this->dieUsage( 'The file you submitted was empty', 'empty-file' );
 126+ break;
 127+ case UploadBase::FILETYPE_MISSING:
 128+ $this->dieUsage( 'The file is missing an extension', 'filetype-missing' );
 129+ break;
 130+ case UploadBase::FILETYPE_BADTYPE:
 131+ global $wgFileExtensions;
 132+ $this->dieUsage( 'This type of file is banned', 'filetype-banned',
 133+ 0, array(
 134+ 'filetype' => $verification['finalExt'],
 135+ 'allowed' => $wgFileExtensions
 136+ ) );
 137+ break;
 138+ case UploadBase::MIN_LENGTH_PARTNAME:
 139+ $this->dieUsage( 'The filename is too short', 'filename-tooshort' );
 140+ break;
 141+ case UploadBase::ILLEGAL_FILENAME:
 142+ $this->dieUsage( 'The filename is not allowed', 'illegal-filename',
 143+ 0, array( 'filename' => $verification['filtered'] ) );
 144+ break;
 145+ case UploadBase::OVERWRITE_EXISTING_FILE:
 146+ $this->dieUsage( 'Overwriting an existing file is not allowed', 'overwrite' );
 147+ break;
 148+ case UploadBase::VERIFICATION_ERROR:
 149+ $this->getResult()->setIndexedTagName( $verification['details'], 'detail' );
 150+ $this->dieUsage( 'This file did not pass file verification', 'verification-error',
 151+ 0, array( 'details' => $verification['details'] ) );
 152+ break;
 153+ case UploadBase::HOOK_ABORTED:
 154+ $this->dieUsage( "The modification you tried to make was aborted by an extension hook",
 155+ 'hookaborted', 0, array( 'error' => $verification['error'] ) );
 156+ break;
 157+ default:
 158+ $this->dieUsage( 'An unknown error occurred', 'unknown-error',
 159+ 0, array( 'code' => $verification['status'] ) );
 160+ break;
 161+ }
 162+ }
 163+
114164 public function mustBePosted() {
115165 return true;
116166 }
Index: branches/REL1_16/extensions/FirefoggChunkedUpload/tests/bootstrap.php
@@ -8,7 +8,7 @@
99 */
1010
1111 global $wgCommandLineMode, $IP, $optionsWithArgs;
12 -$IP = dirname( dirname( dirname( dirname( __FILE__ ) ) ) ) . "/mw-svn";
 12+$IP = dirname( dirname( dirname( dirname( __FILE__ ) ) ) ) . "/phase3";
1313 define( 'MW_PHPUNIT_TEST', true );
1414
1515 require_once( "$IP/maintenance/commandLine.inc" );
Index: branches/REL1_16/extensions/FirefoggChunkedUpload/tests/UploadFromChunksTest.php
@@ -2,8 +2,8 @@
33
44 global $IP;
55 require_once( "$IP/maintenance/tests/ApiSetup.php" );
6 -require_once( "$IP/maintenance/deleteArchivedFiles.inc" );
7 -require_once( "$IP/maintenance/deleteArchivedRevisions.inc" );
 6+/* require_once( "$IP/maintenance/deleteArchivedFiles.inc" ); */
 7+/* require_once( "$IP/maintenance/deleteArchivedRevisions.inc" ); */
88 require_once( dirname( dirname( __FILE__ ) ) . '/FirefoggChunkedUpload.php' );
99
1010 class nullClass {
@@ -246,10 +246,10 @@
247247 global $wgUser, $wgVerifyMimeType;
248248 $wgVerifyMimeType = false;
249249
250 - $this->markTestIncomplete("Not working yet ... fails every other time b/c we're not dealing with a temporary db");
 250+# $this->markTestIncomplete("Not working yet ... fails every other time b/c we're not dealing with a temporary db");
251251
252 - DeleteArchivedFilesImplementation::doDelete(new nullClass, true);
253 - DeleteArchivedRevisionsImplementation::doDelete(new nullClass);
 252+ /* DeleteArchivedFilesImplementation::doDelete(new nullClass, true); */
 253+ /* DeleteArchivedRevisionsImplementation::doDelete(new nullClass); */
254254
255255 $id = Title::newFromText( "Twar.png", NS_FILE )->getArticleID();
256256 $oldFile = Article::newFromID( $id );
Index: branches/REL1_16/extensions/FirefoggChunkedUpload/FirefoggChunkedUploadHandler.php
@@ -37,19 +37,19 @@
3838 foreach ( array( 'mFilteredName', 'repoPath', 'mFileSize', 'mDesiredDestName' )
3939 as $key ) {
4040 if ( isset( $this->$key ) ) {
41 - $_SESSION[self::SESSION_KEYNAME][$this->sessionKey][$key] = $this->$key;
 41+ $_SESSION['wsUploadData'][$this->sessionKey][$key] = $this->$key;
4242 }
4343 }
4444 if ( isset( $comment ) ) {
45 - $_SESSION[self::SESSION_KEYNAME][$this->sessionKey]['commment'] = $comment;
 45+ $_SESSION['wsUploadData'][$this->sessionKey]['commment'] = $comment;
4646 }
4747 if ( isset( $pageText ) ) {
48 - $_SESSION[self::SESSION_KEYNAME][$this->sessionKey]['pageText'] = $pageText;
 48+ $_SESSION['wsUploadData'][$this->sessionKey]['pageText'] = $pageText;
4949 }
5050 if ( isset( $watch ) ) {
51 - $_SESSION[self::SESSION_KEYNAME][$this->sessionKey]['watch'] = $watch;
 51+ $_SESSION['wsUploadData'][$this->sessionKey]['watch'] = $watch;
5252 }
53 - $_SESSION[self::SESSION_KEYNAME][$this->sessionKey]['version'] = self::SESSION_VERSION;
 53+ $_SESSION['wsUploadData'][$this->sessionKey]['version'] = self::SESSION_VERSION;
5454
5555 return $this->sessionKey;
5656 }
@@ -125,6 +125,30 @@
126126 }
127127
128128 /**
 129+ * Return the file size
 130+ * After 1.16, this function is in UploadBase
 131+ *
 132+ * @return integer
 133+ */
 134+ public function getFileSize() {
 135+ return $this->mFileSize;
 136+ }
 137+
 138+ /**
 139+ * Append a file to the Repo file
 140+ * After 1.16, this function is in UploadBase
 141+ *
 142+ * @param string $srcPath Path to source file
 143+ * @param string $toAppendPath Path to the Repo file that will be appended to.
 144+ * @return Status Status
 145+ */
 146+ protected function appendToUploadFile( $srcPath, $toAppendPath ) {
 147+ $repo = RepoGroup::singleton()->getLocalRepo();
 148+ $status = $repo->append( $srcPath, $toAppendPath );
 149+ return $status;
 150+ }
 151+
 152+ /**
129153 * Append a chunk to the temporary file.
130154 *
131155 * @return void
@@ -137,7 +161,7 @@
138162
139163 if ( $this->status->isOK() ) {
140164 $this->repoPath = $this->status->value;
141 - $_SESSION[self::SESSION_KEYNAME][$this->sessionKey]['repoPath'] = $this->repoPath;
 165+ $_SESSION['wsUploadData'][$this->sessionKey]['repoPath'] = $this->repoPath;
142166 }
143167 return $this->status;
144168 }
@@ -161,4 +185,68 @@
162186 $this->appendChunk();
163187 $this->mTempPath = $this->getRealPath( $this->repoPath );
164188 }
 189+
 190+ /**
 191+ * Check if there's an overwrite conflict and, if so, if restrictions
 192+ * forbid this user from performing the upload.
 193+ * After 1.16, this function is in UploadBase
 194+ *
 195+ * @return mixed true on success, error string on failure
 196+ */
 197+ private function checkOverwrite() {
 198+ global $wgUser;
 199+ // First check whether the local file can be overwritten
 200+ $file = $this->getLocalFile();
 201+ if( $file->exists() ) {
 202+ if( !self::userCanReUpload( $wgUser, $file ) ) {
 203+ return 'fileexists-forbidden';
 204+ } else {
 205+ return true;
 206+ }
 207+ }
 208+
 209+ /* Check shared conflicts: if the local file does not exist, but
 210+ * wfFindFile finds a file, it exists in a shared repository.
 211+ */
 212+ $file = wfFindFile( $this->getTitle() );
 213+ if ( $file && !$wgUser->isAllowed( 'reupload-shared' ) ) {
 214+ return 'fileexists-shared-forbidden';
 215+ }
 216+
 217+ return true;
 218+ }
 219+
 220+ /**
 221+ * Verify that the name is valid and, if necessary, that we can overwrite
 222+ * After 1.16, this function is in UploadBase
 223+ *
 224+ * @return mixed true if valid, otherwise and array with 'status'
 225+ * and other keys
 226+ **/
 227+ public function validateNameAndOverwrite() {
 228+ $nt = $this->getTitle();
 229+ if( is_null( $nt ) ) {
 230+ $result = array( 'status' => $this->mTitleError );
 231+ if( $this->mTitleError == self::ILLEGAL_FILENAME ) {
 232+ $result['filtered'] = $this->mFilteredName;
 233+ }
 234+ if ( $this->mTitleError == self::FILETYPE_BADTYPE ) {
 235+ $result['finalExt'] = $this->mFinalExtension;
 236+ }
 237+ return $result;
 238+ }
 239+ $this->mDestName = $this->getLocalFile()->getName();
 240+
 241+ /**
 242+ * In some cases we may forbid overwriting of existing files.
 243+ */
 244+ $overwrite = $this->checkOverwrite();
 245+ if( $overwrite !== true ) {
 246+ return array(
 247+ 'status' => self::OVERWRITE_EXISTING_FILE,
 248+ 'overwrite' => $overwrite
 249+ );
 250+ }
 251+ return true;
 252+ }
165253 }
\ No newline at end of file
Index: branches/REL1_16/extensions/FirefoggChunkedUpload/FirefoggChunkedUpload.php
@@ -13,6 +13,9 @@
1414 'descriptionmsg' => 'firefoggcu-desc',
1515 );
1616
 17+$dir = dirname( __FILE__ ) . '/';
 18+$wgExtensionMessagesFiles['FirefoggChunkedUpload'] = $dir . 'FirefoggChunkedUpload.i18n.php';
 19+$wgAutoloadClasses['ApiFirefoggChunkedUpload'] = $dir . 'ApiFirefoggChunkedUpload.php';
 20+$wgAutoloadClasses['FirefoggChunkedUploadHandler'] = $dir . 'FirefoggChunkedUploadHandler.php';
1721
18 -$dir = dirname( __FILE__ ) . '/';
19 -$wgExtensionMessagesFiles['FirefoggChunkedUploading'] = $dir . 'FirefoggChunkedUpload.i18n.php';
 22+$wgAPIModules['firefoggupload'] = 'ApiFirefoggChunkedUpload';

Status & tagging log