* added missing setIndexedTagName for some upload api array results
[lhc/web/wiklou.git] / includes / api / ApiUpload.php
index 1bb2935..57f3541 100644 (file)
@@ -1,5 +1,4 @@
 <?php
-
 /*
  * Created on Aug 21, 2008
  * API for MediaWiki 1.8+
@@ -73,8 +72,9 @@ class ApiUpload extends ApiBase {
                                $this->dieUsageMsg( $this->mUpload->status['error'] );
 
                } else if( $this->mParams['internalhttpsession'] ){
-                       $sd = & $_SESSION['wsDownload'][$this->mParams['internalhttpsession']];
+                       $sd = & $_SESSION['wsDownload'][ $this->mParams['internalhttpsession'] ];
 
+                       wfDebug("InternalHTTP:: " . print_r($this->mParams, true));
                        // get the params from the init session:
                        $this->mUpload = new UploadFromFile();
 
@@ -237,7 +237,13 @@ class ApiUpload extends ApiBase {
                        $warnings = $this->mUpload->checkWarnings();
                        if( $warnings ) {
                                $this->getResult()->setIndexedTagName( $warnings, 'warning' );
-
+                               //also add index to duplicate: 
+                               if(isset($warnings['duplicate']))
+                                       $this->getResult()->setIndexedTagName( $warnings['duplicate'], 'duplicate');
+                               
+                               if(isset($warnings['exists']))
+                                       $this->getResult()->setIndexedTagName( $warnings['exists'], 'exists');
+                                       
                                $result['result'] = 'Warning';
                                $result['warnings'] = $warnings;
                                if( isset( $result['filewasdeleted'] ) )
@@ -275,8 +281,6 @@ class ApiUpload extends ApiBase {
                        array_flip( $imProp ),
                        $this->getResult() );
 
-               wfDebug( "\n\n return result: " . print_r( $result, true ) );
-
                return $result;
        }
 
@@ -291,21 +295,21 @@ class ApiUpload extends ApiBase {
        public function getAllowedParams() {
                return array(
                        'filename' => null,
-                       'file' => null,
-                       'chunk' => null,
-                       'url' => null,
-                       'token' => null,
-                       'enablechunks' => null,
                        'comment' => array(
                                ApiBase::PARAM_DFLT => ''
                        ),
-                       'asyncdownload' => false,
+                       'token' => null,
                        'watch' => false,
                        'ignorewarnings' => false,
+                       'file' => null,
+                       'enablechunks' => null,
+                       'chunksessionkey' => null,
+                       'chunk' => null,
                        'done' => false,
-                       'sessionkey' => null,
+                       'url' => null,
+                       'asyncdownload' => false,
                        'httpstatus' => false,
-                       'chunksessionkey' => null,
+                       'sessionkey' => null,
                        'internalhttpsession' => null,
                );
        }
@@ -313,32 +317,51 @@ class ApiUpload extends ApiBase {
        public function getParamDescription() {
                return array(
                        'filename' => 'Target filename',
-                       'file' => 'File contents',
-                       'chunk'=> 'Chunk File Contents',
-                       'url' => 'Url to upload from',
-                       'comment' => 'Upload comment or initial page text',
-                       'token' => 'Edit token. You can get one of these through prop=info (this helps avoid remote ajax upload requests with your credentials)',
-                       'enablechunks' => 'Boolean If we are in chunk mode; accepts many small file POSTs',
-                       'asyncdownload' => 'If we should download the url asyncrously usefull for large http downloads (returns a upload session key to get status updates in subquent calls)',
+                       'token' => 'Edit token. You can get one of these through prop=info',
+                       'comment' => 'Upload comment. Also used as the initial page text for new files',
                        'watch' => 'Watch the page',
                        'ignorewarnings' => 'Ignore any warnings',
-                       'done'  => 'When used with "chunks", Is sent to notify the api The last chunk is being uploaded.',
-                       'sessionkey' => 'Session key in case there were any warnings.',
-                       'httpstatus' => 'When set to true, will return the status of a given sessionKey (used for progress meters)',
+                       'file' => 'File contents',
+                       'enablechunks' => 'Set to use chunk mode; see http://firefogg.org/dev/chunk_post.html for protocol',
                        'chunksessionkey' => 'Used to sync uploading of chunks',
-                       'internalhttpsession' => 'Used internally for http session downloads',
+                       'chunk' => 'Chunk contents',
+                       'done' => 'Set when the last chunk is being uploaded',
+                       'url' => 'Url to fetch the file from',
+                       'asyncdownload' => 'Set to download the url asynchronously. Useful for large files that will take more than php max_execution_time to download',
+                       'httpstatus' => 'Set to return the status of an asynchronous upload (specify the key in sessionkey)',
+                       'sessionkey' => array(
+                               'Session key returned by a previous upload that failed due to warnings, or',
+                               '(with httpstatus) The upload_session_key of an asynchronous upload',
+                       ),
+                       'internalhttpsession' => 'Used internally',
                );
        }
 
        public function getDescription() {
                return array(
-                       'Upload a file'
+                       'Upload a file, or get the status of pending uploads. Several methods are available:',
+                       ' * Upload file contents directly, using the "file" parameter',
+                       ' * Upload a file in chunks, using the "enablechunks", "chunk", and "chunksessionkey", and "done" parameters',
+                       ' * Have the MediaWiki server fetch a file from a URL, using the "url" and "asyncdownload" parameters',
+                       ' * Retrieve the status of an asynchronous upload, using the "httpstatus" and "sessionkey" parameters',
+                       ' * Complete an earlier upload that failed due to warnings, using the "sessionkey" parameter',
+                       'Note that the HTTP POST must be done as a file upload (i.e. using multipart/form-data) when',
+                       'sending the "file" or "chunk" parameters. Note also that queries using session keys must be',
+                       'done in the same login session as the query that originally returned the key (i.e. do not',
+                       'log out and then log back in). Also you must get and send an edit token before doing any upload stuff.'
                );
        }
 
        protected function getExamples() {
                return array(
-                       'api.php?action=upload&filename=Wiki.png&url=http%3A//upload.wikimedia.org/wikipedia/en/b/bc/Wiki.png&ignorewarnings'
+                       'Upload from a URL:',
+                       '    api.php?action=upload&filename=Wiki.png&url=http%3A//upload.wikimedia.org/wikipedia/en/b/bc/Wiki.png',
+                       'Get the status of an asynchronous upload:',
+                       '    api.php?action=upload&filename=Wiki.png&httpstatus=1&sessionkey=upload_session_key',
+                       'Complete an upload that failed due to warnings:',
+                       '    api.php?action=upload&filename=Wiki.png&sessionkey=sessionkey&ignorewarnings=1',
+                       'Begin a chunked upload:',
+                       '    api.php?action=upload&filename=Wiki.png&enablechunks=1'
                );
        }