From eb8541eab5f329a308f0c3c7611ae929a377f2f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C4=9Bj=20Such=C3=A1nek?= Date: Mon, 26 Dec 2016 10:34:16 +0000 Subject: [PATCH] Use mw.Api.parse() for previewing warnings And add the filter id as the second parameter to the message. Bug: T68351 Change-Id: Iee8ac20d3cc9c0f6340ec6f339b0e51d7c88f976 --- extension.json | 1 + modules/ext.abuseFilter.edit.js | 40 ++++++++++++++++++++------------- 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/extension.json b/extension.json index f0e98231b..75838ef2f 100644 --- a/extension.json +++ b/extension.json @@ -128,6 +128,7 @@ "dependencies": [ "mediawiki.util", "mediawiki.api", + "mediawiki.api.parse", "jquery.textSelection", "jquery.spinner" ] diff --git a/modules/ext.abuseFilter.edit.js b/modules/ext.abuseFilter.edit.js index 9fe111094..c5b0577a4 100644 --- a/modules/ext.abuseFilter.edit.js +++ b/modules/ext.abuseFilter.edit.js @@ -188,23 +188,31 @@ } /** - * Fetches the selected warning message for previewing - */ + * Fetches the selected warning message for previewing + */ function previewWarnMessage() { - $.get( - mw.config.get( 'wgScript' ), { - title: 'MediaWiki:' + getCurrentWarningMessage(), - action: 'render' - } - ) - .done( function( messageHtml ) { - // Replace $1 with the description of the filter - messageHtml = messageHtml.replace( - /\$1/g, - mw.html.escape( $( 'input[name=wpFilterDescription]' ).val() ) - ); - - $( '#mw-abusefilter-warn-preview' ).html( messageHtml ); + var api = new mw.Api(), + args = [ + $( 'input[name=wpFilterDescription]' ).val(), + $( '#mw-abusefilter-edit-id' ).children().last().text() + ], + message = getCurrentWarningMessage(); + api.get( { + action: 'query', + meta: 'allmessages', + ammessages: message, + amargs: args.join( '|' ), + } ) + .done( function( data ) { + api.parse( data.query.allmessages[0]['*'], { + disablelimitreport: '', + preview: '', + prop: 'text', + title: 'MediaWiki:' + message, + } ) + .done( function( html ) { + $( '#mw-abusefilter-warn-preview' ).html( html ); + } ); } ); }