Adding mw.util.wikiScript + small fix in mediawiki.action.watch.ajax.js
authorKrinkle <krinkle@users.mediawiki.org>
Sat, 21 May 2011 11:26:27 +0000 (11:26 +0000)
committerKrinkle <krinkle@users.mediawiki.org>
Sat, 21 May 2011 11:26:27 +0000 (11:26 +0000)
* 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

RELEASE-NOTES-1.19
resources/mediawiki.action/mediawiki.action.watch.ajax.js
resources/mediawiki.util/mediawiki.util.js
tests/qunit/suites/resources/mediawiki.util/mediawiki.util.js

index e7b2611..67703b4 100644 (file)
@@ -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
index 7fb26db..484b3b0 100644 (file)
@@ -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 );
index 0678e86..a23af62 100644 (file)
                                .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
                 *
                        }
                },
 
-               /**
-                * 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.
index 736f40b..8bb004f 100644 (file)
@@ -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 );
 
 });