From: Bryan Tong Minh Date: Wed, 13 Jan 2010 14:28:48 +0000 (+0000) Subject: Upload license preview now uses the API instead of action=ajax X-Git-Tag: 1.31.0-rc.0~38292 X-Git-Url: https://git.cyclocoop.org/%242?a=commitdiff_plain;h=824b9bcfa8ffc82d7244b4f79c3baac60ff77756;p=lhc%2Fweb%2Fwiklou.git Upload license preview now uses the API instead of action=ajax --- diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 7b8085efdd..4fe18fb32e 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -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 === diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index ddef2a0263..0b710e5d37 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -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; diff --git a/includes/Setup.php b/includes/Setup.php index 4887038e3f..6f310c7c60 100644 --- a/includes/Setup.php +++ b/includes/Setup.php @@ -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; diff --git a/includes/specials/SpecialUpload.php b/includes/specials/SpecialUpload.php index 2df3cea53c..69cf96ee33 100644 --- a/includes/specials/SpecialUpload.php +++ b/includes/specials/SpecialUpload.php @@ -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, ); diff --git a/skins/common/upload.js b/skins/common/upload.js index cc506e7b5e..fcccdd2507 100644 --- a/skins/common/upload.js +++ b/skins/common/upload.js @@ -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 ) {