ResourceLoader/Legacy JavaScript
This page documents deprecated identifiers that will be removed from mediawiki eventually (see bug 33836). Their replacements are in the "Replaced by" columns below.
Also see the ResourceLoader migration guides for extension developers and for users.
All replacements and some new modules are available as-is since 1.17. Please use the modern replacements for new code and rewrite old code immediately.
If you encounter no replacement and believe there should be one, please Let us know!
Please note the current implementation in Git may differ from the latest stable release and what might eventually be included with mediawiki. Any code relying on details obtained from Git may break.
ajax.js
Code: ajax.js
| Identifier | Type | Replaced by |
|---|---|---|
| sajax_debug_mode | string |
Use $( '#mybox' ).load( '/wiki/Template:ResourceLoader_navigation #bodyContent' );
$.get(
mw.config.get( 'wgScript' ), {
title: 'ResourceLoader',
action: 'raw'
},
function( data ) {
/* Call was successful do something with "data" */
}
);
$.getJSON(
mw.util.wikiScript( 'api' ), {
format: 'json',
action: 'query',
titles: 'Main Page',
prop: 'info'
},
function( obj ) {
/* API call was successful do something with obj */
}
);
For more information see documentation for .load(), .get(), .getJSON() and the other jQuery Ajax functions. See also this guide from WikiProject User scripts, for an example of how to edit a wikipage using AJAX. |
| sajax_request_type | string | |
| sajax_debug | function | |
| sajax_init_object | function | |
| wfSupportsAjax | function | |
| sajax_do_call | function |
$.get(
mw.util.wikiScript(), {
action: 'ajax',
rs: 'SomeExtensionFunction',
rsargs: [arg1, arg2, arg3] // becomes &rsargs[]=arg1&rsargs[]=arg2...
}
);
Note: These calls using action=ajax should be rewritten to use an API module |
edit.js
The toolbar interfaces will likely migrate into an extension. The default bundle would include the Extension:WikiEditor, which already has an advanced API that replaces all of this.
| Identifier | Type | Replaced by |
|---|---|---|
| currentFocused | HTMLElement | (private/obsolete) |
| addButton | function | mw.toolbar.addButton |
| mwInsertEditButton | function | (private/obsolete) |
| mwSetupToolbar | function | (private/obsolete) |
| insertTags | function | mw.toolbar.insertTags |
| scrollEditBox | function | (private/obsolete) |
| mwEditButtons | Array | (private/obsolete) |
mwsuggest.js
Replaced by jQuery.suggestions
See documentation for more information.
wikibits.js
Code: wikibits.js
| Identifier | Type | Replaced by |
|---|---|---|
| clientPC | string | |
| is_gecko | boolean | |
| is_safari | boolean | |
| is_safari_win | boolean | |
| is_chrome | boolean | |
| is_chrome_mac | boolean | |
| is_ff2 | boolean | |
| is_ff2_win | boolean | |
| is_ff2_x11 | boolean | |
| webkit_match | object | |
| ff2_bugs | boolean |
» jQuery.support maybe? |
| ie6_bugs | boolean | |
| doneOnloadHook | boolean |
» jQuery Use jQuery( document ).ready( function( $ ) {
/* your inline code to be executed after the page is loaded */
} );
// or:
jQuery( document ).ready( LoadMyApp );
Or shorthand: jQuery( function( $ ) {
/* your inline code to be executed after the page is loaded */
} );
// or:
$( LoadMyApp );
|
| onloadFuncts | object | |
| addOnloadHook | function | |
| runOnloadHook | function | |
| killEvt | function |
» jQuery.Event: /**
* @param e {jQuery.Event} Cross-browser compatible/normalized event object
*/
$( '#mw-fooBar' ).click( function( e ) {
e.preventDefault();
/* do something else */
} );
|
| loadedScripts | object | redundant |
| importScript | function |
// Full script url
mw.loader.load( 'https://commons.wikimedia.org/w/index.php?title=MediaWiki:Gadget-HotCat.js&action=raw&ctype=text/javascript' );
// Protocol-relative script url
mw.loader.load( '//commons.wikimedia.org/w/index.php?title=MediaWiki:Gadget-HotCat.js&action=raw&ctype=text/javascript' );
// Local script url
mw.loader.load( '/w/index.php?title=MediaWiki:Gadget-HotCat.js&action=raw&ctype=text/javascript' );
// Stylesheet
mw.loader.load( '/w/index.php?title=User:Example/custom-foo.css&action=raw&ctype=text/css', 'text/css' );
|
| importStylesheet | function | |
| importScriptURI | function | |
| importStylesheetURI | function | |
| appendCSS | function | » mediaWiki.util.addCSS |
| addHandler | function |
» jQuery Events Using // Attach multiple events to an element and attach an anonymous function
$( '#fooBar' ).on( 'mouseenter mouseleave', function() {
alert( '#fooBar is moused!' );
} );
// Attach multiple events with different handlers to a single element
$( '#fooBar' ).on( {
click: function() {
// do something on click
},
mouseenter: function() {
// do something on mouseenter
}
} );
// Attach a handler to the click events of an earlier defined DOM element
$( myElement ).click( myFunction );
|
| addClickHandler | function | |
| removeHandler | function | |
| hookEvent | function | |
| mwEditButtons | object | obsolete |
| mwCustomEditButtons | object |
» WikiEditor The new WikiEditor (which also works fine in Monobook, see here) has built-in function to customize the toolbar. For more info see Extension:WikiEditor/Toolbar customization. For examples to insert buttons using the native script see Extension:WikiEditor/Toolbar customization/Library. For a script to insert buttons using a simple syntax similar to the old way check out m:User:Krinkle/Scripts/insertVectorButtons#Description mw.loader.load( '//meta.wikimedia.org/w/index.php?title=User:Krinkle/insertVectorButtons.js'
+ '&action=raw&ctype=text/javascript' );
function kCustomMainInsertButton_config(){
// {{Welcome}} ~~~~
kCustomMainInsertButton(
'welcome', // Id
'//commons.wikimedia.org/w/thumb.php?f=Nuvola_apps_edu_languages.svg&w=22', // File
'Welcome', // tooltip
'{\{Welcome}\}\~\~\~\~', // Open tag
'', // Close tag
'' // sampleText
);
// {{subst:Test2}} ~~~~
kCustomMainInsertButton(
'test2', // Id
'//commons.wikimedia.org/w/thumb.php?f=Nuvola_apps_important.svg&w=22', // File
'Test2', // tooltip
'{\{subst:test2|', // Open tag
'}\}\~\~\~\~', // Close tag
'' // sample text
);
}
|
| tooltipAccessKeyPrefix | string | $( myElement ).updateTooltipAccessKeys()
|
| tooltipAccessKeyRegexp | object | |
| updateTooltipAccessKeys | function | |
| ta | object | MediaWiki:Accesskey-* and MediaWiki:Tooltip-*. |
| akeytt | function | obsolete |
| checkboxes | object | |
| lastCheckbox | object | |
| setupCheckboxShiftClick | function | |
| addCheckboxClickHandlers | function | |
| checkboxClickHandler | function | |
| showTocToggle | function | |
| toggleToc | function | |
| ts_image_path | string | |
| ts_image_up | string | |
| ts_image_down | string | |
| ts_image_none | string | |
| ts_europeandate | boolean | |
| ts_alternate_row_colors | boolean | |
| ts_number_transform_table | object | |
| ts_number_regex | object | |
| sortables_init | function | |
| ts_makeSortable | function | |
| ts_getInnerText | function | |
| ts_resortTable | function | |
| ts_initTransformTable | function | |
| ts_toLowerCase | function | |
| ts_dateToSortKey | function | |
| ts_parseFloat | function | |
| ts_currencyToSortKey | function | |
| ts_sort_generic | function | |
| ts_alternate | function | |
| changeText | function |
» jQuery Using // Set text of an earlier defined element
$( myElement ).text( 'New text!' );
// Set text for multiple elements at once
$( '.mw-userlink' ).text( 'Mr. Foobar' );
// Get the text of an element
$( myElement ).text();
|
| getInnerText | function | |
| escapeQuotes | function | |
| escapeQuotesHTML | function | |
| addPortletLink | function | |
| jsMsg | function | |
| injectSpinner | function |
» jquery.spinner (Documentation) jQuery( .. ).injectSpinner('some-id');
jQuery.removeSpinner('some-id');
|
| removeSpinner | function | |
| getElementsByClassName | function |
» jQuery Use the CSS Selector in jQuery to select elements by classname. Here examples for the three most common usecases of // Get everything with a classname
$( '.myclass' );
// Get all of element X (ie. table) with a classname
$( 'table.wikitable' );
// Get all of something within another element
$( myDomElement ).find( '.myclass' );
$( myDomElement ).find( '> .myclass' ); // only direct children
// Get all class-elements that are direct children of an element
$( '#someElement .myclass' );
$( '#someElement > .myclass' ); // only direct children
|
| redirectToFragment | function |
| ResourceLoader |
|---|
| Reference |
| Tutorials |