Index: trunk/extensions/Push/includes/ext.push.tab.js |
— | — | @@ -46,13 +46,67 @@ |
47 | 47 | else { |
48 | 48 | sender.innerHTML = sender.innerHTML + '.'; |
49 | 49 | for (first in data.query.pages) break; |
50 | | - getTokenAndContinue( sender, targetUrl, data.query.pages[first] ); |
| 50 | + doLoginAndContinue( sender, targetUrl, data.query.pages[first] ); |
51 | 51 | } |
52 | 52 | } |
53 | 53 | ); |
54 | 54 | } |
55 | 55 | |
56 | | - function getTokenAndContinue( sender, targetUrl, page ) { |
| 56 | + function doLoginAndContinue( sender, targetUrl, page ) { |
| 57 | + if ( false ) { // TODO |
| 58 | + var name = 'WikiSysop'; // TODO |
| 59 | + var password = 'inurwiki'; // TODO |
| 60 | + |
| 61 | + $.post( |
| 62 | + targetUrl + '/api.php', |
| 63 | + { |
| 64 | + 'action': 'login', |
| 65 | + 'format': 'json', |
| 66 | + 'lgname': name, |
| 67 | + 'lgpassword': password, |
| 68 | + }, |
| 69 | + function( data ) { |
| 70 | + if ( data.error ) { |
| 71 | + handleError( sender, targetUrl, data.error ); |
| 72 | + } |
| 73 | + else { |
| 74 | + if ( data.login.result == "NeedToken" ) { |
| 75 | + confirmLoginTokenAndContinue( sender, targetUrl, page, data.login.token, name, password ); |
| 76 | + } |
| 77 | + else { |
| 78 | + getEditTokenAndContinue( sender, targetUrl, page ); |
| 79 | + } |
| 80 | + } |
| 81 | + } |
| 82 | + ); |
| 83 | + } |
| 84 | + else { |
| 85 | + getEditTokenAndContinue( sender, targetUrl, page ); |
| 86 | + } |
| 87 | + } |
| 88 | + |
| 89 | + function confirmLoginTokenAndContinue( sender, targetUrl, page, token, name, password ) { |
| 90 | + $.post( |
| 91 | + targetUrl + '/api.php', |
| 92 | + { |
| 93 | + 'action': 'login', |
| 94 | + 'format': 'json', |
| 95 | + 'lgname': name, |
| 96 | + 'lgpassword': password, |
| 97 | + 'lgtoken': token |
| 98 | + }, |
| 99 | + function( data ) { |
| 100 | + if ( data.error ) { |
| 101 | + handleError( sender, targetUrl, data.error ); |
| 102 | + } |
| 103 | + else { |
| 104 | + getEditTokenAndContinue( sender, targetUrl, page ); |
| 105 | + } |
| 106 | + } |
| 107 | + ); |
| 108 | + } |
| 109 | + |
| 110 | + function getEditTokenAndContinue( sender, targetUrl, page ) { |
57 | 111 | $.getJSON( |
58 | 112 | targetUrl + '/api.php', |
59 | 113 | { |
— | — | @@ -73,12 +127,8 @@ |
74 | 128 | } |
75 | 129 | } |
76 | 130 | ); |
77 | | - } |
| 131 | + } |
78 | 132 | |
79 | | - function doLoginAndContinue() { |
80 | | - |
81 | | - } |
82 | | - |
83 | 133 | function doPush( sender, targetUrl, page, token ) { |
84 | 134 | var summary = mediaWiki.msg( 'push-import-revision-message' ); |
85 | 135 | summary = summary.replace( '$1', $('#siteName').attr('value') ); |