* Change to use $dbr->getProperty()
[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 * --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
21 */
22
23
24 $optionsWithArgs = array( 's', 'd', 'e' );
25
26 $profiling = false;
27
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;
35 }
36 }
37
38 require_once( "commandLine.inc" );
39 require_once( "dumpHTML.inc" );
40
41 error_reporting( E_ALL & (~E_NOTICE) );
42 define( 'CHUNK_SIZE', 50 );
43
44 if ( !empty( $options['s'] ) ) {
45 $start = $options['s'];
46 } else {
47 $start = 1;
48 }
49
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 );
55 }
56
57 if ( !empty( $options['d'] ) ) {
58 $dest = $options['d'];
59 } else {
60 $dest = 'static';
61 }
62
63 $wgHTMLDump = new DumpHTML( array(
64 'dest' => $dest,
65 'forceCopy' => $options['force-copy'],
66 'alternateScriptPath' => $options['interlang'],
67 'interwiki' => $options['interlang'],
68 ));
69
70
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");
82
83 $dbr =& wfGetDB( DB_SLAVE );
84 $server = $dbr->getProperty( 'mServer' );
85 print "Using database {$server}\n";
86
87 $wgHTMLDump->doArticles( $start, $end );
88 if ( !isset( $options['e'] ) ) {
89 $wgHTMLDump->doImageDescriptions();
90 $wgHTMLDump->doCategories();
91 $wgHTMLDump->doSpecials();
92 }
93
94 /*
95 if ( $end - $start > CHUNK_SIZE * 2 ) {
96 // Split the problem into smaller chunks, run them in different PHP instances
97 // This is a memory/resource leak workaround
98 print("Creating static HTML dump in directory $dest. \n".
99 "Starting from page_id $start of $end.\n");
100
101 chdir( "maintenance" );
102 for ( $chunkStart = $start; $chunkStart < $end; $chunkStart += CHUNK_SIZE ) {
103 $chunkEnd = $chunkStart + CHUNK_SIZE - 1;
104 if ( $chunkEnd > $end ) {
105 $chunkEnd = $end;
106 }
107 passthru( "php dumpHTML.php -d " . wfEscapeShellArg( $dest ) . " -s $chunkStart -e $chunkEnd" );
108 }
109 chdir( ".." );
110 $d->doImageDescriptions();
111 $d->doCategories();
112 $d->doMainPage( $dest );
113 } else {
114 $d->doArticles( $start, $end );
115 }
116 */
117 }
118
119 if ( isset( $options['debug'] ) ) {
120 print_r($GLOBALS);
121 }
122
123 if ( $profiling ) {
124 echo $wgProfiler->getOutput();
125 }
126
127 ?>