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