29 require_once __DIR__ .
'/Maintenance.php';
147 parent::__construct();
151 'The file system path to save to, e.g. /tmp/sitemap; defaults to current directory',
157 'The URL path corresponding to --fspath, prepended to filenames in the index; '
158 .
'defaults to an empty string',
164 'Compress the sitemap files, can take value yes|no, default yes',
168 $this->
addOption(
'skip-redirects',
'Do not include redirecting articles in the sitemap' );
171 'What site identifier to use for the wiki, defaults to $wgDBname',
182 $this->url_limit = 50000;
183 $this->size_limit = pow( 2, 20 ) * 10;
185 # Create directory if needed
188 $this->
error(
"Can not create directory $fspath.", 1 );
191 $this->fspath = realpath(
$fspath ) . DIRECTORY_SEPARATOR;
192 $this->urlpath = $this->
getOption(
'urlpath',
"" );
193 if ( $this->urlpath !==
"" && substr( $this->urlpath, -1 ) !==
'/' ) {
194 $this->urlpath .=
'/';
197 $this->compress = $this->
getOption(
'compress',
'yes' ) !==
'no';
198 $this->skipRedirects = $this->
getOption(
'skip-redirects',
false ) !==
false;
202 $this->findex = fopen(
"{$this->fspath}sitemap-index-{$this->identifier}.xml",
'wb' );
207 global $wgSitemapNamespacesPriorities;
210 $this->priorities[self::GS_MAIN] =
'0.5';
212 $this->priorities[self::GS_TALK] =
'0.1';
214 $this->priorities[
NS_MAIN] =
'1.0';
215 $this->priorities[
NS_TALK] =
'0.1';
216 $this->priorities[
NS_USER] =
'0.5';
220 $this->priorities[
NS_FILE] =
'0.5';
226 $this->priorities[
NS_HELP] =
'0.5';
232 if ( $wgSitemapNamespacesPriorities !==
false ) {
236 foreach ( $wgSitemapNamespacesPriorities
as $namespace => $priority ) {
237 $float = floatval( $priority );
238 if ( $float > 1.0 ) {
240 } elseif ( $float < 0.0 ) {
243 $this->priorities[$namespace] = $priority;
253 global $wgSitemapNamespaces;
254 if ( is_array( $wgSitemapNamespaces ) ) {
260 $res = $this->dbr->select(
'page',
261 [
'page_namespace' ],
265 'GROUP BY' =>
'page_namespace',
266 'ORDER BY' =>
'page_namespace',
270 foreach (
$res as $row ) {
282 return isset( $this->priorities[$namespace] )
283 ? $this->priorities[$namespace]
297 ? $this->priorities[self::GS_MAIN]
298 : $this->priorities[self::GS_TALK];
308 return $this->dbr->select(
'page',
315 [
'page_namespace' => $namespace ],
326 fwrite( $this->findex, $this->
openIndex() );
332 $length = $this->limit[0];
335 $fns = $wgContLang->getFormattedNsText( $namespace );
336 $this->
output(
"$namespace ($fns)\n" );
337 $skippedRedirects = 0;
338 foreach (
$res as $row ) {
339 if ( $this->skipRedirects && $row->page_is_redirect ) {
345 || $i === $this->url_limit + 1
346 || $length + $this->limit[1] + $this->limit[2] > $this->size_limit
348 if ( $this->
file !==
false ) {
353 $this->
file = $this->
open( $this->fspath . $filename,
'wb' );
355 fwrite( $this->findex, $this->
indexEntry( $filename ) );
356 $this->
output(
"\t$this->fspath$filename\n" );
357 $length = $this->limit[0];
363 $length += strlen( $entry );
366 if ( $wgContLang->hasVariants() ) {
367 $variants = $wgContLang->getVariants();
368 foreach ( $variants
as $vCode ) {
369 if ( $vCode == $wgContLang->getCode() ) {
373 $title->getCanonicalURL(
'', $vCode ),
377 $length += strlen( $entry );
383 if ( $this->skipRedirects && $skippedRedirects > 0 ) {
384 $this->
output(
" skipped $skippedRedirects redirect(s)\n" );
393 fclose( $this->findex );
405 if ( $resource ===
false ) {
407 .
" error opening file $file with flags $flags. Check permissions?" );
420 if ( $handle ===
true || $handle ===
false ) {
421 throw new MWException( __METHOD__ .
" was passed a boolean as a file handle.\n" );
423 if ( $this->compress ) {
424 gzwrite( $handle, $str );
426 fwrite( $handle, $str );
436 if ( $this->compress ) {
451 $ext = $this->compress ?
'.gz' :
'';
453 return "sitemap-{$this->identifier}-NS_$namespace-$count.xml$ext";
462 return '<?xml version="1.0" encoding="UTF-8"?>' .
"\n";
471 return 'http://www.sitemaps.org/schemas/sitemap/0.9';
480 return $this->
xmlHead() .
'<sitemapindex xmlns="' . $this->
xmlSchema() .
'">' .
"\n";
492 "\t\t<loc>{$this->urlpath}$filename</loc>\n" .
493 "\t\t<lastmod>{$this->timestamp}</lastmod>\n" .
503 return "</sitemapindex>\n";
512 return $this->
xmlHead() .
'<urlset xmlns="' . $this->
xmlSchema() .
'">' .
"\n";
527 "\t\t<loc>" . htmlspecialchars( $url ) .
"</loc>\n" .
528 "\t\t<lastmod>$date</lastmod>\n" .
529 "\t\t<priority>$priority</priority>\n" .
539 return "</urlset>\n";
554 $title->getCanonicalURL(),
resource $findex
A resource pointing to the sitemap index file.
indexEntry($filename)
Return the XML for a single sitemap indexfile entry.
Maintenance script that generates a sitemap for the site.
to move a page</td >< td > &*You are moving the page across namespaces
array $namespaces
A one-dimensional array of namespaces in the wiki.
array $limit
The number of entries to save in each sitemap file.
wfMkdirParents($dir, $mode=null, $caller=null)
Make directory, and make all parent directories if they don't exist.
write(&$handle, $str)
gzwrite() / fwrite() wrapper
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
generateNamespaces()
Generate a one-dimensional array of existing namespaces.
getDB($db, $groups=[], $wiki=false)
Returns a database to be used by current maintenance script.
it s the revision text itself In either if gzip is the revision text is gzipped $flags
string $identifier
Identifier to use in filenames, default $wgDBname.
array $priorities
Key => value entries of namespaces and their priorities.
xmlHead()
Return the XML required to open an XML file.
require_once RUN_MAINTENANCE_IF_MAIN
guessPriority($namespace)
If the namespace isn't listed on the priority list return the default priority for the namespace...
when a variable name is used in a it is silently declared as a new local masking the global
const TS_ISO_8601
ISO 8601 format with no timezone: 1986-02-09T20:00:00Z.
__construct()
Constructor.
bool $compress
Whether or not to use compression.
closeFile()
Return the XML required to close sitemap file.
bool $skipRedirects
Whether or not to include redirection pages.
wfTimestamp($outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
addOption($name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
We ve cleaned up the code here by removing clumps of infrequently used code and moving them off somewhere else It s much easier for someone working with this code to see what s _really_ going and make changes or fix bugs In we can take all the code that deals with the little used title reversing we can concentrate it all in an extension file
int $url_limit
The maximum amount of urls in a sitemap file.
close(&$handle)
gzclose() / fclose() wrapper
closeIndex()
Return the XML required to close a sitemap index file.
openIndex()
Return the XML required to open a sitemap index file.
wfTimestampNow()
Convenience function; returns MediaWiki timestamp for the present time.
namespace and then decline to actually register it file or subcat img or subcat $title
wfWikiID()
Get an ASCII string identifying this wiki This is used as a prefix in memcached keys.
addDescription($text)
Set the description text.
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
getOption($name, $default=null)
Get an option, or return the default.
output($out, $channel=null)
Throw some output to the user.
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
static isSubject($index)
Is the given namespace is a subject (non-talk) namespace?
int $size_limit
The maximum size of a sitemap file.
object $dbr
A database replica DB object.
generateLimit($namespace)
Populate $this->limit.
error($err, $die=0)
Throw an error to the user.
this class mediates it Skin Encapsulates a look and feel for the wiki All of the functions that render HTML and make choices about how to render it are here and are called from various other places when and is meant to be subclassed with other skins that may override some of its functions The User object contains a reference to a and so rather than having a global skin object we just rely on the global User and get the skin with $wgUser and also has some character encoding functions and other locale stuff The current user interface language is instantiated as and the local content language as $wgContLang
string $fspath
The path to prepend to the filename.
getPageRes($namespace)
Return a database resolution of all the pages in a given namespace.
xmlSchema()
Return the XML schema being used.
string $urlpath
The URL path to prepend to filenames in the index; should resolve to the same directory as $fspath...
open($file, $flags)
gzopen() / fopen() wrapper
resource $file
A resource pointing to a sitemap file.
fileEntry($url, $date, $priority)
Return the XML for a single sitemap entry.
priority($namespace)
Get the priority of a given namespace.
static makeTitle($ns, $title, $fragment= '', $interwiki= '')
Create a new Title from a namespace index and a DB key.
openFile()
Return the XML required to open a sitemap file.
sitemapFilename($namespace, $count)
Get a sitemap filename.
string $timestamp
When this sitemap batch was generated.