mediawiki.special.upload: Use mediawiki.api.parse
authorFomafix <fomafix@googlemail.com>
Sun, 21 Jan 2018 13:54:14 +0000 (14:54 +0100)
committerFomafix <fomafix@googlemail.com>
Sun, 21 Jan 2018 14:21:07 +0000 (15:21 +0100)
This also adds the parameter contentmodel=wikitext to the API request.
This ensures that the text is always parsed as wikitext, even with a
title with a different content model like 'MediaWiki:Common.js'.

Change-Id: I29f0c76c3354a8c97b8296224e14341f71726c2f

resources/Resources.php
resources/src/mediawiki.special/mediawiki.special.upload.js

index 109ab7d..0e9ab18 100644 (file)
@@ -2208,6 +2208,7 @@ return [
                        'jquery.spinner',
                        'mediawiki.jqueryMsg',
                        'mediawiki.api',
+                       'mediawiki.api.parse',
                        'mediawiki.libs.jpegmeta',
                        'mediawiki.Title',
                        'mediawiki.util',
index 9bf6255..0c3eb21 100644 (file)
 
                        $spinner = $.createSpinner().insertAfter( $element );
 
-                       ( new mw.Api() ).get( {
-                               formatversion: 2,
-                               action: 'parse',
-                               text: '{{' + template + '}}',
+                       ( new mw.Api() ).parse( '{{' + template + '}}', {
                                title: $( '#wpDestFile' ).val() || 'File:Sample.jpg',
                                prop: 'text',
                                pst: true,
                },
 
                processResult: function ( result, template, $previewContainer ) {
-                       this.responseCache[ template ] = result.parse.text;
+                       this.responseCache[ template ] = result;
                        this.showPreview( this.responseCache[ template ], $previewContainer );
                },