3 * @addtogroup Maintenance
6 define( 'REPORTING_INTERVAL', 10 );
8 require_once( 'includes/ImagePage.php' );
9 require_once( 'includes/CategoryPage.php' );
10 require_once( 'includes/RawPage.php' );
12 # Explicitly disable article view counter (bug 6823)
13 global $wgDisableCounters;
14 $wgDisableCounters = true;
17 # Destination directory
21 var $noOverwrite = false;
23 # Show interlanguage links?
24 var $interwiki = true;
26 # Depth of HTML directory tree
29 # Directory that commons images are copied into
30 var $sharedStaticDirectory;
32 # Directory that the images are in, after copying
33 var $destUploadDirectory;
35 # Relative path to image directory
36 var $imageRel = 'upload';
38 # Copy commons images instead of symlinking
39 var $forceCopy = false;
41 # Make a copy of all images encountered
42 var $makeSnapshot = false;
44 # Don't image description pages in doEverything()
45 var $noSharedDesc = false;
47 # Make links assuming the script path is in the same directory as
49 var $alternateScriptPath = false;
51 # Original values of various globals
52 var $oldArticlePath = false, $oldCopyrightIcon = false;
54 # Has setupGlobals been called?
55 var $setupDone = false;
57 # Has to compress html pages
58 var $compress = false;
60 # List of raw pages used in the current article
64 var $skin = 'htmldump';
67 var $checkpointFile = false, $checkpoints = false;
69 var $startID = 1, $endID = false;
71 var $sliceNumerator = 1, $sliceDenominator = 1;
73 # Max page ID, lazy initialised
74 var $maxPageID = false;
77 var $udpProfile, $udpProfileCounter = 0, $udpProfileInit = false;
82 function DumpHTML( $settings = array() ) {
83 foreach ( $settings as $var => $value ) {
88 function loadCheckpoints() {
89 if ( $this->checkpoints !== false ) {
91 } elseif ( !$this->checkpointFile ) {
94 $lines = @file( $this->checkpointFile );
95 if ( $lines === false ) {
96 print "Starting new checkpoint file \"{$this->checkpointFile}\"\n";
97 $this->checkpoints = array();
99 $lines = array_map( 'trim', $lines );
100 $this->checkpoints = array();
101 foreach ( $lines as $line ) {
102 list( $name, $value ) = explode( '=', $line, 2 );
103 $this->checkpoints[$name] = $value;
110 function getCheckpoint( $type, $defValue = false ) {
111 if ( !$this->loadCheckpoints() ) {
114 if ( !isset( $this->checkpoints[$type] ) ) {
117 return $this->checkpoints[$type];
121 function setCheckpoint( $type, $value ) {
122 if ( !$this->checkpointFile ) {
125 $this->checkpoints[$type] = $value;
127 foreach ( $this->checkpoints as $type => $value ) {
128 $blob .= "$type=$value\n";
130 file_put_contents( $this->checkpointFile, $blob );
133 function doEverything() {
134 if ( $this->getCheckpoint( 'everything' ) == 'done' ) {
135 print "Checkpoint says everything is already done\n";
139 $this->doCategories();
140 $this->doRedirects();
141 if ( $this->sliceNumerator == 1 ) {
144 $this->doLocalImageDescriptions();
146 if ( !$this->noSharedDesc ) {
147 $this->doSharedImageDescriptions();
150 $this->setCheckpoint( 'everything', 'done' );
154 * Write a set of articles specified by start and end page_id
155 * Skip categories and images, they will be done separately
157 function doArticles() {
158 if ( $this->endID === false ) {
159 $end = $this->getMaxPageID();
163 $start = $this->startID;
165 # Start from the checkpoint
166 $cp = $this->getCheckpoint( 'article' );
167 if ( $cp == 'done' ) {
168 print "Articles already done\n";
170 } elseif ( $cp !== false ) {
172 print "Resuming article dump from checkpoint at page_id $start of $end\n";
174 print "Starting from page_id $start of $end\n";
177 # Move the start point to the correct slice if it isn't there already
178 $start = $this->modSliceStart( $start );
180 $this->setupGlobals();
182 $mainPageObj = Title::newMainPage();
183 $mainPage = $mainPageObj->getPrefixedDBkey();
185 for ( $id = $start, $i = 0; $id <= $end; $id += $this->sliceDenominator, $i++ ) {
186 wfWaitForSlaves( 20 );
187 if ( !( $i % REPORTING_INTERVAL) ) {
188 print "Processing ID: $id\r";
189 $this->setCheckpoint( 'article', $id );
191 if ( !($i % (REPORTING_INTERVAL*10) ) ) {
194 $title = Title::newFromID( $id );
196 $ns = $title->getNamespace() ;
197 if ( $ns != NS_CATEGORY && $ns != NS_MEDIAWIKI &&
198 $title->getPrefixedDBkey() != $mainPage ) {
199 $this->doArticle( $title );
203 $this->setCheckpoint( 'article', 'done' );
207 function doSpecials() {
210 $this->setupGlobals();
211 print "Special:Categories...";
212 $this->doArticle( SpecialPage::getTitleFor( 'Categories' ) );
216 /** Write the main page as index.html */
217 function doMainPage() {
219 print "Making index.html ";
221 // Set up globals with no ../../.. in the link URLs
222 $this->setupGlobals( 0 );
224 $title = Title::newMainPage();
225 $text = $this->getArticleHTML( $title );
227 # Parse the XHTML to find the images
228 $images = $this->findImages( $text );
229 $this->copyImages( $images );
231 $file = fopen( "{$this->dest}/index.html", "w" );
233 print "\nCan't open index.html for writing\n";
236 fwrite( $file, $text );
241 function doImageDescriptions() {
242 $this->doLocalImageDescriptions();
243 if ( !$this->noSharedDesc ) {
244 $this->doSharedImageDescriptions();
249 * Dump image description pages that don't have an associated article, but do
252 function doLocalImageDescriptions() {
255 $dbr = wfGetDB( DB_SLAVE );
257 $cp = $this->getCheckpoint( 'local image' );
258 if ( $cp == 'done' ) {
259 print "Local image descriptions already done\n";
261 } elseif ( $cp !== false ) {
262 print "Writing image description pages starting from $cp\n";
263 $conds = array( 'img_name >= ' . $dbr->addQuotes( $cp ) );
265 print "Writing image description pages for local images\n";
269 $this->setupGlobals();
273 $res = $dbr->select( 'image', array( 'img_name' ), $conds, __METHOD__,
274 array( 'ORDER BY' => 'img_name', 'LIMIT' => $chunkSize ) );
275 $numRows = $dbr->numRows( $res );
277 while ( $row = $dbr->fetchObject( $res ) ) {
278 # Update conds for the next chunk query
279 $conds = array( 'img_name > ' . $dbr->addQuotes( $row->img_name ) );
281 // Slice the result set with a filter
282 if ( !$this->sliceFilter( $row->img_name ) ) {
286 wfWaitForSlaves( 10 );
287 if ( !( ++$i % REPORTING_INTERVAL ) ) {
288 print "{$row->img_name}\n";
289 if ( $row->img_name !== 'done' ) {
290 $this->setCheckpoint( 'local image', $row->img_name );
293 $title = Title::makeTitle( NS_IMAGE, $row->img_name );
294 if ( $title->getArticleID() ) {
295 // Already done by dumpHTML
298 $this->doArticle( $title );
300 $dbr->freeResult( $res );
301 } while ( $numRows );
303 $this->setCheckpoint( 'local image', 'done' );
308 * Dump images which only have a real description page on commons
310 function doSharedImageDescriptions() {
311 list( $start, $end ) = $this->sliceRange( 0, 255 );
313 $cp = $this->getCheckpoint( 'shared image' );
314 if ( $cp == 'done' ) {
315 print "Shared description pages already done\n";
317 } elseif ( $cp !== false ) {
318 print "Writing description pages for commons images starting from directory $cp/255\n";
321 print "Writing description pages for commons images\n";
324 $this->setupGlobals();
326 for ( $hash = $start; $hash <= $end; $hash++ ) {
327 $this->setCheckpoint( 'shared image', $hash );
329 $dir = sprintf( "%s/%01x/%02x", $this->sharedStaticDirectory,
330 intval( $hash / 16 ), $hash );
331 $handle = @opendir( $dir );
332 while ( $handle && $file = readdir( $handle ) ) {
333 if ( $file[0] == '.' ) {
336 if ( !(++$i % REPORTING_INTERVAL ) ) {
340 $title = Title::makeTitleSafe( NS_IMAGE, $file );
341 $this->doArticle( $title );
347 $this->setCheckpoint( 'shared image', 'done' );
351 function doCategories() {
354 $this->setupGlobals();
355 $dbr = wfGetDB( DB_SLAVE );
357 $cp = $this->getCheckpoint( 'category' );
358 if ( $cp == 'done' ) {
359 print "Category pages already done\n";
361 } elseif ( $cp !== false ) {
362 print "Resuming category page dump from $cp\n";
363 $conds = array( 'cl_to >= ' . $dbr->addQuotes( $cp ) );
365 print "Starting category pages\n";
371 $res = $dbr->select( 'categorylinks', 'DISTINCT cl_to', $conds, __METHOD__,
372 array( 'ORDER BY' => 'cl_to', 'LIMIT' => $chunkSize ) );
373 $numRows = $dbr->numRows( $res );
375 while ( $row = $dbr->fetchObject( $res ) ) {
376 // Set conditions for next chunk
377 $conds = array( 'cl_to > ' . $dbr->addQuotes( $row->cl_to ) );
379 // Filter pages from other slices
380 if ( !$this->sliceFilter( $row->cl_to ) ) {
384 wfWaitForSlaves( 10 );
385 if ( !(++$i % REPORTING_INTERVAL ) ) {
386 print "{$row->cl_to}\n";
387 if ( $row->cl_to != 'done' ) {
388 $this->setCheckpoint( 'category', $row->cl_to );
391 $title = Title::makeTitle( NS_CATEGORY, $row->cl_to );
392 $this->doArticle( $title );
394 $dbr->freeResult( $res );
395 } while ( $numRows );
397 $this->setCheckpoint( 'category', 'done' );
401 function doRedirects() {
402 print "Doing redirects...\n";
405 $end = $this->getMaxPageID();
406 $cp = $this->getCheckpoint( 'redirect' );
407 if ( $cp == 'done' ) {
408 print "Redirects already done\n";
410 } elseif ( $cp !== false ) {
411 print "Resuming redirect generation from page_id $cp\n";
412 $start = intval( $cp );
417 $this->setupGlobals();
418 $dbr = wfGetDB( DB_SLAVE );
421 for ( $chunkStart = $start; $chunkStart <= $end; $chunkStart += $chunkSize ) {
422 $chunkEnd = min( $end, $chunkStart + $chunkSize - 1 );
424 'page_is_redirect' => 1,
425 "page_id BETWEEN $chunkStart AND $chunkEnd"
427 # Modulo slicing in SQL
428 if ( $this->sliceDenominator != 1 ) {
429 $n = intval( $this->sliceNumerator );
430 $m = intval( $this->sliceDenominator );
431 $conds[] = "page_id % $m = $n";
433 $res = $dbr->select( 'page', array( 'page_id', 'page_namespace', 'page_title' ),
434 $conds, __METHOD__ );
436 while ( $row = $dbr->fetchObject( $res ) ) {
437 $title = Title::makeTitle( $row->page_namespace, $row->page_title );
438 if ( !(++$i % (REPORTING_INTERVAL*10) ) ) {
439 printf( "Done %d redirects (%2.3f%%)\n", $i, $row->page_id / $end * 100 );
440 $this->setCheckpoint( 'redirect', $row->page_id );
442 $this->doArticle( $title );
444 $dbr->freeResult( $res );
446 $this->setCheckpoint( 'redirect', 'done' );
449 /** Write an article specified by title */
450 function doArticle( $title ) {
451 if ( $this->noOverwrite ) {
452 $fileName = $this->dest.'/'.$this->getHashedFilename( $title );
453 if ( file_exists( $fileName ) ) {
460 $this->rawPages = array();
461 $text = $this->getArticleHTML( $title );
463 if ( $text === false ) {
467 # Parse the XHTML to find the images
468 $images = $this->findImages( $text );
469 $this->copyImages( $images );
472 $this->writeArticle( $title, $text );
475 wfMkdirParents( "{$this->dest}/raw", 0755 );
476 foreach( $this->rawPages as $record ) {
477 list( $file, $title, $params ) = $record;
479 $path = "{$this->dest}/raw/$file";
480 if ( !file_exists( $path ) ) {
481 $article = new Article( $title );
482 $request = new FauxRequest( $params );
483 $rp = new RawPage( $article, $request );
484 $text = $rp->getRawText();
486 print "Writing $file\n";
487 $file = fopen( $path, 'w' );
489 print("Can't open file $path for writing\n");
492 fwrite( $file, $text );
497 wfIncrStats( 'dumphtml_article' );
500 /** Write the given text to the file identified by the given title object */
501 function writeArticle( $title, $text ) {
502 $filename = $this->getHashedFilename( $title );
504 # Temporary hack for current dump, this should be moved to
505 # getFriendlyName() at the earliest opportunity.
507 # Limit filename length to 255 characters, so it works on ext3.
508 # Titles are in fact limited to 255 characters, but dumpHTML
509 # adds a suffix which may put them over the limit.
510 $length = strlen( $filename );
511 if ( $length > 255 ) {
512 print "Warning: Filename too long ($length bytes). Skipping.\n";
516 $fullName = "{$this->dest}/$filename";
517 $fullDir = dirname( $fullName );
519 if ( $this->compress ) {
521 $text = gzencode( $text, 9 );
524 wfMkdirParents( $fullDir, 0755 );
526 wfSuppressWarnings();
527 $file = fopen( $fullName, 'w' );
531 die("Can't open file '$fullName' for writing.\nCheck permissions or use another destination (-d).\n");
535 fwrite( $file, $text );
539 /** Set up globals required for parsing */
540 function setupGlobals( $currentDepth = NULL ) {
541 global $wgUser, $wgStylePath, $wgArticlePath, $wgMathPath;
542 global $wgUploadPath, $wgLogo, $wgMaxCredits, $wgSharedUploadPath;
543 global $wgHideInterlanguageLinks, $wgUploadDirectory, $wgThumbnailScriptPath;
544 global $wgSharedThumbnailScriptPath, $wgEnableParserCache, $wgHooks, $wgServer;
545 global $wgRightsUrl, $wgRightsText, $wgCopyrightIcon, $wgEnableSidebarCache;
546 global $wgGenerateThumbnailOnParse;
548 static $oldLogo = NULL;
550 if ( !$this->setupDone ) {
551 $wgHooks['GetLocalURL'][] =& $this;
552 $wgHooks['GetFullURL'][] =& $this;
553 $wgHooks['SiteNoticeBefore'][] =& $this;
554 $wgHooks['SiteNoticeAfter'][] =& $this;
555 $this->oldArticlePath = $wgServer . $wgArticlePath;
558 if ( is_null( $currentDepth ) ) {
559 $currentDepth = $this->depth;
562 if ( $this->alternateScriptPath ) {
563 if ( $currentDepth == 0 ) {
566 $wgScriptPath = '..' . str_repeat( '/..', $currentDepth - 1 );
569 $wgScriptPath = '..' . str_repeat( '/..', $currentDepth );
572 $wgArticlePath = str_repeat( '../', $currentDepth ) . '$1';
575 # Allow for repeated setup
576 if ( !is_null( $oldLogo ) ) {
582 if ( strpos( $wgLogo, $wgUploadPath ) === 0 ) {
583 # If it's in the upload directory, rewrite it to the new upload directory
584 $wgLogo = "$wgScriptPath/{$this->imageRel}/" . substr( $wgLogo, strlen( $wgUploadPath ) + 1 );
585 } elseif ( $wgLogo{0} == '/' ) {
586 # This is basically heuristic
587 # Rewrite an absolute logo path to one relative to the the script path
588 $wgLogo = $wgScriptPath . $wgLogo;
592 if ( !$this->setupDone ) {
593 $this->oldCopyrightIcon = $wgCopyrightIcon;
595 $wgCopyrightIcon = str_replace( 'src="/images',
596 'src="' . htmlspecialchars( $wgScriptPath ) . '/images', $this->oldCopyrightIcon );
598 $wgStylePath = "$wgScriptPath/skins";
599 $wgUploadPath = "$wgScriptPath/{$this->imageRel}";
600 $wgSharedUploadPath = "$wgUploadPath/shared";
602 $wgHideInterlanguageLinks = !$this->interwiki;
603 $wgThumbnailScriptPath = $wgSharedThumbnailScriptPath = false;
604 $wgEnableParserCache = false;
605 $wgMathPath = "$wgScriptPath/math";
606 $wgEnableSidebarCache = false;
607 $wgGenerateThumbnailOnParse = true;
609 if ( !empty( $wgRightsText ) ) {
610 $wgRightsUrl = "$wgScriptPath/COPYING.html";
614 $wgUser->setOption( 'skin', $this->skin );
615 $wgUser->setOption( 'editsection', 0 );
617 $this->destUploadDirectory = "{$this->dest}/{$this->imageRel}";
618 if ( realpath( $this->destUploadDirectory ) == realpath( $wgUploadDirectory ) ) {
619 print "Disabling image snapshot because the destination is the same as the source\n";
620 $this->makeSnapshot = false;
622 $this->sharedStaticDirectory = "{$this->destUploadDirectory}/shared";
624 $this->setupDone = true;
627 /** Reads the content of a title object, executes the skin and captures the result */
628 function getArticleHTML( $title ) {
629 global $wgOut, $wgTitle, $wgArticle, $wgUser;
631 if ( $this->debug ) {
632 print $title->getPrefixedDBkey() . "\n";
634 $linkCache =& LinkCache::singleton();
637 if ( is_null( $wgTitle ) ) {
641 $ns = $wgTitle->getNamespace();
642 if ( $ns == NS_SPECIAL ) {
643 $wgOut = new OutputPage;
644 $wgOut->setParserOptions( new ParserOptions );
645 SpecialPage::executePath( $wgTitle );
647 /** @todo merge with Wiki.php code */
648 if ( $ns == NS_IMAGE ) {
649 $wgArticle = new ImagePage( $wgTitle );
650 } elseif ( $ns == NS_CATEGORY ) {
651 $wgArticle = new CategoryPage( $wgTitle );
653 $wgArticle = new Article( $wgTitle );
655 $rt = Title::newFromRedirect( $wgArticle->fetchContent() );
657 return $this->getRedirect( $rt );
659 $wgOut = new OutputPage;
660 $wgOut->setParserOptions( new ParserOptions );
667 $sk =& $wgUser->getSkin();
669 $sk->outputPage( $wgOut );
670 $text = ob_get_contents();
676 function getRedirect( $rt ) {
677 $url = $rt->escapeLocalURL();
678 $text = $rt->getPrefixedText();
680 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
681 <html xmlns="http://www.w3.org/1999/xhtml">
683 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
684 <meta http-equiv="Refresh" content="0;url=$url" />
687 <p>Redirecting to <a href="$url">$text</a></p>
693 /** Returns image paths used in an XHTML document */
694 function findImages( $text ) {
695 global $wgOutputEncoding, $wgDumpImages;
696 $parser = xml_parser_create( $wgOutputEncoding );
697 xml_set_element_handler( $parser, 'wfDumpStartTagHandler', 'wfDumpEndTagHandler' );
699 $wgDumpImages = array();
700 xml_parse( $parser, $text );
701 xml_parser_free( $parser );
703 return $wgDumpImages;
707 * Copy a file specified by a URL to a given directory
709 * @param string $srcPath The source URL
710 * @param string $srcPathBase The base directory of the source URL
711 * @param string $srcDirBase The base filesystem directory of the source URL
712 * @param string $destDirBase The base filesystem directory of the destination URL
714 function relativeCopy( $srcPath, $srcPathBase, $srcDirBase, $destDirBase ) {
715 $rel = substr( $srcPath, strlen( $srcPathBase ) + 1 ); // +1 for slash
716 $sourceLoc = "$srcDirBase/$rel";
717 $destLoc = "$destDirBase/$rel";
718 #print "Copying $sourceLoc to $destLoc\n";
719 if ( !file_exists( $destLoc ) ) {
720 wfMkdirParents( dirname( $destLoc ), 0755 );
721 if ( function_exists( 'symlink' ) && !$this->forceCopy ) {
722 if ( !symlink( $sourceLoc, $destLoc ) ) {
723 print "Warning: unable to create symlink at $destLoc\n";
726 if ( !copy( $sourceLoc, $destLoc ) ) {
727 print "Warning: unable to copy $sourceLoc to $destLoc\n";
734 * Copy an image, and if it is a thumbnail, copy its parent image too
736 function copyImage( $srcPath, $srcPathBase, $srcDirBase, $destDirBase ) {
737 global $wgUploadPath, $wgUploadDirectory, $wgSharedUploadPath;
738 $this->relativeCopy( $srcPath, $srcPathBase, $srcDirBase, $destDirBase );
739 if ( substr( $srcPath, strlen( $srcPathBase ) + 1, 6 ) == 'thumb/' ) {
740 # The image was a thumbnail
741 # Copy the source image as well
742 $rel = substr( $srcPath, strlen( $srcPathBase ) + 1 );
743 $parts = explode( '/', $rel );
744 $rel = "{$parts[1]}/{$parts[2]}/{$parts[3]}";
745 $newSrc = "$srcPathBase/$rel";
746 $this->relativeCopy( $newSrc, $srcPathBase, $srcDirBase, $destDirBase );
751 * Copy images (or create symlinks) from commons to a static directory.
752 * This is necessary even if you intend to distribute all of commons, because
753 * the directory contents is used to work out which image description pages
756 * Also copies math images, and full-sized images if the makeSnapshot option
760 function copyImages( $images ) {
761 global $wgUploadPath, $wgUploadDirectory, $wgSharedUploadPath, $wgSharedUploadDirectory,
762 $wgMathPath, $wgMathDirectory;
763 # Find shared uploads and copy them into the static directory
764 $sharedPathLength = strlen( $wgSharedUploadPath );
765 $mathPathLength = strlen( $wgMathPath );
766 $uploadPathLength = strlen( $wgUploadPath );
767 foreach ( $images as $escapedImage => $dummy ) {
768 $image = urldecode( $escapedImage );
770 if ( substr( $image, 0, $sharedPathLength ) == $wgSharedUploadPath ) {
771 $this->copyImage( $image, $wgSharedUploadPath, $wgSharedUploadDirectory, $this->sharedStaticDirectory );
772 } elseif ( substr( $image, 0, $mathPathLength ) == $wgMathPath ) {
773 $this->relativeCopy( $image, $wgMathPath, $wgMathDirectory, "{$this->dest}/math" );
774 } elseif ( $this->makeSnapshot && substr( $image, 0, $uploadPathLength ) == $wgUploadPath ) {
775 $this->copyImage( $image, $wgUploadPath, $wgUploadDirectory, $this->destUploadDirectory );
780 function onGetFullURL( &$title, &$url, $query ) {
781 global $wgContLang, $wgArticlePath;
783 $iw = $title->getInterwiki();
784 if ( $title->isExternal() && $wgContLang->getLanguageName( $iw ) ) {
785 if ( $title->getDBkey() == '' ) {
786 $url = str_replace( '$1', "../$iw/index.html", $wgArticlePath );
788 $url = str_replace( '$1', "../$iw/" . wfUrlencode( $this->getHashedFilename( $title ) ),
791 $url .= $this->compress ? ".gz" : "";
798 function onGetLocalURL( &$title, &$url, $query ) {
799 global $wgArticlePath;
801 if ( $title->isExternal() ) {
802 # Default is fine for interwiki
807 if ( $query != '' ) {
809 parse_str( $query, $params );
810 if ( isset($params['action']) && $params['action'] == 'raw' ) {
811 if ( $params['gen'] == 'css' || $params['gen'] == 'js' ) {
812 $file = 'gen.' . $params['gen'];
814 $file = $this->getFriendlyName( $title->getPrefixedDBkey() );
815 // Clean up Monobook.css etc.
817 if ( preg_match( '/^(.*)\.(css|js)_[0-9a-f]{4}$/', $file, $matches ) ) {
818 $file = $matches[1] . '.' . $matches[2];
821 $this->rawPages[$file] = array( $file, $title, $params );
822 $url = str_replace( '$1', "raw/" . wfUrlencode( $file ), $wgArticlePath );
825 if ( $url === false ) {
826 $url = str_replace( '$1', wfUrlencode( $this->getHashedFilename( $title ) ), $wgArticlePath );
828 $url .= $this->compress ? ".gz" : "";
832 function getHashedFilename( &$title ) {
833 if ( '' != $title->mInterwiki ) {
834 $dbkey = $title->getDBkey();
836 $dbkey = $title->getPrefixedDBkey();
839 $mainPage = Title::newMainPage();
840 if ( $mainPage->getPrefixedDBkey() == $dbkey ) {
844 return $this->getHashedDirectory( $title ) . '/' .
845 $this->getFriendlyName( $dbkey ) . '.html';
848 function getFriendlyName( $name ) {
850 # Replace illegal characters for Windows paths with underscores
851 $friendlyName = strtr( $name, '/\\*?"<>|~', '_________' );
853 # Work out lower case form. We assume we're on a system with case-insensitive
854 # filenames, so unless the case is of a special form, we have to disambiguate
855 if ( function_exists( 'mb_strtolower' ) ) {
856 $lowerCase = $wgLang->ucfirst( mb_strtolower( $name ) );
858 $lowerCase = ucfirst( strtolower( $name ) );
861 # Make it mostly unique
862 if ( $lowerCase != $friendlyName ) {
863 $friendlyName .= '_' . substr(md5( $name ), 0, 4);
865 # Handle colon specially by replacing it with tilde
866 # Thus we reduce the number of paths with hashes appended
867 $friendlyName = str_replace( ':', '~', $friendlyName );
869 return $friendlyName;
873 * Get a relative directory for putting a title into
875 function getHashedDirectory( &$title ) {
876 if ( '' != $title->getInterwiki() ) {
877 $pdbk = $title->getDBkey();
879 $pdbk = $title->getPrefixedDBkey();
882 # Find the first colon if there is one, use characters after it
883 $p = strpos( $pdbk, ':' );
884 if ( $p !== false ) {
885 $dbk = substr( $pdbk, $p + 1 );
886 $dbk = substr( $dbk, strspn( $dbk, '_' ) );
891 # Split into characters
893 preg_match_all( '/./us', $dbk, $m );
896 $length = count( $chars );
899 for ( $i = 0; $i < $this->depth; $i++ ) {
903 if ( $i >= $length ) {
907 if ( ord( $c ) >= 128 || preg_match( '/[a-zA-Z0-9!#$%&()+,[\]^_`{}-]/', $c ) ) {
908 if ( function_exists( 'mb_strtolower' ) ) {
909 $dir .= mb_strtolower( $c );
911 $dir .= strtolower( $c );
914 $dir .= sprintf( "%02X", ord( $c ) );
922 * Calculate the start end end of a job based on the current slice
923 * @param integer $start
924 * @param integer $end
925 * @return array of integers
927 function sliceRange( $start, $end ) {
928 $count = $end - $start + 1;
929 $each = $count / $this->sliceDenominator;
930 $sliceStart = $start + intval( $each * ( $this->sliceNumerator - 1 ) );
931 if ( $this->sliceNumerator == $this->sliceDenominator ) {
934 $sliceEnd = $start + intval( $each * $this->sliceNumerator ) - 1;
936 return array( $sliceStart, $sliceEnd );
940 * Adjust a start point so that it belongs to the current slice, where slices are defined by integer modulo
941 * @param integer $start
942 * @param integer $base The true start of the range; the minimum start
944 function modSliceStart( $start, $base = 1 ) {
945 return $start - ( $start % $this->sliceDenominator ) + $this->sliceNumerator - 1 + $base;
949 * Determine whether a string belongs to the current slice, based on hash
951 function sliceFilter( $s ) {
952 return crc32( $s ) % $this->sliceDenominator == $this->sliceNumerator - 1;
958 function onSiteNoticeBefore( &$text ) {
962 function onSiteNoticeAfter( &$text ) {
967 function getMaxPageID() {
968 if ( $this->maxPageID === false ) {
969 $dbr = wfGetDB( DB_SLAVE );
970 $this->maxPageID = $dbr->selectField( 'page', 'max(page_id)', false, __METHOD__ );
972 return $this->maxPageID;
978 if ( !$this->udpProfile ) {
981 if ( !$this->udpProfileInit ) {
982 $this->udpProfileInit = true;
983 } elseif ( $this->udpProfileCounter == 1 % $this->udpProfile ) {
984 $wgProfiler->getFunctionReport();
985 $wgProfiler = new DumpHTML_ProfilerStub;
987 if ( $this->udpProfileCounter == 0 ) {
988 $wgProfiler = new ProfilerSimpleUDP;
989 $wgProfiler->setProfileID( 'dumpHTML' );
991 $this->udpProfileCounter = ( $this->udpProfileCounter + 1 ) % $this->udpProfile;
995 class DumpHTML_ProfilerStub {
996 function profileIn() {}
997 function profileOut() {}
998 function getOutput() {}
1000 function getFunctionReport() {}
1003 /** XML parser callback */
1004 function wfDumpStartTagHandler( $parser, $name, $attribs ) {
1005 global $wgDumpImages;
1007 if ( $name == 'IMG' && isset( $attribs['SRC'] ) ) {
1008 $wgDumpImages[$attribs['SRC']] = true;
1012 /** XML parser callback */
1013 function wfDumpEndTagHandler( $parser, $name ) {}