* Parent message altered, purging old translations
[lhc/web/wiklou.git] / maintenance / generateSitemap.php
1 <?php
2 /**
3 * @package MediaWiki
4 * @subpackage Maintenance
5 *
6 * Creates a Google sitemap.
7 * https://www.google.com/webmasters/sitemaps/docs/en/about.html
8 */
9
10 # Copyright (C) 2005 Jens Frank <jeluf@gmx.de>, Brion Vibber <brion@pobox.com>
11 # http://www.mediawiki.org/
12 #
13 # This program is free software; you can redistribute it and/or modify
14 # it under the terms of the GNU General Public License as published by
15 # the Free Software Foundation; either version 2 of the License, or
16 # (at your option) any later version.
17 #
18 # This program is distributed in the hope that it will be useful,
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 # GNU General Public License for more details.
22 #
23 # You should have received a copy of the GNU General Public License along
24 # with this program; if not, write to the Free Software Foundation, Inc.,
25 # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26 # http://www.gnu.org/copyleft/gpl.html
27
28 if ( $argc < 2) {
29 print "Usage: php generateSitemap.php servername [options]\n";
30 print " servername is the name of the website, e.g. mywiki.mydomain.org\n";
31 exit ;
32 }
33 $_SERVER['HOSTNAME'] = $argv[1];
34 print $argv[1] . "\n";
35
36
37 /** */
38 require_once( "commandLine.inc" );
39 print "DB name: $wgDBname\n";
40 print "DB user: $wgDBuser\n";
41 # print "DB password: $wgDBpassword\n";
42
43
44 $priorities = array (
45 NS_MAIN => 0.9,
46 NS_TALK => 0.4,
47 NS_USER => 0.3,
48 NS_USER_TALK => 0.3,
49 NS_PROJECT => 0.5,
50 NS_PROJECT_TALK => 0.2,
51 NS_IMAGE => 0.2,
52 NS_IMAGE_TALK => 0.1,
53 NS_MEDIAWIKI => 0.1,
54 NS_MEDIAWIKI_TALK => 0.1,
55 NS_TEMPLATE => 0.1,
56 NS_TEMPLATE_TALK => 0.1,
57 NS_HELP => 0.3,
58 NS_HELP_TALK => 0.1,
59 NS_CATEGORY => 0.3,
60 NS_CATEGORY_TALK => 0.1,
61 );
62
63 $dbr =& wfGetDB( DB_SLAVE );
64 $page = $dbr->tableName( 'page' );
65 $rev = $dbr->tableName( 'revision' );
66
67 $findex = fopen( "sitemap_index.xml", "wb" );
68 fwrite( $findex, '<?xml version="1.0" encoding="UTF-8"?>
69 <sitemapindex xmlns="http://www.google.com/schemas/sitemap/0.84">
70 ' );
71
72 foreach ( $priorities as $ns => $priority) {
73 $sql = "SELECT page_namespace,page_title,page_is_redirect,rev_timestamp FROM $page, $rev ".
74 "WHERE page_namespace = $ns AND page_latest = rev_id ";
75 print "DB query : $sql\nprocessing ...";
76 $res = $dbr->query( $sql );
77 print " done\n";
78
79 $gzfile = false;
80 $rowcount=0;
81 $sitemapcount=0;
82 while ( $row = $dbr->fetchObject( $res ) ) {
83 if ( $rowcount % 9000 == 0 ) {
84 if ( $gzfile !== false ) {
85 gzwrite( $gzfile, '</urlset>' );
86 gzclose( $gzfile );
87 }
88 $sitemapcount ++;
89 $fname = "sitemap-NS".$ns."-".$sitemapcount.".xml.gz";
90 $gzfile = gzopen( $fname, "wb" );
91 gzwrite( $gzfile, '<?xml version="1.0" encoding="UTF-8"?>
92 < urlset xmlns="http://www.google.com/schemas/sitemap/0.84">' );
93 fwrite( $findex, '<sitemap><loc>'.$wgServer.'/'.$fname."</loc></sitemap>\n" );
94 print "$fname\n";
95 }
96 $rowcount ++;
97 $nt = Title::makeTitle( $row->page_namespace, $row->page_title );
98 $date = substr($row->rev_timestamp, 0, 4). '-' .
99 substr($row->rev_timestamp, 4, 2). '-' .
100 substr($row->rev_timestamp, 6, 2);
101 gzwrite( $gzfile, "<url>\n <loc>" . $nt->getFullURL() .
102 "</loc>\n <lastmod>".$date."</lastmod>\n " .
103 '<priority>' . $priority . '</priority>' .
104 "\n</url>\n" );
105 }
106 if ( $gzfile ) {
107 gzwrite( $gzfile, "</urlset>\n" );
108 gzclose( $gzfile );
109 }
110 print "\n";
111 }
112 fwrite( $findex, "</sitemapindex>\n" );
113 fclose( $findex );
114
115
116 ?>