http://www.mediawiki.org/wiki/Special:Code/MediaWiki/82918

Revision: 82918
Author:   jeroendedauw
Date:     2011-02-27 22:07:31 +0000 (Sun, 27 Feb 2011)
Log Message:
-----------
fixed issue with file pushing

Modified Paths:
--------------
    trunk/extensions/Push/Push.i18n.php
    trunk/extensions/Push/Push.php
    trunk/extensions/Push/Push_Settings.php
    trunk/extensions/Push/RELEASE-NOTES
    trunk/extensions/Push/api/ApiPush.php
    trunk/extensions/Push/api/ApiPushImages.php
    trunk/extensions/Push/includes/Push_Functions.php
    trunk/extensions/Push/includes/ext.push.tab.js
    trunk/extensions/Push/specials/Push_Body.php
    trunk/extensions/Push/specials/ext.push.special.js

Modified: trunk/extensions/Push/Push.i18n.php
===================================================================
--- trunk/extensions/Push/Push.i18n.php 2011-02-27 22:01:59 UTC (rev 82917)
+++ trunk/extensions/Push/Push.i18n.php 2011-02-27 22:07:31 UTC (rev 82918)
@@ -81,6 +81,13 @@
        'push-special-obtaining-fileinfo' => '$1: Obtaining file 
information...',
        'push-special-pushing-file' => '$1: Pushing file $2...',
        'push-special-return' => 'Push more pages',
