r25851 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r25850‎ | r25851 | r25852 >
Date:12:19, 14 September 2007
Author:abernala
Status:old
Tags:
Comment:
internalProcessUpload added. processUpload without input parameters as original code.
Modified paths:
  • /branches/ApiEdit_Vodafone/includes/SpecialUpload.php (modified) (history)
  • /branches/ApiEdit_Vodafone/includes/api/ApiUploadFile.php (modified) (history)

Diff [purge]

Index: branches/ApiEdit_Vodafone/includes/SpecialUpload.php
@@ -259,9 +259,7 @@
260260 }
261261 $this->mainUploadForm();
262262 } else if( 'submit' == $this->mAction || $this->mUploadClicked ) {
263 - $details = null;
264 - $retval = $this->processUpload( $details );
265 - $this->processRest($retval, $details);
 263+ $this->processUpload();
266264 } else {
267265 $this->mainUploadForm();
268266 }
@@ -269,11 +267,18 @@
270268 $this->cleanupTempFile();
271269 }
272270
273 - function processRest($value, $details) {
 271+ /**
 272+ * Do the upload
 273+ * Checks are made in SpecialUpload::execute()
 274+ *
 275+ * @access private
 276+ */
 277+ function processUpload(){
274278 global $wgUser, $wgOut, $wgFileExtensions;
275 -
276 - switch ($value)
277 - {
 279+ $results = null;
 280+ $value = null;
 281+ $value = internalProcessUpload($results);
 282+ switch($value) {
278283 case self::SUCCESS:
279284 $wgOut->redirect( $this->mLocalFile->getTitle()->getFullURL() );
280285 break;
@@ -335,28 +340,25 @@
336341 $warning = $details['warning'];
337342 $this->uploadWarning( $warning );
338343 break;
339 -
340 - }
 344+ }
341345 }
342346
343 -
344 - /* -------------------------------------------------------------- */
345 -
346347 /**
347348 * Really do the upload
348349 * Checks are made in SpecialUpload::execute()
349 - *
 350+ *
350351 * @param array $resultDetails contains result-specific dict of additional values
351 - *
 352+ *
352353 * @access private
353354 */
354 - function processUpload( &$resultDetails="" ) {
 355+ function internalProcessUpload( &$resultDetails="" ) {
355356 global $wgUser, $wgOut;
356357
357358 if( !wfRunHooks( 'UploadForm:BeforeProcessing', array( &$this ) ) )
358359 {
359360 wfDebug( "Hook 'UploadForm:BeforeProcessing' broke processing the file." );
360361 return self::BEFORE_PROCESSING;
 362+
361363 }
362364
363365 /* Check for PHP error if any, requires php 4.2 or newer */
@@ -397,7 +399,8 @@
398400 for( $i = 0; $i < count( $ext ) - 1; $i++ )
399401 $partname .= '.' . $ext[$i];
400402 }
401 -
 403+
 404+
402405 if( strlen( $partname ) < 1 ) {
403406 return self::MIN_LENGHT_PARTNAME;
404407 }
@@ -408,6 +411,7 @@
409412 */
410413 $filtered = preg_replace ( "/[^".Title::legalChars()."]|:/", '-', $filtered );
411414 $nt = Title::makeTitleSafe( NS_IMAGE, $filtered );
 415+
412416 if( is_null( $nt ) ) {
413417 $resultDetails = array( 'filtered' => $filtered );
414418 return self::ILLEGAL_FILENAME;
@@ -436,8 +440,10 @@
437441 /* Don't allow users to override the blacklist (check file extension) */
438442 global $wgStrictFileExtensions;
439443 global $wgFileExtensions, $wgFileBlacklist;
 444+
440445 if ($finalExt == '') {
441446 return self::FILETYPE_MISSING;
 447+
442448 } elseif ( $this->checkFileExtensionList( $ext, $wgFileBlacklist ) ||
443449 ($wgStrictFileExtensions && !$this->checkFileExtension( $finalExt, $wgFileExtensions ) ) ) {
444450 $resultDetails = array( 'finalExt' => $finalExt );
@@ -476,7 +482,6 @@
477483 */
478484 if ( ! $this->mIgnoreWarning ) {
479485 $warning = '';
480 -
481486 global $wgCapitalLinks;
482487 if( $wgCapitalLinks ) {
483488 $filtered = ucfirst( $filtered );
@@ -488,7 +493,7 @@
489494 global $wgCheckFileExtensions;
490495 if ( $wgCheckFileExtensions ) {
491496 if ( ! $this->checkFileExtension( $finalExt, $wgFileExtensions ) ) {
492 - $warning .= '<li>'.wfMsgExt( 'filetype-badtype', array ( 'parseinline' ),
 497+ $warning .= '<li>'.wfMsgExt( 'filetype-badtype', array ( 'parseinline' ),
493498 htmlspecialchars( $finalExt ), implode ( ', ', $wgFileExtensions ) ).'</li>';
494499 }
495500 }
@@ -507,6 +512,7 @@
508513 if ( !$this->mDestWarningAck ) {
509514 $warning .= self::getExistsWarning( $this->mLocalFile );
510515 }
 516+
511517 if( $warning != '' ) {
512518 /**
513519 * Stash the file in a temporary location; the user can choose
@@ -524,7 +530,7 @@
525531 $pageText = self::getInitialPageText( $this->mComment, $this->mLicense,
526532 $this->mCopyrightStatus, $this->mCopyrightSource );
527533
528 - $status = $this->mLocalFile->upload( $this->mTempPath, $this->mComment, $pageText,
 534+ $status = $this->mLocalFile->upload( $this->mTempPath, $this->mComment, $pageText,
529535 File::DELETE_SOURCE, $this->mFileProps );
530536 if ( !$status->isGood() ) {
531537 $this->showError( $status->getWikiText() );
Index: branches/ApiEdit_Vodafone/includes/api/ApiUploadFile.php
@@ -41,8 +41,8 @@
4242 const UPLOAD_BLOCKED_PAGE = -5;
4343 const UPLOAD_READ_ONLY = -6;
4444 const UPLOAD_BAD_TOKEN = -7;
 45+ const UPLOAD_WITHOUT_POSTPARAMETERS = -8;
4546
46 -
4747 public function __construct($query, $moduleName) {
4848 parent :: __construct($query, $moduleName, 'up');
4949 }
@@ -147,7 +147,7 @@
148148 // $this->cleanupTempFile();
149149
150150 } else {
151 - $this->process( self::UPLOAD_INVALID );
 151+ $this->process( self::UPLOAD_WITHOUT_POSTPARAMETERS );
152152 }
153153 }
154154
@@ -156,89 +156,93 @@
157157
158158 switch ($value) {
159159 case ApiUploadFile::UPLOAD_INVALID :
160 - $result['result'] = 'Upload_Invalid';
 160+ $result['result'] = 'UPLOAD_INVALID';
161161 break;
162162
163163 case ApiUploadFile::UPLOAD_ENABLED_UPLOADS :
164 - $result['result'] = 'Upload_Enabled_Uploads';
 164+ $result['result'] = 'UPLOAD_ENABLED_UPLOADS';
165165 break;
166166
167167 case ApiUploadFile::UPLOAD_NOT_LOGGED :
168 - $result['result'] = 'Upload_Not_Logged';
 168+ $result['result'] = 'UPLOAD_NOT_LOGGED';
169169 break;
170170
171171 case ApiUploadFile::UPLOAD_NOT_ALLOWED :
172 - $result['result'] = 'Upload_Not_Allowed';
 172+ $result['result'] = 'UPLOAD_NOT_ALLOWED';
173173 break;
174174
175175 case ApiUploadFile::UPLOAD_BLOCKED_PAGE :
176 - $result['result'] = 'Upload_Blocked_Page';
 176+ $result['result'] = 'UPLOAD_BLOCKED_PAGE';
177177 break;
178178
179179 case ApiUploadFile::UPLOAD_READ_ONLY :
180 - $result['result'] = 'Upload_Read_Only';
 180+ $result['result'] = 'UPLOAD_READ_ONLY';
181181 break;
182182
183183 case ApiUploadFile::UPLOAD_BAD_TOKEN :
184184 $result['result'] = 'UPLOAD_BAD_TOKEN';
185185 break;
186186
 187+ case ApiUploadFile::UPLOAD_WITHOUT_POSTPARAMETERS :
 188+ $result['result'] = 'UPLOAD_WITHOUT_POSTPARAMETERS';
 189+ break;
 190+
187191 case UploadForm::SUCCESS :
188 - $result['result'] = 'Success';
 192+ $result['result'] = 'SUCCESS';
189193 $result['title'] = $wgRequest->getText( 'updestfile' );
190194 $result['ns'] = "6";
191195 break;
192196
193197 case UploadForm::BEFORE_PROCESSING:
194 - $result['result'] = 'Upload_BeforeProcessing';
 198+ $result['result'] = 'UPLOAD_BEFORE_PROCESSING ';
195199 break;
196200
197201 case UploadForm::LARGE_FILE_SERVER:
198 - $result['result'] = 'Upload_LargeFileServer';
 202+ $result['result'] = 'UPLOAD_LARGE_FILE_SERVER';
199203 break;
200204
201205 case UploadForm::EMPTY_FILE:
202 - $result['result'] = 'Upload_EmptyFile';
 206+ $result['result'] = 'UPLOAD_EMPTY_FILE';
203207 break;
204208
205209 case UploadForm::MIN_LENGHT_PARTNAME:
206 - $result['result'] = 'Upload_MinLenghtPartName';
 210+ $result['result'] = 'UPLOAD_MIN_LENGHT_PARTNAME';
207211 break;
208212
209213 case UploadForm::ILLEGAL_FILENAME:
210 - $result['result'] = 'Upload_IllegalFilename';
 214+ $result['result'] = 'UPLOAD_ILLEGAL_FILENAME';
211215 break;
212216
213217 case UploadForm::PROTECTED_PAGE:
214 - $result['result'] = 'Upload_ProtectedPage';
 218+ $result['result'] = 'UPLOAD_PROTECTED_PAGE';
215219 break;
216220
217221 case UploadForm::OVERWRITE_EXISTING_FILE:
218 - $result['result'] = 'Upload_OverwriteExistingFile';
 222+ $result['result'] = 'UPLOAD_OVERWRITE_EXISTING_FILE';
219223 break;
220224
221225 case UploadForm::FILETYPE_MISSING:
222 - $result['result'] = 'Upload_FiletypeMissing';
 226+ $result['result'] = 'UPLOAD_FILETYPE_MISSING';
223227 break;
224228
225229 case UploadForm::FILETYPE_BADTYPE:
226 - $result['result'] = 'Upload_FiletypeBadType';
 230+ $result['result'] = 'UPLOAD_FILETYPE_BADTYPE';
227231 break;
228232
229233 case UploadForm::VERIFICATION_ERROR:
230 - $result['result'] = 'Upload_VerificationError';
 234+ $result['result'] = 'UPLOAD_VERIFICATION_ERROR';
231235 break;
232236
233237 case UploadForm::UPLOAD_VERIFICATION_ERROR:
234 - $result['result'] = 'Upload_UploadVerificationError';
 238+ $result['result'] = 'UPLOAD_UPLOADVERIFICATION_ERROR';
235239 break;
236240
237241 case UploadForm::UPLOAD_WARNING:
238 - $result['result'] = 'Upload_Warning';
 242+ $result['result'] = 'UPLOAD_WARNING';
239243 break;
240244
241245 default :
242 - $result['result'] = 'Upload_Invalid';
 246+ $result['result'] = 'UPLOAD_INVALID';
243247 }
244248
245249 $this->getResult()->addValue(null, 'upload', $result);

Status & tagging log