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