185 $this->setNamespacePriorities();
186 $this->url_limit = 50000;
187 $this->size_limit = ( 2 ** 20 ) * 10;
189 # Create directory if needed
192 $this->
fatalError(
"Can not create directory $fspath." );
195 $dbDomain = WikiMap::getCurrentWikiDbDomain()->getId();
196 $this->fspath = realpath(
$fspath ) . DIRECTORY_SEPARATOR;
197 $this->urlpath = $this->
getOption(
'urlpath',
"" );
198 if ( $this->urlpath !==
"" && substr( $this->urlpath, -1 ) !==
'/' ) {
199 $this->urlpath .=
'/';
201 $this->identifier = $this->
getOption(
'identifier', $dbDomain );
202 $this->compress = $this->
getOption(
'compress',
'yes' ) !==
'no';
203 $this->skipRedirects = $this->
hasOption(
'skip-redirects' );
205 $this->generateNamespaces();
207 $encIdentifier = rawurlencode( $this->identifier );
208 $this->findex = fopen(
"{$this->fspath}sitemap-index-{$encIdentifier}.xml",
'wb' );
340 $services = MediaWikiServices::getInstance();
341 $contLang = $services->getContentLanguage();
342 $langConverter = $services->getLanguageConverterFactory()->getLanguageConverter( $contLang );
344 fwrite( $this->findex, $this->openIndex() );
346 foreach ( $this->namespaces as $namespace ) {
347 $res = $this->getPageRes( $namespace );
349 $this->generateLimit( $namespace );
350 $length = $this->limit[0];
353 $fns = $contLang->getFormattedNsText( $namespace );
354 $this->
output(
"$namespace ($fns)\n" );
355 $skippedRedirects = 0;
357 foreach (
$res as $row ) {
358 if ( $row->pp_propname ===
'noindex' ) {
363 if ( $this->skipRedirects && $row->page_is_redirect ) {
369 || $i === $this->url_limit + 1
370 || $length + $this->limit[1] + $this->limit[2] > $this->size_limit
372 if ( $this->file !==
false ) {
373 $this->write( $this->file, $this->closeFile() );
374 $this->close( $this->file );
376 $filename = $this->sitemapFilename( $namespace, $smcount++ );
377 $this->file = $this->open( $this->fspath . $filename,
'wb' );
378 $this->write( $this->file, $this->openFile() );
379 fwrite( $this->findex, $this->indexEntry( $filename ) );
380 $this->
output(
"\t$this->fspath$filename\n" );
381 $length = $this->limit[0];
384 $title = Title::makeTitle( $row->page_namespace, $row->page_title );
385 $date =
wfTimestamp( TS_ISO_8601, $row->page_touched );
386 $entry = $this->fileEntry(
$title->getCanonicalURL(), $date, $this->priority( $namespace ) );
387 $length += strlen( $entry );
388 $this->write( $this->file, $entry );
390 if ( $langConverter->hasVariants() ) {
391 $variants = $langConverter->getVariants();
392 foreach ( $variants as $vCode ) {
393 if ( $vCode == $contLang->getCode() ) {
396 $entry = $this->fileEntry(
397 $title->getCanonicalURL(
'', $vCode ),
399 $this->priority( $namespace )
401 $length += strlen( $entry );
402 $this->write( $this->file, $entry );
407 if ( $skippedNoindex > 0 ) {
408 $this->
output(
" skipped $skippedNoindex page(s) with __NOINDEX__ switch\n" );
411 if ( $this->skipRedirects && $skippedRedirects > 0 ) {
412 $this->
output(
" skipped $skippedRedirects redirect(s)\n" );
416 $this->write( $this->file, $this->closeFile() );
417 $this->close( $this->file );
420 fwrite( $this->findex, $this->closeIndex() );
421 fclose( $this->findex );