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