r55661 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r55660‎ | r55661 | r55662 >
Date:21:18, 28 August 2009
Author:btongminh
Status:ok
Tags:
Comment:
* 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
Modified paths:
  • /trunk/phase3/includes/api/ApiFormatBase.php (modified) (history)
  • /trunk/phase3/includes/api/ApiUpload.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/api/ApiFormatBase.php
@@ -36,6 +36,7 @@
3737 abstract class ApiFormatBase extends ApiBase {
3838
3939 private $mIsHtml, $mFormat, $mUnescapeAmps, $mHelp, $mCleared;
 40+ private $mBufferResult = false, $mBuffer;
4041
4142 /**
4243 * Constructor
@@ -188,10 +189,11 @@
189190 * @param $text string
190191 */
191192 public function printText($text) {
192 - if ($this->getIsHtml())
 193+ if ($this->mBufferResult) {
 194+ $this->mBuffer = $text;
 195+ } elseif ($this->getIsHtml()) {
193196 echo $this->formatHTML($text);
194 - else
195 - {
 197+ } else {
196198 // For non-HTML output, clear all errors that might have been
197199 // displayed if display_errors=On
198200 // Do this only once, of course
@@ -203,6 +205,19 @@
204206 echo $text;
205207 }
206208 }
 209+
 210+ /**
 211+ * Get the contents of the buffer.
 212+ */
 213+ public function getBuffer() {
 214+ return $this->mBuffer;
 215+ }
 216+ /**
 217+ * Set the flag to buffer the result instead of printing it.
 218+ */
 219+ public function setBufferResult( $value ) {
 220+ $this->mBufferResult = $value;
 221+ }
207222
208223 /**
209224 * Sets whether the pretty-printer should format *bold* and $italics$
Index: trunk/phase3/includes/api/ApiUpload.php
@@ -44,7 +44,7 @@
4545 $this->mParams = $this->extractRequestParams();
4646 $request = $this->getMain()->getRequest();
4747
48 - // do token checks:
 48+ // Do token checks:
4949 if ( is_null( $this->mParams['token'] ) )
5050 $this->dieUsageMsg( array( 'missingparam', 'token' ) );
5151 if ( !$wgUser->matchEditToken( $this->mParams['token'] ) )
@@ -57,21 +57,23 @@
5858 // Check whether upload is enabled
5959 if ( !UploadBase::isEnabled() )
6060 $this->dieUsageMsg( array( 'uploaddisabled' ) );
61 -
 61+
6262 // One and only one of the following parameters is needed
6363 $this->requireOnlyOneParameter( $this->mParams,
64 - 'sessionkey', 'file', 'url', 'enablechunks' );
 64+ 'sessionkey', 'file', 'url', 'enablechunks' );
 65+
 66+ if ( $this->mParams['enablechunks'] ) {
 67+ /**
 68+ * Chunked upload mode
 69+ */
6570
66 - if ( $this->mParams['enablechunks'] ) {
67 - // chunks upload enabled
6871 $this->mUpload = new UploadFromChunks();
6972 $status = $this->mUpload->initializeFromParams( $this->mParams, $request );
7073
7174 if( isset( $status['error'] ) )
7275 $this->dieUsageMsg( $status['error'] );
7376
74 - } elseif ( $this->mParams['internalhttpsession'] ) {
75 - // TODO: Move to subclass
 77+ } elseif ( isset( $this->mParams['internalhttpsession'] ) && $this->mParams['internalhttpsession'] ) {
7678 $sd = & $_SESSION['wsDownload'][ $this->mParams['internalhttpsession'] ];
7779
7880 //wfDebug("InternalHTTP:: " . print_r($this->mParams, true));
@@ -82,16 +84,17 @@
8385 $sd['target_file_path'],
8486 filesize( $sd['target_file_path'] )
8587 );
86 -
8788 } elseif ( $this->mParams['httpstatus'] && $this->mParams['sessionkey'] ) {
88 - // return the status of the given upload session_key:
 89+ /**
 90+ * Return the status of the given background upload session_key:
 91+ */
8992
9093 // Check the session key
9194 if( !isset( $_SESSION['wsDownload'][$this->mParams['sessionkey']] ) )
9295 return $this->dieUsageMsg( array( 'invalid-session-key' ) );
9396
9497 $sd =& $_SESSION['wsDownload'][$this->mParams['sessionkey']];
95 - // keep passing down the upload sessionkey
 98+ // Keep passing down the upload sessionkey
9699 $statusResult = array(
97100 'upload_session_key' => $this->mParams['sessionkey']
98101 );
@@ -105,16 +108,20 @@
106109 $statusResult['content_length'] = $sd['content_length'];
107110
108111 return $this->getResult()->addValue( null,
109 - $this->getModuleName(), $statusResult);
 112+ $this->getModuleName(), $statusResult );
110113
111 - } else if( $this->mParams['sessionkey'] ) {
112 - // Stashed upload
 114+ } elseif( $this->mParams['sessionkey'] ) {
 115+ /**
 116+ * Upload stashed in a previous request
 117+ */
113118 $this->mUpload = new UploadFromStash();
114119 $this->mUpload->initialize( $this->mParams['filename'],
115120 $_SESSION['wsUploadData'][$this->mParams['sessionkey']] );
116121 } else {
117 - // Upload from url or file
118 - // Parameter filename is required
 122+ /**
 123+ * Upload from url or file
 124+ * Parameter filename is required
 125+ */
119126 if ( !isset( $this->mParams['filename'] ) )
120127 $this->dieUsageMsg( array( 'missingparam', 'filename' ) );
121128
@@ -132,7 +139,7 @@
133140 $this->mParams['url'], $this->mParams['asyncdownload'] );
134141
135142 $status = $this->mUpload->fetchFile();
136 - if( !$status->isOK() ){
 143+ if( !$status->isOK() ) {
137144 return $this->dieUsage( 'fetchfileerror', $status->getWikiText() );
138145 }
139146
@@ -152,15 +159,16 @@
153160 array( 'upload_session_key' => $upload_session_key
154161 ));
155162 }
156 - //else the file downloaded in place continue with validation:
157163 }
158164 }
159 -
 165+
160166 if( !isset( $this->mUpload ) )
161167 $this->dieUsage( 'No upload module set', 'nomodule' );
 168+
 169+
 170+ // Finish up the exec command:
 171+ $this->doExecUpload();
162172
163 - //finish up the exec command:
164 - $this->doExecUpload();
165173 }
166174
167175 protected function doExecUpload(){
@@ -287,8 +295,6 @@
288296 $result['filename'] = $file->getName();
289297
290298 // Append imageinfo to the result
291 -
292 - //get all the image properties:
293299 $imParam = ApiQueryImageInfo::getPropertyNames();
294300 $result['imageinfo'] = ApiQueryImageInfo::getInfo( $file,
295301 array_flip( $imParam ), $this->getResult() );
@@ -322,12 +328,15 @@
323329 'url' => null,
324330 'httpstatus' => false,
325331 'sessionkey' => null,
326 - 'internalhttpsession' => null,
327332 );
 333+
 334+ if ( $this->getMain()->isInternalMode() )
 335+ $params['internalhttpsession'] = null;
328336 if($wgEnableAsyncDownload){
329337 $params['asyncdownload'] = false;
330338 }
331339 return $params;
 340+
332341 }
333342
334343 public function getParamDescription() {
@@ -386,3 +395,4 @@
387396 }
388397 }
389398
 399+

Status & tagging log