r82918 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r82917‎ | r82918 | r82919 >
Date:22:07, 27 February 2011
Author:jeroendedauw
Status:deferred
Tags:
Comment:
fixed issue with file pushing
Modified paths:
  • /trunk/extensions/Push/Push.i18n.php (modified) (history)
  • /trunk/extensions/Push/Push.php (modified) (history)
  • /trunk/extensions/Push/Push_Settings.php (modified) (history)
  • /trunk/extensions/Push/RELEASE-NOTES (modified) (history)
  • /trunk/extensions/Push/api/ApiPush.php (modified) (history)
  • /trunk/extensions/Push/api/ApiPushImages.php (modified) (history)
  • /trunk/extensions/Push/includes/Push_Functions.php (modified) (history)
  • /trunk/extensions/Push/includes/ext.push.tab.js (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
@@ -81,6 +81,13 @@
8282 'push-special-obtaining-fileinfo' => '$1: Obtaining file information...',
8383 'push-special-pushing-file' => '$1: Pushing file $2...',
8484 'push-special-return' => 'Push more pages',
 85+
 86+ // API
 87+ 'push-api-err-nocurl' => 'cURL is not installed.
 88+Set $egPushDirectFileUploads to false on public wikis, or install cURL for private wikis',
 89+ 'push-api-err-nofilesupport' => 'The local MediaWiki does not have support for posting files.
 90+On public wikis, set $egPushDirectFileUploads to false.
 91+On private wikis, apply the patch linkd from the Push documentation or update MediaWiki itself.',
8592 );
8693
8794 /** Message documentation (Message documentation)
Index: trunk/extensions/Push/specials/Push_Body.php
@@ -81,7 +81,7 @@
8282 if ( $catpages ) $pages .= "\n" . implode( "\n", $catpages );
8383 }
8484 }
85 - }
 85+ }
8686 else if( $wgRequest->getCheck( 'addns' ) ) {
8787 $pages = $wgRequest->getText( 'pages' );
8888 $nsindex = $wgRequest->getText( 'nsindex', '' );
Index: trunk/extensions/Push/specials/ext.push.special.js
@@ -173,18 +173,24 @@
174174 function( data ) {
175175 var fail = false;
176176
177 - for ( i in data ) {
178 - if ( data[i].error ) {
179 - handleError( listItem, pageName, { info: mediaWiki.msg( 'push-tab-err-filepush', data[i].error.info ) } );
180 - fail = true;
181 - break;
182 - }
183 - else if ( !data[i].upload ) {
184 - handleError( listItem, pageName, { info: mediaWiki.msg( 'push-tab-err-filepush-unknown' ) } );
185 - fail = true;
186 - break;
187 - }
 177+ if ( data.error ) {
 178+ handleError( listItem, pageName, { info: mediaWiki.msg( 'push-tab-err-filepush', data.error.info ) } );
 179+ fail = true;
188180 }
 181+ else {
 182+ for ( i in data ) {
 183+ if ( data[i].error ) {
 184+ handleError( listItem, pageName, { info: mediaWiki.msg( 'push-tab-err-filepush', data[i].error.info ) } );
 185+ fail = true;
 186+ break;
 187+ }
 188+ else if ( !data[i].upload ) {
 189+ handleError( listItem, pageName, { info: mediaWiki.msg( 'push-tab-err-filepush-unknown' ) } );
 190+ fail = true;
 191+ break;
 192+ }
 193+ }
 194+ }
189195
190196 if ( !fail ) {
191197 startFilePush( pageName, images, targetOffset, listItem, fileName );
Index: trunk/extensions/Push/Push.php
@@ -25,7 +25,7 @@
2626 die( 'Not an entry point.' );
2727 }
2828
29 -define( 'Push_VERSION', '0.8 alpha' );
 29+define( 'Push_VERSION', '0.8 rc' );
3030
3131 $wgExtensionCredits['other'][] = array(
3232 'path' => __FILE__,
Index: trunk/extensions/Push/Push_Settings.php
@@ -65,3 +65,8 @@
6666
6767 # The maximum amount of targets to push a page to in one go.
6868 $egPushBatchSize = 3;
 69+
 70+# Use direct file uploads (requires patch to MW 1.16 and 1.17).
 71+# This is needed when pushing to a wiki that cannot access the source file
 72+# (for example from a private wiki to a wiki on the internet).
 73+$egPushDirectFileUploads = !$wgAllowCopyUploads;
Index: trunk/extensions/Push/RELEASE-NOTES
@@ -5,9 +5,9 @@
66
77
88 === Version 0.8 ===
9 -2011-xx-xx
 9+2011-0x-xx
1010
11 -*
 11+* Fixed issue with pushing files from private wikis.
1212
1313 === Version 0.7 ===
1414 2011-01-14
Index: trunk/extensions/Push/includes/Push_Functions.php
@@ -131,7 +131,7 @@
132132 $flipped[$egPushTargets[$key]] = $value;
133133 }
134134 }
135 -
 135+
136136 $arr = $flipped;
137137 }
138138 }
Index: trunk/extensions/Push/includes/ext.push.tab.js
@@ -301,20 +301,27 @@
302302 function( data ) {
303303 var fail = false;
304304
305 - for ( i in data ) {
306 - if ( data[i].error ) {
307 - data[i].error.info = mediaWiki.msg( 'push-tab-err-filepush', data[i].error.info );
308 - handleError( sender, targetUrl, data[i].error );
309 - fail = true;
310 - break;
311 - }
312 - else if ( !data[i].upload ) {
313 - data[i].error.info = mediaWiki.msg( 'push-tab-err-filepush-unknown' );
314 - handleError( sender, targetUrl, data[i].error );
315 - fail = true;
316 - break;
317 - }
 305+ if ( data.error ) {
 306+ data.error.info = mediaWiki.msg( 'push-tab-err-filepush', data.error.info );
 307+ handleError( sender, targetUrl, data.error );
 308+ fail = true;
318309 }
 310+ else {
 311+ for ( i in data ) {
 312+ if ( data[i].error ) {
 313+ data[i].error.info = mediaWiki.msg( 'push-tab-err-filepush', data[i].error.info );
 314+ handleError( sender, targetUrl, data[i].error );
 315+ fail = true;
 316+ break;
 317+ }
 318+ else if ( !data[i].upload ) {
 319+ data[i].error.info = mediaWiki.msg( 'push-tab-err-filepush-unknown' );
 320+ handleError( sender, targetUrl, data[i].error );
 321+ fail = true;
 322+ break;
 323+ }
 324+ }
 325+ }
319326
320327 if ( !fail ) {
321328 sender.innerHTML = mediaWiki.msg( 'push-button-completed' );
Index: trunk/extensions/Push/api/ApiPush.php
@@ -107,6 +107,8 @@
108108 'lgpassword' => $password
109109 );
110110
 111+ //static $fail = 0;$fail++;
 112+
111113 if ( !is_null( $token ) ) {
112114 $requestData['lgtoken'] = $token;
113115 }
Index: trunk/extensions/Push/api/ApiPushImages.php
@@ -243,25 +243,46 @@
244244 * @param string $token
245245 */
246246 protected function pushToTarget( Title $title, $target, $token ) {
 247+ global $egPushDirectFileUploads;
 248+
247249 $imagePage = new ImagePage( $title );
248 -
 250+
249251 $requestData = array(
250252 'action' => 'upload',
251253 'format' => 'json',
252254 'token' => $token,
253 - 'url' => $imagePage->getDisplayedFile()->getFullUrl(),
254255 'filename' => $title->getText(),
255256 'ignorewarnings' => '1'
256257 );
257 -
258 - $req = PushFunctions::getHttpRequest( $target,
259 - array(
260 - 'method' => 'POST',
261 - 'timeout' => 'default',
262 - 'postData' => $requestData,
263 - )
 258+
 259+ if ( $egPushDirectFileUploads ) {
 260+ $requestData['file'] = '@' . $imagePage->getFile()->getFullPath();
 261+ }
 262+ else {
 263+ $requestData['url'] = $imagePage->getDisplayedFile()->getFullUrl();
 264+ }
 265+
 266+ $reqArgs = array(
 267+ 'method' => 'POST',
 268+ 'timeout' => 'default',
 269+ 'postData' => $requestData
264270 );
265271
 272+ if ( $egPushDirectFileUploads ) {
 273+ if ( !function_exists( 'curl_init' ) ) {
 274+ $this->dieUsage( wfMsg( 'push-api-err-nocurl' ), 'image-push-nocurl' );
 275+ }
 276+ else if ( !defined( 'CurlHttpRequest::SUPPORTS_FILE_POSTS' ) || !CurlHttpRequest::SUPPORTS_FILE_POSTS ) {
 277+ $this->dieUsage( wfMsg( 'push-api-err-nofilesupport' ), 'image-push-nofilesupport' );
 278+ }
 279+ else {
 280+ $req = new CurlHttpRequest( $target, $reqArgs );
 281+ }
 282+ }
 283+ else {
 284+ $req = PushFunctions::getHttpRequest( $target, $reqArgs );
 285+ }
 286+
266287 if ( array_key_exists( $target, $this->cookieJars ) ) {
267288 $req->setCookieJar( $this->cookieJars[$target] );
268289 }

Status & tagging log