29require_once __DIR__ .
'/Maintenance.php';
144 parent::__construct();
148 'The file system path to save to, e.g. /tmp/sitemap; defaults to current directory',
154 'The URL path corresponding to --fspath, prepended to filenames in the index; '
155 .
'defaults to an empty string',
161 'Compress the sitemap files, can take value yes|no, default yes',
165 $this->
addOption(
'skip-redirects',
'Do not include redirecting articles in the sitemap' );
168 'What site identifier to use for the wiki, defaults to $wgDBname',
179 $this->url_limit = 50000;
180 $this->size_limit = pow( 2, 20 ) * 10;
182 # Create directory if needed
185 $this->
error(
"Can not create directory $fspath.", 1 );
188 $this->fspath = realpath(
$fspath ) . DIRECTORY_SEPARATOR;
189 $this->urlpath = $this->
getOption(
'urlpath',
"" );
190 if ( $this->urlpath !==
"" && substr( $this->urlpath, -1 ) !==
'/' ) {
191 $this->urlpath .=
'/';
194 $this->compress = $this->
getOption(
'compress',
'yes' ) !==
'no';
195 $this->skipRedirects = $this->
hasOption(
'skip-redirects' );
199 $this->findex = fopen(
"{$this->fspath}sitemap-index-{$this->identifier}.xml",
'wb' );
211 $this->priorities[
NS_MAIN] =
'1.0';
212 $this->priorities[
NS_TALK] =
'0.1';
213 $this->priorities[
NS_USER] =
'0.5';
217 $this->priorities[
NS_FILE] =
'0.5';
223 $this->priorities[
NS_HELP] =
'0.5';
234 $float = floatval( $priority );
235 if ( $float > 1.0 ) {
237 } elseif ( $float < 0.0 ) {
240 $this->priorities[$namespace] = $priority;
257 $res = $this->dbr->select(
'page',
258 [
'page_namespace' ],
262 'GROUP BY' =>
'page_namespace',
263 'ORDER BY' =>
'page_namespace',
267 foreach (
$res as $row ) {
279 return isset( $this->priorities[$namespace] )
280 ? $this->priorities[$namespace]
293 return MWNamespace::isSubject( $namespace )
305 return $this->dbr->select(
'page',
312 [
'page_namespace' => $namespace ],
323 fwrite( $this->findex, $this->
openIndex() );
329 $length = $this->limit[0];
332 $fns =
$wgContLang->getFormattedNsText( $namespace );
333 $this->
output(
"$namespace ($fns)\n" );
334 $skippedRedirects = 0;
335 foreach (
$res as $row ) {
336 if ( $this->skipRedirects && $row->page_is_redirect ) {
342 || $i === $this->url_limit + 1
343 || $length + $this->limit[1] + $this->limit[2] > $this->size_limit
345 if ( $this->file !==
false ) {
347 $this->
close( $this->file );
350 $this->file = $this->
open( $this->fspath . $filename,
'wb' );
352 fwrite( $this->findex, $this->
indexEntry( $filename ) );
353 $this->
output(
"\t$this->fspath$filename\n" );
354 $length = $this->limit[0];
357 $title = Title::makeTitle( $row->page_namespace, $row->page_title );
358 $date =
wfTimestamp( TS_ISO_8601, $row->page_touched );
359 $entry = $this->
fileEntry( $title->getCanonicalURL(), $date, $this->priority( $namespace ) );
360 $length += strlen( $entry );
361 $this->
write( $this->file, $entry );
365 foreach ( $variants as $vCode ) {
370 $title->getCanonicalURL(
'', $vCode ),
372 $this->priority( $namespace )
374 $length += strlen( $entry );
375 $this->
write( $this->file, $entry );
380 if ( $this->skipRedirects && $skippedRedirects > 0 ) {
381 $this->
output(
" skipped $skippedRedirects redirect(s)\n" );
386 $this->
close( $this->file );
390 fclose( $this->findex );
401 $resource = $this->compress ? gzopen( $file,
$flags ) : fopen( $file,
$flags );
402 if ( $resource ===
false ) {
404 .
" error opening file $file with flags $flags. Check permissions?" );
417 if ( $handle ===
true || $handle ===
false ) {
418 throw new MWException( __METHOD__ .
" was passed a boolean as a file handle.\n" );
420 if ( $this->compress ) {
421 gzwrite( $handle, $str );
423 fwrite( $handle, $str );
433 if ( $this->compress ) {
448 $ext = $this->compress ?
'.gz' :
'';
450 return "sitemap-{$this->identifier}-NS_$namespace-$count.xml$ext";
459 return '<?xml version="1.0" encoding="UTF-8"?>' .
"\n";
468 return 'http://www.sitemaps.org/schemas/sitemap/0.9';
477 return $this->
xmlHead() .
'<sitemapindex xmlns="' . $this->
xmlSchema() .
'">' .
"\n";
489 "\t\t<loc>{$this->urlpath}$filename</loc>\n" .
490 "\t\t<lastmod>{$this->timestamp}</lastmod>\n" .
500 return "</sitemapindex>\n";
509 return $this->
xmlHead() .
'<urlset xmlns="' . $this->
xmlSchema() .
'">' .
"\n";
524 "\t\t<loc>" . htmlspecialchars( $url ) .
"</loc>\n" .
525 "\t\t<lastmod>$date</lastmod>\n" .
526 "\t\t<priority>$priority</priority>\n" .
536 return "</urlset>\n";
546 $title = Title::makeTitle( $namespace, str_repeat(
"\xf0\xa8\xae\x81", 63 ) .
"\xe5\x96\x83" );
551 $title->getCanonicalURL(),
to move a page</td >< td > &*You are moving the page across namespaces
$wgSitemapNamespaces
Array of namespaces to generate a Google sitemap for when the maintenance/generateSitemap....
$wgSitemapNamespacesPriorities
Custom namespace priorities for sitemaps.
wfTimestampNow()
Convenience function; returns MediaWiki timestamp for the present time.
wfMkdirParents( $dir, $mode=null, $caller=null)
Make directory, and make all parent directories if they don't exist.
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
wfWikiID()
Get an ASCII string identifying this wiki This is used as a prefix in memcached keys.
Maintenance script that generates a sitemap for the site.
generateLimit( $namespace)
Populate $this->limit.
string $timestamp
When this sitemap batch was generated.
xmlSchema()
Return the XML schema being used.
indexEntry( $filename)
Return the XML for a single sitemap indexfile entry.
close(&$handle)
gzclose() / fclose() wrapper
generateNamespaces()
Generate a one-dimensional array of existing namespaces.
closeFile()
Return the XML required to close sitemap file.
string $identifier
Identifier to use in filenames, default $wgDBname.
string $fspath
The path to prepend to the filename.
closeIndex()
Return the XML required to close a sitemap index file.
write(&$handle, $str)
gzwrite() / fwrite() wrapper
array $priorities
Key => value entries of namespaces and their priorities.
bool $skipRedirects
Whether or not to include redirection pages.
__construct()
Default constructor.
array $limit
The number of entries to save in each sitemap file.
open( $file, $flags)
gzopen() / fopen() wrapper
int $size_limit
The maximum size of a sitemap file.
xmlHead()
Return the XML required to open an XML file.
getPageRes( $namespace)
Return a database resolution of all the pages in a given namespace.
priority( $namespace)
Get the priority of a given namespace.
bool $compress
Whether or not to use compression.
array $namespaces
A one-dimensional array of namespaces in the wiki.
string $urlpath
The URL path to prepend to filenames in the index; should resolve to the same directory as $fspath.
guessPriority( $namespace)
If the namespace isn't listed on the priority list return the default priority for the namespace,...
resource $findex
A resource pointing to the sitemap index file.
int $url_limit
The maximum amount of urls in a sitemap file.
fileEntry( $url, $date, $priority)
Return the XML for a single sitemap entry.
openFile()
Return the XML required to open a sitemap file.
object $dbr
A database replica DB object.
resource $file
A resource pointing to a sitemap file.
sitemapFilename( $namespace, $count)
Get a sitemap filename.
openIndex()
Return the XML required to open a sitemap index file.
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
getDB( $db, $groups=[], $wiki=false)
Returns a database to be used by current maintenance script.
hasOption( $name)
Checks to see if a particular param exists.
addDescription( $text)
Set the description text.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
getOption( $name, $default=null)
Get an option, or return the default.
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
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at etc Handles the details of getting and saving to the user table of the and dealing with sessions and cookies OutputPage Encapsulates the entire HTML page that will be sent in response to any server request It is used by calling its functions to add in any and then calling output() to send it all. It could be easily changed to send incrementally if that becomes useful
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults error
it s the revision text itself In either if gzip is the revision text is gzipped $flags
require_once RUN_MAINTENANCE_IF_MAIN