* (bug 1938) Fix normalization of character references in link text and
[mediawiki.git] / maintenance / dumpHTML.inc
blob7c145a9cdae68a5014cf24555b9055a7b82c8e43
1 <?php
3 define( 'REPORTING_INTERVAL', 10 );
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( 'cur', 'max(cur_id)', false );
16         
17         /*global $wgValidSkinNames;
18         var_dump( $wgValidSkinNames );
19         exit;*/
21         print("Creating static HTML dump. Starting from cur_id $start of $end.\n");
23         $wgUser = new User;
24         $wgUser->setOption( 'skin', 'htmldump' );
25         $sk =& $wgUser->getSkin();
26         
27         if ( !is_dir( $dest ) ) {
28                 if ( !mkdir( $dest, 0644 ) ) {
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                 }
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                 );
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";
81                 
82                 if ( !is_dir( $parentDir ) ) {
83                         if ( !mkdir( $parentDir, 0644 ) ) {
84                                 print("Can't write to directory $parentDir\n");
85                                 return;
86                         }
87                 }
88                 if ( !is_dir( $fullDir ) ) {
89                         if ( !mkdir( $fullDir, 0644 ) ) {
90                                 print("Can't write to directory $fullDir\n");
91                                 return;
92                         }
93                 }
94                 
95                 $file = fopen( $fullName, 'w' );
96                 if ( !$file ) {
97                         print("Can't open file $fullName for writing\n");
98                         return;
99                 }
100                 
101                 fwrite( $file, $text );
102                 fclose( $file );
103         }
104 }       
106 # vim: syn=php