r78309 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r78308‎ | r78309 | r78310 >
Date:15:48, 13 December 2010
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Added image push support to Special:Push
Modified paths:
  • /trunk/extensions/Push/Push.i18n.php (modified) (history)
  • /trunk/extensions/Push/Push.php (modified) (history)
  • /trunk/extensions/Push/RELEASE-NOTES (modified) (history)
  • /trunk/extensions/Push/specials/Push_Body.php (modified) (history)
  • /trunk/extensions/Push/specials/ext.push.special.js (modified) (history)

Diff [purge]

Index: trunk/extensions/Push/Push.i18n.php
@@ -68,7 +68,11 @@
6969 'push-special-push-done' => 'Push completed',
7070 'push-special-err-token-failed' => 'Could not obtain an edit token on the target wiki.',
7171 'push-special-err-pageget-failed' => 'Could not obtain local page content.',
72 - 'push-special-err-push-failed' => 'Target wiki refused the pushed page.'
 72+ 'push-special-err-push-failed' => 'Target wiki refused the pushed page.',
 73+ 'push-special-inc-files' => 'Include files',
 74+ 'push-special-err-imginfo-failed' => 'Could not determine if any files needed to be pushed.',
 75+ 'push-special-obtaining-fileinfo' => '$1: Obtaining file information.',
 76+ 'push-special-pushing-file' => '$1: Pushing file $2.',
7377 );
7478
7579 /** Message documentation (Message documentation)
Index: trunk/extensions/Push/specials/Push_Body.php
@@ -177,7 +177,8 @@
178178 'var wgPushPages = ' . json_encode( $pages ) . ';' .
179179 'var wgPushTargets = ' . json_encode( $targets ) . ';' .
180180 'var wgPushWorkerCount = ' . $egPushBulkWorkers . ';' .
181 - 'var wgPushBatchSize = ' . $egPushBatchSize . ';'
 181+ 'var wgPushBatchSize = ' . $egPushBatchSize . ';' .
 182+ 'var wgPushIncFiles = ' . ( $wgRequest->getCheck( 'files' ) ? 'true' : 'false' ) . ';'
182183 );
183184
184185 $this->loadJs();
@@ -187,7 +188,7 @@
188189 * @since 0.2
189190 */
190191 protected function displayPushInterface( $arg, $pages ) {
191 - global $wgOut, $wgUser, $wgRequest, $egPushTargets;
 192+ global $wgOut, $wgUser, $wgRequest, $egPushTargets, $egPushIncTemplates, $egPushIncFiles;
192193
193194 $wgOut->addWikiMsg( 'push-special-description' );
194195
@@ -205,10 +206,19 @@
206207 $form .= Xml::checkLabel(
207208 wfMsg( 'export-templates' ),
208209 'templates',
209 - 'wpExportTemplates',
210 - $wgRequest->wasPosted() ? $wgRequest->getCheck( 'templates' ) : false
 210+ 'wpPushTemplates',
 211+ $wgRequest->wasPosted() ? $wgRequest->getCheck( 'templates' ) : $egPushIncTemplates
211212 ) . '<br />';
212213
 214+ if ( $wgUser->isAllowed( 'filepush' ) ) {
 215+ $form .= Xml::checkLabel(
 216+ wfMsg( 'push-special-inc-files' ),
 217+ 'files',
 218+ 'wpPushFiles',
 219+ $wgRequest->wasPosted() ? $wgRequest->getCheck( 'files' ) : $egPushIncFiles
 220+ ) . '<br />';
 221+ }
 222+
213223 if ( count( $egPushTargets ) == 1 ) {
214224 $names = array_keys( $egPushTargets );
215225 $form .= '<b>' . htmlspecialchars( wfMsgExt( 'push-special-target-is', 'parsemag', $names[0] ) ) . '</b><br />';
Index: trunk/extensions/Push/specials/ext.push.special.js
@@ -33,6 +33,8 @@
3434 var requestAmount = Math.min( pages.length, window.wgPushWorkerCount );
3535 var batchSize = Math.min( targets.length, window.wgPushBatchSize );
3636
 37+ var pushedFiles = [];
 38+
3739 for ( i = requestAmount; i > 0; i-- ) {
3840 initiateNextPush();
3941 }
@@ -86,7 +88,7 @@
8789 }
8890 else if ( data.length > 0 && data[0].edit && data[0].edit.captcha ) {
8991 handleError( listItem, pageName, { info: mediaWiki.msg( 'push-err-captcha-page', pageName ) } );
90 - }
 92+ }
