r36585 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r36584‎ | r36585 | r36586 >
Date:21:36, 23 June 2008
Author:aaron
Status:old
Tags:
Comment:
Remove duplication
Modified paths:
  • /trunk/extensions/ConfirmAccount/RequestAccount_body.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialUpload.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/specials/SpecialUpload.php
@@ -1331,7 +1331,7 @@
13321332
13331333 wfDebug ( "\n\nmime: <$mime> extension: <$extension>\n\n");
13341334 #check mime type against file extension
1335 - if( !$this->verifyExtension( $mime, $extension ) ) {
 1335+ if( !self::verifyExtension( $mime, $extension ) ) {
13361336 return new WikiErrorMsg( 'uploadcorrupt' );
13371337 }
13381338
@@ -1367,7 +1367,7 @@
13681368 * @param string $extension The filename extension that the file is to be served with
13691369 * @return bool
13701370 */
1371 - function verifyExtension( $mime, $extension ) {
 1371+ static function verifyExtension( $mime, $extension ) {
13721372 $magic = MimeMagic::singleton();
13731373
13741374 if ( ! $mime || $mime == 'unknown' || $mime == 'unknown/unknown' )
Index: trunk/extensions/ConfirmAccount/RequestAccount_body.php
@@ -23,7 +23,7 @@
2424 $wgOut->blockedPage();
2525 return;
2626 }
27 - if ( wfReadOnly() ) {
 27+ if( wfReadOnly() ) {
2828 $wgOut->readOnlyPage();
2929 return;
3030 }
@@ -71,9 +71,8 @@
7272
7373 $this->skin = $wgUser->getSkin();
7474
75 - if ( $wgRequest->wasPosted() && $wgUser->matchEditToken( $wgRequest->getVal('wpEditToken') ) ) {
76 - if( !$this->mPrevAttachment )
77 - $this->mPrevAttachment = $this->mSrcName;
 75+ if( $wgRequest->wasPosted() && $wgUser->matchEditToken( $wgRequest->getVal('wpEditToken') ) ) {
 76+ $this->mPrevAttachment = $this->mPrevAttachment ? $this->mPrevAttachment : $this->mSrcName;
7877 $this->doSubmit();
7978 } else if( $action == 'confirmemail' ) {
8079 $this->confirmEmailToken( $emailCode );
@@ -245,6 +244,7 @@
246245 $this->showForm( $abortError );
247246 return;
248247 }
 248+ # Set it back!
249249 if( !$wgConfirmAccountCaptchas && isset($wgCaptchaTriggers) ) {
250250 $wgCaptchaTriggers['createaccount'] = $old;
251251 }
@@ -301,7 +301,6 @@
302302 $this->showForm( wfMsgHtml('requestaccount-emaildup') );
303303 return;
304304 }
305 -
306305 $u->setRealName( $this->mRealName );
307306 # Per security reasons, file dir cannot be pulled from client,
308307 # so ask them to resubmit it then...
@@ -413,7 +412,6 @@
414413 # BC: check if isPingLimitable() exists
415414 if( $wgAccountRequestThrottle && ( !method_exists($wgUser,'isPingLimitable') || $wgUser->isPingLimitable() ) ) {
416415 global $wgMemc;
417 -
418416 $key = wfMemcKey( 'acctrequest', 'ip', wfGetIP() );
419417 $value = $wgMemc->incr( $key );
420418 if( !$value ) {
@@ -426,15 +424,13 @@
427425
428426 function showSuccess() {
429427 global $wgOut;
430 -
431428 $wgOut->setPagetitle( wfMsg( "requestaccount" ) );
432429 $wgOut->addWikiText( wfMsg( "requestaccount-sent" ) );
433 -
434430 $wgOut->returnToMain();
435431 }
436432
437433 /**
438 - * Flatten an areas of interest array
 434+ * Flatten areas of interest array
439435 * @access private
440436 */
441437 static function flattenAreas( $areas ) {
@@ -445,6 +441,10 @@
446442 return $flatAreas;
447443 }
448444
 445+ /**
 446+ * Expand areas of interest to array
 447+ * @access private
 448+ */
449449 static function expandAreas( $areas ) {
450450 $list = explode("\n",$areas);
451451 foreach( $list as $n => $item ) {
@@ -483,7 +483,7 @@
484484
485485 wfDebug ( "\n\nmime: <$mime> extension: <$extension>\n\n");
486486 #check mime type against file extension
487 - if( !$this->verifyExtension( $mime, $extension ) ) {
 487+ if( !UploadForm::verifyExtension( $mime, $extension ) ) {
488488 return new WikiErrorMsg( 'uploadcorrupt' );
489489 }
490490
@@ -500,44 +500,6 @@
501501 }
502502
503503 /**
504 - * Checks if the mime type of the uploaded file matches the file extension.
505 - *
506 - * @param string $mime the mime type of the uploaded file
507 - * @param string $extension The filename extension that the file is to be served with
508 - * @return bool
509 - */
510 - function verifyExtension( $mime, $extension ) {
511 - $magic =& MimeMagic::singleton();
512 -
513 - if ( ! $mime || $mime == 'unknown' || $mime == 'unknown/unknown' )
514 - if ( ! $magic->isRecognizableExtension( $extension ) ) {
515 - wfDebug( __METHOD__.": passing file with unknown detected mime type; " .
516 - "unrecognized extension '$extension', can't verify\n" );
517 - return true;
518 - } else {
519 - wfDebug( __METHOD__.": rejecting file with unknown detected mime type; ".
520 - "recognized extension '$extension', so probably invalid file\n" );
521 - return false;
522 - }
523 -
524 - $match = $magic->isMatchingExtension($extension,$mime);
525 -
526 - if ($match===NULL) {
527 - wfDebug( __METHOD__.": no file extension known for mime type $mime, passing file\n" );
528 - return true;
529 - } elseif ($match===true) {
530 - wfDebug( __METHOD__.": mime type $mime matches extension $extension, passing file\n" );
531 -
532 - #TODO: if it's a bitmap, make sure PHP or ImageMagic resp. can handle it!
533 - return true;
534 -
535 - } else {
536 - wfDebug( __METHOD__.": mime type $mime mismatches file extension $extension, rejecting file\n" );
537 - return false;
538 - }
539 - }
540 -
541 - /**
542504 * Perform case-insensitive match against a list of file extensions.
543505 * Returns true if the extension is in the list.
544506 *

Status & tagging log