The war on redundant ampersand usage!
[lhc/web/wiklou.git] / maintenance / dumpHTML.php
1 <?php
2 /**
3 * @todo document
4 * @addtogroup Maintenance
5 */
6
7 /**
8 * Usage:
9 * php dumpHTML.php [options...]
10 *
11 * -d <dest> destination directory
12 * -s <start> start ID
13 * -e <end> end ID
14 * -k <skin> skin to use (defaults to htmldump)
15 * --no-overwrite skip existing HTML files
16 * --checkpoint <file> use a checkpoint file to allow restarting of interrupted dumps
17 * --slice <n/m> split the job into m segments and do the n'th one
18 * --images only do image description pages
19 * --shared-desc only do shared (commons) image description pages
20 * --no-shared-desc don't do shared image description pages
21 * --categories only do category pages
22 * --redirects only do redirects
23 * --special only do miscellaneous stuff
24 * --force-copy copy commons instead of symlink, needed for Wikimedia
25 * --interlang allow interlanguage links
26 * --image-snapshot copy all images used to the destination directory
27 * --compress generate compressed version of the html pages
28 * --udp-profile <N> profile 1/N rendering operations using ProfilerSimpleUDP
29 */
30
31
32 $optionsWithArgs = array( 's', 'd', 'e', 'k', 'checkpoint', 'slice', 'udp-profile' );
33
34 $profiling = false;
35
36 if ( $profiling ) {
37 define( 'MW_CMDLINE_CALLBACK', 'wfSetupDump' );
38 function wfSetupDump() {
39 global $wgProfiling, $wgProfileToDatabase, $wgProfileSampleRate;
40 $wgProfiling = true;
41 $wgProfileToDatabase = false;
42 $wgProfileSampleRate = 1;
43 }
44 }
45
46 if ( in_array( '--udp-profile', $argv ) ) {
47 define( 'MW_FORCE_PROFILE', 1 );
48 }
49
50 require_once( "commandLine.inc" );
51 require_once( "dumpHTML.inc" );
52
53 error_reporting( E_ALL & (~E_NOTICE) );
54
55 if ( !empty( $options['s'] ) ) {
56 $start = $options['s'];
57 } else {
58 $start = 1;
59 }
60
61 if ( !empty( $options['e'] ) ) {
62 $end = $options['e'];
63 } else {
64 $dbr = wfGetDB( DB_SLAVE );
65 $end = $dbr->selectField( 'page', 'max(page_id)', false );
66 }
67
68 if ( !empty( $options['d'] ) ) {
69 $dest = $options['d'];
70 } else {
71 $dest = "$IP/static";
72 }
73
74 $skin = isset( $options['k'] ) ? $options['k'] : 'htmldump';
75
76 if ( $options['slice'] ) {
77 $bits = explode( '/', $options['slice'] );
78 if ( count( $bits ) != 2 || $bits[0] < 1 || $bits[0] > $bits[1] ) {
79 print "Invalid slice specification";
80 exit;
81 }
82 $sliceNumerator = $bits[0];
83 $sliceDenominator = $bits[1];
84 } else {
85 $sliceNumerator = $sliceDenominator = 1;
86 }
87
88 $wgHTMLDump = new DumpHTML( array(
89 'dest' => $dest,
90 'forceCopy' => $options['force-copy'],
91 'alternateScriptPath' => $options['interlang'],
92 'interwiki' => $options['interlang'],
93 'skin' => $skin,
94 'makeSnapshot' => $options['image-snapshot'],
95 'checkpointFile' => $options['checkpoint'],
96 'startID' => $start,
97 'endID' => $end,
98 'sliceNumerator' => $sliceNumerator,
99 'sliceDenominator' => $sliceDenominator,
100 'noOverwrite' => $options['no-overwrite'],
101 'compress' => $options['compress'],
102 'noSharedDesc' => $options['no-shared-desc'],
103 'udpProfile' => $options['udp-profile'],
104 ));
105
106
107 if ( $options['special'] ) {
108 $wgHTMLDump->doSpecials();
109 } elseif ( $options['images'] ) {
110 $wgHTMLDump->doImageDescriptions();
111 } elseif ( $options['categories'] ) {
112 $wgHTMLDump->doCategories();
113 } elseif ( $options['redirects'] ) {
114 $wgHTMLDump->doRedirects();
115 } elseif ( $options['shared-desc'] ) {
116 $wgHTMLDump->doSharedImageDescriptions();
117 } else {
118 print "Creating static HTML dump in directory $dest. \n";
119 $dbr = wfGetDB( DB_SLAVE );
120 $server = $dbr->getProperty( 'mServer' );
121 print "Using database {$server}\n";
122
123 if ( !isset( $options['e'] ) ) {
124 $wgHTMLDump->doEverything();
125 } else {
126 $wgHTMLDump->doArticles();
127 }
128 }
129
130 if ( isset( $options['debug'] ) ) {
131 #print_r($GLOBALS);
132 # Workaround for bug #36957
133 $globals = array_keys( $GLOBALS );
134 #sort( $globals );
135 $sizes = array();
136 foreach ( $globals as $name ) {
137 $sizes[$name] = strlen( serialize( $GLOBALS[$name] ) );
138 }
139 arsort($sizes);
140 $sizes = array_slice( $sizes, 0, 20 );
141 foreach ( $sizes as $name => $size ) {
142 printf( "%9d %s\n", $size, $name );
143 }
144 }
145
146 if ( $profiling ) {
147 echo $wgProfiler->getOutput();
148 }
149
150 ?>