5 * @subpackage Maintenance
10 * php dumpHTML.php [options...]
12 * -d <dest> destination directory
15 * -k <skin> skin to use (defaults to htmldump)
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 * --image-snapshot copy all images used to the destination directory
26 $optionsWithArgs = array( 's', 'd', 'e', 'k' );
31 define( 'MW_CMDLINE_CALLBACK', 'wfSetupDump' );
32 function wfSetupDump() {
33 global $wgProfiling, $wgProfileToDatabase, $wgProfileSampleRate;
35 $wgProfileToDatabase = false;
36 $wgProfileSampleRate = 1;
40 require_once( "commandLine.inc" );
41 require_once( "dumpHTML.inc" );
43 error_reporting( E_ALL
& (~E_NOTICE
) );
44 define( 'CHUNK_SIZE', 50 );
46 if ( !empty( $options['s'] ) ) {
47 $start = $options['s'];
52 if ( !empty( $options['e'] ) ) {
55 $dbr =& wfGetDB( DB_SLAVE
);
56 $end = $dbr->selectField( 'page', 'max(page_id)', false );
59 if ( !empty( $options['d'] ) ) {
60 $dest = $options['d'];
65 $skin = isset( $options['k'] ) ?
$options['k'] : 'htmldump';
67 $wgHTMLDump = new DumpHTML( array(
69 'forceCopy' => $options['force-copy'],
70 'alternateScriptPath' => $options['interlang'],
71 'interwiki' => $options['interlang'],
73 'makeSnapshot' => $options['image-snapshot'],
77 if ( $options['special'] ) {
78 $wgHTMLDump->doSpecials();
79 } elseif ( $options['images'] ) {
80 $wgHTMLDump->doImageDescriptions();
81 } elseif ( $options['categories'] ) {
82 $wgHTMLDump->doCategories();
83 } elseif ( $options['redirects'] ) {
84 $wgHTMLDump->doRedirects();
86 print("Creating static HTML dump in directory $dest. \n".
87 "Starting from page_id $start of $end.\n");
89 $dbr =& wfGetDB( DB_SLAVE
);
90 $server = $dbr->getProperty( 'mServer' );
91 print "Using database {$server}\n";
93 $wgHTMLDump->doArticles( $start, $end );
94 if ( !isset( $options['e'] ) ) {
95 $wgHTMLDump->doImageDescriptions();
96 $wgHTMLDump->doCategories();
97 $wgHTMLDump->doSpecials();
101 if ( $end - $start > CHUNK_SIZE * 2 ) {
102 // Split the problem into smaller chunks, run them in different PHP instances
103 // This is a memory/resource leak workaround
104 print("Creating static HTML dump in directory $dest. \n".
105 "Starting from page_id $start of $end.\n");
107 chdir( "maintenance" );
108 for ( $chunkStart = $start; $chunkStart < $end; $chunkStart += CHUNK_SIZE ) {
109 $chunkEnd = $chunkStart + CHUNK_SIZE - 1;
110 if ( $chunkEnd > $end ) {
113 passthru( "php dumpHTML.php -d " . wfEscapeShellArg( $dest ) . " -s $chunkStart -e $chunkEnd" );
116 $d->doImageDescriptions();
118 $d->doMainPage( $dest );
120 $d->doArticles( $start, $end );
125 if ( isset( $options['debug'] ) ) {
130 echo $wgProfiler->getOutput();