4 * @subpackage Maintenance
6 * Creates a Google sitemap.
7 * https://www.google.com/webmasters/sitemaps/docs/en/about.html
10 # Copyright (C) 2005 Jens Frank <jeluf@gmx.de>, Brion Vibber <brion@pobox.com>
11 # http://www.mediawiki.org/
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.
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.
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
29 print "Usage: php generateSitemap.php servername [options]\n";
30 print " servername is the name of the website, e.g. mywiki.mydomain.org\n";
33 $_SERVER['HOSTNAME'] = $argv[1];
34 print $argv[1] . "\n";
38 require_once( "commandLine.inc" );
39 print "DB name: $wgDBname\n";
40 print "DB user: $wgDBuser\n";
48 NS_PROJECT_TALK
=> 0.2,
52 NS_MEDIAWIKI_TALK
=> 0.1,
54 NS_TEMPLATE_TALK
=> 0.1,
58 NS_CATEGORY_TALK
=> 0.1,
61 $dbr =& wfGetDB( DB_SLAVE
);
62 $page = $dbr->tableName( 'page' );
63 $rev = $dbr->tableName( 'revision' );
65 $findex = fopen( "sitemap-index-$wgDBname.xml", "wb" );
66 fwrite( $findex, '<?xml version="1.0" encoding="UTF-8"?>
67 <sitemapindex xmlns="http://www.google.com/schemas/sitemap/0.84">
70 foreach ( $priorities as $ns => $priority) {
71 $sql = "SELECT page_namespace,page_title,page_is_redirect,rev_timestamp FROM $page, $rev ".
72 "WHERE page_namespace = $ns AND page_latest = rev_id ";
73 print "DB query : $sql\nprocessing ...";
74 $res = $dbr->query( $sql );
80 while ( $row = $dbr->fetchObject( $res ) ) {
81 if ( $rowcount %
9000 == 0 ) {
82 if ( $gzfile !== false ) {
83 gzwrite( $gzfile, '</urlset>' );
87 $fname = "sitemap-{$wgDBname}-NS{$ns}-{$sitemapcount}.xml.gz";
88 $gzfile = gzopen( $fname, "wb" );
89 gzwrite( $gzfile, '<?xml version="1.0" encoding="UTF-8"?>
90 < urlset xmlns="http://www.google.com/schemas/sitemap/0.84">' );
91 fwrite( $findex, '<sitemap><loc>'.$wgServer.'/'.$fname."</loc></sitemap>\n" );
95 $nt = Title
::makeTitle( $row->page_namespace
, $row->page_title
);
96 $date = substr($row->rev_timestamp
, 0, 4). '-' .
97 substr($row->rev_timestamp
, 4, 2). '-' .
98 substr($row->rev_timestamp
, 6, 2);
99 gzwrite( $gzfile, "<url>\n <loc>" . $nt->getFullURL() .
100 "</loc>\n <lastmod>".$date."</lastmod>\n " .
101 '<priority>' . $priority . '</priority>' .
105 gzwrite( $gzfile, "</urlset>\n" );
110 fwrite( $findex, "</sitemapindex>\n" );