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