184 $this->setNamespacePriorities();
185 $this->url_limit = 50000;
186 $this->size_limit = ( 2 ** 20 ) * 10;
188 # Create directory if needed
191 $this->
fatalError(
"Can not create directory $fspath." );
194 $dbDomain = WikiMap::getCurrentWikiDbDomain()->getId();
195 $this->fspath = realpath(
$fspath ) . DIRECTORY_SEPARATOR;
196 $this->urlpath = $this->
getOption(
'urlpath',
"" );
197 if ( $this->urlpath !==
"" && substr( $this->urlpath, -1 ) !==
'/' ) {
198 $this->urlpath .=
'/';
200 $this->identifier = $this->
getOption(
'identifier', $dbDomain );
201 $this->compress = $this->
getOption(
'compress',
'yes' ) !==
'no';
202 $this->skipRedirects = $this->
hasOption(
'skip-redirects' );
204 $this->generateNamespaces();
206 $encIdentifier = rawurlencode( $this->identifier );
207 $this->findex = fopen(
"{$this->fspath}sitemap-index-{$encIdentifier}.xml",
'wb' );
321 $contLang = $services->getContentLanguage();
322 $langConverter = $services->getLanguageConverterFactory()->getLanguageConverter( $contLang );
324 fwrite( $this->findex, $this->openIndex() );
326 foreach ( $this->namespaces as $namespace ) {
327 $res = $this->getPageRes( $namespace );
329 $this->generateLimit( $namespace );
330 $length = $this->limit[0];
333 $fns = $contLang->getFormattedNsText( $namespace );
334 $this->
output(
"$namespace ($fns)\n" );
335 $skippedRedirects = 0;
337 foreach ( $res as $row ) {
338 if ( $row->pp_propname ===
'noindex' ) {
343 if ( $this->skipRedirects && $row->page_is_redirect ) {
349 || $i === $this->url_limit + 1
350 || $length + $this->limit[1] + $this->limit[2] > $this->size_limit
352 if ( $this->file !==
false ) {
353 $this->write( $this->file, $this->closeFile() );
354 $this->close( $this->file );
356 $filename = $this->sitemapFilename( $namespace, $smcount++ );
357 $this->file = $this->open( $this->fspath . $filename,
'wb' );
358 $this->write( $this->file, $this->openFile() );
359 fwrite( $this->findex, $this->indexEntry( $filename ) );
360 $this->
output(
"\t$this->fspath$filename\n" );
361 $length = $this->limit[0];
364 $title = Title::makeTitle( $row->page_namespace, $row->page_title );
365 $date =
wfTimestamp( TS_ISO_8601, $row->page_touched );
366 $entry = $this->fileEntry( $title->getCanonicalURL(), $date, $this->priority( $namespace ) );
367 $length += strlen( $entry );
368 $this->write( $this->file, $entry );
370 if ( $langConverter->hasVariants() ) {
371 $variants = $langConverter->getVariants();
372 foreach ( $variants as $vCode ) {
373 if ( $vCode == $contLang->getCode() ) {
376 $entry = $this->fileEntry(
377 $title->getCanonicalURL( [
'variant' => $vCode ] ),
379 $this->priority( $namespace )
381 $length += strlen( $entry );
382 $this->write( $this->file, $entry );
387 if ( $skippedNoindex > 0 ) {
388 $this->
output(
" skipped $skippedNoindex page(s) with __NOINDEX__ switch\n" );
391 if ( $this->skipRedirects && $skippedRedirects > 0 ) {
392 $this->
output(
" skipped $skippedRedirects redirect(s)\n" );
396 $this->write( $this->file, $this->closeFile() );
397 $this->close( $this->file );
400 fwrite( $this->findex, $this->closeIndex() );
401 fclose( $this->findex );