r77936 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r77935‎ | r77936 | r77937 >
Date:00:39, 7 December 2010
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Now getting the actual page data
Modified paths:
  • /trunk/extensions/Push/Push.i18n.php (modified) (history)
  • /trunk/extensions/Push/Push.php (modified) (history)
  • /trunk/extensions/Push/includes/Push_Tab.php (modified) (history)
  • /trunk/extensions/Push/includes/ext.push.tab.js (modified) (history)

Diff [purge]

Index: trunk/extensions/Push/Push.i18n.php
@@ -16,12 +16,13 @@
1717 */
1818 $messages['en'] = array(
1919 'push-desc' => 'Lightweight extension to push content to other wiki\'s',
20 - 'push-tab-text' => 'push',
 20+ 'push-tab-text' => 'Push',
2121 'push-button-text' => 'Push',
22 - 'push-button-pushing' => 'Pushing...',
 22+ 'push-button-pushing' => 'Pushing',
2323 'push-button-completed' => 'Push completed',
2424 'push-button-failed' => 'Push failed',
2525 'push-tab-title' => 'Pushing $1',
2626 'push-targets' => 'Push targets',
2727 'push-add-target' => 'Add target',
 28+ 'push-import-revision-message' => 'Import from $1 by $2. Last comment: $3',
2829 );
\ No newline at end of file
Index: trunk/extensions/Push/Push.php
@@ -66,7 +66,8 @@
6767 'messages' => array(
6868 'push-button-pushing',
6969 'push-button-completed',
70 - 'push-button-failed'
 70+ 'push-button-failed',
 71+ 'push-import-revision-message',
7172 )
7273 );
7374
Index: trunk/extensions/Push/includes/Push_Tab.php
@@ -66,10 +66,14 @@
6767 * special pages)
6868 */
6969 public static function displayPushPage( Article $article ) {
70 - global $wgOut, $wgUser;
 70+ global $wgOut, $wgUser, $wgTitle;
7171
7272 $wgOut->setPageTitle( wfMsgExt( 'push-tab-title', 'parsemag', $article->getTitle()->getText() ) );
7373
 74+ $wgOut->addHTML(
 75+ Html::hidden( 'pageName', $wgTitle->getFullText(), array( 'id' => 'pageName' ) )
 76+ );
 77+
7478 $wgOut->addModules( 'ext.push.tab' );
7579
7680 if ( $wgUser->isAllowed( 'push' ) ) {
Index: trunk/extensions/Push/includes/ext.push.tab.js
@@ -11,50 +11,80 @@
1212 this.disabled = true;
1313 this.innerHTML = mediaWiki.msg( 'push-button-pushing' );
1414
15 - getTokenAndDoPush( this, $(this).attr( 'pushtarget' ) );
 15+ getLocalArtcileAndContinue( this, $(this).attr( 'pushtarget' ) );
1616 });
1717
18 - function getTokenAndDoPush( sender, targetUrl ) {
 18+ function getLocalArtcileAndContinue( sender, targetUrl ) {
 19+ var pageName = $('#pageName').attr('value');
 20+
1921 $.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(
2045 targetUrl + '/api.php',
2146 {
2247 'action': 'query',
2348 'format': 'json',
2449 'intoken': 'edit',
2550 'prop': 'info',
26 - 'titles': 'Test page', // TODO
 51+ 'titles': page.title,
2752 },
2853 function( data ) {
2954 if ( data.error ) {
30 - alert( data.error.info );
31 - sender.innerHTML = mediaWiki.msg( 'push-button-failed' );
 55+ handleError( sender, targetUrl, data.error );
3256 }
3357 else {
3458 sender.innerHTML = sender.innerHTML + '.';
3559 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 );
3761 }
3862 }
3963 );
 64+ }
4065
41 -
 66+ function doLoginAndContinue() {
 67+
4268 }
4369
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+
4576 $.post(
4677 targetUrl + '/api.php',
4778 {
4879 'action': 'edit',
4980 'format': 'json',
5081 '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].*
5485 },
5586 function( data ) {
5687 if ( data.error ) {
57 - alert( data.error.info );
58 - sender.innerHTML = mediaWiki.msg( 'push-button-failed' );
 88+ handleError( sender, targetUrl, data.error );
5989 }
6090 else {
6191 sender.innerHTML = mediaWiki.msg( 'push-button-completed' );
@@ -63,4 +93,9 @@
6494 );
6595 }
6696
 97+ function handleError( sender, targetUrl, error ) {
 98+ alert( error.info );
 99+ sender.innerHTML = mediaWiki.msg( 'push-button-failed' );
 100+ }
 101+
67102 } );

Status & tagging log