* Get the link to a page name (relative to `wgServer`),
*
* @param {string} str Page name to get the link for.
+ * @param {Object} params A mapping of query parameter names to values,
+ * e.g. { action: 'edit' }. Optional.
* @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',
+ wikiGetlink: function ( str, params ) {
+ var url = mw.config.get( 'wgArticlePath' ).replace( '$1',
util.wikiUrlencode( typeof str === 'string' ? str : mw.config.get( 'wgPageName' ) ) );
+ if ( params && !$.isEmptyObject( params ) ) {
+ url += url.indexOf( '?' ) !== -1 ? '&' : '?';
+ url += $.param( params );
+ }
+ return url;
},
/**
assert.equal( mw.util.wikiUrlencode( 'Test:A & B/Here' ), 'Test:A_%26_B/Here' );
} );
- QUnit.test( 'wikiGetlink', 3, function ( assert ) {
+ QUnit.test( 'wikiGetlink', 4, function ( assert ) {
// Not part of startUp module
mw.config.set( 'wgArticlePath', '/wiki/$1' );
mw.config.set( 'wgPageName', 'Foobar' );
href = mw.util.wikiGetlink();
assert.equal( href, '/wiki/Foobar', 'Default title; Get link for current page ("Foobar")' );
+
+ href = mw.util.wikiGetlink( 'Sandbox', { action: 'edit' } );
+ assert.equal( href, '/wiki/Sandbox?action=edit',
+ 'Simple title with query string; Get link for "Sandbox" with action=edit' );
} );
QUnit.test( 'wikiScript', 4, function ( assert ) {