183 $this->setNamespacePriorities();
184 $this->url_limit = 50000;
185 $this->size_limit = ( 2 ** 20 ) * 10;
187 # Create directory if needed
190 $this->
fatalError(
"Can not create directory $fspath." );
193 $dbDomain = WikiMap::getCurrentWikiDbDomain()->getId();
194 $this->fspath = realpath(
$fspath ) . DIRECTORY_SEPARATOR;
195 $this->urlpath = $this->
getOption(
'urlpath',
"" );
196 if ( $this->urlpath !==
"" && substr( $this->urlpath, -1 ) !==
'/' ) {
197 $this->urlpath .=
'/';
199 $this->identifier = $this->
getOption(
'identifier', $dbDomain );
200 $this->compress = $this->
getOption(
'compress',
'yes' ) !==
'no';
201 $this->skipRedirects = $this->
hasOption(
'skip-redirects' );
203 $this->generateNamespaces();
205 $encIdentifier = rawurlencode( $this->identifier );
206 $this->findex = fopen(
"{$this->fspath}sitemap-index-{$encIdentifier}.xml",
'wb' );
338 $services = MediaWikiServices::getInstance();
339 $contLang = $services->getContentLanguage();
340 $langConverter = $services->getLanguageConverterFactory()->getLanguageConverter( $contLang );
342 fwrite( $this->findex, $this->openIndex() );
344 foreach ( $this->namespaces as $namespace ) {
345 $res = $this->getPageRes( $namespace );
347 $this->generateLimit( $namespace );
348 $length = $this->limit[0];
351 $fns = $contLang->getFormattedNsText( $namespace );
352 $this->
output(
"$namespace ($fns)\n" );
353 $skippedRedirects = 0;
355 foreach (
$res as $row ) {
356 if ( $row->pp_propname ===
'noindex' ) {
361 if ( $this->skipRedirects && $row->page_is_redirect ) {
367 || $i === $this->url_limit + 1
368 || $length + $this->limit[1] + $this->limit[2] > $this->size_limit
370 if ( $this->file !==
false ) {
371 $this->write( $this->file, $this->closeFile() );
372 $this->close( $this->file );
374 $filename = $this->sitemapFilename( $namespace, $smcount++ );
375 $this->file = $this->open( $this->fspath . $filename,
'wb' );
376 $this->write( $this->file, $this->openFile() );
377 fwrite( $this->findex, $this->indexEntry( $filename ) );
378 $this->
output(
"\t$this->fspath$filename\n" );
379 $length = $this->limit[0];
382 $title = Title::makeTitle( $row->page_namespace, $row->page_title );
383 $date =
wfTimestamp( TS_ISO_8601, $row->page_touched );
384 $entry = $this->fileEntry(
$title->getCanonicalURL(), $date, $this->priority( $namespace ) );
385 $length += strlen( $entry );
386 $this->write( $this->file, $entry );
388 if ( $langConverter->hasVariants() ) {
389 $variants = $langConverter->getVariants();
390 foreach ( $variants as $vCode ) {
391 if ( $vCode == $contLang->getCode() ) {
394 $entry = $this->fileEntry(
395 $title->getCanonicalURL(
'', $vCode ),
397 $this->priority( $namespace )
399 $length += strlen( $entry );
400 $this->write( $this->file, $entry );
405 if ( $skippedNoindex > 0 ) {
406 $this->
output(
" skipped $skippedNoindex page(s) with __NOINDEX__ switch\n" );
409 if ( $this->skipRedirects && $skippedRedirects > 0 ) {
410 $this->
output(
" skipped $skippedRedirects redirect(s)\n" );
414 $this->write( $this->file, $this->closeFile() );
415 $this->close( $this->file );
418 fwrite( $this->findex, $this->closeIndex() );
419 fclose( $this->findex );