193 $this->setNamespacePriorities();
194 $this->url_limit = 50000;
195 $this->size_limit = ( 2 ** 20 ) * 10;
197 # Create directory if needed
200 $this->
fatalError(
"Can not create directory $fspath." );
203 $dbDomain = WikiMap::getCurrentWikiDbDomain()->getId();
204 $this->fspath = realpath(
$fspath ) . DIRECTORY_SEPARATOR;
205 $this->urlpath = $this->
getOption(
'urlpath',
"" );
206 if ( $this->urlpath !==
"" && substr( $this->urlpath, -1 ) !==
'/' ) {
207 $this->urlpath .=
'/';
209 $this->identifier = $this->
getOption(
'identifier', $dbDomain );
210 $this->compress = $this->
getOption(
'compress',
'yes' ) !==
'no';
211 $this->skipRedirects = $this->
hasOption(
'skip-redirects' );
213 $this->generateNamespaces();
215 $encIdentifier = rawurlencode( $this->identifier );
216 $this->findex = fopen(
"{$this->fspath}sitemap-index-{$encIdentifier}.xml",
'wb' );
338 $contLang = $services->getContentLanguage();
339 $langConverter = $services->getLanguageConverterFactory()->getLanguageConverter( $contLang );
340 $serverUrl = $services->getUrlUtils()->getServer(
PROTO_CANONICAL ) ??
'';
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, $serverUrl ) );
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( [
'variant' => $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 );