Commit RELEASE-NOTES line for the wgCategories js variable I added some time ago.
[lhc/web/wiklou.git] / js2 / mwEmbed / tests / testApiProxy.html
1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
2 <html>
3 <head>
4 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
5 <title>Api Proxy Test</title>
6 <script type="text/javascript" src="../mv_embed.js"></script>
7
8 <script type="text/javascript" >
9 //HARD coded local test:
10 var remote_wiki_host = 'http://test.wikipedia.org';
11 var remote_script_path = '/w';
12
13 js2AddOnloadHook( function(){
14 $j('#hostName').text( remote_wiki_host );
15 //run the api-proxy setup:
16 $j.apiProxy(
17 'client',
18 {
19 'server_frame': remote_wiki_host + remote_script_path + '/index.php/MediaWiki:ApiProxy',
20 'client_frame_path' : '/wiki_trunk/js2/mwEmbed/libMwApi/NestedCallbackIframe.html',
21 },
22 function(){
23 //callback function here:
24 $j('#setupDone').show('slow');
25 $j('#doHello').click( doHello );
26 $j('#doAppend').click(doAppend);
27 }
28 );
29 });
30 function doHello(){
31 js_log('to a hello user');
32 $j('#helloTarget').html( mv_get_loading_img() );
33 //first get the user name:
34 getUserName(function( user_name ){
35 $j('#helloTarget').hide().text( user_name ).fadeIn('slow');
36 });
37 return false;
38 }
39 function getUserName( callback ){
40 var rObj = {
41 'action':'query',
42 'meta':'userinfo'
43 }
44 //we use normal do_api_req with keywork 'proxy' for the url
45 $mw.proxy.doRequest( rObj,
46 function( data ){
47 //now we get the data back for that domain
48 if( !data.query || !data.query.userinfo ){
49 js_log("Error no query.userinfo ");
50 return false;
51 }
52 callback( data.query.userinfo.name );
53 }
54 );
55 }
56
57 //simple "hello from api proxy" append on talk page
58 function doAppend(){
59 $j('#appendTarget').html( mv_get_loading_img() );
60 //get user name
61 getUserName(function(userName){
62 var eTitle = 'User_talk:' + userName;
63 //get a edit token
64 get_mw_token(eTitle, 'proxy', function( token ){
65 js_log("got token: " + token) ;
66 var aReq = {
67 'action':'edit',
68 'title': eTitle,
69 'summary': "Api proxy test edit",
70 'appendtext': "\n\n==== Hello from Api proxy At: " + Date() + " ====",
71 'token': token
72 }
73 do_api_req({
74 'data': aReq,
75 'url': 'proxy'
76 },function(result){
77 if(result.edit && result.edit.newrevid){
78 $j('#appendTarget').html( "success: " + JSON.stringify ( result) );
79 url = remote_wiki_host + remote_script_path + '/index.php/';
80 url+= result.edit.title.replace(' ', '_');
81 $j('#appendTarget').append( '<br><a target="_new" href="' + url + '">visit page</a>' );
82 }else{
83 $j('#appendTarget').html( "falied: " + JSON.stringify ( result) );
84 }
85 });
86
87 });
88 });
89 }
90 </script>
91
92 </head>
93 <body>
94 <h3> Simple API proxy testing system </h3>
95
96 <div id="setupProxy">Proxy for: <span id="hostName"></span> <br><span style="font-size:small">( be sure to enable the mwEmbed gadget or add importScriptURI( 'path_to_local_mw_install' + /js2/remoteMwEmbed.js ) to your User skin .js page </span></div>
97 <div id="setupDone" style="display:none;">
98 <br> <a href="#" id="doHello" >Hello User:</a> <span id="helloTarget"></span>
99 <br><br><br> <a href="#" id="doAppend">Append Msg to Talk page:</a>
100 <div id="appendTarget"></div>
101 </div>
102
103 </body>
104 </html>