r105649 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r105648‎ | r105649 | r105650 >
Date:04:55, 9 December 2011
Author:neilk
Status:ok
Tags:
Comment:
remove useless api-related snippets
Modified paths:
  • /trunk/extensions/UploadWizard/resources/apiTokenMisc.js (deleted) (history)
  • /trunk/extensions/UploadWizard/resources/mw.ApiMisc.js (deleted) (history)
  • /trunk/extensions/UploadWizard/resources/mw.ApiProxy.js (deleted) (history)

Diff [purge]

Index: trunk/extensions/UploadWizard/resources/mw.ApiMisc.js
@@ -1,164 +0,0 @@
2 - /**
3 - *
4 - * Helper function to get revision text for a given title
5 - *
6 - * Assumes "follow redirects"
7 - *
8 - * $j.getTextFromTitle( [apiUrl], title, callback )
9 - *
10 - * @param {String} url or title key
11 - * @parma {Mixed} title or callback function
12 - * @param {Function} callback Function or NULL
13 - *
14 - * @return callback is called with:
15 - * {Boolean} false if no page found
16 - * {String} text of wiki page
17 - */
18 - getTextFromTitle: function( title, callback ) {
19 - var request = {
20 - // Normalize the File NS (ie sometimes its present in apiTitleKey other times not
21 - 'titles' : title,
22 - 'prop' : 'revisions',
23 - 'rvprop' : 'content'
24 - };
25 -
26 - this.get( request, function( response ) {
27 - if( !response || !response.query || !response.query.pages ) {
28 - callback( false );
29 - }
30 - var pages = response.query.pages;
31 - for(var i in pages) {
32 - page = pages[ i ];
33 - if( page[ 'revisions' ] && page[ 'revisions' ][0]['*'] ) {
34 - callback( page[ 'revisions' ][0]['*'] );
35 - }
36 - }
37 - } );
38 - },
39 -
40 -/*
41 - // Stub feature apiUserNameCache to avoid multiple calls
42 - // ( a more general api framework should be developed )
43 - apiUserNameCache: {},
44 -
45 - /**
46 - * Api helper to grab the username
47 - * @param {Function} callback Function to callback with username or false if not found
48 - * @param {Boolean} fresh A fresh check is issued.
49 - */
50 - getUserName: function( callback, fresh ){
51 -
52 - /*
53 - // If apiUrl is local check wgUserName global
54 - // before issuing the api request.
55 - if( mw.isLocalDomain( apiUrl ) ){
56 - if( typeof wgUserName != 'undefined' && wgUserName !== null ) {
57 - callback( wgUserName )
58 - // In case someone called this function without a callback
59 - return wgUserName;
60 - }
61 - }
62 -
63 - */
64 -
65 - if( ! fresh && apiUserNameCache[ apiUrl ] ) {
66 - callback( apiUserNameCache[ apiUrl ] );
67 - return ;
68 - }
69 -
70 - // Setup the api request
71 - var parameters = {
72 - 'action':'query',
73 - 'meta':'userinfo'
74 - };
75 -
76 - // Do request
77 - this.get( request, function( data ) {
78 - if( !data || !data.query || !data.query.userinfo || !data.query.userinfo.name ){
79 - // Could not get user name user is not-logged in
80 - mw.log( " No userName in response " );
81 - callback( false );
82 - return ;
83 - }
84 - // Check for "not logged in" id == 0
85 - if( data.query.userinfo.id == 0 ){
86 - callback( false );
87 - return ;
88 - }
89 - /* apiUserNameCache[ apiUrl ] = data.query.userinfo.name; */
90 - // Else return the username:
91 - callback( data.query.userinfo.name );
92 - }, function(){
93 - // Timeout also results in callback( false ) ( no user found)
94 - callback( false );
95 - } );
96 - }
97 -*/
98 -
99 - /**
100 - * Issues the wikitext parse call
101 - *
102 - * @param {String} wikitext Wiki Text to be parsed by mediaWiki api call
103 - * @param {String} title Context title of the content to be parsed
104 - * @param {Function} callback Function called with api parser output
105 - */
106 - parseWikiText: function( wikitext, title, callback ) {
107 - mw.log("mw.parseWikiText text length: " + wikitext.length + ' title context: ' + title );
108 - // TODO mw.load? ajax? why?
109 - mw.load( 'JSON', function(){
110 - $j.ajax( {
111 - type: 'POST',
112 - url: this.url,
113 - // Give the wiki 60 seconds to parse the wiki-text
114 - timeout : 60000,
115 - data: {
116 - 'action': 'parse',
117 - 'format': 'json',
118 - 'title' : title,
119 - 'text': wikitext
120 - },
121 - dataType: 'text',
122 - success: function( data ) {
123 - var jsonData = JSON.parse( data ) ;
124 - // xxx should handle other failures
125 - callback( jsonData.parse.text['*'] );
126 - },
127 - error: function( XMLHttpRequest, textStatus, errorThrown ){
128 - // xxx should better handle failures
129 - mw.log( "Error: mw.parseWikiText:" + textStatus );
130 - callback( "Error: failed to parse wikitext " );
131 - }
132 - } );
133 - } );
134 - },
135 -
136 -
137 -
138 - // Api actions that must be submitted in a POST, and need an api proxy for cross domain calls
139 - // TODO protecting app code from knowing it's supposed to POST or not is a dubious benefit. :(
140 - apiPostActions: [ 'login', 'purge', 'rollback', 'delete', 'undelete',
141 - 'protect', 'block', 'unblock', 'move', 'edit', 'upload', 'emailuser',
142 - 'import', 'userrights' ],
143 -
144 -
145 - /**
146 - * Checks if a mw request data requires a post request or not
147 - * @param {Object}
148 - * @return {Boolean}
149 - * true if the request requires a post request
150 - * false if the request does not
151 - */
152 - mw.checkRequestPost = function ( data ) {
153 - if( $j.inArray( data['action'], this.apiPostActions ) != -1 ) {
154 - return true;
155 - }
156 - if( data['prop'] == 'info' && data['intoken'] ) {
157 - return true;
158 - }
159 - if( data['meta'] == 'userinfo' ) {
160 - return true;
161 - }
162 - return false;
163 - };
164 -
165 -
Index: trunk/extensions/UploadWizard/resources/apiTokenMisc.js
@@ -1,61 +0,0 @@
2 -/* mistaken attempt to add tokens to all posts.
3 - there are way too many ways of getting tokens to generalize this.
4 - for uploading we are using forms (not constructing our own multiparts, for the most part) so we should obtain a reasonably fresh
5 - token for each upload instead.
6 - however this could make sense with editing
7 - */
8 -
9 - // All POST actions need an edit token. TODO confirm this
10 - // Edit tokens expire at a time unpredictable to the client.
11 - // It is not desirable to fetch a new token before every POST.
12 - // So: we will have to obtain one if we don't have one already or encounter
13 - // a 'badtoken' error. Logic here is a bit convoluted but it's the best I can do.
14 -
15 - // A token may be cached already in the api. If we have one, use it; if not, get one and
16 - // then do the same post we were going to do.
17 - if ( this.token ) {
18 - // we have an API token, but it might be expired.
19 - // So, in the parameters of the post call, use an error handler to deal with bad tokens
20 - // that tries the post again with a brand new token.
21 - if ( ! ajaxOptions.apiError.badtoken ) {
22 - var api = this;
23 - ajaxOptions.apiError.badtoken = function() {
24 - // don't infinite loop
25 - delete ajaxOptions.apiError.badtoken;
26 - api._postWithNewToken( parameters, ajaxOptions );
27 - };
28 - }
29 - this._post( parameters, ajaxOptions );
30 - } else {
31 - this._postWithNewToken( parameters, ajaxOptions );
32 - }
33 - /**
34 - * Post API request using the token that exists already in the API (standard case)
35 - *
36 - * @param {Object} request parameters
37 - * @param {Object} ajax properties
38 - */
39 - _post: function( parameters, ajaxOptions ) {
40 - parameters['token'] = this.token;
41 - this.ajax( parameters, ajaxOptions );
42 - },
43 -
44 - /**
45 - * Get a new token, cache it in the API, and then do a post
46 - *
47 - * @param {Object} request parameters
48 - * @param {Object} ajax properties
49 - */
50 - _postWithNewToken: function( parameters, ajaxOptions ) {
51 - var api = this;
52 - this.getToken( function( token ) {
53 - if ( token === false ) {
54 - // XXX getting the token failed
55 - } else {
56 - api.token = token;
57 - api._post( parameters, ajaxOptions );
58 - }
59 - } );
60 - },
61 -
62 -
Index: trunk/extensions/UploadWizard/resources/mw.ApiProxy.js
@@ -1,36 +0,0 @@
2 -
3 -
4 -
5 -
6 -/*
7 -
8 -apiproxy stuff -- we will do this in a different way
9 - if( mw.checkRequestPost( parameters ) ) {
10 -
11 - // Check if we need to setup a proxy
12 - if( ! mw.isLocalDomain( url ) ) {
13 -
14 - // Load the proxy and issue the parameters
15 - mw.load( 'ApiProxy', function( ) {
16 - mw.ApiProxy.doRequest( url, parameters, callback, timeoutCallback);
17 - } );
18 -
19 - } else {
20 -
21 - }
22 - return ;
23 - }
24 -
25 - // If cross domain setup a callback:
26 - if( ! mw.isLocalDomain( url ) ) {
27 - if( url.indexOf( 'callback=' ) == -1 || parameters[ 'callback' ] == -1 ) {
28 - // jQuery specific jsonp format: ( second ? is replaced with the callback )
29 - url += ( url.indexOf('?') == -1 ) ? '?callback=?' : '&callback=?';
30 - }
31 - }
32 -
33 - // Pass off the jQuery getJSON parameters:
34 - $j.getJSON( this.url, parameters, myCallback );
35 - }
36 -
37 -*/

Status & tagging log