Index: trunk/extensions/Push/Push.i18n.php |
— | — | @@ -16,12 +16,13 @@ |
17 | 17 | */ |
18 | 18 | $messages['en'] = array( |
19 | 19 | 'push-desc' => 'Lightweight extension to push content to other wiki\'s', |
20 | | - 'push-tab-text' => 'push', |
| 20 | + 'push-tab-text' => 'Push', |
21 | 21 | 'push-button-text' => 'Push', |
22 | | - 'push-button-pushing' => 'Pushing...', |
| 22 | + 'push-button-pushing' => 'Pushing', |
23 | 23 | 'push-button-completed' => 'Push completed', |
24 | 24 | 'push-button-failed' => 'Push failed', |
25 | 25 | 'push-tab-title' => 'Pushing $1', |
26 | 26 | 'push-targets' => 'Push targets', |
27 | 27 | 'push-add-target' => 'Add target', |
| 28 | + 'push-import-revision-message' => 'Import from $1 by $2. Last comment: $3', |
28 | 29 | ); |
\ No newline at end of file |
Index: trunk/extensions/Push/Push.php |
— | — | @@ -66,7 +66,8 @@ |
67 | 67 | 'messages' => array( |
68 | 68 | 'push-button-pushing', |
69 | 69 | 'push-button-completed', |
70 | | - 'push-button-failed' |
| 70 | + 'push-button-failed', |
| 71 | + 'push-import-revision-message', |
71 | 72 | ) |
72 | 73 | ); |
73 | 74 | |
Index: trunk/extensions/Push/includes/Push_Tab.php |
— | — | @@ -66,10 +66,14 @@ |
67 | 67 | * special pages) |
68 | 68 | */ |
69 | 69 | public static function displayPushPage( Article $article ) { |
70 | | - global $wgOut, $wgUser; |
| 70 | + global $wgOut, $wgUser, $wgTitle; |
71 | 71 | |
72 | 72 | $wgOut->setPageTitle( wfMsgExt( 'push-tab-title', 'parsemag', $article->getTitle()->getText() ) ); |
73 | 73 | |
| 74 | + $wgOut->addHTML( |
| 75 | + Html::hidden( 'pageName', $wgTitle->getFullText(), array( 'id' => 'pageName' ) ) |
| 76 | + ); |
| 77 | + |
74 | 78 | $wgOut->addModules( 'ext.push.tab' ); |
75 | 79 | |
76 | 80 | if ( $wgUser->isAllowed( 'push' ) ) { |
Index: trunk/extensions/Push/includes/ext.push.tab.js |
— | — | @@ -11,50 +11,80 @@ |
12 | 12 | this.disabled = true; |
13 | 13 | this.innerHTML = mediaWiki.msg( 'push-button-pushing' ); |
14 | 14 | |
15 | | - getTokenAndDoPush( this, $(this).attr( 'pushtarget' ) ); |
| 15 | + getLocalArtcileAndContinue( this, $(this).attr( 'pushtarget' ) ); |
16 | 16 | }); |
17 | 17 | |
18 | | - function getTokenAndDoPush( sender, targetUrl ) { |
| 18 | + function getLocalArtcileAndContinue( sender, targetUrl ) { |
| 19 | + var pageName = $('#pageName').attr('value'); |
| 20 | + |
19 | 21 | $.getJSON( |
| 22 | + wgScriptPath + '/api.php', |
| 23 | + { |
| 24 | + 'action': 'query', |
| 25 | + 'format': 'json', |
| 26 | + 'prop': 'revisions', |
| 27 | + 'rvprop': 'timestamp|user|comment|content', |
| 28 | + 'titles': pageName, |
| 29 | + }, |
| 30 | + function( data ) { |
| 31 | + if ( data.error ) { |
| 32 | + handleError( sender, targetUrl, data.error ); |
| 33 | + } |
| 34 | + else { |
| 35 | + sender.innerHTML = sender.innerHTML + '.'; |
| 36 | + for (first in data.query.pages) break; |
| 37 | + getTokenAndContinue( sender, targetUrl, data.query.pages[first] ); |
| 38 | + } |
| 39 | + } |
| 40 | + ); |
| 41 | + } |
| 42 | + |
| 43 | + function getTokenAndContinue( sender, targetUrl, page ) { |
| 44 | + $.getJSON( |
20 | 45 | targetUrl + '/api.php', |
21 | 46 | { |
22 | 47 | 'action': 'query', |
23 | 48 | 'format': 'json', |
24 | 49 | 'intoken': 'edit', |
25 | 50 | 'prop': 'info', |
26 | | - 'titles': 'Test page', // TODO |
| 51 | + 'titles': page.title, |
27 | 52 | }, |
28 | 53 | function( data ) { |
29 | 54 | if ( data.error ) { |
30 | | - alert( data.error.info ); |
31 | | - sender.innerHTML = mediaWiki.msg( 'push-button-failed' ); |
| 55 | + handleError( sender, targetUrl, data.error ); |
32 | 56 | } |
33 | 57 | else { |
34 | 58 | sender.innerHTML = sender.innerHTML + '.'; |
35 | 59 | for (first in data.query.pages) break; |
36 | | - doPush( sender, targetUrl, data.query.pages[first].edittoken ); |
| 60 | + doPush( sender, targetUrl, page, data.query.pages[first].edittoken ); |
37 | 61 | } |
38 | 62 | } |
39 | 63 | ); |
| 64 | + } |
40 | 65 | |
41 | | - |
| 66 | + function doLoginAndContinue() { |
| 67 | + |
42 | 68 | } |
43 | 69 | |
44 | | - function doPush( sender, targetUrl, token ) { |
| 70 | + function doPush( sender, targetUrl, page, token ) { |
| 71 | + var summary = mediaWiki.msg( 'push-import-revision-message' ); |
| 72 | + summary = summary.replace( '$1', 'Some wiki' ); // TODO |
| 73 | + summary = summary.replace( '$2', page.revisions[0].user ); |
| 74 | + summary = summary.replace( '$3', page.revisions[0].comment ); |
| 75 | + |
45 | 76 | $.post( |
46 | 77 | targetUrl + '/api.php', |
47 | 78 | { |
48 | 79 | 'action': 'edit', |
49 | 80 | 'format': 'json', |
50 | 81 | 'token': token, |
51 | | - 'title': 'Test page', // TODO |
52 | | - 'summary': 'Pushed content', // TODO |
53 | | - 'text': 'Test push content' // TODO |
| 82 | + 'title': page.title, |
| 83 | + 'summary': summary, |
| 84 | + 'text': page.revisions[0].* |
54 | 85 | }, |
55 | 86 | function( data ) { |
56 | 87 | if ( data.error ) { |
57 | | - alert( data.error.info ); |
58 | | - sender.innerHTML = mediaWiki.msg( 'push-button-failed' ); |
| 88 | + handleError( sender, targetUrl, data.error ); |
59 | 89 | } |
60 | 90 | else { |
61 | 91 | sender.innerHTML = mediaWiki.msg( 'push-button-completed' ); |
— | — | @@ -63,4 +93,9 @@ |
64 | 94 | ); |
65 | 95 | } |
66 | 96 | |
| 97 | + function handleError( sender, targetUrl, error ) { |
| 98 | + alert( error.info ); |
| 99 | + sender.innerHTML = mediaWiki.msg( 'push-button-failed' ); |
| 100 | + } |
| 101 | + |
67 | 102 | } ); |