Upload license preview now uses the API instead of action=ajax
This commit is contained in:
parent
0da22435e3
commit
824b9bcfa8
5 changed files with 27 additions and 35 deletions
|
|
@ -297,6 +297,7 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN
|
|||
* Send new password e-mail in users preference language
|
||||
* LanguageConverter now support nested using of manual convert syntax like "-{-{}-}-"
|
||||
* (bug 16281) Show copyright system message on special pages
|
||||
* Upload license preview now uses the API instead of action=ajax
|
||||
|
||||
=== Bug fixes in 1.16 ===
|
||||
|
||||
|
|
|
|||
|
|
@ -1658,7 +1658,7 @@ $wgCacheEpoch = '20030516000000';
|
|||
* to ensure that client-side caches do not keep obsolete copies of global
|
||||
* styles.
|
||||
*/
|
||||
$wgStyleVersion = '261';
|
||||
$wgStyleVersion = '262';
|
||||
|
||||
|
||||
# Server-side caching:
|
||||
|
|
@ -3753,7 +3753,7 @@ $wgAjaxWatch = true;
|
|||
$wgAjaxUploadDestCheck = true;
|
||||
|
||||
/**
|
||||
* Enable previewing licences via AJAX
|
||||
* Enable previewing licences via AJAX. Also requires $wgEnableAPI to be true.
|
||||
*/
|
||||
$wgAjaxLicensePreview = true;
|
||||
|
||||
|
|
|
|||
|
|
@ -337,8 +337,6 @@ $wgPostCommitUpdateList = array();
|
|||
|
||||
if ( $wgAjaxWatch ) $wgAjaxExportList[] = 'wfAjaxWatch';
|
||||
if ( $wgAjaxUploadDestCheck ) $wgAjaxExportList[] = 'SpecialUpload::ajaxGetExistsWarning';
|
||||
if( $wgAjaxLicensePreview )
|
||||
$wgAjaxExportList[] = 'SpecialUpload::ajaxGetLicensePreview';
|
||||
|
||||
# Placeholders in case of DB error
|
||||
$wgTitle = null;
|
||||
|
|
|
|||
|
|
@ -644,25 +644,6 @@ class SpecialUpload extends SpecialPage {
|
|||
return $s;
|
||||
}
|
||||
|
||||
/**
|
||||
* Render a preview of a given license for the AJAX preview on upload
|
||||
*
|
||||
* @param string $license
|
||||
* @return string
|
||||
*/
|
||||
public static function ajaxGetLicensePreview( $license ) {
|
||||
global $wgParser, $wgUser;
|
||||
$text = '{{' . $license . '}}';
|
||||
$title = Title::makeTitle( NS_FILE, 'Sample.jpg' );
|
||||
$options = ParserOptions::newFromUser( $wgUser );
|
||||
|
||||
// Expand subst: first, then live templates...
|
||||
$text = $wgParser->preSaveTransform( $text, $title, $wgUser, $options );
|
||||
$output = $wgParser->parse( $text, $title, $options );
|
||||
|
||||
return $output->getText();
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a warning and a gallery from an array of duplicate files.
|
||||
*/
|
||||
|
|
@ -984,15 +965,15 @@ class UploadForm extends HTMLForm {
|
|||
* filename text box
|
||||
*/
|
||||
protected function addUploadJS( ) {
|
||||
global $wgUseAjax, $wgAjaxUploadDestCheck, $wgAjaxLicensePreview;
|
||||
global $wgUseAjax, $wgAjaxUploadDestCheck, $wgAjaxLicensePreview, $wgEnableAPI;
|
||||
global $wgOut;
|
||||
|
||||
$useAjaxDestCheck = $wgUseAjax && $wgAjaxUploadDestCheck;
|
||||
$useAjaxLicensePreview = $wgUseAjax && $wgAjaxLicensePreview;
|
||||
$useAjaxLicensePreview = $wgUseAjax && $wgAjaxLicensePreview && $wgEnableAPI;
|
||||
|
||||
$scriptVars = array(
|
||||
'wgAjaxUploadDestCheck' => $wgUseAjax && $wgAjaxUploadDestCheck,
|
||||
'wgAjaxLicensePreview' => $wgUseAjax && $wgAjaxLicensePreview,
|
||||
'wgAjaxUploadDestCheck' => $useAjaxDestCheck,
|
||||
'wgAjaxLicensePreview' => $useAjaxLicensePreview,
|
||||
'wgUploadAutoFill' => !$this->mForReUpload,
|
||||
'wgUploadSourceIds' => $this->mSourceIds,
|
||||
);
|
||||
|
|
|
|||
|
|
@ -296,7 +296,7 @@ var wgUploadLicenseObj = {
|
|||
'responseCache' : { '' : '' },
|
||||
|
||||
'fetchPreview': function( license ) {
|
||||
if( !wgAjaxLicensePreview || !sajax_init_object() ) return;
|
||||
if( !wgAjaxLicensePreview ) return;
|
||||
for (cached in this.responseCache) {
|
||||
if (cached == license) {
|
||||
this.showPreview( this.responseCache[license] );
|
||||
|
|
@ -304,17 +304,29 @@ var wgUploadLicenseObj = {
|
|||
}
|
||||
}
|
||||
injectSpinner( document.getElementById( 'wpLicense' ), 'license' );
|
||||
sajax_do_call( 'SpecialUpload::ajaxGetLicensePreview', [license],
|
||||
function( result ) {
|
||||
wgUploadLicenseObj.processResult( result, license );
|
||||
}
|
||||
);
|
||||
|
||||
var title = document.getElementById('wpDestFile').value;
|
||||
if ( !title ) title = 'File:Sample.jpg';
|
||||
|
||||
var url = wgScriptPath + '/api' + wgScriptExtension
|
||||
+ '?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( '' );
|
||||
},
|
||||
|
||||
'processResult' : function( result, license ) {
|
||||
removeSpinner( 'license' );
|
||||
this.showPreview( result.responseText );
|
||||
this.responseCache[license] = result.responseText;
|
||||
this.responseCache[license] = result['parse']['text']['*'];
|
||||
this.showPreview( this.responseCache[license] );
|
||||
|
||||
},
|
||||
|
||||
'showPreview' : function( preview ) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue