r88513 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r88512‎ | r88513 | r88514 >
Date:11:26, 21 May 2011
Author:krinkle
Status:ok (Comments)
Tags:
Comment:
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 (modified) (history)
  • /trunk/phase3/resources/mediawiki.action/mediawiki.action.watch.ajax.js (modified) (history)
  • /trunk/phase3/resources/mediawiki.util/mediawiki.util.js (modified) (history)
  • /trunk/phase3/tests/qunit/suites/resources/mediawiki.util/mediawiki.util.js (modified) (history)

Diff [purge]

Index: trunk/phase3/RELEASE-NOTES-1.19
@@ -36,7 +36,9 @@
3737 Also built-in support for distribution through a TestSwarm instance.
3838 * (bug 29036) For cascade-protected pages, the mw-textarea-cprotected class is
3939 added to the textarea on the edit form.
 40+* mw.util.getScript has been implemented (like wfScript in GlobalFunctions.php)
4041
 42+
4143 === Bug fixes in 1.19 ===
4244 * (bug 10154) Don't allow user to specify days beyond $wgRCMaxAge.
4345 * (bug 28868) Show total pages in the subtitle of an image on the
@@ -72,6 +74,7 @@
7375 also in RTL text.
7476 * (bug 29055) Make don't send email on minor edits preference apply to
7577 changes to talk page in addition to watchlist edits.
 78+* (bug 29071) mediawiki.action.watch.ajax.js should pass uselang to API.
7679
7780 === API changes in 1.19 ===
7881 * (bug 27790) add query type for querymodules to action=paraminfo
Index: trunk/phase3/tests/qunit/suites/resources/mediawiki.util/mediawiki.util.js
@@ -18,6 +18,33 @@
1919
2020 });
2121
 22+test( 'wikiGetlink', function(){
 23+
 24+ // Not part of startUp module
 25+ mw.config.set( 'wgArticlePath', '/wiki/$1' );
 26+
 27+ var hrefA = mw.util.wikiGetlink( 'Sandbox' );
 28+
 29+ equal( hrefA, '/wiki/Sandbox', 'Simple title; Get link for "Sandbox"' );
 30+
 31+ var hrefB = mw.util.wikiGetlink( 'Foo:Sandbox ? 5+5=10 ! (test)/subpage' );
 32+
 33+ 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"' );
 34+
 35+});
 36+
 37+test( 'wikiScript', function(){
 38+
 39+ mw.config.set({
 40+ 'wgScript': '/w/index.php',
 41+ 'wgScriptPath': '/w',
 42+ 'wgScriptExtension': '.php',
 43+ });
 44+
 45+ equal( mw.util.wikiScript(), mw.config.get( 'wgScript' ), 'Defaults to index.php and is equal to wgScript.' );
 46+
 47+});
 48+
2249 test( 'addCSS', function(){
2350
2451 var a = mw.util.addCSS( '#bodyContent { visibility: hidden; }' );
@@ -36,21 +63,6 @@
3764
3865 });
3966
40 -test( 'wikiGetlink', function(){
41 -
42 - // Not part of startUp module
43 - mw.config.set( 'wgArticlePath', '/wiki/$1' );
44 -
45 - var hrefA = mw.util.wikiGetlink( 'Sandbox' );
46 -
47 - equal( hrefA, '/wiki/Sandbox', 'Simple title; Get link for "Sandbox"' );
48 -
49 - var hrefB = mw.util.wikiGetlink( 'Foo:Sandbox ? 5+5=10 ! (test)/subpage' );
50 -
51 - 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"' );
52 -
53 -});
54 -
5567 test( 'getParamValue', function(){
5668
5769 var url = 'http://mediawiki.org/?foo=wrong&foo=right#&foo=bad';
Index: trunk/phase3/resources/mediawiki.action/mediawiki.action.watch.ajax.js
@@ -80,17 +80,18 @@
8181 }
8282
8383 setLinkText( $link, $link.data( 'action' ) + 'ing' );
84 -
 84+
8585 var reqData = {
8686 'action': 'watch',
8787 'format': 'json',
88 - 'title': $link.data( 'target' )
 88+ 'title': $link.data( 'target' ),
 89+ // API return contains a localized data.watch.message string.
 90+ 'uselang': mw.config.get( 'wgUserLanguage' )
8991 };
9092 if ( $link.data( 'action' ) == 'unwatch' ) {
91 - reqData['unwatch'] = '';
 93+ reqData.unwatch = '';
9294 }
93 - $.getJSON( mw.config.get( 'wgScriptPath' )
94 - + '/api' + mw.config.get( 'wgScriptExtension' ),
 95+ $.getJSON( mw.util.wikiScript( 'api' ),
9596 reqData,
9697 function( data, textStatus, xhr ) {
9798 processResult( data, $link );
Index: trunk/phase3/resources/mediawiki.util/mediawiki.util.js
@@ -138,6 +138,28 @@
139139 },
140140
141141 /**
 142+ * Get the link to a page name (relative to wgServer)
 143+ *
 144+ * @param str Page name to get the link for.
 145+ * @return string Location for a page with name of 'str' or boolean false on error.
 146+ */
 147+ 'wikiGetlink' : function( str ) {
 148+
 149+ return mw.config.get( 'wgArticlePath' ).replace( '$1', this.wikiUrlencode( str ) );
 150+ },
 151+
 152+ /**
 153+ * Get address to a script in the wiki root.
 154+ * For index.php use mw.config.get( 'wgScript' )
 155+ *
 156+ * @param str Name of script (eg. 'api'), defaults to 'index'
 157+ * @return str Address to script (eg. '/w/api.php' )
 158+ */
 159+ 'wikiScript' : function( str ) {
 160+ return mw.config.get( 'wgScriptPath' ) + '/' + ( str || 'index' ) + mw.config.get( 'wgScriptExtension' );
 161+ },
 162+
 163+ /**
142164 * Append a new style block to the head
143165 *
144166 * @param text String CSS to be appended
@@ -191,17 +213,6 @@
192214 },
193215
194216 /**
195 - * Get the link to a page name (relative to wgServer)
196 - *
197 - * @param str Page name to get the link for.
198 - * @return string Location for a page with name of 'str' or boolean false on error.
199 - */
200 - 'wikiGetlink' : function( str ) {
201 -
202 - return mw.config.get( 'wgArticlePath' ).replace( '$1', this.wikiUrlencode( str ) );
203 - },
204 -
205 - /**
206217 * Grab the URL parameter value for the given parameter.
207218 * Returns null if not found.
208219 * Beware! When action paths are enabled (wgActionPaths) using this function

Follow-up revisions

RevisionCommit summaryAuthorDate
r88514Follow-up r88513: /me blames Chrome for ignoring trailing comma's in object n...krinkle12:27, 21 May 2011
r92328REL1_18 MFT r79056, r80612, r81499, r87627, r87628, r87630, r87998, r88134, r...reedy22:46, 15 July 2011
r106722[RELEASE-NOTES] Fix typo...krinkle23:32, 19 December 2011

Comments

#Comment by Krinkle (talk | contribs)   11:27, 21 May 2011

Sorry for not putting it in a seperate commit. How about we backport (bug 29071) :


-			'title': $link.data( 'target' )
+			'title': $link.data( 'target' ),
+			// API return contains a localized data.watch.message string.
+			'uselang': mw.config.get( 'wgUserLanguage' )

to REL1_18 ?

#Comment by Duplicatebug (talk | contribs)   18:17, 25 May 2011

'uselang' is undocumented in the api doc. It is possible to add documentation and use it explicit in the code? Thanks.

#Comment by Reedy (talk | contribs)   18:19, 25 May 2011
			'uselang' => 'Which language to parse the request in',

on Parse, but I don't think it exists elsewhere

#Comment by Catrope (talk | contribs)   19:19, 26 May 2011

uselang does actually work elsewhere, because it's handled at a lower level shared by index.php and api.php . This is an undocumented feature that shouldn't be relied upon, though.

#Comment by Duplicatebug (talk | contribs)   08:08, 28 May 2011

That is right, but there are not so many modules depending on $wgLang, direct or indirect.

Maybe add that param to ApiMain::getAllowedParams()? Than has it a documentation, and all api users can know about that.

meta=allmessages and action=parse handle its language param by self.

#Comment by Catrope (talk | contribs)   15:35, 1 June 2011

Yes, allmessages and parse handle it themselves, and other modules should not be outputting i18ned messages ideally. Instead, they should output error codes and any JS calling these modules should take care of i18ned error messages itself.

I said this to Krinkle on IRC yesterday, and he pointed out this isn't quite possible just yet, because we don't have support for {{PAGENAME}} and [[Links|$1]] in JS messages yet (but there's code in UploadWizard that supports this already and is slated to be integrated with core).

#Comment by Duplicatebug (talk | contribs)   19:20, 1 June 2011

Addition: prop=revisions&rvparse depends indirect on uselang for messages inside the page content.

Status & tagging log