Skip to content

Commit

Permalink
Better error message for no files found.
Browse files Browse the repository at this point in the history
  • Loading branch information
samwilson committed Nov 29, 2017
1 parent dec9939 commit 73bf348
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
3 changes: 2 additions & 1 deletion i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,6 @@
"invalid-length": "'$1' is too long",
"no-found-on-ia": "'$1' is not a valid Internet Archive identifier",
"already-on-commons": "A file named '$1' already exists on Wikimedia Commons",
"creator-template-missing": "The author '$1' doesn’t have a <a href='https://commons.wikimedia.org/wiki/Commons:Creator'>creator</a> template. If you know their Wikidata ID, you can <a href='https://tools.wmflabs.org/wikidata-todo/creator_from_wikidata.php'>create the template now</a>."
"creator-template-missing": "The author '$1' doesn’t have a <a href='https://commons.wikimedia.org/wiki/Commons:Creator'>creator</a> template. If you know their Wikidata ID, you can <a href='https://tools.wmflabs.org/wikidata-todo/creator_from_wikidata.php'>create the template now</a>.",
"no-usable-files-found": "No usable files (DjVu, PDF, or JP2) were found for that item."
}
3 changes: 2 additions & 1 deletion i18n/qqq.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,6 @@
"invalid-commons-name": "Message displayed when the provided Commons filename is not valid; $1 is a full HTML link",
"no-found-on-ia": "Message displayed when the provided IA identifier does not exist; $1 is a full HTML link",
"already-on-commons": "Message displayed when the provided Commons filename already exists; $1 is a full HTML link",
"creator-template-missing": "{{doc-singularthey}}"
"creator-template-missing": "{{doc-singularthey}}",
"no-usable-files-found": "Error message explaining that none of the required file formats were found on Internet Archive"
}
18 changes: 15 additions & 3 deletions src/IaUpload/CommonsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,18 @@ public function fill( Request $request ) {
}
$iaId = $iaData['metadata']['identifier'][0];

// Make sure at least one of the required input formats is available.
$djvuFilename = $this->getIaFileName( $iaData, 'djvu' );
$pdfFilename = $this->getIaFileName( $iaData, 'pdf' );
$jp2Filename = $this->getIaFileName( $iaData, 'jp2' );
if ( ! ( $djvuFilename || $pdfFilename || $jp2Filename ) ) {
return $this->outputsInitTemplate( [
'iaId' => $iaId,
'commonsName' => $commonsName,
'error' => $this->app['i18n']->message( 'no-usable-files-found' ),
] );
}

// See if the file already exists on Commons.
$fullCommonsName = $commonsName . '.djvu';
if ( $this->commonsClient->pageExist( 'File:' . $fullCommonsName ) ) {
Expand All @@ -215,9 +227,9 @@ public function fill( Request $request ) {
$templateParams = [
'iaId' => $iaId,
'commonsName' => $fullCommonsName,
'djvuFilename' => $this->getIaFileName( $iaData, 'djvu' ),
'pdfFilename' => $this->getIaFileName( $iaData, 'pdf' ),
'jp2Filename' => $this->getIaFileName( $iaData, 'jp2' ),
'djvuFilename' => $djvuFilename,
'pdfFilename' => $pdfFilename,
'jp2Filename' => $jp2Filename,
'fileSource' => $fileSource,
];
list( $description, $notes ) = $this->createPageContent( $iaData );
Expand Down
2 changes: 1 addition & 1 deletion views/commons/fill.twig
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<div class="form-group">
<label for="sourceFile" class="col-lg-2 control-label">{{ 'form-label-file-source'|message }}</label>
<div class="col-lg-10">
<select name="fileSource" id="sourceFile" class="form-control">
<select name="fileSource" id="sourceFile" class="form-control" required="required">
<option value="djvu" {% if fileSource == 'djvu' and djvuFilename %}selected{% endif %} {% if not djvuFilename %}disabled{% endif %}>
{{ 'file-source-djvu'|message }}
{% if not djvuFilename %}{{ 'file-source-not-available'|message }}{% endif %}
Expand Down

0 comments on commit 73bf348

Please sign in to comment.