r56639 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r56638‎ | r56639 | r56640 >
Date:15:42, 19 September 2009
Author:btongminh
Status:ok
Tags:
Comment:
Fix several messages generated by SpecialUpload::getExistsWarning which were malformatted. Also removed all HTML generation from that function.
Modified paths:
  • /trunk/phase3/includes/specials/SpecialUpload.php (modified) (history)
  • /trunk/phase3/includes/upload/UploadBase.php (modified) (history)
  • /trunk/phase3/languages/messages/MessagesEn.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/upload/UploadBase.php
@@ -965,44 +965,56 @@
966966 */
967967 public static function getExistsWarning( $file ) {
968968 if( $file->exists() )
969 - return array( 'exists', $file );
 969+ return array( 'warning' => 'exists', 'file' => $file );
970970
971971 if( $file->getTitle()->getArticleID() )
972 - return array( 'page-exists', $file );
973 -
 972+ return array( 'warning' => 'page-exists', 'file' => $file );
 973+
 974+ if ( $file->wasDeleted() && !$file->exists() )
 975+ return array( 'warning' => 'was-deleted', 'file' => $file );
 976+
974977 if( strpos( $file->getName(), '.' ) == false ) {
975978 $partname = $file->getName();
976 - $rawExtension = '';
 979+ $extension = '';
977980 } else {
978981 $n = strrpos( $file->getName(), '.' );
979 - $rawExtension = substr( $file->getName(), $n + 1 );
 982+ $extension = substr( $file->getName(), $n + 1 );
980983 $partname = substr( $file->getName(), 0, $n );
981984 }
 985+ $normalizedExtension = File::normalizeExtension( $extension );
982986
983 - if ( $rawExtension != $file->getExtension() ) {
 987+ if ( $normalizedExtension != $extension ) {
984988 // We're not using the normalized form of the extension.
985989 // Normal form is lowercase, using most common of alternate
986990 // extensions (eg 'jpg' rather than 'JPEG').
987991 //
988992 // Check for another file using the normalized form...
989 - $nt_lc = Title::makeTitle( NS_FILE, $partname . '.' . $file->getExtension() );
 993+ $nt_lc = Title::makeTitle( NS_FILE, "{$partname}.{$normalizedExtension}" );
990994 $file_lc = wfLocalFile( $nt_lc );
991995
992996 if( $file_lc->exists() )
993 - return array( 'exists-normalized', $file_lc );
 997+ return array( 'warning' => 'exists-normalized', 'file' => $file, 'normalizedFile' => $file_lc );
994998 }
995999
9961000 if ( self::isThumbName( $file->getName() ) ) {
9971001 # Check for filenames like 50px- or 180px-, these are mostly thumbnails
998 - $nt_thb = Title::newFromText( substr( $partname , strpos( $partname , '-' ) +1 ) . '.' . $rawExtension );
 1002+ $nt_thb = Title::newFromText( substr( $partname , strpos( $partname , '-' ) +1 ) . '.' . $extension, NS_FILE );
9991003 $file_thb = wfLocalFile( $nt_thb );
10001004 if( $file_thb->exists() )
1001 - return array( 'thumb', $file_thb );
 1005+ return array( 'warning' => 'thumb', 'file' => $file, 'thumbFile' => $file_thb );
10021006 else
10031007 // File does not exist, but we just don't like the name
1004 - return array( 'thumb-name', $file_thb );
 1008+ return array( 'warning' => 'thumb-name', 'file' => $file, 'thumbFile' => $file_thb );
10051009 }
 1010+
10061011
 1012+ foreach( self::getFilenamePrefixBlacklist() as $prefix ) {
 1013+ if ( substr( $partname, 0, strlen( $prefix ) ) == $prefix )
 1014+ return array( 'warning' => 'bad-prefix', 'file' => $file, 'prefix' => $prefix );
 1015+ }
 1016+
 1017+
 1018+
10071019 return false;
10081020 }
10091021
Index: trunk/phase3/includes/specials/SpecialUpload.php
@@ -131,7 +131,7 @@
132132 if( !$this->mTokenOk && !$this->mReUpload && ($this->mUpload && (
133133 'submit' == $this->mAction || $this->mUploadClicked ) ) )
134134 {
135 - $this->mainUploadForm ( wfMsg( 'session_fail_preview' ) );
 135+ $this->mainUploadForm ( wfMsg( 'session_fail_preview', 'parseinline' ) );
136136 return ;
137137 }
138138
@@ -333,105 +333,34 @@
334334 if ( !$exists )
335335 return '';
336336
337 - $warning = '';
338 - $align = $wgContLang->alignEnd();
 337+ $file = $exists['file'];
 338+ $filename = $file->getTitle()->getPrefixedText();
 339+ $warning = array();
339340
340 - list( $existsType, $file ) = $exists;
341 -
342 - if ( strpos( $file->getName(), '.' ) == false ) {
343 - // File does not have an extension or starts with a dot
344 - $partname = $file->getName();
345 - $rawExtension = '';
346 - } else {
347 - $n = strrpos( $file->getName(), '.' );
348 - $rawExtension = substr( $file->getName(), $n + 1 );
349 - $partname = substr( $file->getName(), 0, $n );
350 - }
351 -
352341 $sk = $wgUser->getSkin();
353342
354 - if( $existsType == 'exists' ) {
 343+ if( $exists['warning'] == 'exists' ) {
355344 // Exact match
356 - $dlink = $sk->linkKnown( $file->getTitle() );
357 - if ( $file->allowInlineDisplay() ) {
358 - $dlink2 = $sk->makeImageLinkObj( $file->getTitle(), wfMsgExt( 'fileexists-thumb', 'parseinline' ),
359 - $file->getName(), $align, array(), false, true );
360 - } elseif ( !$file->allowInlineDisplay() && $file->isSafeFile() ) {
361 - $icon = $file->iconThumb();
362 - $dlink2 = '<div style="float:' . $align . '" id="mw-media-icon">' .
363 - $icon->toHtml( array( 'desc-link' => true ) ) . '<br />' . $dlink . '</div>';
364 - } else {
365 - $dlink2 = '';
366 - }
367 -
368 - $warning .= '<li>' . wfMsgExt( 'fileexists', array('parseinline','replaceafter'), $dlink ) . '</li>' . $dlink2;
369 -
370 - } elseif( $existsType == 'page-exists' ) {
 345+ $warning[] = '<li>' . wfMsgExt( 'fileexists', 'parseinline', $filename ) . '</li>';
 346+ } elseif( $exists['warning'] == 'page-exists' ) {
371347 // Page exists but file does not
372 - $lnk = $sk->linkKnown( $file->getTitle(), '', '',array('redirect'=>'no') );
373 - $warning .= '<li>' . wfMsgExt( 'filepageexists', array( 'parseinline', 'replaceafter' ), $lnk ) . '</li>';
374 - } elseif ( $existsType == 'exists-normalized' ) {
375 - # Check if image with lowercase extension exists.
376 - # It's not forbidden but in 99% it makes no sense to upload the same filename with uppercase extension
377 - $normalizedTitle = $file->getTitle();
378 - $dlink = $sk->linkKnown( $normalizedTitle );
379 - if ( $file->allowInlineDisplay() ) {
380 - // FIXME: replace deprecated makeImageLinkObj by link()
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();
385 - $dlink2 = '<div style="float:' . $align . '" id="mw-media-icon">' .
386 - $icon->toHtml( array( 'desc-link' => true ) ) . '<br />' . $dlink . '</div>';
387 - } else {
388 - $dlink2 = '';
389 - }
390 -
391 - $warning .= '<li>' .
392 - wfMsgExt( 'fileexists-extension', 'parsemag',
393 - $file->getTitle()->getPrefixedText(), $dlink ) .
394 - '</li>' . $dlink2;
395 -
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>';
409 - } else {
410 - $dlink2 = '';
411 - }
412 -
413 - $warning .= '<li>' . wfMsgExt( 'fileexists-thumbnail-yes', 'parsemag', $dlink ) .
414 - '</li>' . $dlink2;
415 - } elseif ( $existsType == 'thumb-name' ) {
416 - # Image w/o '180px-' does not exists, but we do not like these filenames
417 - $warning .= '<li>' . wfMsgExt( 'file-thumbnail-no', 'parseinline' ,
418 - substr( $partname , 0, strpos( $partname , '-' ) +1 ) ) . '</li>';
419 - }
420 -
421 - $filenamePrefixBlacklist = UploadBase::getFilenamePrefixBlacklist();
422 - # Do the match
423 - if( !isset( $partname ) )
424 - $partname = '';
425 - foreach( $filenamePrefixBlacklist as $prefix ) {
426 - if ( substr( $partname, 0, strlen( $prefix ) ) == $prefix ) {
427 - $warning .= '<li>' . wfMsgExt( 'filename-bad-prefix', 'parseinline', $prefix ) . '</li>';
428 - break;
429 - }
430 - }
431 -
432 - // TODO: This should be put deeper down (i.e. UploadBase::getExistsWarning)
433 - if ( $file->wasDeleted() && !$file->exists() ) {
 348+ $warning[] = '<li>' . wfMsgExt( 'filepageexists', 'parseinline', $filename ) . '</li>';
 349+ } elseif ( $exists['warning'] == 'exists-normalized' ) {
 350+ $warning[] = '<li>' . wfMsgExt( 'fileexists-extension', 'parseinline', $filename,
 351+ $exists['normalizedFile']->getTitle()->getPrefixedText() ) . '</li>';
 352+ } elseif ( $exists['warning'] == 'thumb' ) {
 353+ // Swapped argument order compared with other messages for backwards compatibility
 354+ $warning[] = '<li>' . wfMsgExt( 'fileexists-thumbnail-yes', 'parseinline',
 355+ $exists['thumbFile']->getTitle()->getPrefixedText(), $filename ) . '</li>';
 356+ } elseif ( $exists['warning'] == 'thumb-name' ) {
 357+ # Image w/o '180px-' does not exists, but we do not like these filenames
 358+ $name = $file->getName();
 359+ $badPart = substr( $name, 0, strpos( $name, '-' ) + 1 );
 360+ $warning[] = '<li>' . wfMsgExt( 'file-thumbnail-no', 'parseinline', $badPart ) . '</li>';
 361+ } elseif ( $exists['warning'] == 'bad-prefix' ) {
 362+ $warning[] = '<li>' . wfMsgExt( 'filename-bad-prefix', 'parseinline', $exists['prefix'] ) . '</li>';
 363+ } elseif ( $exists['warning'] == 'was-deleted' ) {
434364 # If the file existed before and was deleted, warn the user of this
435 - # Don't bother doing so if the file exists now, however
436365 $ltitle = SpecialPage::getTitleFor( 'Log' );
437366 $llink = $sk->linkKnown(
438367 $ltitle,
@@ -439,12 +368,13 @@
440369 array(),
441370 array(
442371 'type' => 'delete',
443 - 'page' => $file->getTitle()->getPrefixedText()
 372+ 'page' => $filename
444373 )
445374 );
446 - $warning .= '<li>' . wfMsgWikiHtml( 'filewasdeleted', $llink ) . '</li>';
 375+ $warning[] = '<li>' . wfMsgWikiHtml( 'filewasdeleted', $llink ) . '</li>';
447376 }
448 - return $warning;
 377+
 378+ return implode( "\n", $warning );
449379 }
450380
451381 /**
Index: trunk/phase3/languages/messages/MessagesEn.php
@@ -2078,17 +2078,16 @@
20792079 'emptyfile' => 'The file you uploaded seems to be empty.
20802080 This might be due to a typo in the file name.
20812081 Please check whether you really want to upload this file.',
2082 -'fileexists' => "A file with this name exists already, please check '''<tt>$1</tt>''' if you are not sure if you want to change it.",
2083 -'filepageexists' => "The description page for this file has already been created at '''<tt>$1</tt>''', but no file with this name currently exists.
 2082+'fileexists' => "A file with this name exists already, please check '''<tt>[[:$1]]</tt>''' if you are not sure if you want to change it. [[$1|thumb]]",
 2083+'filepageexists' => "The description page for this file has already been created at '''<tt>[[:$1]]</tt>''', but no file with this name currently exists.
20842084 The summary you enter will not appear on the description page.
2085 -To make your summary appear there, you will need to manually edit it",
2086 -'fileexists-extension' => "A file with a similar name exists:<br />
2087 -Name of the uploading file: '''<tt>$1</tt>'''<br />
2088 -Name of the existing file: '''<tt>$2</tt>'''<br />
 2085+To make your summary appear there, you will need to manually edit it. [[$1|thumb]]",
 2086+'fileexists-extension' => "A file with a similar name exists: [[$2|thumb]]
 2087+* Name of the uploading file: '''<tt>[[:$1]]</tt>'''
 2088+* Name of the existing file: '''<tt>[[:$2]]</tt>'''
20892089 Please choose a different name.",
2090 -'fileexists-thumb' => "<center>'''Existing file'''</center>",
2091 -'fileexists-thumbnail-yes' => "The file seems to be an image of reduced size ''(thumbnail)''.
2092 -Please check the file '''<tt>$1</tt>'''.<br />
 2090+'fileexists-thumbnail-yes' => "The file seems to be an image of reduced size ''(thumbnail)''. [[$1|thumb]]
 2091+Please check the file '''<tt>[[:$1]]</tt>'''.
20932092 If the checked file is the same image of original size it is not necessary to upload an extra thumbnail.",
20942093 'file-thumbnail-no' => "The filename begins with '''<tt>$1</tt>'''.
20952094 It seems to be an image of reduced size ''(thumbnail)''.

Follow-up revisions

RevisionCommit summaryAuthorDate
r56640Follow up to r56639: Remove some existence check duplication and fix ApiUploa...btongminh15:49, 19 September 2009
r56734Merge r56631, fix for bug 20677....werdna21:01, 21 September 2009

Status & tagging log