5 * @subpackage Maintenance
10 * php dumpHTML.php [options...]
12 * -d <dest> destination directory
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
25 $optionsWithArgs = array( 's', 'd', 'e', 'k' );
30 define( 'MW_CMDLINE_CALLBACK', 'wfSetupDump' );
31 function wfSetupDump() {
32 global $wgProfiling, $wgProfileToDatabase, $wgProfileSampleRate;
34 $wgProfileToDatabase = false;
35 $wgProfileSampleRate = 1;
39 require_once( "commandLine.inc" );
40 require_once( "dumpHTML.inc" );
42 error_reporting( E_ALL
& (~E_NOTICE
) );
43 define( 'CHUNK_SIZE', 50 );
45 if ( !empty( $options['s'] ) ) {
46 $start = $options['s'];
51 if ( !empty( $options['e'] ) ) {
54 $dbr =& wfGetDB( DB_SLAVE
);
55 $end = $dbr->selectField( 'page', 'max(page_id)', false );
58 if ( !empty( $options['d'] ) ) {
59 $dest = $options['d'];
64 $skin = isset( $options['k'] ) ?
$options['k'] : 'dumphtml';
66 $wgHTMLDump = new DumpHTML( array(
68 'forceCopy' => $options['force-copy'],
69 'alternateScriptPath' => $options['interlang'],
70 'interwiki' => $options['interlang'],
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();
84 print("Creating static HTML dump in directory $dest. \n".
85 "Starting from page_id $start of $end.\n");
87 $dbr =& wfGetDB( DB_SLAVE
);
88 $server = $dbr->getProperty( 'mServer' );
89 print "Using database {$server}\n";
91 $wgHTMLDump->doArticles( $start, $end );
92 if ( !isset( $options['e'] ) ) {
93 $wgHTMLDump->doImageDescriptions();
94 $wgHTMLDump->doCategories();
95 $wgHTMLDump->doSpecials();
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");
105 chdir( "maintenance" );
106 for ( $chunkStart = $start; $chunkStart < $end; $chunkStart += CHUNK_SIZE ) {
107 $chunkEnd = $chunkStart + CHUNK_SIZE - 1;
108 if ( $chunkEnd > $end ) {
111 passthru( "php dumpHTML.php -d " . wfEscapeShellArg( $dest ) . " -s $chunkStart -e $chunkEnd" );
114 $d->doImageDescriptions();
116 $d->doMainPage( $dest );
118 $d->doArticles( $start, $end );
123 if ( isset( $options['debug'] ) ) {
128 echo $wgProfiler->getOutput();