fname never used
[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 print "Using database {$dbr->mServer}\n";
85
86 $wgHTMLDump->doArticles( $start, $end );
87 if ( !isset( $options['e'] ) ) {
88 $wgHTMLDump->doImageDescriptions();
89 $wgHTMLDump->doCategories();
90 $wgHTMLDump->doSpecials();
91 }
92
93 /*
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");
99
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;
105 }
106 passthru( "php dumpHTML.php -d " . wfEscapeShellArg( $dest ) . " -s $chunkStart -e $chunkEnd" );
107 }
108 chdir( ".." );
109 $d->doImageDescriptions();
110 $d->doCategories();
111 $d->doMainPage( $dest );
112 } else {
113 $d->doArticles( $start, $end );
114 }
115 */
116 }
117
118 if ( isset( $options['debug'] ) ) {
119 print_r($GLOBALS);
120 }
121
122 if ( $profiling ) {
123 echo $wgProfiler->getOutput();
124 }
125
126 ?>