9193 else {
9294 startPush( pageName, targetOffset, listItem );
9395 }
@@ -94,20 +96,125 @@
9597 );
9698 }
9799 else {
98 - listItem.text( mediaWiki.msg( 'push-special-item-completed', pageName ) );
99 - listItem.css( 'color', 'darkgray' );
100 - initiateNextPush();
 100+ if ( window.wgPushIncFiles ) {
 101+ getIncludedImagesAndInitPush( pageName, listItem );
 102+ }
 103+ else {
 104+ completeItem( pageName, listItem );
 105+ }
101106 }
102107 }
103108
104 - function showCompletion() {
105 - resultList.append( $( '<li />' ).append( $( '<b />' ).text( mediaWiki.msg( 'push-special-push-done' ) ) ) );
 109+ function getIncludedImagesAndInitPush( pageName, listItem ) {
 110+ listItem.text( mediaWiki.msg( 'push-special-obtaining-fileinfo', pageName ) );
 111+
 112+ $.getJSON(
 113+ wgScriptPath + '/api.php',
 114+ {
 115+ 'action': 'query',
 116+ 'prop': 'images',
 117+ 'format': 'json',
 118+ 'titles': pageName,
 119+ },
 120+ function( data ) {
 121+ if ( data.query ) {
 122+ var images = [];
 123+
 124+ for ( page in data.query.pages ) {
 125+ for ( var i = data.query.pages[page].images.length - 1; i >= 0; i-- ) {
 126+ if ( $.inArray( data.query.pages[page].images[i].title, pushedFiles ) == -1 ) {
 127+ pushedFiles.push( data.query.pages[page].images[i].title );
 128+ images.push( data.query.pages[page].images[i].title );
 129+ }
 130+ }
 131+ }
 132+
 133+ if ( images.length > 0 ) {
 134+ var currentFile = images.pop();
 135+ startFilePush( pageName, images, 0, listItem, currentFile );
 136+ }
 137+ else {
 138+ completeItem( pageName, listItem );
 139+ }
 140+ }
 141+ else {
 142+ handleError( pageName, { info: mediaWiki.msg( 'push-special-err-imginfo-failed' ) } );
 143+ }
 144+ }
 145+ );
106146 }
107147
 148+ function startFilePush( pageName, images, targetOffset, listItem, fileName ) {
 149+ if ( targetOffset == 0 ) {
 150+ listItem.text( mediaWiki.msg( 'push-special-pushing-file', pageName, fileName ) );
 151+ }
 152+ else {
 153+ listItem.text( listItem.text() + '...' );
 154+ }
 155+
 156+ var currentBatchLimit = Math.min( targetOffset + batchSize, targets.length );
 157+ var currentBatchStart = targetOffset;
 158+
 159+ if ( targetOffset < targets.length ) {
 160+ listItem.text( listItem.text() + '...' );
 161+
 162+ targetOffset = currentBatchLimit;
 163+
 164+ $.getJSON(
 165+ wgScriptPath + '/api.php',
 166+ {
 167+ 'action': 'pushimages',
 168+ 'format': 'json',
 169+ 'images': fileName,
 170+ 'targets': targets.slice( currentBatchStart, currentBatchLimit ).join( '|' )
 171+ },
 172+ function( data ) {
 173+ var fail = false;
 174+
 175+ for ( i in data.upload ) {
 176+ if ( data.error ) {
 177+ handleError( pageName, data.error );
 178+ fail = true;
 179+ break;
 180+ }
 181+ else if ( !data.upload ) {
 182+ handleError( pageName, { info: 'Unknown error' } ); // TODO
 183+ fail = true;
 184+ break;
 185+ }
 186+ }
 187+
 188+ if ( !fail ) {
 189+ startFilePush( pageName, images, targetOffset, listItem, fileName );
 190+ }
 191+ }
 192+ );
 193+ }
 194+ else {
 195+ if ( images.length > 0 ) {
 196+ var currentFile = images.pop();
 197+ startFilePush( pageName, images, 0, listItem, currentFile );
 198+ }
 199+ else {
 200+ completeItem( pageName, listItem );
 201+ }
 202+ }
 203+ }
 204+
 205+ function completeItem( pageName, listItem ) {
 206+ listItem.text( mediaWiki.msg( 'push-special-item-completed', pageName ) );
 207+ listItem.css( 'color', 'darkgray' );
 208+ initiateNextPush();
 209+ }
 210+
108211 function handleError( listItem, pageName, error ) {
109212 listItem.text( mediaWiki.msg( 'push-special-item-failed', pageName, error.info ) );
110213 listItem.css( 'color', 'darkred' );
111214 initiateNextPush();
 215+ }
 216+
 217+ function showCompletion() {
 218+ resultList.append( $( '<li />' ).append( $( '<b />' ).text( mediaWiki.msg( 'push-special-push-done' ) ) ) );
112219 }
113220
114221 } ); })(jQuery);
\ No newline at end of file
Index: trunk/extensions/Push/Push.php
@@ -82,6 +82,9 @@
8383 'push-tab-not-created',
8484 'push-err-captcha-page',
8585 'push-button-pushing-files',
 86+ 'push-special-err-imginfo-failed',
 87+ 'push-special-obtaining-fileinfo',
 88+ 'push-special-pushing-file',
8689 );
8790
8891 // For backward compatibility with MW < 1.17.
Index: trunk/extensions/Push/RELEASE-NOTES
@@ -7,7 +7,7 @@
88 === Version 0.5 ===
99 2010-12-xx
1010
11 -* Added support for image-pushing.
 11+* Added support for file-pushing.
1212
1313 === Version 0.4 ===
1414 2010-12-12

Follow-up revisions

RevisionCommit summaryAuthorDate
r78311Follow up to r78309 - some small fixesjeroendedauw16:01, 13 December 2010

Status & tagging log