r88511 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r88510‎ | r88511 | r88512 >
Date:11:06, 21 May 2011
Author:krinkle
Status:ok (Comments)
Tags:
Comment:
Removing wgAjaxWatch javascript global object.
* Not in use anywhere in /trunk: http://toolserver.org/~krinkle/wikimedia-svn-search/view.php?id=199&hash=b56d9bd81e14ebca5e02ce7cbc19c2b6#F5 (never has been from what I can remember)
* Wrapping in an IIFE instead with local variables.
* Removed unused "supported" variable (it was declared and then checked to see if it's false), jQuery takes care of this in $.ajax (through $.getJSON etc.)
Modified paths:
  • /trunk/phase3/resources/mediawiki.action/mediawiki.action.watch.ajax.js (modified) (history)

Diff [purge]

Index: trunk/phase3/resources/mediawiki.action/mediawiki.action.watch.ajax.js
@@ -2,12 +2,10 @@
33 * Animate watch/unwatch links to use asynchronous API requests to
44 * watch pages, rather than clicking on links. Requires jQuery.
55 */
 6+( function( $ ) {
 7+var $links;
68
7 -if ( typeof wgAjaxWatch === 'undefined' || !wgAjaxWatch ) {
8 - window.wgAjaxWatch = { };
9 -}
10 -
11 -wgAjaxWatch.setLinkText = function( $link, action ) {
 9+var setLinkText = function( $link, action ) {
1210 if ( action == 'watch' || action == 'unwatch' ) {
1311 // save the accesskey from the title
1412 var keyCommand = $link.attr( 'title' ).match( /\[.*?\]$/ ) ? $link.attr( 'title' ).match( /\[.*?\]$/ )[0] : '';
@@ -25,26 +23,26 @@
2624 }
2725 };
2826
29 -wgAjaxWatch.processResult = function( response, $link ) {
30 - response = response.watch;
 27+var processResult = function( response, $link ) {
 28+ watchResponse = response.watch;
3129
3230 // To ensure we set the same status for all watch links with the
3331 // same target we trigger a custom event on *all* watch links.
34 - if( response.watched !== undefined ) {
35 - wgAjaxWatch.$links.trigger( 'mw-ajaxwatch', [response.title, 'watch', $link] );
36 - } else if ( response.unwatched !== undefined ) {
37 - wgAjaxWatch.$links.trigger( 'mw-ajaxwatch', [response.title, 'unwatch', $link] );
 32+ if ( watchResponse.watched !== undefined ) {
 33+ $links.trigger( 'mw-ajaxwatch', [watchResponse.title, 'watch', $link] );
 34+ } else if ( watchResponse.unwatched !== undefined ) {
 35+ $links.trigger( 'mw-ajaxwatch', [watchResponse.title, 'unwatch', $link] );
3836 } else {
3937 // Either we got an error code or it just plain broke.
4038 window.location.href = $link[0].href;
4139 return;
4240 }
4341
44 - mw.util.jsMessage( response.message, 'watch' );
 42+ mw.util.jsMessage( watchResponse.message, 'watch' );
4543
4644 // Bug 12395 - update the watch checkbox on edit pages when the
4745 // page is watched or unwatched via the tab.
48 - if( response.watched !== undefined ) {
 46+ if ( watchResponse.watched !== undefined ) {
4947 $( '#wpWatchthis' ).attr( 'checked', 'checked' );
5048 } else {
5149 $( '#wpWatchthis' ).removeAttr( 'checked' );
@@ -52,7 +50,7 @@
5351 };
5452
5553 $( document ).ready( function() {
56 - var $links = $( '.mw-watchlink a, a.mw-watchlink' );
 54+ $links = $( '.mw-watchlink a, a.mw-watchlink' );
5755 // BC with older skins
5856 $links = $links
5957 .add( '#ca-watch a, #ca-unwatch a, a#mw-unwatch-link1, ' +
@@ -73,15 +71,15 @@
7472 $links.click( function( event ) {
7573 var $link = $( this );
7674
77 - if( wgAjaxWatch.supported === false || !mw.config.get( 'wgEnableWriteAPI' ) ) {
 75+ if ( !mw.config.get( 'wgEnableWriteAPI' ) ) {
7876 // Lazy initialization so we don't toss up
7977 // ActiveX warnings on initial page load
8078 // for IE 6 users with security settings.
81 - wgAjaxWatch.$links.unbind( 'click' );
 79+ $links.unbind( 'click' );
8280 return true;
8381 }
8482
85 - wgAjaxWatch.setLinkText( $link, $link.data( 'action' ) + 'ing' );
 83+ setLinkText( $link, $link.data( 'action' ) + 'ing' );
8684
8785 var reqData = {
8886 'action': 'watch',
@@ -95,7 +93,7 @@
9694 + '/api' + mw.config.get( 'wgScriptExtension' ),
9795 reqData,
9896 function( data, textStatus, xhr ) {
99 - wgAjaxWatch.processResult( data, $link );
 97+ processResult( data, $link );
10098 }
10199 );
102100
@@ -106,19 +104,19 @@
107105 // on *all* watch links, so they can be updated if necessary
108106 $links.bind( 'mw-ajaxwatch', function( event, target, action, $link ) {
109107 var foo = $link.data( 'target' );
110 - if( $link.data( 'target' ) == target ) {
 108+ if ( $link.data( 'target' ) == target ) {
111109 var otheraction = action == 'watch'
112110 ? 'unwatch'
113111 : 'watch';
114112
115113 $link.data( 'action', otheraction );
116 - wgAjaxWatch.setLinkText( $link, otheraction );
 114+ setLinkText( $link, otheraction );
117115 $link.attr( 'href',
118116 mw.config.get( 'wgScript' )
119117 + '?title=' + mw.util.wikiUrlencode( mw.config.get( 'wgPageName' ) )
120118 + '&action=' + otheraction
121119 );
122 - if( $link.closest( 'li' ).attr( 'id' ) == 'ca-' + action ) {
 120+ if ( $link.closest( 'li' ).attr( 'id' ) == 'ca-' + action ) {
123121 $link.closest( 'li' ).attr( 'id', 'ca-' + otheraction );
124122 // update the link text with the new message
125123 $link.text( mw.msg( otheraction ) );
@@ -128,5 +126,6 @@
129127 return false;
130128 });
131129
132 - wgAjaxWatch.$links = $links;
133130 });
 131+
 132+})( jQuery );

Follow-up revisions

RevisionCommit summaryAuthorDate
r88554Passing token paremeter in mw.action.watch.ajax since this is required as of ...krinkle23:14, 21 May 2011
r88627Release notes for r88625, r88553, r88511 (bringing back 'Other changes' like ...krinkle00:01, 23 May 2011
r107354[mediawiki.action.watch.ajax.js] Rewrite using mw.Api and fixes bug 27146...krinkle01:21, 27 December 2011

Comments

#Comment by Liangent (talk | contribs)   17:54, 19 October 2012

wgAjaxWatch is still used in jawiki site JS...

Status & tagging log