Index: branches/REL1_16/extensions/FirefoggChunkedUpload/ApiFirefoggChunkedUpload.php |
— | — | @@ -31,7 +31,7 @@ |
32 | 32 | $request->getVal( 'chunksession', null ), |
33 | 33 | $request->getFileTempName( 'chunk' ), |
34 | 34 | $request->getFileSize( 'chunk' ), |
35 | | - $request->getSessionData( UploadBase::getSessionKeyname() ) |
| 35 | + $request->getSessionData( 'wsUploadData' ) |
36 | 36 | ); |
37 | 37 | |
38 | 38 | if ( $status !== true ) { |
— | — | @@ -110,6 +110,56 @@ |
111 | 111 | return $ret; |
112 | 112 | } |
113 | 113 | |
| 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 | + |
114 | 164 | public function mustBePosted() { |
115 | 165 | return true; |
116 | 166 | } |
Index: branches/REL1_16/extensions/FirefoggChunkedUpload/tests/bootstrap.php |
— | — | @@ -8,7 +8,7 @@ |
9 | 9 | */ |
10 | 10 | |
11 | 11 | global $wgCommandLineMode, $IP, $optionsWithArgs; |
12 | | -$IP = dirname( dirname( dirname( dirname( __FILE__ ) ) ) ) . "/mw-svn"; |
| 12 | +$IP = dirname( dirname( dirname( dirname( __FILE__ ) ) ) ) . "/phase3"; |
13 | 13 | define( 'MW_PHPUNIT_TEST', true ); |
14 | 14 | |
15 | 15 | require_once( "$IP/maintenance/commandLine.inc" ); |
Index: branches/REL1_16/extensions/FirefoggChunkedUpload/tests/UploadFromChunksTest.php |
— | — | @@ -2,8 +2,8 @@ |
3 | 3 | |
4 | 4 | global $IP; |
5 | 5 | 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" ); */ |
8 | 8 | require_once( dirname( dirname( __FILE__ ) ) . '/FirefoggChunkedUpload.php' ); |
9 | 9 | |
10 | 10 | class nullClass { |
— | — | @@ -246,10 +246,10 @@ |
247 | 247 | global $wgUser, $wgVerifyMimeType; |
248 | 248 | $wgVerifyMimeType = false; |
249 | 249 | |
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"); |
251 | 251 | |
252 | | - DeleteArchivedFilesImplementation::doDelete(new nullClass, true); |
253 | | - DeleteArchivedRevisionsImplementation::doDelete(new nullClass); |
| 252 | + /* DeleteArchivedFilesImplementation::doDelete(new nullClass, true); */ |
| 253 | + /* DeleteArchivedRevisionsImplementation::doDelete(new nullClass); */ |
254 | 254 | |
255 | 255 | $id = Title::newFromText( "Twar.png", NS_FILE )->getArticleID(); |
256 | 256 | $oldFile = Article::newFromID( $id ); |
Index: branches/REL1_16/extensions/FirefoggChunkedUpload/FirefoggChunkedUploadHandler.php |
— | — | @@ -37,19 +37,19 @@ |
38 | 38 | foreach ( array( 'mFilteredName', 'repoPath', 'mFileSize', 'mDesiredDestName' ) |
39 | 39 | as $key ) { |
40 | 40 | if ( isset( $this->$key ) ) { |
41 | | - $_SESSION[self::SESSION_KEYNAME][$this->sessionKey][$key] = $this->$key; |
| 41 | + $_SESSION['wsUploadData'][$this->sessionKey][$key] = $this->$key; |
42 | 42 | } |
43 | 43 | } |
44 | 44 | if ( isset( $comment ) ) { |
45 | | - $_SESSION[self::SESSION_KEYNAME][$this->sessionKey]['commment'] = $comment; |
| 45 | + $_SESSION['wsUploadData'][$this->sessionKey]['commment'] = $comment; |
46 | 46 | } |
47 | 47 | if ( isset( $pageText ) ) { |
48 | | - $_SESSION[self::SESSION_KEYNAME][$this->sessionKey]['pageText'] = $pageText; |
| 48 | + $_SESSION['wsUploadData'][$this->sessionKey]['pageText'] = $pageText; |
49 | 49 | } |
50 | 50 | if ( isset( $watch ) ) { |
51 | | - $_SESSION[self::SESSION_KEYNAME][$this->sessionKey]['watch'] = $watch; |
| 51 | + $_SESSION['wsUploadData'][$this->sessionKey]['watch'] = $watch; |
52 | 52 | } |
53 | | - $_SESSION[self::SESSION_KEYNAME][$this->sessionKey]['version'] = self::SESSION_VERSION; |
| 53 | + $_SESSION['wsUploadData'][$this->sessionKey]['version'] = self::SESSION_VERSION; |
54 | 54 | |
55 | 55 | return $this->sessionKey; |
56 | 56 | } |
— | — | @@ -125,6 +125,30 @@ |
126 | 126 | } |
127 | 127 | |
128 | 128 | /** |
| 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 | + /** |
129 | 153 | * Append a chunk to the temporary file. |
130 | 154 | * |
131 | 155 | * @return void |
— | — | @@ -137,7 +161,7 @@ |
138 | 162 | |
139 | 163 | if ( $this->status->isOK() ) { |
140 | 164 | $this->repoPath = $this->status->value; |
141 | | - $_SESSION[self::SESSION_KEYNAME][$this->sessionKey]['repoPath'] = $this->repoPath; |
| 165 | + $_SESSION['wsUploadData'][$this->sessionKey]['repoPath'] = $this->repoPath; |
142 | 166 | } |
143 | 167 | return $this->status; |
144 | 168 | } |
— | — | @@ -161,4 +185,68 @@ |
162 | 186 | $this->appendChunk(); |
163 | 187 | $this->mTempPath = $this->getRealPath( $this->repoPath ); |
164 | 188 | } |
| 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 | + } |
165 | 253 | } |
\ No newline at end of file |
Index: branches/REL1_16/extensions/FirefoggChunkedUpload/FirefoggChunkedUpload.php |
— | — | @@ -13,6 +13,9 @@ |
14 | 14 | 'descriptionmsg' => 'firefoggcu-desc', |
15 | 15 | ); |
16 | 16 | |
| 17 | +$dir = dirname( __FILE__ ) . '/'; |
| 18 | +$wgExtensionMessagesFiles['FirefoggChunkedUpload'] = $dir . 'FirefoggChunkedUpload.i18n.php'; |
| 19 | +$wgAutoloadClasses['ApiFirefoggChunkedUpload'] = $dir . 'ApiFirefoggChunkedUpload.php'; |
| 20 | +$wgAutoloadClasses['FirefoggChunkedUploadHandler'] = $dir . 'FirefoggChunkedUploadHandler.php'; |
17 | 21 | |
18 | | -$dir = dirname( __FILE__ ) . '/'; |
19 | | -$wgExtensionMessagesFiles['FirefoggChunkedUploading'] = $dir . 'FirefoggChunkedUpload.i18n.php'; |
| 22 | +$wgAPIModules['firefoggupload'] = 'ApiFirefoggChunkedUpload'; |