+
+       // API
+       'push-api-err-nocurl' => 'cURL is not installed.
+Set $egPushDirectFileUploads to false on public wikis, or install cURL for 
private wikis',
+       'push-api-err-nofilesupport' => 'The local MediaWiki does not have 
support for posting files.
+On public wikis, set $egPushDirectFileUploads to false.
+On private wikis, apply the patch linkd from the Push documentation or update 
MediaWiki itself.',
 );
 
 /** Message documentation (Message documentation)

Modified: trunk/extensions/Push/Push.php
===================================================================
--- trunk/extensions/Push/Push.php      2011-02-27 22:01:59 UTC (rev 82917)
+++ trunk/extensions/Push/Push.php      2011-02-27 22:07:31 UTC (rev 82918)
@@ -25,7 +25,7 @@
        die( 'Not an entry point.' );
 }
 
-define( 'Push_VERSION', '0.8 alpha' );
+define( 'Push_VERSION', '0.8 rc' );
 
 $wgExtensionCredits['other'][] = array(
        'path' => __FILE__,

Modified: trunk/extensions/Push/Push_Settings.php
===================================================================
--- trunk/extensions/Push/Push_Settings.php     2011-02-27 22:01:59 UTC (rev 
82917)
+++ trunk/extensions/Push/Push_Settings.php     2011-02-27 22:07:31 UTC (rev 
82918)
@@ -65,3 +65,8 @@
 
 # The maximum amount of targets to push a page to in one go.
 $egPushBatchSize = 3;
+
+# Use direct file uploads (requires patch to MW 1.16 and 1.17).
+# This is needed when pushing to a wiki that cannot access the source file
+# (for example from a private wiki to a wiki on the internet).
+$egPushDirectFileUploads = !$wgAllowCopyUploads;

Modified: trunk/extensions/Push/RELEASE-NOTES
===================================================================
--- trunk/extensions/Push/RELEASE-NOTES 2011-02-27 22:01:59 UTC (rev 82917)
+++ trunk/extensions/Push/RELEASE-NOTES 2011-02-27 22:07:31 UTC (rev 82918)
@@ -5,9 +5,9 @@
 
 
 === Version 0.8 ===
-2011-xx-xx
+2011-0x-xx
 
-*
+* Fixed issue with pushing files from private wikis.
 
 === Version 0.7 ===
 2011-01-14

Modified: trunk/extensions/Push/api/ApiPush.php
===================================================================
--- trunk/extensions/Push/api/ApiPush.php       2011-02-27 22:01:59 UTC (rev 
82917)
+++ trunk/extensions/Push/api/ApiPush.php       2011-02-27 22:07:31 UTC (rev 
82918)
@@ -107,6 +107,8 @@
                        'lgpassword' => $password
                );
                
+               //static $fail = 0;$fail++;
+               
                if ( !is_null( $token ) ) {
                        $requestData['lgtoken'] = $token;
                }

Modified: trunk/extensions/Push/api/ApiPushImages.php
===================================================================
--- trunk/extensions/Push/api/ApiPushImages.php 2011-02-27 22:01:59 UTC (rev 
82917)
+++ trunk/extensions/Push/api/ApiPushImages.php 2011-02-27 22:07:31 UTC (rev 
82918)
@@ -243,25 +243,46 @@
         * @param string $token
         */             
        protected function pushToTarget( Title $title, $target, $token ) {
+               global $egPushDirectFileUploads;
+               
                $imagePage = new ImagePage( $title );
-               
+
                $requestData = array(
                        'action' => 'upload',
                        'format' => 'json',
                        'token' => $token,
-                       'url' => $imagePage->getDisplayedFile()->getFullUrl(),
                        'filename' => $title->getText(),
                        'ignorewarnings' => '1'
                );
-
-               $req = PushFunctions::getHttpRequest( $target, 
-                       array(
-                               'method' => 'POST',
-                               'timeout' => 'default',
-                               'postData' => $requestData,
-                       )
+               
+               if ( $egPushDirectFileUploads ) {
+                       $requestData['file'] = '@' . 
$imagePage->getFile()->getFullPath();
+               }
+               else {
+                       $requestData['url'] = 
$imagePage->getDisplayedFile()->getFullUrl();
+               }
+               
+               $reqArgs = array(
+                       'method' => 'POST',
+                       'timeout' => 'default',
+                       'postData' => $requestData
                );
                
+               if ( $egPushDirectFileUploads ) {
+                       if ( !function_exists( 'curl_init' ) ) {
+                               $this->dieUsage( wfMsg( 'push-api-err-nocurl' 
), 'image-push-nocurl' );
+                       }
+                       else if ( !defined( 
'CurlHttpRequest::SUPPORTS_FILE_POSTS' ) || 
!CurlHttpRequest::SUPPORTS_FILE_POSTS ) {
+                               $this->dieUsage( wfMsg( 
'push-api-err-nofilesupport' ), 'image-push-nofilesupport' );
+                       }
+                       else {
+                               $req = new CurlHttpRequest( $target, $reqArgs );
+                       }
+               }
+               else {
+                       $req = PushFunctions::getHttpRequest( $target, $reqArgs 
);
+               }
+               
                if ( array_key_exists( $target, $this->cookieJars ) ) {
                        $req->setCookieJar( $this->cookieJars[$target] );
                }                       

Modified: trunk/extensions/Push/includes/Push_Functions.php
===================================================================
--- trunk/extensions/Push/includes/Push_Functions.php   2011-02-27 22:01:59 UTC 
(rev 82917)
+++ trunk/extensions/Push/includes/Push_Functions.php   2011-02-27 22:07:31 UTC 
(rev 82918)
@@ -131,7 +131,7 @@
                                        $flipped[$egPushTargets[$key]] = $value;
                                }
                        }
-                       
+
                        $arr = $flipped;                        
                }
        }

