Notes:
* JSHint stuff
* Code conventions
* jQuery best practices
* mediawiki.debug:
- Append a text node instead of html. Though .append()
does check if it looks "like" not-html and creates a text
node, this is not more a sanity/security thing than a
reliable documented feature. http://api.jquery.com/append/ :
"HTML string, DOM element(s) or jQuery object".
While at it:
* Update .jshintignore to also cover:
- resources/mediawiki.libs/CLDRPluralRuleParser.js
* Update .jshintrc to set onevar back to true (was set to false
temporarily but not removed).
* Fix files in resources/mediawiki and resources/jquery as well.
These dirs where already covered, perhaps these were missed or
recently introduced, again.
* Add missing dependencies:
jquery.highlightText -> jquery.mwExtension ($.escapeRE)
jquery.tablesorter -> jquery.mwExtension ($.escapeRE)
mediawiki.page.watch.ajax -> jquery.mwExtension ($.escapeRE)
Change-Id: I30a55717d0963ce23e51cef1f1df9e549e4c232e
56 lines
1.7 KiB
JavaScript
56 lines
1.7 KiB
JavaScript
/**
|
|
* Additional mw.Api methods to assist with (un)watching wiki pages.
|
|
* @since 1.19
|
|
*/
|
|
( function ( mw, $ ) {
|
|
|
|
/**
|
|
* @context {mw.Api}
|
|
*/
|
|
function doWatchInternal( page, success, err, addParams ) {
|
|
var params = {
|
|
action: 'watch',
|
|
title: String( page ),
|
|
token: mw.user.tokens.get( 'watchToken' ),
|
|
uselang: mw.config.get( 'wgUserLanguage' )
|
|
};
|
|
function ok( data ) {
|
|
success( data.watch );
|
|
}
|
|
if ( addParams ) {
|
|
$.extend( params, addParams );
|
|
}
|
|
return this.post( params, { ok: ok, err: err } );
|
|
}
|
|
|
|
$.extend( mw.Api.prototype, {
|
|
/**
|
|
* Convinience method for 'action=watch'.
|
|
*
|
|
* @param page {String|mw.Title} Full page name or instance of mw.Title
|
|
* @param success {Function} Callback to which the watch object will be passed.
|
|
* Watch object contains properties 'title' (full pagename), 'watched' (boolean) and
|
|
* 'message' (parsed HTML of the 'addedwatchtext' message).
|
|
* @param err {Function} Error callback (optional)
|
|
* @return {jqXHR}
|
|
*/
|
|
watch: function ( page, success, err ) {
|
|
return doWatchInternal.call( this, page, success, err );
|
|
},
|
|
/**
|
|
* Convinience method for 'action=watch&unwatch=1'.
|
|
*
|
|
* @param page {String|mw.Title} Full page name or instance of mw.Title
|
|
* @param success {Function} Callback to which the watch object will be passed.
|
|
* Watch object contains properties 'title' (full pagename), 'watched' (boolean) and
|
|
* 'message' (parsed HTML of the 'removedwatchtext' message).
|
|
* @param err {Function} Error callback (optional)
|
|
* @return {jqXHR}
|
|
*/
|
|
unwatch: function ( page, success, err ) {
|
|
return doWatchInternal.call( this, page, success, err, { unwatch: 1 } );
|
|
}
|
|
|
|
} );
|
|
|
|
}( mediaWiki, jQuery ) );
|