r17778 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r17777‎ | r17778 | r17779 >
Date:05:23, 18 November 2006
Author:tstarling
Status:old
Tags:
Comment:
Don't dump the MediaWiki namespace. Protection against overlong filenames. Always use dest/$imageRel as the upload directory. Display a warning if makeSnapshot is disabled. Display a warning if symlink/copy fails.
Modified paths:
  • /trunk/phase3/maintenance/dumpHTML.inc (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/dumpHTML.inc
@@ -185,7 +185,8 @@
186186 $title = Title::newFromID( $id );
187187 if ( $title ) {
188188 $ns = $title->getNamespace() ;
189 - if ( $ns != NS_CATEGORY && $title->getPrefixedDBkey() != $mainPage ) {
 189+ if ( $ns != NS_CATEGORY && $ns != NS_MEDIAWIKI &&
 190+ $title->getPrefixedDBkey() != $mainPage ) {
190191 $this->doArticle( $title );
191192 }
192193 }
@@ -485,11 +486,26 @@
486487 fclose( $file );
487488 }
488489 }
 490+
 491+ wfIncrStats( 'dumphtml_article' );
489492 }
490493
491494 /** Write the given text to the file identified by the given title object */
492495 function writeArticle( &$title, $text ) {
493496 $filename = $this->getHashedFilename( $title );
 497+
 498+ # Temporary hack for current dump, this should be moved to
 499+ # getFriendlyName() at the earliest opportunity.
 500+ #
 501+ # Limit filename length to 255 characters, so it works on ext3.
 502+ # Titles are in fact limited to 255 characters, but dumpHTML
 503+ # adds a suffix which may put them over the limit.
 504+ $length = strlen( $filename );
 505+ if ( $length > 255 ) {
 506+ print "Warning: Filename too long ($length bytes). Skipping.\n";
 507+ return;
 508+ }
 509+
494510 $fullName = "{$this->dest}/$filename";
495511 $fullDir = dirname( $fullName );
496512
@@ -591,13 +607,11 @@
592608 $wgUser->setOption( 'skin', $this->skin );
593609 $wgUser->setOption( 'editsection', 0 );
594610
595 - if ( $this->makeSnapshot ) {
596 - $this->destUploadDirectory = "{$this->dest}/{$this->imageRel}";
597 - if ( realpath( $this->destUploadDirectory == $wgUploadDirectory ) ) {
598 - $this->makeSnapshot = false;
599 - }
 611+ $this->destUploadDirectory = "{$this->dest}/{$this->imageRel}";
 612+ if ( realpath( $this->destUploadDirectory ) == realpath( $wgUploadDirectory ) ) {
 613+ print "Disabling image snapshot because the destination is the same as the source\n";
 614+ $this->makeSnapshot = false;
600615 }
601 -
602616 $this->sharedStaticDirectory = "{$this->destUploadDirectory}/shared";
603617
604618 $this->setupDone = true;
@@ -695,9 +709,13 @@
696710 if ( !file_exists( $destLoc ) ) {
697711 wfMkdirParents( dirname( $destLoc ), 0755 );
698712 if ( function_exists( 'symlink' ) && !$this->forceCopy ) {
699 - symlink( $sourceLoc, $destLoc );
 713+ if ( !symlink( $sourceLoc, $destLoc ) ) {
 714+ print "Warning: unable to create symlink at $destLoc\n";
 715+ }
700716 } else {
701 - copy( $sourceLoc, $destLoc );
 717+ if ( !copy( $sourceLoc, $destLoc ) ) {
 718+ print "Warning: unable to copy $sourceLoc to $destLoc\n";
 719+ }
702720 }
703721 }
704722 }