From: Bryan Tong Minh Date: Fri, 28 Aug 2009 21:18:39 +0000 (+0000) Subject: * Add buffering to ApiFormatBase, which allows buffering the result without needing... X-Git-Tag: 1.31.0-rc.0~40008 X-Git-Url: https://git.cyclocoop.org/%27.WWW_URL.%27admin/?a=commitdiff_plain;h=efd86ed3aaac0aeadfc0dec9b8e370a1b7faa185;p=lhc%2Fweb%2Fwiklou.git * Add buffering to ApiFormatBase, which allows buffering the result without needing ob_* functions. This is for async downloads, but I couldn't get it to work yet so this commit does not contain the files that actually use the buffering. * Hide internalhttpsession parameter from web requests --- diff --git a/includes/api/ApiFormatBase.php b/includes/api/ApiFormatBase.php index d5c87626a8..0294fcea68 100644 --- a/includes/api/ApiFormatBase.php +++ b/includes/api/ApiFormatBase.php @@ -36,6 +36,7 @@ if (!defined('MEDIAWIKI')) { abstract class ApiFormatBase extends ApiBase { private $mIsHtml, $mFormat, $mUnescapeAmps, $mHelp, $mCleared; + private $mBufferResult = false, $mBuffer; /** * Constructor @@ -188,10 +189,11 @@ See complete documentation, or * @param $text string */ public function printText($text) { - if ($this->getIsHtml()) + if ($this->mBufferResult) { + $this->mBuffer = $text; + } elseif ($this->getIsHtml()) { echo $this->formatHTML($text); - else - { + } else { // For non-HTML output, clear all errors that might have been // displayed if display_errors=On // Do this only once, of course @@ -203,6 +205,19 @@ See complete documentation, or echo $text; } } + + /** + * Get the contents of the buffer. + */ + public function getBuffer() { + return $this->mBuffer; + } + /** + * Set the flag to buffer the result instead of printing it. + */ + public function setBufferResult( $value ) { + $this->mBufferResult = $value; + } /** * Sets whether the pretty-printer should format *bold* and $italics$ diff --git a/includes/api/ApiUpload.php b/includes/api/ApiUpload.php index 41be72d340..64866ea5fc 100644 --- a/includes/api/ApiUpload.php +++ b/includes/api/ApiUpload.php @@ -44,7 +44,7 @@ class ApiUpload extends ApiBase { $this->mParams = $this->extractRequestParams(); $request = $this->getMain()->getRequest(); - // do token checks: + // Do token checks: if ( is_null( $this->mParams['token'] ) ) $this->dieUsageMsg( array( 'missingparam', 'token' ) ); if ( !$wgUser->matchEditToken( $this->mParams['token'] ) ) @@ -57,21 +57,23 @@ class ApiUpload extends ApiBase { // Check whether upload is enabled if ( !UploadBase::isEnabled() ) $this->dieUsageMsg( array( 'uploaddisabled' ) ); - + // One and only one of the following parameters is needed $this->requireOnlyOneParameter( $this->mParams, - 'sessionkey', 'file', 'url', 'enablechunks' ); - + 'sessionkey', 'file', 'url', 'enablechunks' ); + if ( $this->mParams['enablechunks'] ) { - // chunks upload enabled + /** + * Chunked upload mode + */ + $this->mUpload = new UploadFromChunks(); $status = $this->mUpload->initializeFromParams( $this->mParams, $request ); if( isset( $status['error'] ) ) $this->dieUsageMsg( $status['error'] ); - } elseif ( $this->mParams['internalhttpsession'] ) { - // TODO: Move to subclass + } elseif ( isset( $this->mParams['internalhttpsession'] ) && $this->mParams['internalhttpsession'] ) { $sd = & $_SESSION['wsDownload'][ $this->mParams['internalhttpsession'] ]; //wfDebug("InternalHTTP:: " . print_r($this->mParams, true)); @@ -82,16 +84,17 @@ class ApiUpload extends ApiBase { $sd['target_file_path'], filesize( $sd['target_file_path'] ) ); - } elseif ( $this->mParams['httpstatus'] && $this->mParams['sessionkey'] ) { - // return the status of the given upload session_key: + /** + * Return the status of the given background upload session_key: + */ // Check the session key if( !isset( $_SESSION['wsDownload'][$this->mParams['sessionkey']] ) ) return $this->dieUsageMsg( array( 'invalid-session-key' ) ); $sd =& $_SESSION['wsDownload'][$this->mParams['sessionkey']]; - // keep passing down the upload sessionkey + // Keep passing down the upload sessionkey $statusResult = array( 'upload_session_key' => $this->mParams['sessionkey'] ); @@ -105,16 +108,20 @@ class ApiUpload extends ApiBase { $statusResult['content_length'] = $sd['content_length']; return $this->getResult()->addValue( null, - $this->getModuleName(), $statusResult); + $this->getModuleName(), $statusResult ); - } else if( $this->mParams['sessionkey'] ) { - // Stashed upload + } elseif( $this->mParams['sessionkey'] ) { + /** + * Upload stashed in a previous request + */ $this->mUpload = new UploadFromStash(); $this->mUpload->initialize( $this->mParams['filename'], $_SESSION['wsUploadData'][$this->mParams['sessionkey']] ); } else { - // Upload from url or file - // Parameter filename is required + /** + * Upload from url or file + * Parameter filename is required + */ if ( !isset( $this->mParams['filename'] ) ) $this->dieUsageMsg( array( 'missingparam', 'filename' ) ); @@ -132,7 +139,7 @@ class ApiUpload extends ApiBase { $this->mParams['url'], $this->mParams['asyncdownload'] ); $status = $this->mUpload->fetchFile(); - if( !$status->isOK() ){ + if( !$status->isOK() ) { return $this->dieUsage( 'fetchfileerror', $status->getWikiText() ); } @@ -152,15 +159,16 @@ class ApiUpload extends ApiBase { array( 'upload_session_key' => $upload_session_key )); } - //else the file downloaded in place continue with validation: } } - + if( !isset( $this->mUpload ) ) $this->dieUsage( 'No upload module set', 'nomodule' ); - - //finish up the exec command: + + + // Finish up the exec command: $this->doExecUpload(); + } protected function doExecUpload(){ @@ -287,8 +295,6 @@ class ApiUpload extends ApiBase { $result['filename'] = $file->getName(); // Append imageinfo to the result - - //get all the image properties: $imParam = ApiQueryImageInfo::getPropertyNames(); $result['imageinfo'] = ApiQueryImageInfo::getInfo( $file, array_flip( $imParam ), $this->getResult() ); @@ -322,12 +328,15 @@ class ApiUpload extends ApiBase { 'url' => null, 'httpstatus' => false, 'sessionkey' => null, - 'internalhttpsession' => null, ); + + if ( $this->getMain()->isInternalMode() ) + $params['internalhttpsession'] = null; if($wgEnableAsyncDownload){ $params['asyncdownload'] = false; } return $params; + } public function getParamDescription() { @@ -386,3 +395,4 @@ class ApiUpload extends ApiBase { } } +