summaryrefslogtreecommitdiff
path: root/maintenance/dumpHTML.php
blob: 26e914ff3f92665420cc49b6e2bbffaaafec102c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
<?php
/**
 * @todo document
 * @addtogroup Maintenance
 */

function ShowUsage() {
echo <<<END
Usage:
php dumpHTML.php --help
php dumpHTML.php [options...]

	--help               show this message

	-d <dest>            destination directory
	-s <start>           start ID
	-e <end>             end ID
	-k <skin>            skin to use (defaults to htmldump)
	--no-overwrite       skip existing HTML files
	--checkpoint <file>  use a checkpoint file to allow restarting of interrupted dumps
	--slice <n/m>        split the job into m segments and do the n'th one
	--images             only do image description pages
	--shared-desc        only do shared (commons) image description pages
	--no-shared-desc     don't do shared image description pages
	--categories         only do category pages
	--redirects          only do redirects
	--special            only do miscellaneous stuff
	--force-copy         copy commons instead of symlink, needed for Wikimedia
	--interlang          allow interlanguage links
	--image-snapshot     copy all images used to the destination directory
	--compress           generate compressed version of the html pages
	--udp-profile <N>    profile 1/N rendering operations using ProfilerSimpleUDP

END;
}

$optionsWithArgs = array( 's', 'd', 'e', 'k', 'checkpoint', 'slice', 'udp-profile' );
$options = array( 'help' );
$profiling = false;

if ( $profiling ) {
	define( 'MW_CMDLINE_CALLBACK', 'wfSetupDump' );
	function wfSetupDump() {
		global $wgProfiling, $wgProfileToDatabase, $wgProfileSampleRate;
		$wgProfiling = true;
		$wgProfileToDatabase = false;
		$wgProfileSampleRate = 1;
	}
}

if ( in_array( '--udp-profile', $argv ) ) {
	define( 'MW_FORCE_PROFILE', 1 );
}

require_once( "commandLine.inc" );
require_once( "dumpHTML.inc" );

error_reporting( E_ALL & (~E_NOTICE) );

if( isset( $options['help'] ) ) {
	ShowUsage();
	exit();
}

if ( !empty( $options['s'] ) ) {
	$start = $options['s'];
} else {
	$start = 1;
}

if ( !empty( $options['e'] ) ) {
	$end = $options['e'];
} else {
	$dbr = wfGetDB( DB_SLAVE );
	$end = $dbr->selectField( 'page', 'max(page_id)', false );
}

if ( !empty( $options['d'] ) ) {
	$dest = $options['d'];
} else {
	$dest = "$IP/static";
}

$skin = isset( $options['k'] ) ? $options['k'] : 'htmldump';

if ( $options['slice'] ) {
	$bits = explode( '/', $options['slice'] );
	if ( count( $bits ) != 2 || $bits[0] < 1 || $bits[0] > $bits[1] ) {
		print "Invalid slice specification";
		exit;
	}
	$sliceNumerator = $bits[0];
	$sliceDenominator = $bits[1];
} else {
	$sliceNumerator = $sliceDenominator = 1;
}

$wgHTMLDump = new DumpHTML( array(
	'dest' => $dest,
	'forceCopy' => $options['force-copy'],
	'alternateScriptPath' => $options['interlang'],
	'interwiki' => $options['interlang'],
	'skin' => $skin,
	'makeSnapshot' => $options['image-snapshot'],
	'checkpointFile' => $options['checkpoint'],
	'startID' => $start,
	'endID' => $end,
	'sliceNumerator' => $sliceNumerator,
	'sliceDenominator' => $sliceDenominator,
	'noOverwrite' => $options['no-overwrite'],
	'compress' => $options['compress'],
	'noSharedDesc' => $options['no-shared-desc'],
	'udpProfile' => $options['udp-profile'],
));


if ( $options['special'] ) {
	$wgHTMLDump->doSpecials();
} elseif ( $options['images'] ) {
	$wgHTMLDump->doImageDescriptions();
} elseif ( $options['categories'] ) {
	$wgHTMLDump->doCategories();
} elseif ( $options['redirects'] ) {
	$wgHTMLDump->doRedirects();
} elseif ( $options['shared-desc'] ) {
	$wgHTMLDump->doSharedImageDescriptions();
} else {
	print "Creating static HTML dump in directory $dest. \n";
	$dbr = wfGetDB( DB_SLAVE );
	$server = $dbr->getProperty( 'mServer' );
	print "Using database {$server}\n";

	if ( !isset( $options['e'] ) ) {
		$wgHTMLDump->doEverything();
	} else {
		$wgHTMLDump->doArticles();
	}
}

if ( isset( $options['debug'] ) ) {
	#print_r($GLOBALS);
	# Workaround for bug #36957
	$globals = array_keys( $GLOBALS );
	#sort( $globals );
	$sizes = array();
	foreach ( $globals as $name ) {
		 $sizes[$name] = strlen( serialize( $GLOBALS[$name] ) );
	}
	arsort($sizes);
	$sizes = array_slice( $sizes, 0, 20 );
	foreach ( $sizes as $name => $size ) {
		printf( "%9d %s\n", $size, $name );
	}
}

if ( $profiling ) {
	echo $wgProfiler->getOutput();
}