jenkins-bot has submitted this change and it was merged.
Change subject: Replace remaining sajax use
......................................................................
Replace remaining sajax use
Bug: 40785
Change-Id: I4a0af8986f924cd127a73828e72da6998f28536c
---
M includes/Setup.php
M includes/api/ApiQueryImageInfo.php
M includes/specials/SpecialUpload.php
M resources/Resources.php
M skins/common/upload.js
5 files changed, 48 insertions(+), 62 deletions(-)
Approvals:
Tim Starling: Looks good to me, approved
jenkins-bot: Verified
diff --git a/includes/Setup.php b/includes/Setup.php
index 4f5ac92..cfe5f1c 100644
--- a/includes/Setup.php
+++ b/includes/Setup.php
@@ -377,10 +377,6 @@
$wgCacheEpoch = max( $wgCacheEpoch, gmdate( 'YmdHis', @filemtime(
"$IP/LocalSettings.php" ) ) );
}
-if ( $wgAjaxUploadDestCheck ) {
- $wgAjaxExportList[] = 'SpecialUpload::ajaxGetExistsWarning';
-}
-
if ( $wgNewUserLog ) {
# Add a new log type
$wgLogTypes[] = 'newusers';
diff --git a/includes/api/ApiQueryImageInfo.php
b/includes/api/ApiQueryImageInfo.php
index 40041d8..0ea2868 100644
--- a/includes/api/ApiQueryImageInfo.php
+++ b/includes/api/ApiQueryImageInfo.php
@@ -82,12 +82,17 @@
$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 */
@@ -358,6 +363,7 @@
$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 ) ) {
@@ -425,6 +431,10 @@
if ( $bitdepth ) {
$vals['bitdepth'] = $file->getBitDepth();
+ }
+
+ if ( $uploadwarning ) {
+ $vals['html'] = SpecialUpload::getExistsWarning(
UploadBase::getExistsWarning( $file ) );
}
return $vals;
@@ -556,6 +566,7 @@
'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',
);
}
diff --git a/includes/specials/SpecialUpload.php
b/includes/specials/SpecialUpload.php
index 98d0c9a..efde5cb 100644
--- a/includes/specials/SpecialUpload.php
+++ b/includes/specials/SpecialUpload.php
@@ -673,30 +673,6 @@
}
/**
- * 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
* @return string
diff --git a/resources/Resources.php b/resources/Resources.php
index 6352843..6f0d3be 100644
--- a/resources/Resources.php
+++ b/resources/Resources.php
@@ -1080,6 +1080,8 @@
'remoteBasePath' => $GLOBALS['wgStylePath'],
'localBasePath' => $GLOBALS['wgStyleDirectory'],
'dependencies' => array(
+ 'mediawiki.api',
+ 'mediawiki.Title',
'mediawiki.legacy.wikibits',
'mediawiki.util',
),
diff --git a/skins/common/upload.js b/skins/common/upload.js
index 4246e82..2c2203c 100644
--- a/skins/common/upload.js
+++ b/skins/common/upload.js
@@ -96,7 +96,7 @@
'timeoutID': false,
'keypress': function () {
- if ( !ajaxUploadDestCheck || !sajax_init_object() ) return;
+ if ( !ajaxUploadDestCheck ) return;
// Find file to upload
var destFile = document.getElementById('wpDestFile');
@@ -121,7 +121,7 @@
},
'checkNow': function (fname) {
- if ( !ajaxUploadDestCheck || !sajax_init_object() ) return;
+ if ( !ajaxUploadDestCheck ) return;
if ( this.timeoutID ) {
window.clearTimeout( this.timeoutID );
}
@@ -130,25 +130,29 @@
},
'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) {
@@ -159,7 +163,7 @@
// 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';
@@ -279,18 +283,15 @@
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 ) {
--
To view, visit https://gerrit.wikimedia.org/r/65641
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I4a0af8986f924cd127a73828e72da6998f28536c
Gerrit-PatchSet: 8
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Alex Monk <[email protected]>
Gerrit-Reviewer: Alex Monk <[email protected]>
Gerrit-Reviewer: Catrope <[email protected]>
Gerrit-Reviewer: Daniel Friesen <[email protected]>
Gerrit-Reviewer: Krinkle <[email protected]>
Gerrit-Reviewer: Ori.livneh <[email protected]>
Gerrit-Reviewer: PleaseStand <[email protected]>
Gerrit-Reviewer: TheDJ <[email protected]>
Gerrit-Reviewer: Tim Starling <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits