tables that have a corresponding ORMTable class.
* (bug 40876) Icon for PSD (Adobe Photoshop) file types.
* (bug 40641) Implemented Special:Version/Credits with a list of contributors.
+* (bug 7851) Implemented one-click AJAX patrolling.
=== Bug fixes in 1.21 ===
* (bug 40353) SpecialDoubleRedirect should support interwiki redirects.
* If patrol is possible, output a patrol UI box. This is called from the
* footer section of ordinary page views. If patrol is not possible or not
* desired, does nothing.
+ * Side effect: When the patrol link is build, this method will call
+ * OutputPage::preventClickjacking() and load mediawiki.page.patrol.ajax.
*/
public function showPatrolFooter() {
$request = $this->getContext()->getRequest();
}
$token = $user->getEditToken( $rcid );
+
$outputPage->preventClickjacking();
+ $outputPage->addModules( 'mediawiki.page.patrol.ajax' );
$link = Linker::linkKnown(
$this->getTitle(),
/**
* Get a link to mark the change as patrolled, or '' if there's either no
* revision to patrol or the user is not allowed to to it.
- * Side effect: this method will call OutputPage::preventClickjacking()
- * when a link is builded.
+ * Side effect: When the patrol link is build, this method will call
+ * OutputPage::preventClickjacking() and load mediawiki.page.patrol.ajax.
*
* @return String
*/
// Build the link
if ( $rcid ) {
$this->getOutput()->preventClickjacking();
+ $this->getOutput()->addModules( 'mediawiki.page.patrol.ajax' );
+
$token = $this->getUser()->getEditToken( $rcid );
$this->mMarkPatrolledLink = ' <span class="patrollink">[' . Linker::linkKnown(
$this->mNewPage,
return array(
'editToken' => $wgUser->getEditToken(),
- 'watchToken' => ApiQueryInfo::getWatchToken(null, null),
+ 'patrolToken' => ApiQueryRecentChanges::getPatrolToken( null, null ),
+ 'watchToken' => ApiQueryInfo::getWatchToken( null, null ),
);
}
'markedaspatrollederror' => 'Cannot mark as patrolled',
'markedaspatrollederrortext' => 'You need to specify a revision to mark as patrolled.',
'markedaspatrollederror-noautopatrol' => 'You are not allowed to mark your own changes as patrolled.',
+'markedaspatrollednotify' => 'This change to $1 has been marked as patrolled.',
+'markedaspatrollederrornotify' => 'Marking as patrolled failed.',
# Patrol log
'patrol-log-page' => 'Patrol log',
# Patrolling
'markedaspatrolledtext' => '{{Identical|Markedaspatrolled}}',
+'markedaspatrollednotify' => 'Notification shown after a change has been marked as patrolled, $1 is the page title',
+'markedaspatrollederrornotify' => 'Notification shown after marking a change as patrolled failed',
# Patrol log
'patrol-log-page' => '{{doc-logpage}}',
'markedaspatrollederror',
'markedaspatrollederrortext',
'markedaspatrollederror-noautopatrol',
+ 'markedaspatrollednotify',
+ 'markedaspatrollederrornotify',
),
'patrol-log' => array(
'patrol-log-page',
),
'position' => 'top',
),
+ 'mediawiki.page.patrol.ajax' => array(
+ 'scripts' => 'resources/mediawiki.page/mediawiki.page.patrol.ajax.js',
+ 'dependencies' => array(
+ 'mediawiki.page.startup',
+ 'mediawiki.api',
+ 'mediawiki.util',
+ 'mediawiki.Title',
+ 'mediawiki.notify',
+ 'jquery.spinner',
+ 'user.tokens'
+ ),
+ 'messages' => array(
+ 'markedaspatrollednotify',
+ 'markedaspatrollederrornotify',
+ 'markedaspatrollederror-noautopatrol'
+ ),
+ ),
'mediawiki.page.watch.ajax' => array(
'scripts' => 'resources/mediawiki.page/mediawiki.page.watch.ajax.js',
'dependencies' => array(
--- /dev/null
+/**
+ * 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 ) );