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