$start = $title === $fromTitle ? $fromTimestamp : $params['start'];
if ( !isset( $images[$title] ) ) {
- $result->addValue(
- array( 'query', 'pages', intval( $pageId ) ),
- 'imagerepository', ''
- );
- // The above can't fail because it doesn't increase the result size
- continue;
+ if ( isset( $prop['uploadwarning'] ) ) {
+ // Uploadwarning needs info about non-existing files
+ $images[$title] = wfLocalFile( $title );
+ } else {
+ $result->addValue(
+ array( 'query', 'pages', intval( $pageId ) ),
+ 'imagerepository', ''
+ );
+ // The above can't fail because it doesn't increase the result size
+ continue;
+ }
}
/** @var $img File */
$mediatype = isset( $prop['mediatype'] );
$archive = isset( $prop['archivename'] );
$bitdepth = isset( $prop['bitdepth'] );
+ $uploadwarning = isset( $prop['uploadwarning'] );
if ( ( $url || $sha1 || $meta || $mime || $mediatype || $archive || $bitdepth )
&& $file->isDeleted( File::DELETED_FILE ) ) {
$vals['bitdepth'] = $file->getBitDepth();
}
+ if ( $uploadwarning ) {
+ $vals['html'] = SpecialUpload::getExistsWarning( UploadBase::getExistsWarning( $file ) );
+ }
+
return $vals;
}
'metadata' => ' metadata - Lists Exif metadata for the version of the image',
'archivename' => ' archivename - Adds the file name of the archive version for non-latest versions',
'bitdepth' => ' bitdepth - Adds the bit depth of the version',
+ 'uploadwarning' => ' uploadwarning - Used by the Special:Upload page to get information about an existing file. Not intended for use outside MediaWiki core',
);
}
return $warning;
}
- /**
- * Get a list of warnings
- *
- * @param string $filename local filename, e.g. 'file exists', 'non-descriptive filename'
- * @return Array: list of warning messages
- */
- public static function ajaxGetExistsWarning( $filename ) {
- $file = wfFindFile( $filename );
- if ( !$file ) {
- // Force local file so we have an object to do further checks against
- // if there isn't an exact match...
- $file = wfLocalFile( $filename );
- }
- $s = ' ';
- if ( $file ) {
- $exists = UploadBase::getExistsWarning( $file );
- $warning = self::getExistsWarning( $exists );
- if ( $warning !== '' ) {
- $s = "<div>$warning</div>";
- }
- }
- return $s;
- }
-
/**
* Construct a warning and a gallery from an array of duplicate files.
* @param $dupes array
'timeoutID': false,
'keypress': function () {
- if ( !ajaxUploadDestCheck || !sajax_init_object() ) return;
+ if ( !ajaxUploadDestCheck ) return;
// Find file to upload
var destFile = document.getElementById('wpDestFile');
},
'checkNow': function (fname) {
- if ( !ajaxUploadDestCheck || !sajax_init_object() ) return;
+ if ( !ajaxUploadDestCheck ) return;
if ( this.timeoutID ) {
window.clearTimeout( this.timeoutID );
}
},
'timeout' : function() {
- if ( !ajaxUploadDestCheck || !sajax_init_object() ) return;
+ if ( !ajaxUploadDestCheck || this.nameToCheck === '' ) return;
injectSpinner( document.getElementById( 'wpDestFile' ), 'destcheck' );
- // Get variables into local scope so that they will be preserved for the
- // anonymous callback. fileName is copied so that multiple overlapping
- // ajax requests can be supported.
- var obj = this;
- var fileName = this.nameToCheck;
- sajax_do_call( 'SpecialUpload::ajaxGetExistsWarning', [this.nameToCheck],
- function (result) {
- obj.processResult(result, fileName)
+ var uploadWarningObj = this;
+ ( new mw.Api ).get( {
+ action: 'query',
+ titles: ( new mw.Title( this.nameToCheck, mw.config.get( 'wgNamespaceIds' ).file ) ).getPrefixedText(),
+ prop: 'imageinfo',
+ iiprop: 'uploadwarning',
+ indexpageids: '',
+ } ).done( function ( result ) {
+ var result = '';
+ if ( result.query ) {
+ result = result.query.pages[result.query.pageids[0]].imageinfo[0];
}
- );
+ uploadWarningObj.processResult( result, uploadWarningObj.nameToCheck );
+ } );
},
- 'processResult' : function (result, fileName) {
+ 'processResult' : function ( result, fileName ) {
removeSpinner( 'destcheck' );
- this.setWarning(result.responseText);
- this.responseCache[fileName] = result.responseText;
+ this.setWarning( result.html );
+ this.responseCache[fileName] = result.html;
},
'setWarning' : function (warning) {
// Set a value in the form indicating that the warning is acknowledged and
// doesn't need to be redisplayed post-upload
- if ( warning == '' || warning == ' ' ) {
+ if ( warning == '' ) {
ackElt[0].value = '';
} else {
ackElt[0].value = '1';
var title = document.getElementById('wpDestFile').value;
if ( !title ) title = 'File:Sample.jpg';
- var url = mw.util.wikiScript( 'api' )
- + '?action=parse&text={{' + encodeURIComponent( license ) + '}}'
- + '&title=' + encodeURIComponent( title )
- + '&prop=text&pst&format=json';
-
- var req = sajax_init_object();
- req.onreadystatechange = function() {
- if ( req.readyState == 4 && req.status == 200 )
- wgUploadLicenseObj.processResult( eval( '(' + req.responseText + ')' ), license );
- };
- req.open( 'GET', url, true );
- req.send( '' );
+ ( new mw.Api ).get( {
+ action: 'parse',
+ text: '{{' + license + '}}',
+ title: title,
+ prop: 'text',
+ pst: ''
+ } ).done( function ( result ) {
+ wgUploadLicenseObj.processResult( result, license );
+ } );
},
'processResult' : function( result, license ) {