summaryrefslogtreecommitdiff
path: root/resources/mediawiki.page
diff options
context:
space:
mode:
Diffstat (limited to 'resources/mediawiki.page')
-rw-r--r--resources/mediawiki.page/mediawiki.page.patrol.ajax.js63
-rw-r--r--resources/mediawiki.page/mediawiki.page.ready.js40
-rw-r--r--resources/mediawiki.page/mediawiki.page.watch.ajax.js17
3 files changed, 95 insertions, 25 deletions
diff --git a/resources/mediawiki.page/mediawiki.page.patrol.ajax.js b/resources/mediawiki.page/mediawiki.page.patrol.ajax.js
new file mode 100644
index 00000000..d7a07d71
--- /dev/null
+++ b/resources/mediawiki.page/mediawiki.page.patrol.ajax.js
@@ -0,0 +1,63 @@
+/**
+ * Animate patrol links to use asynchronous API requests to
+ * patrol pages, rather than navigating to a different URI.
+ *
+ * @since 1.21
+ * @author Marius Hoch <hoo@online.de>
+ */
+( function ( mw, $ ) {
+ if ( !mw.user.tokens.exists( 'patrolToken' ) ) {
+ // Current user has no patrol right, or an old cached version of user.tokens
+ // that didn't have patrolToken yet.
+ return;
+ }
+ $( document ).ready( function () {
+ var $patrolLinks = $( '.patrollink a' );
+ $patrolLinks.on( 'click', function ( e ) {
+ var $spinner, href, rcid, apiRequest;
+
+ // Hide the link and create a spinner to show it inside the brackets.
+ $spinner = $.createSpinner( {
+ size: 'small',
+ type: 'inline'
+ } );
+ $( this ).hide().after( $spinner );
+
+ href = $( this ).attr( 'href' );
+ rcid = mw.util.getParamValue( 'rcid', href );
+ apiRequest = new mw.Api();
+
+ apiRequest.post( {
+ action: 'patrol',
+ token: mw.user.tokens.get( 'patrolToken' ),
+ rcid: rcid
+ } )
+ .done( function ( data ) {
+ // Remove all patrollinks from the page (including any spinners inside).
+ $patrolLinks.closest( '.patrollink' ).remove();
+ if ( data.patrol !== undefined ) {
+ // Success
+ var title = new mw.Title( data.patrol.title );
+ mw.notify( mw.msg( 'markedaspatrollednotify', title.toText() ) );
+ } else {
+ // This should never happen as errors should trigger fail
+ mw.notify( mw.msg( 'markedaspatrollederrornotify' ) );
+ }
+ } )
+ .fail( function ( error ) {
+ $spinner.remove();
+ // Restore the patrol link. This allows the user to try again
+ // (or open it in a new window, bypassing this ajax module).
+ $patrolLinks.show();
+ if ( error === 'noautopatrol' ) {
+ // Can't patrol own
+ mw.notify( mw.msg( 'markedaspatrollederror-noautopatrol' ) );
+ } else {
+ mw.notify( mw.msg( 'markedaspatrollederrornotify' ) );
+ }
+ } );
+
+ e.preventDefault();
+ } );
+ } );
+}( mediaWiki, jQuery ) );
diff --git a/resources/mediawiki.page/mediawiki.page.ready.js b/resources/mediawiki.page/mediawiki.page.ready.js
index 370c3a19..684f582f 100644
--- a/resources/mediawiki.page/mediawiki.page.ready.js
+++ b/resources/mediawiki.page/mediawiki.page.ready.js
@@ -1,24 +1,28 @@
-jQuery( document ).ready( function( $ ) {
+( function ( mw, $ ) {
+ $( function () {
+ var $sortableTables;
- /* Emulate placeholder if not supported by browser */
- if ( !( 'placeholder' in document.createElement( 'input' ) ) ) {
- $( 'input[placeholder]' ).placeholder();
- }
+ /* Emulate placeholder if not supported by browser */
+ if ( !( 'placeholder' in document.createElement( 'input' ) ) ) {
+ $( 'input[placeholder]' ).placeholder();
+ }
- /* Enable makeCollapsible */
- $( '.mw-collapsible' ).makeCollapsible();
+ /* Enable makeCollapsible */
+ $( '.mw-collapsible' ).makeCollapsible();
- /* Lazy load jquery.tablesorter */
- if ( $( 'table.sortable' ).length ) {
- mw.loader.using( 'jquery.tablesorter', function() {
- $( 'table.sortable' ).tablesorter();
- });
- }
+ /* Lazy load jquery.tablesorter */
+ $sortableTables = $( 'table.sortable' );
+ if ( $sortableTables.length ) {
+ mw.loader.using( 'jquery.tablesorter', function () {
+ $sortableTables.tablesorter();
+ });
+ }
- /* Enable CheckboxShiftClick */
- $( 'input[type=checkbox]:not(.noshiftselect)' ).checkboxShiftClick();
+ /* Enable CheckboxShiftClick */
+ $( 'input[type=checkbox]:not(.noshiftselect)' ).checkboxShiftClick();
- /* Add accesskey hints to the tooltips */
- mw.util.updateTooltipAccessKeys();
+ /* Add accesskey hints to the tooltips */
+ mw.util.updateTooltipAccessKeys();
-} );
+ } );
+}( mediaWiki, jQuery ) );
diff --git a/resources/mediawiki.page/mediawiki.page.watch.ajax.js b/resources/mediawiki.page/mediawiki.page.watch.ajax.js
index a7e059c4..f945fa9d 100644
--- a/resources/mediawiki.page/mediawiki.page.watch.ajax.js
+++ b/resources/mediawiki.page/mediawiki.page.watch.ajax.js
@@ -24,13 +24,14 @@
otherAction = action === 'watch' ? 'unwatch' : 'watch';
accesskeyTip = $link.attr( 'title' ).match( mw.util.tooltipAccessKeyRegexp );
$li = $link.closest( 'li' );
+
/**
* Trigger a 'watchpage' event for this List item.
* Announce the otherAction value as the first param.
* Used to monitor the state of watch link.
* TODO: Revise when system wide hooks are implemented
*/
- if( state === undefined ) {
+ if ( state === undefined ) {
$li.trigger( 'watchpage.mw', otherAction );
}
@@ -96,7 +97,7 @@
// Expose local methods
mw.page.watch = {
- 'updateWatchLink': updateWatchLink
+ updateWatchLink: updateWatchLink
};
$( document ).ready( function () {
@@ -134,7 +135,9 @@
otherAction = action === 'watch' ? 'unwatch' : 'watch';
$li = $link.closest( 'li' );
- mw.notify( $.parseHTML( watchResponse.message ), { tag: 'watch-self' } );
+ mw.notify( $.parseHTML( watchResponse.message ), {
+ tag: 'watch-self'
+ } );
// Set link to opposite
updateWatchLink( $link, otherAction );
@@ -144,7 +147,7 @@
if ( watchResponse.watched !== undefined ) {
$( '#wpWatchthis' ).prop( 'checked', true );
} else {
- $( '#wpWatchthis' ).removeProp( 'checked' );
+ $( '#wpWatchthis' ).prop( 'checked', false );
}
},
// Error
@@ -162,14 +165,14 @@
title: cleanTitle
}, cleanTitle
);
- msg = mw.messsage( 'watcherrortext', link );
+ msg = mw.message( 'watcherrortext', link );
// Report to user about the error
mw.notify( msg, { tag: 'watch-self' } );
}
);
- });
- });
+ } );
+ } );
}( mediaWiki, jQuery ) );