(bug 769) OutputPage::permissionRequired() should suggest groups with the needed...
[mediawiki.git] / maintenance / dumpHTML.php
blob37a46465d6dea5317344634b6749f5ff04c51b46
1 <?php
2 /**
3 * @todo document
4 * @package MediaWiki
5 * @subpackage Maintenance
6 */
8 /**
9 * Usage:
10 * php dumpHTML.php [options...]
12 * -d <dest> destination directory
13 * -s <start> start ID
14 * -e <end> end ID
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' );
27 $profiling = false;
29 if ( $profiling ) {
30 define( 'MW_CMDLINE_CALLBACK', 'wfSetupDump' );
31 function wfSetupDump() {
32 global $wgProfiling, $wgProfileToDatabase, $wgProfileSampleRate;
33 $wgProfiling = true;
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'];
47 } else {
48 $start = 1;
51 if ( !empty( $options['e'] ) ) {
52 $end = $options['e'];
53 } else {
54 $dbr =& wfGetDB( DB_SLAVE );
55 $end = $dbr->selectField( 'page', 'max(page_id)', false );
58 if ( !empty( $options['d'] ) ) {
59 $dest = $options['d'];
60 } else {
61 $dest = 'static';
64 $skin = isset( $options['k'] ) ? $options['k'] : 'dumphtml';
66 $wgHTMLDump = new DumpHTML( array(
67 'dest' => $dest,
68 'forceCopy' => $options['force-copy'],
69 'alternateScriptPath' => $options['interlang'],
70 'interwiki' => $options['interlang'],
71 'skin' => $skin,
72 ));
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();
83 } else {
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 ) {
109 $chunkEnd = $end;
111 passthru( "php dumpHTML.php -d " . wfEscapeShellArg( $dest ) . " -s $chunkStart -e $chunkEnd" );
113 chdir( ".." );
114 $d->doImageDescriptions();
115 $d->doCategories();
116 $d->doMainPage( $dest );
117 } else {
118 $d->doArticles( $start, $end );
123 if ( isset( $options['debug'] ) ) {
124 print_r($GLOBALS);
127 if ( $profiling ) {
128 echo $wgProfiler->getOutput();