* Changed 'cur' to 'page' which we use in 1.5
[lhc/web/wiklou.git] / maintenance / dumpHTML.inc
1 <?php
2
3 define( 'REPORTING_INTERVAL', 10 );
4
5 function dumpHTML( $dest, $start ) {
6 global $wgUser, $wgTitle, $wgArticle, $wgEnablePersistentLC, $wgLinkCache, $wgOut;
7 global $wgMakeDumpLinks, $wgStylePath, $wgArticlePath, $wgUploadPath, $wgLogo;
8 $wgMakeDumpLinks = true;
9 $wgScriptPath = "../../..";
10 $wgStylePath = "$wgScriptPath/skins";
11 $wgUploadPath = "$wgScriptPath/images";
12 $wgLogo = "$wgStylePath/common/images/wiki.png";
13 $wgArticlePath = '../../$1';
14 $dbr =& wfGetDB( DB_SLAVE );
15 $end = $dbr->selectField( 'page', 'max(page_id)', false );
16
17 /*global $wgValidSkinNames;
18 var_dump( $wgValidSkinNames );
19 exit;*/
20
21 print("Creating static HTML dump. Starting from page_id $start of $end.\n");
22
23 $wgUser = new User;
24 $wgUser->setOption( 'skin', 'htmldump' );
25 $sk =& $wgUser->getSkin();
26
27 if ( !is_dir( $dest ) ) {
28 if ( !mkdir( $dest, 0755 ) ) {
29 print("Can't make directory $dir, exiting\n");
30 return;
31 }
32 }
33
34 for ($id = $start; $id <= $end; $id++) {
35 if ( !($id % REPORTING_INTERVAL) ) {
36 print("$id\n");
37 }
38
39 $wgOut = new OutputPage;
40 $wgOut->setArticleFlag( true );
41 $wgOut->setRobotpolicy( 'index,follow' );
42
43 $wgTitle = Title::newFromID( $id );
44 if ( is_null( $wgTitle ) ) {
45 continue;
46 }
47
48 $wgArticle = new Article( $wgTitle );
49 $text = $wgArticle->getContent( true );
50 $wgLinkCache = new LinkCache;
51 $wgLinkCache->forUpdate( true );
52
53 global $wgLinkHolders;
54 $wgLinkHolders = array(
55 'namespaces' => array(),
56 'dbkeys' => array(),
57 'queries' => array(),
58 'texts' => array(),
59 'titles' => array()
60 );
61
62
63 # Parse the text and replace links with placeholders
64 $wgOut->setPageTitle( $wgTitle->getPrefixedText() );
65 $wgOut->addWikiText( $text );
66 $wgOut->transformBuffer();
67
68 # Execute skin to get complete HTML
69 ob_start();
70 $sk->outputPage( $wgOut );
71 $text = ob_get_contents();
72 ob_end_clean();
73
74 # Write to file
75 $fname = $wgTitle->getHashedFilename();
76 $bits = explode( '/', $fname );
77 $parentDir = "$dest/{$bits[0]}";
78 $fullDir = "$dest/{$bits[0]}/{$bits[1]}";
79 $fullName = "$dest/$fname";
80
81 if ( !is_dir( $parentDir ) ) {
82 if ( !mkdir( $parentDir, 0744 ) ) {
83 print("Can't write to directory $parentDir\n");
84 return;
85 }
86 }
87 if ( !is_dir( $fullDir ) ) {
88 if ( !mkdir( $fullDir, 0744 ) ) {
89 print("Can't write to directory $fullDir\n");
90 return;
91 }
92 }
93
94 $file = fopen( $fullName, 'w' );
95 if ( !$file ) {
96 print("Can't open file $fullName for writing\n");
97 return;
98 }
99
100 fwrite( $file, $text );
101 fclose( $file );
102 }
103 }
104
105 # vim: syn=php
106 ?>