* Use double quoted consistently on attributes in linker output; preparing for new...
[mediawiki.git] / maintenance / dumpHTML.php
blob5e042319207867bde014bcd6f564ff3da0c88562
1 <?php
2 /**
3 * @todo document
4 * @package MediaWiki
5 * @subpackage Maintenance
6 */
8 /**
9 * Usage:
10 * php dumpHTML.php [options...]
12 * -d <dest> destination directory
13 * -s <start> start ID
14 * -e <end> end ID
15 * --images only do image description pages
16 * --categories only do category pages
17 * --redirects only do redirects
18 * --special only do miscellaneous stuff
19 * --force-copy copy commons instead of symlink, needed for Wikimedia
20 * --interlang allow interlanguage links
24 $optionsWithArgs = array( 's', 'd', 'e' );
26 $profiling = false;
28 if ( $profiling ) {
29 define( 'MW_CMDLINE_CALLBACK', 'wfSetupDump' );
30 function wfSetupDump() {
31 global $wgProfiling, $wgProfileToDatabase, $wgProfileSampleRate;
32 $wgProfiling = true;
33 $wgProfileToDatabase = false;
34 $wgProfileSampleRate = 1;
38 require_once( "commandLine.inc" );
39 require_once( "dumpHTML.inc" );
41 error_reporting( E_ALL & (~E_NOTICE) );
42 define( 'CHUNK_SIZE', 50 );
44 if ( !empty( $options['s'] ) ) {
45 $start = $options['s'];
46 } else {
47 $start = 1;
50 if ( !empty( $options['e'] ) ) {
51 $end = $options['e'];
52 } else {
53 $dbr =& wfGetDB( DB_SLAVE );
54 $end = $dbr->selectField( 'page', 'max(page_id)', false );
57 if ( !empty( $options['d'] ) ) {
58 $dest = $options['d'];
59 } else {
60 $dest = 'static';
63 $wgHTMLDump = new DumpHTML( array(
64 'dest' => $dest,
65 'forceCopy' => $options['force-copy'],
66 'alternateScriptPath' => $options['interlang'],
67 'interwiki' => $options['interlang'],
68 ));
71 if ( $options['special'] ) {
72 $wgHTMLDump->doSpecials();
73 } elseif ( $options['images'] ) {
74 $wgHTMLDump->doImageDescriptions();
75 } elseif ( $options['categories'] ) {
76 $wgHTMLDump->doCategories();
77 } elseif ( $options['redirects'] ) {
78 $wgHTMLDump->doRedirects();
79 } else {
80 print("Creating static HTML dump in directory $dest. \n".
81 "Starting from page_id $start of $end.\n");
83 $dbr =& wfGetDB( DB_SLAVE );
84 print "Using database {$dbr->mServer}\n";
86 $wgHTMLDump->doArticles( $start, $end );
87 if ( !isset( $options['e'] ) ) {
88 $wgHTMLDump->doImageDescriptions();
89 $wgHTMLDump->doCategories();
90 $wgHTMLDump->doSpecials();
94 if ( $end - $start > CHUNK_SIZE * 2 ) {
95 // Split the problem into smaller chunks, run them in different PHP instances
96 // This is a memory/resource leak workaround
97 print("Creating static HTML dump in directory $dest. \n".
98 "Starting from page_id $start of $end.\n");
100 chdir( "maintenance" );
101 for ( $chunkStart = $start; $chunkStart < $end; $chunkStart += CHUNK_SIZE ) {
102 $chunkEnd = $chunkStart + CHUNK_SIZE - 1;
103 if ( $chunkEnd > $end ) {
104 $chunkEnd = $end;
106 passthru( "php dumpHTML.php -d " . wfEscapeShellArg( $dest ) . " -s $chunkStart -e $chunkEnd" );
108 chdir( ".." );
109 $d->doImageDescriptions();
110 $d->doCategories();
111 $d->doMainPage( $dest );
112 } else {
113 $d->doArticles( $start, $end );
118 if ( isset( $options['debug'] ) ) {
119 print_r($GLOBALS);
122 if ( $profiling ) {
123 echo $wgProfiler->getOutput();