4 * @subpackage Maintenance
7 define( 'REPORTING_INTERVAL', 10 );
9 require_once( 'includes/ImagePage.php' );
10 require_once( 'includes/CategoryPage.php' );
11 require_once( 'includes/RawPage.php' );
14 # Destination directory
18 var $noOverwrite = false;
20 # Show interlanguage links?
21 var $interwiki = true;
23 # Depth of HTML directory tree
26 # Directory that commons images are copied into
27 var $sharedStaticDirectory;
29 # Directory that the images are in, after copying
30 var $destUploadDirectory;
32 # Relative path to image directory
33 var $imageRel = 'upload';
35 # Copy commons images instead of symlinking
36 var $forceCopy = false;
38 # Make a copy of all images encountered
39 var $makeSnapshot = false;
41 # Make links assuming the script path is in the same directory as
43 var $alternateScriptPath = false;
45 # Original values of various globals
46 var $oldArticlePath = false, $oldCopyrightIcon = false;
48 # Has setupGlobals been called?
49 var $setupDone = false;
51 # List of raw pages used in the current article
55 var $skin = 'htmldump';
58 var $checkpointFile = false, $checkpoints = false;
60 var $startID = 1, $endID = false;
62 var $sliceNumerator = 1, $sliceDenominator = 1;
64 # Max page ID, lazy initialised
65 var $maxPageID = false;
67 function DumpHTML( $settings = array() ) {
68 foreach ( $settings as $var => $value ) {
73 function loadCheckpoints() {
74 if ( $this->checkpoints !== false ) {
76 } elseif ( !$this->checkpointFile ) {
79 $lines = @file( $this->checkpointFile );
80 if ( $lines === false ) {
81 print "Starting new checkpoint file \"{$this->checkpointFile}\"\n";
82 $this->checkpoints = array();
84 $lines = array_map( 'trim', $lines );
85 $this->checkpoints = array();
86 foreach ( $lines as $line ) {
87 list( $name, $value ) = explode( '=', $line, 2 );
88 $this->checkpoints[$name] = $value;
95 function getCheckpoint( $type, $defValue = false ) {
96 if ( !$this->loadCheckpoints() ) {
99 if ( !isset( $this->checkpoints[$type] ) ) {
102 return $this->checkpoints[$type];
106 function setCheckpoint( $type, $value ) {
107 if ( !$this->checkpointFile ) {
110 $this->checkpoints[$type] = $value;
112 foreach ( $this->checkpoints as $type => $value ) {
113 $blob .= "$type=$value\n";
115 file_put_contents( $this->checkpointFile, $blob );
118 function doEverything() {
119 if ( $this->getCheckpoint( 'everything' ) == 'done' ) {
120 print "Checkpoint says everything is already done\n";
124 $this->doLocalImageDescriptions();
125 $this->doSharedImageDescriptions();
126 $this->doCategories();
127 $this->doRedirects();
128 if ( $this->sliceNumerator == 1 ) {
132 $this->setCheckpoint( 'everything', 'done' );
136 * Write a set of articles specified by start and end page_id
137 * Skip categories and images, they will be done separately
139 function doArticles() {
140 if ( $this->endID === false ) {
141 $this->endID = $this->getMaxPageID();
144 # Start from the checkpoint
145 $cp = $this->getCheckpoint( 'article' );
146 if ( $cp == 'done' ) {
147 print "Articles already done\n";
149 } elseif ( $cp !== false ) {
151 print "Resuming article dump from checkpoint at page_id $start of $end\n";
153 print "Starting from page_id $start of $end\n";
156 # Move the start point to the correct slice if it isn't there already
157 $start = $this->modSliceStart( $start );
159 $this->setupGlobals();
161 $mainPageObj = Title::newMainPage();
162 $mainPage = $mainPageObj->getPrefixedDBkey();
164 for ( $id = $start, $i = 0; $id <= $end; $id += $this->sliceDenominator, $i++ ) {
165 wfWaitForSlaves( 20 );
166 if ( !( $i % REPORTING_INTERVAL) ) {
167 print "Processing ID: $id\r";
168 $this->setCheckpoint( 'article', $id );
170 if ( !($i % (REPORTING_INTERVAL*10) ) ) {
173 $title = Title::newFromID( $id );
175 $ns = $title->getNamespace() ;
176 if ( $ns != NS_CATEGORY && $title->getPrefixedDBkey() != $mainPage ) {
177 $this->doArticle( $title );
181 $this->setCheckpoint( 'article', 'done' );
185 function doSpecials() {
188 $this->setupGlobals();
189 print "Special:Categories...";
190 $this->doArticle( Title::makeTitle( NS_SPECIAL, 'Categories' ) );
194 /** Write the main page as index.html */
195 function doMainPage() {
197 print "Making index.html ";
199 // Set up globals with no ../../.. in the link URLs
200 $this->setupGlobals( 0 );
202 $title = Title::newMainPage();
203 $text = $this->getArticleHTML( $title );
205 # Parse the XHTML to find the images
206 $images = $this->findImages( $text );
207 $this->copyImages( $images );
209 $file = fopen( "{$this->dest}/index.html", "w" );
211 print "\nCan't open index.html for writing\n";
214 fwrite( $file, $text );
219 function doImageDescriptions() {
220 $this->doLocalImageDescriptions();
221 $this->doSharedImageDescriptions();
225 * Dump image description pages that don't have an associated article, but do
228 function doLocalImageDescriptions() {
229 global $wgSharedUploadDirectory;
232 $dbr =& wfGetDB( DB_SLAVE );
234 $cp = $this->getCheckpoint( 'local image' );
235 if ( $cp == 'done' ) {
236 print "Local image descriptions already done\n";
238 } elseif ( $cp !== false ) {
239 print "Writing image description pages starting from $cp\n";
240 $conds = array( 'img_name >= ' . $dbr->addQuotes( $cp ) );
242 print "Writing image description pages for local images\n";
246 $this->setupGlobals();
250 $res = $dbr->select( 'image', array( 'img_name' ), $conds, __METHOD__,
251 array( 'ORDER BY' => 'img_name', 'LIMIT' => $chunkSize ) );
252 $numRows = $dbr->numRows( $res );
254 while ( $row = $dbr->fetchObject( $res ) ) {
255 # Update conds for the next chunk query
256 $conds = array( 'img_name > ' . $dbr->addQuotes( $row->img_name ) );
258 // Slice the result set with a filter
259 if ( !$this->sliceFilter( $row->img_name ) ) {
263 wfWaitForSlaves( 10 );
264 if ( !( ++$i % REPORTING_INTERVAL ) ) {
265 print "{$row->img_name}\n";
266 if ( $row->img_name !== 'done' ) {
267 $this->setCheckpoint( 'local image', $row->img_name );
270 $title = Title::makeTitle( NS_IMAGE, $row->img_name );
271 if ( $title->getArticleID() ) {
272 // Already done by dumpHTML
275 $this->doArticle( $title );
277 $dbr->freeResult( $res );
278 } while ( $numRows );
280 $this->setCheckpoint( 'local image', 'done' );
285 * Dump images which only have a real description page on commons
287 function doSharedImageDescriptions() {
288 list( $start, $end ) = $this->sliceRange( 0, 255 );
290 $cp = $this->getCheckpoint( 'shared image' );
291 if ( $cp == 'done' ) {
292 print "Shared description pages already done\n";
294 } elseif ( $cp !== false ) {
295 print "Writing description pages for commons images starting from directory $cp/255\n";
298 print "Writing description pages for commons images\n";
301 $this->setupGlobals();
303 for ( $hash = $start; $hash <= $end; $hash++ ) {
304 $this->setCheckpoint( 'shared image', $hash );
306 $dir = sprintf( "%01x/%02x", intval( $hash / 16 ), $hash );
307 $paths = array_merge( glob( "{$this->sharedStaticDirectory}/$dir/*" ),
308 glob( "{$this->sharedStaticDirectory}/thumb/$dir/*" ) );
310 foreach ( $paths as $path ) {
311 $file = wfBaseName( $path );
312 if ( !(++$i % REPORTING_INTERVAL ) ) {
316 $title = Title::makeTitle( NS_IMAGE, $file );
317 $this->doArticle( $title );
320 $this->setCheckpoint( 'shared image', 'done' );
324 function doCategories() {
327 $this->setupGlobals();
328 $dbr =& wfGetDB( DB_SLAVE );
330 $cp = $this->getCheckpoint( 'category' );
331 if ( $cp == 'done' ) {
332 print "Category pages already done\n";
334 } elseif ( $cp !== false ) {
335 print "Resuming category page dump from $cp\n";
336 $conds = array( 'cl_to >= ' $dbr->addQuotes( $cp ) );
338 print "Starting category pages\n";
344 $res = $dbr->select( 'categorylinks', 'DISTINCT cl_to', $conds, __METHOD__
345 array( 'ORDER BY' => 'cl_to', 'LIMIT' => $chunkSize ) );
346 $numRows = $dbr->numRows( $res );
348 while ( $row = $dbr->fetchObject( $res ) ) {
349 // Set conditions for next chunk
350 $conds = array( 'cl_to > ' $dbr->addQuotes( $row->cl_to ) );
352 // Filter pages from other slices
353 if ( !$this->sliceFilter( $row->cl_to ) ) {
357 wfWaitForSlaves( 10 );
358 if ( !(++$i % REPORTING_INTERVAL ) ) {
359 print "{$row->cl_to}\n";
360 if ( $row->cl_to != 'done' ) {
361 $this->setCheckpoint( 'category', $row->cl_to );
364 $title = Title::makeTitle( NS_CATEGORY, $row->cl_to );
365 $this->doArticle( $title );
367 $dbr->freeResult( $res );
368 } while ( $numRows );
370 $this->setCheckpoint( 'category', 'done' );
374 function doRedirects() {
375 print "Doing redirects...\n";
378 $end = $this->getMaxPageID();
379 $cp = $this->getCheckpoint( 'redirect' );
380 if ( $cp == 'done' ) {
381 print "Redirects already done\n";
383 } elseif ( $cp !== false ) {
384 print "Resuming redirect generation from page_id $cp\n";
385 $start = intval( $cp );
388 $this->setupGlobals();
389 $dbr =& wfGetDB( DB_SLAVE );
392 for ( $chunkStart = $start; $chunkStart <= $end; $chunkStart += $chunkSize ) {
393 $chunkEnd = min( $end, $chunkStart + $chunkSize - 1 );
395 'page_is_redirect' => 1,
396 "page_id BETWEEN $chunkStart AND $chunkEnd"
398 # Modulo slicing in SQL
399 if ( $this->sliceDenominator != 1 ) {
400 $n = intval( $this->sliceNumerator );
401 $m = intval( $this->sliceDenominator );
402 $conds[] = "page_id % $m = $n";
404 $res = $dbr->select( 'page', array( 'page_id', 'page_namespace', 'page_title' ),
405 $conds, __METHOD__ );
407 while ( $row = $dbr->fetchObject( $res ) ) {
408 $title = Title::makeTitle( $row->page_namespace, $row->page_title );
409 if ( !(++$i % (REPORTING_INTERVAL*10) ) ) {
410 printf( "Done %d redirects (%2.3f%%)\n", $i, $row->page_id / $end * 100 );
411 $this->setCheckpoint( 'redirect', $row->page_id );
413 $this->doArticle( $title );
415 $dbr->freeResult( $res );
417 $this->setCheckpoint( 'redirect', 'done' );
420 /** Write an article specified by title */
421 function doArticle( $title ) {
422 global $wgTitle, $wgSharedUploadPath, $wgSharedUploadDirectory;
423 global $wgUploadDirectory;
425 if ( $this->noOverwrite ) {
426 $fileName = $this->dest.'/'.$this->getHashedFilename( $title );
427 if ( file_exists( $fileName ) ) {
432 $this->rawPages = array();
433 $text = $this->getArticleHTML( $title );
435 if ( $text === false ) {
439 # Parse the XHTML to find the images
440 $images = $this->findImages( $text );
441 $this->copyImages( $images );
444 $this->writeArticle( $title, $text );
447 wfMkdirParents( "{$this->dest}/raw", 0755 );
448 foreach( $this->rawPages as $record ) {
449 list( $file, $title, $params ) = $record;
451 $path = "{$this->dest}/raw/$file";
452 if ( !file_exists( $path ) ) {
453 $article = new Article( $title );
454 $request = new FauxRequest( $params );
455 $rp = new RawPage( $article, $request );
456 $text = $rp->getRawText();
458 print "Writing $file\n";
459 $file = fopen( $path, 'w' );
461 print("Can't open file $fullName for writing\n");
464 fwrite( $file, $text );
470 /** Write the given text to the file identified by the given title object */
471 function writeArticle( &$title, $text ) {
472 $filename = $this->getHashedFilename( $title );
473 $fullName = "{$this->dest}/$filename";
474 $fullDir = dirname( $fullName );
476 wfMkdirParents( $fullDir, 0755 );
478 wfSuppressWarnings();
479 $file = fopen( $fullName, 'w' );
483 die("Can't open file '$fullName' for writing.\nCheck permissions or use another destination (-d).\n");
487 fwrite( $file, $text );
491 /** Set up globals required for parsing */
492 function setupGlobals( $currentDepth = NULL ) {
493 global $wgUser, $wgTitle, $wgStylePath, $wgArticlePath, $wgMathPath;
494 global $wgUploadPath, $wgLogo, $wgMaxCredits, $wgSharedUploadPath;
495 global $wgHideInterlanguageLinks, $wgUploadDirectory, $wgThumbnailScriptPath;
496 global $wgSharedThumbnailScriptPath, $wgEnableParserCache, $wgHooks, $wgServer;
497 global $wgRightsUrl, $wgRightsText, $wgCopyrightIcon, $wgEnableSidebarCache;
498 global $wgGenerateThumbnailOnParse;
500 static $oldLogo = NULL;
502 if ( !$this->setupDone ) {
503 $wgHooks['GetLocalURL'][] =& $this;
504 $wgHooks['GetFullURL'][] =& $this;
505 $wgHooks['SiteNoticeBefore'][] =& $this;
506 $wgHooks['SiteNoticeAfter'][] =& $this;
507 $this->oldArticlePath = $wgServer . $wgArticlePath;
510 if ( is_null( $currentDepth ) ) {
511 $currentDepth = $this->depth;
514 if ( $this->alternateScriptPath ) {
515 if ( $currentDepth == 0 ) {
518 $wgScriptPath = '..' . str_repeat( '/..', $currentDepth - 1 );
521 $wgScriptPath = '..' . str_repeat( '/..', $currentDepth );
524 $wgArticlePath = str_repeat( '../', $currentDepth ) . '$1';
527 # Allow for repeated setup
528 if ( !is_null( $oldLogo ) ) {
534 if ( strpos( $wgLogo, $wgUploadPath ) === 0 ) {
535 # If it's in the upload directory, rewrite it to the new upload directory
536 $wgLogo = "$wgScriptPath/{$this->imageRel}/" . substr( $wgLogo, strlen( $wgUploadPath ) + 1 );
537 } elseif ( $wgLogo{0} == '/' ) {
538 # This is basically heuristic
539 # Rewrite an absolute logo path to one relative to the the script path
540 $wgLogo = $wgScriptPath . $wgLogo;
544 if ( !$this->setupDone ) {
545 $this->oldCopyrightIcon = $wgCopyrightIcon;
547 $wgCopyrightIcon = str_replace( 'src="/images',
548 'src="' . htmlspecialchars( $wgScriptPath ) . '/images', $this->oldCopyrightIcon );
550 $wgStylePath = "$wgScriptPath/skins";
551 $wgUploadPath = "$wgScriptPath/{$this->imageRel}";
552 $wgSharedUploadPath = "$wgUploadPath/shared";
554 $wgHideInterlanguageLinks = !$this->interwiki;
555 $wgThumbnailScriptPath = $wgSharedThumbnailScriptPath = false;
556 $wgEnableParserCache = false;
557 $wgMathPath = "$wgScriptPath/math";
558 $wgEnableSidebarCache = false;
559 $wgGenerateThumbnailOnParse = true;
561 if ( !empty( $wgRightsText ) ) {
562 $wgRightsUrl = "$wgScriptPath/COPYING.html";
566 $wgUser->setOption( 'skin', $this->skin );
567 $wgUser->setOption( 'editsection', 0 );
569 if ( $this->makeSnapshot ) {
570 $this->destUploadDirectory = "{$this->dest}/{$this->imageRel}";
571 if ( realpath( $this->destUploadDirectory == $wgUploadDirectory ) ) {
572 $this->makeSnapshot = false;
576 $this->sharedStaticDirectory = "{$this->destUploadDirectory}/shared";
578 $this->setupDone = true;
581 /** Reads the content of a title object, executes the skin and captures the result */
582 function getArticleHTML( &$title ) {
583 global $wgOut, $wgTitle, $wgArticle, $wgUser;
585 $linkCache =& LinkCache::singleton();
588 if ( is_null( $wgTitle ) ) {
592 $ns = $wgTitle->getNamespace();
593 if ( $ns == NS_SPECIAL ) {
594 $wgOut = new OutputPage;
595 $wgOut->setParserOptions( new ParserOptions );
596 SpecialPage::executePath( $wgTitle );
598 /** @todo merge with Wiki.php code */
599 if ( $ns == NS_IMAGE ) {
600 $wgArticle = new ImagePage( $wgTitle );
601 } elseif ( $ns == NS_CATEGORY ) {
602 $wgArticle = new CategoryPage( $wgTitle );
604 $wgArticle = new Article( $wgTitle );
606 $rt = Title::newFromRedirect( $wgArticle->fetchContent() );
608 return $this->getRedirect( $rt );
610 $wgOut = new OutputPage;
611 $wgOut->setParserOptions( new ParserOptions );
617 $sk =& $wgUser->getSkin();
619 $sk->outputPage( $wgOut );
620 $text = ob_get_contents();
626 function getRedirect( $rt ) {
627 $url = $rt->escapeLocalURL();
628 $text = $rt->getPrefixedText();
630 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
631 <html xmlns="http://www.w3.org/1999/xhtml">
633 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
634 <meta http-equiv="Refresh" content="0;url=$url" />
637 <p>Redirecting to <a href="$url">$text</a></p>
643 /** Returns image paths used in an XHTML document */
644 function findImages( $text ) {
645 global $wgOutputEncoding, $wgDumpImages;
646 $parser = xml_parser_create( $wgOutputEncoding );
647 xml_set_element_handler( $parser, 'wfDumpStartTagHandler', 'wfDumpEndTagHandler' );
649 $wgDumpImages = array();
650 xml_parse( $parser, $text );
651 xml_parser_free( $parser );
653 return $wgDumpImages;
657 * Copy a file specified by a URL to a given directory
659 * @param string $srcPath The source URL
660 * @param string $srcPathBase The base directory of the source URL
661 * @param string $srcDirBase The base filesystem directory of the source URL
662 * @param string $destDirBase The base filesystem directory of the destination URL
664 function relativeCopy( $srcPath, $srcPathBase, $srcDirBase, $destDirBase ) {
665 $rel = substr( $srcPath, strlen( $srcPathBase ) + 1 ); // +1 for slash
666 $sourceLoc = "$srcDirBase/$rel";
667 $destLoc = "$destDirBase/$rel";
668 #print "Copying $sourceLoc to $destLoc\n";
669 if ( !file_exists( $destLoc ) ) {
670 wfMkdirParents( dirname( $destLoc ), 0755 );
671 if ( function_exists( 'symlink' ) && !$this->forceCopy ) {
672 symlink( $sourceLoc, $destLoc );
674 copy( $sourceLoc, $destLoc );
680 * Copy an image, and if it is a thumbnail, copy its parent image too
682 function copyImage( $srcPath, $srcPathBase, $srcDirBase, $destDirBase ) {
683 global $wgUploadPath, $wgUploadDirectory, $wgSharedUploadPath;
684 $this->relativeCopy( $srcPath, $srcPathBase, $srcDirBase, $destDirBase );
685 if ( substr( $srcPath, strlen( $srcPathBase ) + 1, 6 ) == 'thumb/' ) {
686 # The image was a thumbnail
687 # Copy the source image as well
688 $rel = substr( $srcPath, strlen( $srcPathBase ) + 1 );
689 $parts = explode( '/', $rel );
690 $rel = "{$parts[1]}/{$parts[2]}/{$parts[3]}";
691 $newSrc = "$srcPathBase/$rel";
692 $this->relativeCopy( $newSrc, $srcPathBase, $srcDirBase, $destDirBase );
697 * Copy images (or create symlinks) from commons to a static directory.
698 * This is necessary even if you intend to distribute all of commons, because
699 * the directory contents is used to work out which image description pages
702 * Also copies math images, and full-sized images if the makeSnapshot option
706 function copyImages( $images ) {
707 global $wgUploadPath, $wgUploadDirectory, $wgSharedUploadPath, $wgSharedUploadDirectory,
708 $wgMathPath, $wgMathDirectory;
709 # Find shared uploads and copy them into the static directory
710 $sharedPathLength = strlen( $wgSharedUploadPath );
711 $mathPathLength = strlen( $wgMathPath );
712 $uploadPathLength = strlen( $wgUploadPath );
713 foreach ( $images as $escapedImage => $dummy ) {
714 $image = urldecode( $escapedImage );
716 if ( substr( $image, 0, $sharedPathLength ) == $wgSharedUploadPath ) {
717 $this->copyImage( $image, $wgSharedUploadPath, $wgSharedUploadDirectory, $this->sharedStaticDirectory );
718 } elseif ( substr( $image, 0, $mathPathLength ) == $wgMathPath ) {
719 $this->relativeCopy( $image, $wgMathPath, $wgMathDirectory, "{$this->dest}/math" );
720 } elseif ( $this->makeSnapshot && substr( $image, 0, $uploadPathLength ) == $wgUploadPath ) {
721 $this->copyImage( $image, $wgUploadPath, $wgUploadDirectory, $this->destUploadDirectory );
726 function onGetFullURL( &$title, &$url, $query ) {
727 global $wgContLang, $wgArticlePath;
729 $iw = $title->getInterwiki();
730 if ( $title->isExternal() && $wgContLang->getLanguageName( $iw ) ) {
731 if ( $title->getDBkey() == '' ) {
732 $url = str_replace( '$1', "../$iw/index.html", $wgArticlePath );
734 $url = str_replace( '$1', "../$iw/" . wfUrlencode( $this->getHashedFilename( $title ) ),
743 function onGetLocalURL( &$title, &$url, $query ) {
744 global $wgArticlePath;
746 if ( $title->isExternal() ) {
747 # Default is fine for interwiki
752 if ( $query != '' ) {
753 parse_str( $query, $params );
754 if ( isset($params['action']) && $params['action'] == 'raw' ) {
755 if ( $params['gen'] == 'css' || $params['gen'] == 'js' ) {
756 $file = 'gen.' . $params['gen'];
758 $file = $this->getFriendlyName( $title->getPrefixedDBkey() );
759 // Clean up Monobook.css etc.
760 if ( preg_match( '/^(.*)\.(css|js)_[0-9a-f]{4}$/', $file, $matches ) ) {
761 $file = $matches[1] . '.' . $matches[2];
764 $this->rawPages[$file] = array( $file, $title, $params );
765 $url = str_replace( '$1', "raw/" . wfUrlencode( $file ), $wgArticlePath );
768 if ( $url === false ) {
769 $url = str_replace( '$1', wfUrlencode( $this->getHashedFilename( $title ) ), $wgArticlePath );
775 function getHashedFilename( &$title ) {
776 if ( '' != $title->mInterwiki ) {
777 $dbkey = $title->getDBkey();
779 $dbkey = $title->getPrefixedDBkey();
782 $mainPage = Title::newMainPage();
783 if ( $mainPage->getPrefixedDBkey() == $dbkey ) {
787 return $this->getHashedDirectory( $title ) . '/' .
788 $this->getFriendlyName( $dbkey ) . '.html';
791 function getFriendlyName( $name ) {
793 # Replace illegal characters for Windows paths with underscores
794 $friendlyName = strtr( $name, '/\\*?"<>|~', '_________' );
796 # Work out lower case form. We assume we're on a system with case-insensitive
797 # filenames, so unless the case is of a special form, we have to disambiguate
798 if ( function_exists( 'mb_strtolower' ) ) {
799 $lowerCase = $wgLang->ucfirst( mb_strtolower( $name ) );
801 $lowerCase = ucfirst( strtolower( $name ) );
804 # Make it mostly unique
805 if ( $lowerCase != $friendlyName ) {
806 $friendlyName .= '_' . substr(md5( $name ), 0, 4);
808 # Handle colon specially by replacing it with tilde
809 # Thus we reduce the number of paths with hashes appended
810 $friendlyName = str_replace( ':', '~', $friendlyName );
812 return $friendlyName;
816 * Get a relative directory for putting a title into
818 function getHashedDirectory( &$title ) {
819 if ( '' != $title->getInterwiki() ) {
820 $pdbk = $title->getDBkey();
822 $pdbk = $title->getPrefixedDBkey();
825 # Find the first colon if there is one, use characters after it
826 $p = strpos( $pdbk, ':' );
827 if ( $p !== false ) {
828 $dbk = substr( $pdbk, $p + 1 );
829 $dbk = substr( $dbk, strspn( $dbk, '_' ) );
834 # Split into characters
835 preg_match_all( '/./us', $dbk, $m );
838 $length = count( $chars );
841 for ( $i = 0; $i < $this->depth; $i++ ) {
845 if ( $i >= $length ) {
849 if ( ord( $c ) >= 128 || preg_match( '/[a-zA-Z0-9!#$%&()+,[\]^_`{}-]/', $c ) ) {
850 if ( function_exists( 'mb_strtolower' ) ) {
851 $dir .= mb_strtolower( $c );
853 $dir .= strtolower( $c );
856 $dir .= sprintf( "%02X", ord( $c ) );
864 * Calculate the start end end of a job based on the current slice
865 * @param integer $start
866 * @param integer $end
867 * @return array of integers
869 function sliceRange( $start, $end ) {
870 $count = $end - $start + 1;
871 $each = $count / $this->sliceDenominator;
872 $sliceStart = $start + intval( $each * ( $this->sliceNumerator - 1 ) );
873 if ( $this->sliceNumerator == $this->sliceDenominator ) {
876 $sliceEnd = $start + intval( $each * $this->sliceNumerator ) - 1;
878 return array( $sliceStart, $sliceEnd );
882 * Adjust a start point so that it belongs to the current slice, where slices are defined by integer modulo
883 * @param integer $start
884 * @param integer $base The true start of the range; the minimum start
886 function modSliceStart( $start, $base = 1 ) {
887 return $start - ( $start % $this->sliceDenominator ) + $this->sliceNumerator - 1 + $base;
891 * Determine whether a string belongs to the current slice, based on hash
893 function sliceFilter( $s ) {
894 return crc32( $s ) % $this->sliceDenominator == $this->sliceNumerator - 1;
900 function onSiteNoticeBefore( &$text ) {
904 function onSiteNoticeAfter( &$text ) {
909 function getMaxPageID() {
910 if ( $this->maxPageID === false ) {
911 $dbr =& wfGetDB( DB_SLAVE );
912 $this->maxPageID = $dbr->selectField( 'page', 'max(page_id)', false, __METHOD__ );
914 return $this->maxPageID;
919 /** XML parser callback */
920 function wfDumpStartTagHandler( $parser, $name, $attribs ) {
921 global $wgDumpImages;
923 if ( $name == 'IMG' && isset( $attribs['SRC'] ) ) {
924 $wgDumpImages[$attribs['SRC']] = true;
928 /** XML parser callback */
929 function wfDumpEndTagHandler( $parser, $name ) {}