Modified: trunk/extensions/Push/includes/ext.push.tab.js
===================================================================
--- trunk/extensions/Push/includes/ext.push.tab.js      2011-02-27 22:01:59 UTC 
(rev 82917)
+++ trunk/extensions/Push/includes/ext.push.tab.js      2011-02-27 22:07:31 UTC 
(rev 82918)
@@ -301,20 +301,27 @@
                        function( data ) {
                                var fail = false;
                                
-                               for ( i in data ) {
-                                       if ( data[i].error ) {
-                                               data[i].error.info = 
mediaWiki.msg( 'push-tab-err-filepush', data[i].error.info );
-                                               handleError( sender, targetUrl, 
data[i].error );
-                                               fail = true;
-                                               break;
-                                       }
-                                       else if ( !data[i].upload ) {
-                                               data[i].error.info = 
mediaWiki.msg( 'push-tab-err-filepush-unknown' );
-                                               handleError( sender, targetUrl, 
data[i].error );
-                                               fail = true;
-                                               break;                          
                
-                                       }
+                               if ( data.error ) {
+                                       data.error.info = mediaWiki.msg( 
'push-tab-err-filepush', data.error.info );
+                                       handleError( sender, targetUrl, 
data.error );
+                                       fail = true;                            
        
                                }
+                               else {
+                                       for ( i in data ) {
+                                               if ( data[i].error ) {
+                                                       data[i].error.info = 
mediaWiki.msg( 'push-tab-err-filepush', data[i].error.info );
+                                                       handleError( sender, 
targetUrl, data[i].error );
+                                                       fail = true;
+                                                       break;
+                                               }
+                                               else if ( !data[i].upload ) {
+                                                       data[i].error.info = 
mediaWiki.msg( 'push-tab-err-filepush-unknown' );
+                                                       handleError( sender, 
targetUrl, data[i].error );
+                                                       fail = true;
+                                                       break;                  
                        
+                                               }
+                                       }                                       
+                               }
 
                                if ( !fail ) {
                                        sender.innerHTML = mediaWiki.msg( 
'push-button-completed' );

Modified: trunk/extensions/Push/specials/Push_Body.php
===================================================================
--- trunk/extensions/Push/specials/Push_Body.php        2011-02-27 22:01:59 UTC 
(rev 82917)
+++ trunk/extensions/Push/specials/Push_Body.php        2011-02-27 22:07:31 UTC 
(rev 82918)
@@ -81,7 +81,7 @@
                                        if ( $catpages ) $pages .= "\n" . 
implode( "\n", $catpages );
                                }
                        }
-               }               
+               }
                else if( $wgRequest->getCheck( 'addns' ) ) {
                        $pages = $wgRequest->getText( 'pages' );
                        $nsindex = $wgRequest->getText( 'nsindex', '' );

Modified: trunk/extensions/Push/specials/ext.push.special.js
===================================================================
--- trunk/extensions/Push/specials/ext.push.special.js  2011-02-27 22:01:59 UTC 
(rev 82917)
+++ trunk/extensions/Push/specials/ext.push.special.js  2011-02-27 22:07:31 UTC 
(rev 82918)
@@ -173,18 +173,24 @@
                                function( data ) {
                                        var fail = false;
                                        
-                                       for ( i in data ) {
-                                               if ( data[i].error ) {
-                                                       handleError( listItem, 
pageName, { info: mediaWiki.msg( 'push-tab-err-filepush', data[i].error.info ) 
} );
-                                                       fail = true;
-                                                       break;
-                                               }
-                                               else if ( !data[i].upload ) {
-                                                       handleError( listItem, 
pageName, { info: mediaWiki.msg( 'push-tab-err-filepush-unknown' ) } );
-                                                       fail = true;
-                                                       break;                  
                        
-                                               }
+                                       if ( data.error ) {
+                                               handleError( listItem, 
pageName, { info: mediaWiki.msg( 'push-tab-err-filepush', data.error.info ) } );
+                                               fail = true;                    
                        
                                        }
+                                       else {
+                                               for ( i in data ) {
+                                                       if ( data[i].error ) {
+                                                               handleError( 
listItem, pageName, { info: mediaWiki.msg( 'push-tab-err-filepush', 
data[i].error.info ) } );
+                                                               fail = true;
+                                                               break;
+                                                       }
+                                                       else if ( 
!data[i].upload ) {
+                                                               handleError( 
listItem, pageName, { info: mediaWiki.msg( 'push-tab-err-filepush-unknown' ) } 
);
+                                                               fail = true;
+                                                               break;          
                                
+                                                       }
+                                               }                               
                
+                                       }
                                        
                                        if ( !fail ) {
                                                startFilePush( pageName, 
images, targetOffset, listItem, fileName );


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to