From: Krinkle Date: Sat, 21 May 2011 11:26:27 +0000 (+0000) Subject: Adding mw.util.wikiScript + small fix in mediawiki.action.watch.ajax.js X-Git-Tag: 1.31.0-rc.0~30040 X-Git-Url: https://git.cyclocoop.org/%242?a=commitdiff_plain;h=0ae10f2d0716e23010b21cff9e23716ea9366582;p=lhc%2Fweb%2Fwiklou.git Adding mw.util.wikiScript + small fix in mediawiki.action.watch.ajax.js * Moving wiki* functions together in mediawiki.util.js * Adding Adding mw.util.wikiScript (like wfScript() in GlobalFunctions.php) * Adding test suite for it * Example to use it in mediawiki.action.watch.ajax.js * (bug 29071) mediawiki.action.watch.ajax.js doesn't use uselang --- diff --git a/RELEASE-NOTES-1.19 b/RELEASE-NOTES-1.19 index e7b2611a78..67703b4725 100644 --- a/RELEASE-NOTES-1.19 +++ b/RELEASE-NOTES-1.19 @@ -36,6 +36,8 @@ production. Also built-in support for distribution through a TestSwarm instance. * (bug 29036) For cascade-protected pages, the mw-textarea-cprotected class is added to the textarea on the edit form. +* mw.util.getScript has been implemented (like wfScript in GlobalFunctions.php) + === Bug fixes in 1.19 === * (bug 10154) Don't allow user to specify days beyond $wgRCMaxAge. @@ -72,6 +74,7 @@ production. also in RTL text. * (bug 29055) Make don't send email on minor edits preference apply to changes to talk page in addition to watchlist edits. +* (bug 29071) mediawiki.action.watch.ajax.js should pass uselang to API. === API changes in 1.19 === * (bug 27790) add query type for querymodules to action=paraminfo diff --git a/resources/mediawiki.action/mediawiki.action.watch.ajax.js b/resources/mediawiki.action/mediawiki.action.watch.ajax.js index 7fb26dbc03..484b3b0d12 100644 --- a/resources/mediawiki.action/mediawiki.action.watch.ajax.js +++ b/resources/mediawiki.action/mediawiki.action.watch.ajax.js @@ -80,17 +80,18 @@ $( document ).ready( function() { } setLinkText( $link, $link.data( 'action' ) + 'ing' ); - + var reqData = { 'action': 'watch', 'format': 'json', - 'title': $link.data( 'target' ) + 'title': $link.data( 'target' ), + // API return contains a localized data.watch.message string. + 'uselang': mw.config.get( 'wgUserLanguage' ) }; if ( $link.data( 'action' ) == 'unwatch' ) { - reqData['unwatch'] = ''; + reqData.unwatch = ''; } - $.getJSON( mw.config.get( 'wgScriptPath' ) - + '/api' + mw.config.get( 'wgScriptExtension' ), + $.getJSON( mw.util.wikiScript( 'api' ), reqData, function( data, textStatus, xhr ) { processResult( data, $link ); diff --git a/resources/mediawiki.util/mediawiki.util.js b/resources/mediawiki.util/mediawiki.util.js index 0678e863b5..a23af62c17 100644 --- a/resources/mediawiki.util/mediawiki.util.js +++ b/resources/mediawiki.util/mediawiki.util.js @@ -137,6 +137,28 @@ .replace( /%20/g, '_' ).replace( /%3A/g, ':' ).replace( /%2F/g, '/' ); }, + /** + * Get the link to a page name (relative to wgServer) + * + * @param str Page name to get the link for. + * @return string Location for a page with name of 'str' or boolean false on error. + */ + 'wikiGetlink' : function( str ) { + + return mw.config.get( 'wgArticlePath' ).replace( '$1', this.wikiUrlencode( str ) ); + }, + + /** + * Get address to a script in the wiki root. + * For index.php use mw.config.get( 'wgScript' ) + * + * @param str Name of script (eg. 'api'), defaults to 'index' + * @return str Address to script (eg. '/w/api.php' ) + */ + 'wikiScript' : function( str ) { + return mw.config.get( 'wgScriptPath' ) + '/' + ( str || 'index' ) + mw.config.get( 'wgScriptExtension' ); + }, + /** * Append a new style block to the head * @@ -190,17 +212,6 @@ } }, - /** - * Get the link to a page name (relative to wgServer) - * - * @param str Page name to get the link for. - * @return string Location for a page with name of 'str' or boolean false on error. - */ - 'wikiGetlink' : function( str ) { - - return mw.config.get( 'wgArticlePath' ).replace( '$1', this.wikiUrlencode( str ) ); - }, - /** * Grab the URL parameter value for the given parameter. * Returns null if not found. diff --git a/tests/qunit/suites/resources/mediawiki.util/mediawiki.util.js b/tests/qunit/suites/resources/mediawiki.util/mediawiki.util.js index 736f40be1c..8bb004f1e4 100644 --- a/tests/qunit/suites/resources/mediawiki.util/mediawiki.util.js +++ b/tests/qunit/suites/resources/mediawiki.util/mediawiki.util.js @@ -18,36 +18,48 @@ test( 'wikiUrlencode', function(){ }); -test( 'addCSS', function(){ +test( 'wikiGetlink', function(){ - var a = mw.util.addCSS( '#bodyContent { visibility: hidden; }' ); - ok( a, 'function works' ); - deepEqual( a.disabled, false, 'property "disabled" is available and set to false' ); + // Not part of startUp module + mw.config.set( 'wgArticlePath', '/wiki/$1' ); - var $b = $('#bodyContent'); - equal( $b.css('visibility'), 'hidden', 'Added style properties are in effect.' ); + var hrefA = mw.util.wikiGetlink( 'Sandbox' ); + equal( hrefA, '/wiki/Sandbox', 'Simple title; Get link for "Sandbox"' ); + + var hrefB = mw.util.wikiGetlink( 'Foo:Sandbox ? 5+5=10 ! (test)/subpage' ); + + equal( hrefB, '/wiki/Foo:Sandbox_%3F_5%2B5%3D10_%21_%28test%29/subpage', 'Advanced title; Get link for "Foo:Sandbox ? 5+5=10 ! (test)/subpage"' ); }); -test( 'toggleToc', function(){ +test( 'wikiScript', function(){ - ok( mw.util.toggleToc ); + mw.config.set({ + 'wgScript': '/w/index.php', + 'wgScriptPath': '/w', + 'wgScriptExtension': '.php', + }); + + equal( mw.util.wikiScript(), mw.config.get( 'wgScript' ), 'Defaults to index.php and is equal to wgScript.' ); }); -test( 'wikiGetlink', function(){ +test( 'addCSS', function(){ - // Not part of startUp module - mw.config.set( 'wgArticlePath', '/wiki/$1' ); + var a = mw.util.addCSS( '#bodyContent { visibility: hidden; }' ); + ok( a, 'function works' ); + deepEqual( a.disabled, false, 'property "disabled" is available and set to false' ); - var hrefA = mw.util.wikiGetlink( 'Sandbox' ); + var $b = $('#bodyContent'); + equal( $b.css('visibility'), 'hidden', 'Added style properties are in effect.' ); - equal( hrefA, '/wiki/Sandbox', 'Simple title; Get link for "Sandbox"' ); - var hrefB = mw.util.wikiGetlink( 'Foo:Sandbox ? 5+5=10 ! (test)/subpage' ); +}); - equal( hrefB, '/wiki/Foo:Sandbox_%3F_5%2B5%3D10_%21_%28test%29/subpage', 'Advanced title; Get link for "Foo:Sandbox ? 5+5=10 ! (test)/subpage"' ); +test( 'toggleToc', function(){ + + ok( mw.util.toggleToc ); });