r56416 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r56415‎ | r56416 | r56417 >
Date:15:09, 16 September 2009
Author:btongminh
Status:ok
Tags:
Comment:
Cleanup SpecialUpload::getExistsWarning which referenced some undeclared variables.
There is some more cleanup to be done in SpecialUpload::getExistsWarning and UploadBase::getExistsWarning, but there are currently no errors as far as I'm aware. I will probably break b/c on them though.
Modified paths:
  • /trunk/phase3/includes/specials/SpecialUpload.php (modified) (history)
  • /trunk/phase3/includes/upload/UploadBase.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/upload/UploadBase.php
@@ -994,6 +994,9 @@
995995 $file_thb = wfLocalFile( $nt_thb );
996996 if( $file_thb->exists() )
997997 return array( 'thumb', $file_thb );
 998+ else
 999+ // File does not exist, but we just don't like the name
 1000+ return array( 'thumb-name', $file_thb );
9981001 }
9991002
10001003 return false;
Index: trunk/phase3/includes/specials/SpecialUpload.php
@@ -320,16 +320,17 @@
321321 }
322322
323323 /**
324 - * Do existence checks on a file and produce a warning
 324+ * Formats a result of UploadBase::getExistsWarning as HTML
325325 * This check is static and can be done pre-upload via AJAX
326 - * Returns an HTML fragment consisting of one or more LI elements if there is a warning
327 - * Returns an empty string if there is no warning
 326+ *
 327+ * @param array $exists The result of UploadBase::getExistsWarning
 328+ * @return string Empty string if there is no warning or an HTML fragment
 329+ * consisting of one or more <li> elements if there is a warning.
328330 */
329 - static function getExistsWarning( $exists ) {
 331+ public static function getExistsWarning( $exists ) {
330332 global $wgUser, $wgContLang;
331 - // Check for uppercase extension. We allow these filenames but check if an image
332 - // with lowercase extension exists already
333 - if( $exists === false )
 333+
 334+ if ( !$exists )
334335 return '';
335336
336337 $warning = '';
@@ -337,7 +338,8 @@
338339
339340 list( $existsType, $file ) = $exists;
340341
341 - if( strpos( $file->getName(), '.' ) == false ) {
 342+ if ( strpos( $file->getName(), '.' ) == false ) {
 343+ // File does not have an extension or starts with a dot
342344 $partname = $file->getName();
343345 $rawExtension = '';
344346 } else {
@@ -365,18 +367,20 @@
366368 $warning .= '<li>' . wfMsgExt( 'fileexists', array('parseinline','replaceafter'), $dlink ) . '</li>' . $dlink2;
367369
368370 } elseif( $existsType == 'page-exists' ) {
 371+ // Page exists but file does not
369372 $lnk = $sk->linkKnown( $file->getTitle(), '', '',array('redirect'=>'no') );
370373 $warning .= '<li>' . wfMsgExt( 'filepageexists', array( 'parseinline', 'replaceafter' ), $lnk ) . '</li>';
371374 } elseif ( $existsType == 'exists-normalized' ) {
372375 # Check if image with lowercase extension exists.
373376 # It's not forbidden but in 99% it makes no sense to upload the same filename with uppercase extension
374 - $dlink = $sk->linkKnown( $nt_lc );
375 - if ( $file_lc->allowInlineDisplay() ) {
 377+ $normalizedTitle = $file->getTitle();
 378+ $dlink = $sk->linkKnown( $normalizedTitle );
 379+ if ( $file->allowInlineDisplay() ) {
376380 // FIXME: replace deprecated makeImageLinkObj by link()
377 - $dlink2 = $sk->makeImageLinkObj( $nt_lc, wfMsgExt( 'fileexists-thumb', 'parseinline' ),
378 - $nt_lc->getText(), $align, array(), false, true );
379 - } elseif ( !$file_lc->allowInlineDisplay() && $file_lc->isSafeFile() ) {
380 - $icon = $file_lc->iconThumb();
 381+ $dlink2 = $sk->makeImageLinkObj( $normalizedTitle, wfMsgExt( 'fileexists-thumb', 'parseinline' ),
 382+ $normalizedTitle->getText(), $align, array(), false, true );
 383+ } elseif ( !$file->allowInlineDisplay() && $file->isSafeFile() ) {
 384+ $icon = $file->iconThumb();
381385 $dlink2 = '<div style="float:' . $align . '" id="mw-media-icon">' .
382386 $icon->toHtml( array( 'desc-link' => true ) ) . '<br />' . $dlink . '</div>';
383387 } else {
@@ -388,41 +392,34 @@
389393 $file->getTitle()->getPrefixedText(), $dlink ) .
390394 '</li>' . $dlink2;
391395
392 - } elseif ( ( substr( $partname , 3, 3 ) == 'px-' || substr( $partname , 2, 3 ) == 'px-' )
393 - && preg_match( "/[0-9]{2}/" , substr( $partname , 0, 2 ) ) )
394 - {
395 - # Check for filenames like 50px- or 180px-, these are mostly thumbnails
396 - $nt_thb = Title::newFromText( substr( $partname , strpos( $partname , '-' ) +1 ) . '.' . $rawExtension );
397 - $file_thb = wfLocalFile( $nt_thb );
398 - if ($file_thb->exists() ) {
399 - # Check if an image without leading '180px-' (or similiar) exists
400 - $dlink = $sk->linkKnown( $nt_thb );
401 - if ( $file_thb->allowInlineDisplay() ) {
402 - // FIXME: replace deprecated makeImageLinkObj by link()
403 - $dlink2 = $sk->makeImageLinkObj( $nt_thb,
404 - wfMsgExt( 'fileexists-thumb', 'parseinline' ),
405 - $nt_thb->getText(), $align, array(), false, true );
406 - } elseif ( !$file_thb->allowInlineDisplay() && $file_thb->isSafeFile() ) {
407 - $icon = $file_thb->iconThumb();
408 - $dlink2 = '<div style="float:' . $align . '" id="mw-media-icon">' .
409 - $icon->toHtml( array( 'desc-link' => true ) ) . '<br />' .
410 - $dlink . '</div>';
411 - } else {
412 - $dlink2 = '';
413 - }
414 -
415 - $warning .= '<li>' . wfMsgExt( 'fileexists-thumbnail-yes', 'parsemag', $dlink ) .
416 - '</li>' . $dlink2;
 396+ } elseif ( $existsType == 'thumb' ) {
 397+ $nt_thb = $file->getTitle();
 398+ $dlink = $sk->linkKnown( $nt_thb );
 399+ if ( $file->allowInlineDisplay() ) {
 400+ // FIXME: replace deprecated makeImageLinkObj by link()
 401+ $dlink2 = $sk->makeImageLinkObj( $nt_thb,
 402+ wfMsgExt( 'fileexists-thumb', 'parseinline' ),
 403+ $nt_thb->getText(), $align, array(), false, true );
 404+ } elseif ( !$file_thb->allowInlineDisplay() && $file_thb->isSafeFile() ) {
 405+ $icon = $file_thb->iconThumb();
 406+ $dlink2 = '<div style="float:' . $align . '" id="mw-media-icon">' .
 407+ $icon->toHtml( array( 'desc-link' => true ) ) . '<br />' .
 408+ $dlink . '</div>';
417409 } else {
 410+ $dlink2 = '';
 411+ }
 412+
 413+ $warning .= '<li>' . wfMsgExt( 'fileexists-thumbnail-yes', 'parsemag', $dlink ) .
 414+ '</li>' . $dlink2;
 415+ } elseif ( $existsType == 'thumb-name' ) {
418416 # Image w/o '180px-' does not exists, but we do not like these filenames
419417 $warning .= '<li>' . wfMsgExt( 'file-thumbnail-no', 'parseinline' ,
420418 substr( $partname , 0, strpos( $partname , '-' ) +1 ) ) . '</li>';
421 - }
422419 }
423420
424421 $filenamePrefixBlacklist = UploadBase::getFilenamePrefixBlacklist();
425422 # Do the match
426 - if(!isset($partname))
 423+ if( !isset( $partname ) )
427424 $partname = '';
428425 foreach( $filenamePrefixBlacklist as $prefix ) {
429426 if ( substr( $partname, 0, strlen( $prefix ) ) == $prefix ) {
@@ -431,6 +428,7 @@
432429 }
433430 }
434431
 432+ // TODO: This should be put deeper down (i.e. UploadBase::getExistsWarning)
435433 if ( $file->wasDeleted() && !$file->exists() ) {
436434 # If the file existed before and was deleted, warn the user of this
437435 # Don't bother doing so if the file exists now, however

Follow-up revisions

RevisionCommit summaryAuthorDate
r56619Merge upload fixes from trunk:...brion21:07, 18 September 2009

Status & tagging log