r89677 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r89676‎ | r89677 | r89678 >
Date:19:14, 7 June 2011
Author:catrope
Status:resolved (Comments)
Tags:
Comment:
Modified paths:
  • /branches/REL1_17/phase3/includes/HttpFunctions.php (modified) (history)
  • /branches/REL1_17/phase3/includes/LogEventsList.php (modified) (history)
  • /branches/REL1_17/phase3/includes/installer/CliInstaller.php (modified) (history)
  • /branches/REL1_17/phase3/includes/installer/DatabaseInstaller.php (modified) (history)
  • /branches/REL1_17/phase3/includes/installer/Installer.php (modified) (history)
  • /branches/REL1_17/phase3/includes/media/SVGMetadataExtractor.php (modified) (history)
  • /branches/REL1_17/phase3/includes/specials/SpecialUserlogin.php (modified) (history)
  • /branches/REL1_17/phase3/includes/upload/UploadFromUrl.php (modified) (history)

Diff [purge]

Index: branches/REL1_17/phase3/includes/upload/UploadFromUrl.php
@@ -97,41 +97,62 @@
9898 protected function makeTemporaryFile() {
9999 return tempnam( wfTempDir(), 'URL' );
100100 }
 101+
101102 /**
102 - * Save the result of a HTTP request to the temporary file
 103+ * Callback: save a chunk of the result of a HTTP request to the temporary file
103104 *
104 - * @param $req MWHttpRequest
105 - * @return Status
 105+ * @param $req mixed
 106+ * @param $buffer string
 107+ * @return int number of bytes handled
106108 */
107 - private function saveTempFile( $req ) {
108 - if ( $this->mTempPath === false ) {
109 - return Status::newFatal( 'tmp-create-error' );
 109+ public function saveTempFileChunk( $req, $buffer ) {
 110+ $nbytes = fwrite( $this->mTmpHandle, $buffer );
 111+
 112+ if ( $nbytes == strlen( $buffer ) ) {
 113+ $this->mFileSize += $nbytes;
 114+ } else {
 115+ // Well... that's not good!
 116+ fclose( $this->mTmpHandle );
 117+ $this->mTmpHandle = false;
110118 }
111 - if ( file_put_contents( $this->mTempPath, $req->getContent() ) === false ) {
112 - return Status::newFatal( 'tmp-write-error' );
113 - }
114119
115 - $this->mFileSize = filesize( $this->mTempPath );
 120+ return $nbytes;
 121+ }
116122
117 - return Status::newGood();
118 - }
119123 /**
120124 * Download the file, save it to the temporary file and update the file
121125 * size and set $mRemoveTempFile to true.
122126 */
123127 protected function reallyFetchFile() {
 128+ if ( $this->mTempPath === false ) {
 129+ return Status::newFatal( 'tmp-create-error' );
 130+ }
 131+
 132+ // Note the temporary file should already be created by makeTemporaryFile()
 133+ $this->mTmpHandle = fopen( $this->mTempPath, 'wb' );
 134+ if ( !$this->mTmpHandle ) {
 135+ return Status::newFatal( 'tmp-create-error' );
 136+ }
 137+
 138+ $this->mRemoveTempFile = true;
 139+ $this->mFileSize = 0;
 140+
124141 $req = MWHttpRequest::factory( $this->mUrl );
 142+ $req->setCallback( array( $this, 'saveTempFileChunk' ) );
125143 $status = $req->execute();
126144
127 - if ( !$status->isOk() ) {
128 - return $status;
 145+ if ( $this->mTmpHandle ) {
 146+ // File got written ok...
 147+ fclose( $this->mTmpHandle );
 148+ $this->mTmpHandle = null;
 149+ } else {
 150+ // We encountered a write error during the download...
 151+ return Status::newFatal( 'tmp-write-error' );
129152 }
130153
131 - $status = $this->saveTempFile( $req );
132 - if ( !$status->isGood() ) {
 154+ if ( !$status->isOk() ) {
133155 return $status;
134156 }
135 - $this->mRemoveTempFile = true;
136157
137158 return $status;
138159 }
Index: branches/REL1_17/phase3/includes/LogEventsList.php
@@ -482,8 +482,7 @@
483483 # Fall back to a blue contributions link
484484 $revert = $this->skin->userToolLinks( 1, $title->getDBkey() );
485485 }
486 - $ts = wfTimestamp( TS_UNIX, $row->log_timestamp );
487 - if( $ts < '20080129000000' ) {
 486+ if( wfTimestamp( TS_MW, $row->log_timestamp ) < '20080129000000' ) {
488487 # Suppress $comment from old entries (before 2008-01-29),
489488 # not needed and can contain incorrect links
490489 $comment = '';
Index: branches/REL1_17/phase3/includes/installer/Installer.php
@@ -1143,7 +1143,13 @@
11441144 break;
11451145 }
11461146
1147 - $text = Http::get( $url . $file, array( 'timeout' => 3 ) );
 1147+ try {
 1148+ $text = Http::get( $url . $file, array( 'timeout' => 3 ) );
 1149+ }
 1150+ catch( MWException $e ) {
 1151+ // Http::get throws with allow_url_fopen = false and no curl extension.
 1152+ $text = null;
 1153+ }
11481154 unlink( $dir . $file );
11491155
11501156 if ( $text == 'exec' ) {
Property changes on: branches/REL1_17/phase3/includes/installer/Installer.php
___________________________________________________________________
Modified: svn:mergeinfo
11511157 Merged /trunk/phase3/includes/installer/Installer.php:r88492,88870-88871,89003,89108,89114-89115,89129,89532,89653
Index: branches/REL1_17/phase3/includes/installer/DatabaseInstaller.php
@@ -186,11 +186,6 @@
187187 $updater = DatabaseUpdater::newForDB( $this->db );
188188 $extensionUpdates = $updater->getNewExtensions();
189189
190 - // No extensions need tables (or haven't updated to new installer support)
191 - if( !count( $extensionUpdates ) ) {
192 - return $status;
193 - }
194 -
195190 $ourExtensions = array_map( 'strtolower', $this->getVar( '_Extensions' ) );
196191
197192 foreach( $ourExtensions as $ext ) {
Property changes on: branches/REL1_17/phase3/includes/installer/DatabaseInstaller.php
___________________________________________________________________
Modified: svn:mergeinfo
198193 Merged /trunk/phase3/includes/installer/DatabaseInstaller.php:r88492,88870-88871,89003,89108,89114-89115,89129,89532,89653
Index: branches/REL1_17/phase3/includes/installer/CliInstaller.php
@@ -88,7 +88,7 @@
8989 * Main entry point.
9090 */
9191 public function execute() {
92 - $vars = $this->getExistingLocalSettings();
 92+ $vars = Installer::getExistingLocalSettings();
9393 if( $vars ) {
9494 $this->showStatusMessage(
9595 Status::newFatal( "config-localsettings-cli-upgrade" )
Property changes on: branches/REL1_17/phase3/includes/installer/CliInstaller.php
___________________________________________________________________
Modified: svn:mergeinfo
9696 Merged /trunk/phase3/includes/installer/CliInstaller.php:r88492,88870-88871,89003,89108,89114-89115,89129,89532,89653
Index: branches/REL1_17/phase3/includes/media/SVGMetadataExtractor.php
@@ -35,6 +35,7 @@
3636 class SVGReader {
3737 const DEFAULT_WIDTH = 512;
3838 const DEFAULT_HEIGHT = 512;
 39+ const NS_SVG = 'http://www.w3.org/2000/svg';
3940
4041 private $reader = null;
4142 private $mDebug = false;
@@ -101,9 +102,9 @@
102103 $keepReading = $this->reader->read();
103104 }
104105
105 - if ( !$this->qualifiedNameEquals( $this->reader->name, 'svg', 'svg' ) ) {
 106+ if ( $this->reader->localName != 'svg' || $this->reader->namespaceURI != self::NS_SVG ) {
106107 throw new MWException( "Expected <svg> tag, got ".
107 - $this->reader->name );
 108+ $this->reader->localName . " in NS " . $this->reader->namespaceURI );
108109 }
109110 $this->debug( "<svg> tag is correct." );
110111 $this->handleSVGAttribs();
@@ -111,18 +112,19 @@
112113 $exitDepth = $this->reader->depth;
113114 $keepReading = $this->reader->read();
114115 while ( $keepReading ) {
115 - $tag = $this->reader->name;
 116+ $tag = $this->reader->localName;
116117 $type = $this->reader->nodeType;
 118+ $isSVG = ($this->reader->namespaceURI == self::NS_SVG);
117119
118120 $this->debug( "$tag" );
119121
120 - if ( $this->qualifiedNameEquals( $tag, 'svg', 'svg' ) && $type == XmlReader::END_ELEMENT && $this->reader->depth <= $exitDepth ) {
 122+ if ( $isSVG && $tag == 'svg' && $type == XmlReader::END_ELEMENT && $this->reader->depth <= $exitDepth ) {
121123 break;
122 - } elseif ( $this->qualifiedNameEquals( $tag, 'svg', 'title' ) ) {
 124+ } elseif ( $isSVG && $tag == 'title' ) {
123125 $this->readField( $tag, 'title' );
124 - } elseif ( $this->qualifiedNameEquals( $tag, 'svg', 'desc' ) ) {
 126+ } elseif ( $isSVG && $tag == 'desc' ) {
125127 $this->readField( $tag, 'description' );
126 - } elseif ( $this->qualifiedNameEquals( $tag, 'svg', 'metadata' ) && $type == XmlReader::ELEMENT ) {
 128+ } elseif ( $isSVG && $tag == 'metadata' && $type == XmlReader::ELEMENT ) {
127129 $this->readXml( $tag, 'metadata' );
128130 } elseif ( $tag !== '#text' ) {
129131 $this->debug( "Unhandled top-level XML tag $tag" );
@@ -153,7 +155,7 @@
154156 }
155157 $keepReading = $this->reader->read();
156158 while( $keepReading ) {
157 - if( $this->reader->name == $name && $this->reader->nodeType == XmlReader::END_ELEMENT ) {
 159+ if( $this->reader->localName == $name && $this->namespaceURI == self::NS_SVG && $this->reader->nodeType == XmlReader::END_ELEMENT ) {
158160 break;
159161 } elseif( $this->reader->nodeType == XmlReader::TEXT ){
160162 $this->metadata[$metafield] = trim( $this->reader->value );
@@ -173,7 +175,7 @@
174176 return;
175177 }
176178 // TODO: find and store type of xml snippet. metadata['metadataType'] = "rdf"
177 - $this->metadata[$metafield] = $this->reader->readInnerXML();
 179+ $this->metadata[$metafield] = trim( $this->reader->readInnerXML() );
178180 $this->reader->next();
179181 }
180182
@@ -190,21 +192,16 @@
191193 $exitDepth = $this->reader->depth;
192194 $keepReading = $this->reader->read();
193195 while( $keepReading ) {
194 - if( $this->reader->name == $name && $this->reader->depth <= $exitDepth
 196+ if( $this->reader->localName == $name && $this->reader->depth <= $exitDepth
195197 && $this->reader->nodeType == XmlReader::END_ELEMENT ) {
196198 break;
197 - } elseif ( $this->reader->nodeType == XmlReader::ELEMENT ) {
198 - switch( $this->reader->name ) {
 199+ } elseif ( $this->reader->namespaceURI == self::NS_SVG && $this->reader->nodeType == XmlReader::ELEMENT ) {
 200+ switch( $this->reader->localName ) {
199201 case 'animate':
200 - case 'svg:animate':
201202 case 'set':
202 - case 'svg:set':
203203 case 'animateMotion':
204 - case 'svg:animateMotion':
205204 case 'animateColor':
206 - case 'svg:animateColor':
207205 case 'animateTransform':
208 - case 'svg:animateTransform':
209206 $this->debug( "HOUSTON WE HAVE ANIMATION" );
210207 $this->metadata['animated'] = true;
211208 break;
@@ -313,22 +310,4 @@
314311 return floatval( $length );
315312 }
316313 }
317 -
318 - /**
319 - * XML namespace check
320 - *
321 - * Check if a read node name matches the expected nodeName
322 - * @param $qualifiedName as read by XMLReader
323 - * @param $prefix the namespace prefix that you expect for this element, defaults to svg namespace
324 - * @param $localName the localName part of the element that you want to match
325 - *
326 - * @return boolean
327 - */
328 - private function qualifiedNameEquals( $qualifiedName, $prefix="svg", $localName ) {
329 - if( ($qualifiedName == $localName && $prefix == "svg" ) ||
330 - $qualifiedName == ($prefix . ":" . $localName) ) {
331 - return true;
332 - }
333 - return false;
334 - }
335314 }
Index: branches/REL1_17/phase3/includes/HttpFunctions.php
@@ -307,11 +307,26 @@
308308 }
309309
310310 /**
311 - * Set the callback
 311+ * Set a read callback to accept data read from the HTTP request.
 312+ * By default, data is appended to an internal buffer which can be
 313+ * retrieved through $req->getContent().
312314 *
 315+ * To handle data as it comes in -- especially for large files that
 316+ * would not fit in memory -- you can instead set your own callback,
 317+ * in the form function($resource, $buffer) where the first parameter
 318+ * is the low-level resource being read (implementation specific),
 319+ * and the second parameter is the data buffer.
 320+ *
 321+ * You MUST return the number of bytes handled in the buffer; if fewer
 322+ * bytes are reported handled than were passed to you, the HTTP fetch
 323+ * will be aborted.
 324+ *
313325 * @param $callback Callback
314326 */
315327 public function setCallback( $callback ) {
 328+ if ( !is_callable( $callback ) ) {
 329+ throw new MWException( 'Invalid MwHttpRequest callback' );
 330+ }
316331 $this->callback = $callback;
317332 }
318333
Index: branches/REL1_17/phase3/includes/specials/SpecialUserlogin.php
@@ -148,7 +148,7 @@
149149 global $wgOut;
150150
151151 if ( $this->mEmail == '' ) {
152 - $this->mainLoginForm( wfMsgExt( 'noemailcreate', array( 'parsemag', 'escape' ), $this->mName ) );
 152+ $this->mainLoginForm( wfMsgExt( 'noemailcreate', array( 'parsemag', 'escape' ) ) );
153153 return;
154154 }
155155

Follow-up revisions

RevisionCommit summaryAuthorDate
r89758Added release notes for the remaining changes, r89677 to HEAD.tstarling06:26, 9 June 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r88492Do not block the installer (through an unhandled exception) when we can't con...platonides21:42, 20 May 2011
r88870Reverting r82307 (bug 27465) as initial step to recommitting a cleaner fix.brion23:57, 25 May 2011
r88871* (bug 27465) Fix metadata extraction for SVG files using unusual namespace n...brion23:59, 25 May 2011
r89003* (bug 29174) Fix regression in upload-by-URL: files larger than PHP memory l...brion22:31, 27 May 2011
r89108Followup r89099 per RobertL's CR: Remove now unused parameter. Thanks :)raymond14:53, 29 May 2011
r89114Fix a regression from r63144: "Fixed bizarre $time comparison (compared displ...raymond15:43, 29 May 2011
r89115Followup r89114: Ctrl-S is your friend...raymond15:45, 29 May 2011
r89129Fix for r89114: handle other DBMSesaaron19:18, 29 May 2011
r89532Followup r89529...reedy21:03, 5 June 2011
r89653Fix r85021: extension tables weren't created in some casesmaxsem15:52, 7 June 2011

Comments

#Comment by MaxSem (talk | contribs)   19:23, 7 June 2011

r89532 depends on r89529.

#Comment by 😂 (talk | contribs)   19:25, 7 June 2011

See r89679.

Status & tagging log