http://www.mediawiki.org/wiki/Special:Code/MediaWiki/88513
Revision: 88513
Author: krinkle
Date: 2011-05-21 11:26:27 +0000 (Sat, 21 May 2011)
Log Message:
-----------
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
Modified Paths:
--------------
trunk/phase3/RELEASE-NOTES-1.19
trunk/phase3/resources/mediawiki.action/mediawiki.action.watch.ajax.js
trunk/phase3/resources/mediawiki.util/mediawiki.util.js
trunk/phase3/tests/qunit/suites/resources/mediawiki.util/mediawiki.util.js
Modified: trunk/phase3/RELEASE-NOTES-1.19
===================================================================
--- trunk/phase3/RELEASE-NOTES-1.19 2011-05-21 11:23:06 UTC (rev 88512)
+++ trunk/phase3/RELEASE-NOTES-1.19 2011-05-21 11:26:27 UTC (rev 88513)
@@ -36,7 +36,9 @@
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.
* (bug 28868) Show total pages in the subtitle of an image on the
@@ -72,6 +74,7 @@
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
Modified: trunk/phase3/resources/mediawiki.action/mediawiki.action.watch.ajax.js
===================================================================
--- trunk/phase3/resources/mediawiki.action/mediawiki.action.watch.ajax.js
2011-05-21 11:23:06 UTC (rev 88512)
+++ trunk/phase3/resources/mediawiki.action/mediawiki.action.watch.ajax.js
2011-05-21 11:26:27 UTC (rev 88513)
@@ -80,17 +80,18 @@
}
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 );
Modified: trunk/phase3/resources/mediawiki.util/mediawiki.util.js
===================================================================
--- trunk/phase3/resources/mediawiki.util/mediawiki.util.js 2011-05-21
11:23:06 UTC (rev 88512)
+++ trunk/phase3/resources/mediawiki.util/mediawiki.util.js 2011-05-21
11:26:27 UTC (rev 88513)
@@ -138,6 +138,28 @@
},
/**
+ * 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
*
* @param text String CSS to be appended
@@ -191,17 +213,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.
* Beware! When action paths are enabled (wgActionPaths) using
this function
Modified:
trunk/phase3/tests/qunit/suites/resources/mediawiki.util/mediawiki.util.js
===================================================================
--- trunk/phase3/tests/qunit/suites/resources/mediawiki.util/mediawiki.util.js
2011-05-21 11:23:06 UTC (rev 88512)
+++ trunk/phase3/tests/qunit/suites/resources/mediawiki.util/mediawiki.util.js
2011-05-21 11:26:27 UTC (rev 88513)
@@ -18,6 +18,33 @@
});
+test( 'wikiGetlink', function(){
+
+ // Not part of startUp module
+ mw.config.set( 'wgArticlePath', '/wiki/$1' );
+
+ 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( 'wikiScript', function(){
+
+ 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( 'addCSS', function(){
var a = mw.util.addCSS( '#bodyContent { visibility: hidden; }' );
@@ -36,21 +63,6 @@
});
-test( 'wikiGetlink', function(){
-
- // Not part of startUp module
- mw.config.set( 'wgArticlePath', '/wiki/$1' );
-
- 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( 'getParamValue', function(){
var url = 'http://mediawiki.org/?foo=wrong&foo=right#&foo=bad';
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs