Remove Sajax
authorOri Livneh <ori@wikimedia.org>
Mon, 3 Aug 2015 03:05:51 +0000 (20:05 -0700)
committerOri Livneh <ori@wikimedia.org>
Mon, 3 Aug 2015 17:21:18 +0000 (10:21 -0700)
Calls for the removal of Sajax go back to (at least) October of 2012, when it
was already possible to describe the library as "ancient".[0] The work to mark
the library as deprecated[1] and to update its callers in Core[2] was completed
by Alex Monk two years ago. Usage in extensions was removed long ago in most
cases, and the last holdout -- SecurePoll -- was migrated by Frances Hocutt
last month. There is a long tail of usage in the MediaWiki namespace, but it
should not block this patch.

[0]: http://thread.gmane.org/gmane.science.linguistics.wikipedia.technical/64380
[1]: I4a0af8986
[2]: I52f01e4e7
[3]: I1e4f3107e

Bug: T55120
Change-Id: I22b69113a67c0b3a0979ff6ba1854ee8e95c1b88

RELEASE-NOTES-1.26
includes/skins/Skin.php
resources/Resources.php
resources/src/mediawiki.legacy/ajax.js [deleted file]

index 11da802..3b73024 100644 (file)
@@ -137,6 +137,8 @@ changes to languages because of Phabricator reports.
 * SpecialPageFactory::setGroup was removed (deprecated in 1.21).
 * SpecialPageFactory::getGroup was removed (deprecated in 1.21).
 * DatabaseBase::ignoreErrors() is now protected.
+* BREAKING CHANGE: mediawiki.legacy.ajax has been removed, following
+  a lengthy deprecation period.
 
 == Compatibility ==
 
index 327ef7c..2a1b0a3 100644 (file)
@@ -209,8 +209,6 @@ abstract class Skin extends ContextSource {
 
                // Add various resources if required
                if ( $wgUseAjax ) {
-                       $modules['legacy'][] = 'mediawiki.legacy.ajax';
-
                        if ( $wgEnableAPI ) {
                                if ( $wgEnableWriteAPI && $wgAjaxWatch && $user->isLoggedIn()
                                        && $user->isAllowed( 'writeapi' )
index da5bcf1..3fad66e 100644 (file)
@@ -1669,14 +1669,6 @@ return array(
 
        /* MediaWiki Legacy */
 
-       'mediawiki.legacy.ajax' => array(
-               'scripts' => 'resources/src/mediawiki.legacy/ajax.js',
-               'dependencies' => array(
-                       'mediawiki.util',
-                       'mediawiki.legacy.wikibits',
-               ),
-               'position' => 'top',
-       ),
        'mediawiki.legacy.commonPrint' => array(
                'position' => 'top',
                'styles' => array(
diff --git a/resources/src/mediawiki.legacy/ajax.js b/resources/src/mediawiki.legacy/ajax.js
deleted file mode 100644 (file)
index 3660c20..0000000
+++ /dev/null
@@ -1,194 +0,0 @@
-/**
- * Remote Scripting Library
- * Copyright 2005 modernmethod, inc
- * Under the open source BSD license
- * http://www.modernmethod.com/sajax/
- */
-
-/*jscs:disable requireCamelCaseOrUpperCaseIdentifiers */
-/*global alert */
-( function ( mw ) {
-
-       /**
-        * if sajax_debug_mode is true, this function outputs given the message into
-        * the element with id = sajax_debug; if no such element exists in the document,
-        * it is injected.
-        */
-       function debug( text ) {
-               if ( !window.sajax_debug_mode ) {
-                       return false;
-               }
-
-               var b, m,
-                       e = document.getElementById( 'sajax_debug' );
-
-               if ( !e ) {
-                       e = document.createElement( 'p' );
-                       e.className = 'sajax_debug';
-                       e.id = 'sajax_debug';
-
-                       b = document.getElementsByTagName( 'body' )[0];
-
-                       if ( b.firstChild ) {
-                               b.insertBefore( e, b.firstChild );
-                       } else {
-                               b.appendChild( e );
-                       }
-               }
-
-               m = document.createElement( 'div' );
-               m.appendChild( document.createTextNode( text ) );
-
-               e.appendChild( m );
-
-               return true;
-       }
-
-       /**
-        * Compatibility wrapper for creating a new XMLHttpRequest object.
-        */
-       function createXhr() {
-               debug( 'sajax_init_object() called..' );
-               var a;
-               try {
-                       // Try the new style before ActiveX so we don't
-                       // unnecessarily trigger warnings in IE 7 when
-                       // set to prompt about ActiveX usage
-                       a = new XMLHttpRequest();
-               } catch ( xhrE ) {
-                       try {
-                               a = new window.ActiveXObject( 'Msxml2.XMLHTTP' );
-                       } catch ( msXmlE ) {
-                               try {
-                                       a = new window.ActiveXObject( 'Microsoft.XMLHTTP' );
-                               } catch ( msXhrE ) {
-                                       a = null;
-                               }
-                       }
-               }
-               if ( !a ) {
-                       debug( 'Could not create connection object.' );
-               }
-
-               return a;
-       }
-
-       /**
-        * Perform an AJAX call to MediaWiki. Calls are handled by AjaxDispatcher.php
-        *   func_name - the name of the function to call. Must be registered in $wgAjaxExportList
-        *   args - an array of arguments to that function
-        *   target - the target that will handle the result of the call. If this is a function,
-        *            if will be called with the XMLHttpRequest as a parameter; if it's an input
-        *            element, its value will be set to the resultText; if it's another type of
-        *            element, its innerHTML will be set to the resultText.
-        *
-        * Example:
-        *    sajax_do_call( 'doFoo', [1, 2, 3], document.getElementById( 'showFoo' ) );
-        *
-        * This will call the doFoo function via MediaWiki's AjaxDispatcher, with
-        * (1, 2, 3) as the parameter list, and will show the result in the element
-        * with id = showFoo
-        */
-       function doAjaxRequest( func_name, args, target ) {
-               var i, x, uri, post_data;
-               uri = mw.util.wikiScript() + '?action=ajax';
-               if ( window.sajax_request_type === 'GET' ) {
-                       if ( uri.indexOf( '?' ) === -1 ) {
-                               uri = uri + '?rs=' + encodeURIComponent( func_name );
-                       } else {
-                               uri = uri + '&rs=' + encodeURIComponent( func_name );
-                       }
-                       for ( i = 0; i < args.length; i++ ) {
-                               uri = uri + '&rsargs[]=' + encodeURIComponent( args[i] );
-                       }
-                       // uri = uri + '&rsrnd=' + new Date().getTime();
-                       post_data = null;
-               } else {
-                       post_data = 'rs=' + encodeURIComponent( func_name );
-                       for ( i = 0; i < args.length; i++ ) {
-                               post_data = post_data + '&rsargs[]=' + encodeURIComponent( args[i] );
-                       }
-               }
-               x = createXhr();
-               if ( !x ) {
-                       alert( 'AJAX not supported' );
-                       return false;
-               }
-
-               try {
-                       x.open( window.sajax_request_type, uri, true );
-               } catch ( e ) {
-                       if ( location.hostname === 'localhost' ) {
-                               alert( 'Your browser blocks XMLHttpRequest to "localhost", try using a real hostname for development/testing.' );
-                       }
-                       throw e;
-               }
-               if ( window.sajax_request_type === 'POST' ) {
-                       x.setRequestHeader( 'Method', 'POST ' + uri + ' HTTP/1.1' );
-                       x.setRequestHeader( 'Content-Type', 'application/x-www-form-urlencoded' );
-               }
-               x.setRequestHeader( 'Pragma', 'cache=yes' );
-               x.setRequestHeader( 'Cache-Control', 'no-transform' );
-               x.onreadystatechange = function () {
-                       if ( x.readyState !== 4 ) {
-                               return;
-                       }
-
-                       debug( 'received (' + x.status + ' ' + x.statusText + ') ' + x.responseText );
-
-                       // if ( x.status != 200 )
-                       //   alert( 'Error: ' + x.status + ' ' + x.statusText + ': ' + x.responseText );
-                       // else
-
-                       if ( typeof target === 'function' ) {
-                               target( x );
-                       } else if ( typeof target === 'object' ) {
-                               if ( target.tagName === 'INPUT' ) {
-                                       if ( x.status === 200 ) {
-                                               target.value = x.responseText;
-                                       }
-                                       // else alert( 'Error: ' + x.status + ' ' + x.statusText + ' (' + x.responseText + ')' );
-                               } else {
-                                       if ( x.status === 200 ) {
-                                               target.innerHTML = x.responseText;
-                                       } else {
-                                               target.innerHTML = '<div class="error">Error: ' + x.status +
-                                                       ' ' + x.statusText + ' (' + x.responseText + ')</div>';
-                                       }
-                               }
-                       } else {
-                               alert( 'Bad target for sajax_do_call: not a function or object: ' + target );
-                       }
-               };
-
-               debug( func_name + ' uri = ' + uri + ' / post = ' + post_data );
-               x.send( post_data );
-               debug( func_name + ' waiting..' );
-
-               return true;
-       }
-
-       /**
-        * @return {boolean} Whether the browser supports AJAX
-        */
-       function wfSupportsAjax() {
-               var request = createXhr(),
-                       supportsAjax = request ? true : false;
-
-               request = undefined;
-               return supportsAjax;
-       }
-
-       // Expose + Mark as deprecated
-       var deprecationNotice = 'Sajax is deprecated, use jQuery.ajax or mediawiki.api instead.';
-
-       // Variables
-       mw.log.deprecate( window, 'sajax_debug_mode', false, deprecationNotice );
-       mw.log.deprecate( window, 'sajax_request_type', 'GET', deprecationNotice );
-       // Methods
-       mw.log.deprecate( window, 'sajax_debug', debug, deprecationNotice );
-       mw.log.deprecate( window, 'sajax_init_object', createXhr, deprecationNotice );
-       mw.log.deprecate( window, 'sajax_do_call', doAjaxRequest, deprecationNotice );
-       mw.log.deprecate( window, 'wfSupportsAjax', wfSupportsAjax, deprecationNotice );
-
-}( mediaWiki ) );