assorted improvements
[lhc/web/wiklou.git] / maintenance / dumpHTML.php
1 <?php
2 /**
3 * @todo document
4 * @package MediaWiki
5 * @subpackage Maintenance
6 */
7
8 /**
9 * Usage:
10 * php dumpHTML.php [options...]
11 *
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 * --special only do miscellaneous stuff
18 * --force-copy copy commons instead of symlink, needed for Wikimedia
19 * --interlang allow interlanguage links
20 */
21
22
23 $optionsWithArgs = array( 's', 'd', 'e' );
24
25 $profiling = false;
26
27 if ( $profiling ) {
28 define( 'MW_CMDLINE_CALLBACK', 'wfSetupDump' );
29 function wfSetupDump() {
30 global $wgProfiling, $wgProfileToDatabase, $wgProfileSampleRate;
31 $wgProfiling = true;
32 $wgProfileToDatabase = false;
33 $wgProfileSampleRate = 1;
34 }
35 }
36
37 require_once( "commandLine.inc" );
38 require_once( "dumpHTML.inc" );
39
40 error_reporting( E_ALL & (~E_NOTICE) );
41 define( 'CHUNK_SIZE', 50 );
42
43 if ( !empty( $options['s'] ) ) {
44 $start = $options['s'];
45 } else {
46 $start = 1;
47 }
48
49 if ( !empty( $options['e'] ) ) {
50 $end = $options['e'];
51 } else {
52 $dbr =& wfGetDB( DB_SLAVE );
53 $end = $dbr->selectField( 'page', 'max(page_id)', false );
54 }
55
56 if ( !empty( $options['d'] ) ) {
57 $dest = $options['d'];
58 } else {
59 $dest = 'static';
60 }
61
62 $d = new DumpHTML( array(
63 'dest' => $dest,
64 'forceCopy' => $options['force-copy'],
65 'alternateScriptPath' => $options['interlang'],
66 'interwiki' => $options['interlang'],
67 ));
68
69
70 if ( $options['special'] ) {
71 $d->doSpecials();
72 } elseif ( $options['images'] ) {
73 $d->doImageDescriptions();
74 } elseif ( $options['categories'] ) {
75 $d->doCategories();
76 } else {
77 print("Creating static HTML dump in directory $dest. \n".
78 "Starting from page_id $start of $end.\n");
79
80 $dbr =& wfGetDB( DB_SLAVE );
81 print "Using database {$dbr->mServer}\n";
82
83 $d->doArticles( $start, $end );
84 if ( !isset( $options['e'] ) ) {
85 $d->doImageDescriptions();
86 $d->doCategories();
87 $d->doSpecials();
88 }
89
90 /*
91 if ( $end - $start > CHUNK_SIZE * 2 ) {
92 // Split the problem into smaller chunks, run them in different PHP instances
93 // This is a memory/resource leak workaround
94 print("Creating static HTML dump in directory $dest. \n".
95 "Starting from page_id $start of $end.\n");
96
97 chdir( "maintenance" );
98 for ( $chunkStart = $start; $chunkStart < $end; $chunkStart += CHUNK_SIZE ) {
99 $chunkEnd = $chunkStart + CHUNK_SIZE - 1;
100 if ( $chunkEnd > $end ) {
101 $chunkEnd = $end;
102 }
103 passthru( "php dumpHTML.php -d " . wfEscapeShellArg( $dest ) . " -s $chunkStart -e $chunkEnd" );
104 }
105 chdir( ".." );
106 $d->doImageDescriptions();
107 $d->doCategories();
108 $d->doMainPage( $dest );
109 } else {
110 $d->doArticles( $start, $end );
111 }
112 */
113 }
114
115 if ( isset( $options['debug'] ) ) {
116 print_r($GLOBALS);
117 }
118
119 if ( $profiling ) {
120 echo $wgProfiler->getOutput();
121 }
122
123 ?>