From 0dfba0b25f2ba5802bb1b15b949d9a9e0e50d561 Mon Sep 17 00:00:00 2001 From: Raimond Spekking Date: Fri, 7 Sep 2007 08:42:39 +0000 Subject: [PATCH] * Add a warning for non-descriptive filenames at Special:Upload * Some tweaks to RELEASE-NOTES --- RELEASE-NOTES | 5 +-- includes/SpecialUpload.php | 46 +++++++++++++++++++++++++++ languages/messages/MessagesDe.php | 2 ++ languages/messages/MessagesEn.php | 15 +++++++++ maintenance/language/messageTypes.inc | 1 + maintenance/language/messages.inc | 2 ++ 6 files changed, 69 insertions(+), 2 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 616d9f6697..95edd9a8f1 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -18,9 +18,10 @@ will be made on the development trunk and appear in the next quarterly release. Those wishing to use the latest code instead of a branch release can obtain it from source control: http://www.mediawiki.org/wiki/Download_from_SVN -=== Configuration changes since 1.11 === +=== Configuration changes in 1.12 === === New features in 1.12 === +* Add a warning for non-descriptive filenames at Special:Upload === Bug fixes in 1.12 === @@ -50,7 +51,7 @@ At this time we still recommend 4.0, but 4.1/5.0 will work fine in most cases. == Upgrading == -1.12 has several database changes since 1.10, and will not work without schema +1.12 has several database changes since 1.11, and will not work without schema updates. If upgrading from before 1.7, you may want to run refreshLinks.php to ensure diff --git a/includes/SpecialUpload.php b/includes/SpecialUpload.php index 18c6dd9e14..14338d6918 100644 --- a/includes/SpecialUpload.php +++ b/includes/SpecialUpload.php @@ -542,6 +542,18 @@ class UploadForm { substr( $partname , 0, strpos( $partname , '-' ) +1 ) ) . ''; } } + + $filenamePrefix = self::getFilenamePrefix(); + if ( count( $filenamePrefix ) ) { + # Do the match + foreach( $filenamePrefix as $prefix ) { + if ( substr( $partname, 0, strlen( $prefix ) ) == $prefix ) { + $warning .= '
  • ' . wfMsgExt( 'filename-prefix', 'parseinline', $prefix ) . '
  • '; + break; + } + } + } + if ( $file->wasDeleted() ) { # If the file existed before and was deleted, warn the user of this # Don't bother doing so if the image exists now, however @@ -553,6 +565,12 @@ class UploadForm { return $warning; } + /** + * Get a list of warnings + * + * @param string local filename, e.g. 'file exists', 'non-descriptive filename' + * @return array list of warning messages + */ static function ajaxGetExistsWarning( $filename ) { $file = wfFindFile( $filename ); if( !$file ) { @@ -589,6 +607,34 @@ class UploadForm { return $output->getText(); } + /** + * Get a list of filename prefixes from [[MediaWiki:filename-prefix-list]] + * + * @return array list of prefixes + */ + public static function getFilenamePrefix() { + $message = wfMsgForContent( 'filename-prefix-list' ); + if( $message && !( wfEmptyMsg( 'filename-prefix-list', $message ) || $message == '-' ) ) { + $lines = explode( "\n", $message ); + foreach( $lines as $line ) { + // Remove comment lines + $comment = substr( trim( $line ), 0, 1 ); + if ( $comment == '#' || $comment == '' ) { + continue; + } + // Remove additional comments after a prefix + $comment = strpos( $line, '#' ); + if ( $comment > 0 ) { + $line = substr( $line, 0, $comment-1 ); + } + $filenamePrefix[] = trim( $line ); + } + } else { + $filenamePrefix = array(); + } + return $filenamePrefix; + } + /** * Stash a file in a temporary directory for later processing * after the user has confirmed it. diff --git a/languages/messages/MessagesDe.php b/languages/messages/MessagesDe.php index 7d4b637424..df53966196 100644 --- a/languages/messages/MessagesDe.php +++ b/languages/messages/MessagesDe.php @@ -1073,6 +1073,8 @@ Bitte prüfe, ob du das Bild in voller Auflösung vorliegen hast und lade dieses 'destfilename' => 'Zielname', 'watchthisupload' => 'Diese Seite beobachten', 'filewasdeleted' => 'Eine Datei mit diesem Namen wurde schon einmal hochgeladen und zwischenzeitlich wieder gelöscht. Bitte prüfe zuerst den Eintrag im $1, bevor du die Datei wirklich speicherst.', +'filename-prefix' => 'Der Dateiname beginnt mit „$1“. Dies ist im allgemeinen der von einer Digitalkamera vorgegebener Dateiname und daher nicht sehr aussagekräftig. +Bitte gebe der Datei einen Namen, der den Inhalt besser beschreibt.', 'upload-proto-error' => 'Falsches Protokoll', 'upload-proto-error-text' => 'Die URL muss mit http:// oder ftp:// beginnen.', diff --git a/languages/messages/MessagesEn.php b/languages/messages/MessagesEn.php index b2a7d2c93b..6e6763eb8c 100644 --- a/languages/messages/MessagesEn.php +++ b/languages/messages/MessagesEn.php @@ -1422,6 +1422,21 @@ If you have this image in full resolution upload this one, otherwise change the 'destfilename' => 'Destination filename', 'watchthisupload' => 'Watch this page', 'filewasdeleted' => 'A file of this name has been previously uploaded and subsequently deleted. You should check the $1 before proceeding to upload it again.', +'filename-prefix' => 'The name of the file you are uploading begins with "$1", which is a non-descriptive name typically assigned automatically by digital cameras. Please choose a more descriptive name for your file.', +'filename-prefix-list' => ' #
    +# Syntax is as follows: 
    +#   * Everything from a "#" character to the end of the line is a comment
    +#   * Every non-blank line is a prefix for typical file names assigned automatically by digital cameras
    +CIMG # Casio
    +DSC_ # Nikon
    +DSCF # Fuji
    +DSCN # Nikon
    +DUW # some mobil phones
    +IMG # generic
    +JD # Jenoptik
    +MGP # Pentax
    +PICT # misc.
    + #
    ', # only translate this message to other languages if you have to change it 'upload-proto-error' => 'Incorrect protocol', 'upload-proto-error-text' => 'Remote upload requires URLs beginning with http:// or ftp://.', diff --git a/maintenance/language/messageTypes.inc b/maintenance/language/messageTypes.inc index 21734eb394..77fcb7595e 100644 --- a/maintenance/language/messageTypes.inc +++ b/maintenance/language/messageTypes.inc @@ -204,6 +204,7 @@ $wgOptionalMessages = array( 'filerevert-backlink', 'filedelete-backlink', 'pagetitle', + 'filename-prefix-list', ); /** EXIF messages, which may be set as optional in several checks, but are generally mandatory */ diff --git a/maintenance/language/messages.inc b/maintenance/language/messages.inc index 007630335d..3fafbac168 100644 --- a/maintenance/language/messages.inc +++ b/maintenance/language/messages.inc @@ -824,6 +824,8 @@ $wgMessageStructure = array( 'destfilename', 'watchthisupload', 'filewasdeleted', + 'filename-prefix', + 'filename-prefix-list', ), 'upload-errors' => array( 'upload-proto-error', -- 2.20.1