Upload license preview now uses the API instead of action=ajax
authorBryan Tong Minh <btongminh@users.mediawiki.org>
Wed, 13 Jan 2010 14:28:48 +0000 (14:28 +0000)
committerBryan Tong Minh <btongminh@users.mediawiki.org>
Wed, 13 Jan 2010 14:28:48 +0000 (14:28 +0000)
RELEASE-NOTES
includes/DefaultSettings.php
includes/Setup.php
includes/specials/SpecialUpload.php
skins/common/upload.js

index 7b8085e..4fe18fb 100644 (file)
@@ -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 ===
 
index ddef2a0..0b710e5 100644 (file)
@@ -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;
 
index 4887038..6f310c7 100644 (file)
@@ -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;
index 2df3cea..69cf96e 100644 (file)
@@ -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,
                );
index cc506e7..fcccdd2 100644 (file)
@@ -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 ) {