X-Git-Url: https://git.cyclocoop.org/?a=blobdiff_plain;f=maintenance%2FgenerateSitemap.php;h=12711ea3ff389acaa9e3f7a4aa47a55c851960e6;hb=865f4f8d6b22d166039f6721bbfe098309594aff;hp=b5681c186af3d2712c5d6ae8b80419fc73c15ce3;hpb=1d00b757fc894d93624cd53121aa274118f17cb2;p=lhc%2Fweb%2Fwiklou.git diff --git a/maintenance/generateSitemap.php b/maintenance/generateSitemap.php index b5681c186a..12711ea3ff 100644 --- a/maintenance/generateSitemap.php +++ b/maintenance/generateSitemap.php @@ -181,7 +181,14 @@ class GenerateSitemap extends Maintenance { $this->setNamespacePriorities(); $this->url_limit = 50000; $this->size_limit = pow( 2, 20 ) * 10; - $this->fspath = self::init_path( $this->getOption( 'fspath', getcwd() ) ); + + # Create directory if needed + $fspath = $this->getOption( 'fspath', getcwd() ); + if ( !wfMkdirParents( $fspath, null, __METHOD__ ) ) { + $this->error( "Can not create directory $fspath.", 1 ); + } + + $this->fspath = realpath( $fspath ) . DIRECTORY_SEPARATOR; $this->urlpath = $this->getOption( 'urlpath', "" ); if ( $this->urlpath !== "" && substr( $this->urlpath, -1 ) !== '/' ) { $this->urlpath .= '/'; @@ -238,23 +245,6 @@ class GenerateSitemap extends Maintenance { } } - /** - * Create directory if it does not exist and return pathname with a trailing slash - * @param string $fspath - * @return null|string - */ - private static function init_path( $fspath ) { - if ( !isset( $fspath ) ) { - return null; - } - # Create directory if needed - if ( $fspath && !is_dir( $fspath ) ) { - wfMkdirParents( $fspath, null, __METHOD__ ) or die( "Can not create directory $fspath.\n" ); - } - - return realpath( $fspath ) . DIRECTORY_SEPARATOR; - } - /** * Generate a one-dimensional array of existing namespaces */ @@ -263,6 +253,7 @@ class GenerateSitemap extends Maintenance { global $wgSitemapNamespaces; if ( is_array( $wgSitemapNamespaces ) ) { $this->namespaces = $wgSitemapNamespaces; + return; } @@ -343,7 +334,7 @@ class GenerateSitemap extends Maintenance { $fns = $wgContLang->getFormattedNsText( $namespace ); $this->output( "$namespace ($fns)\n" ); - $skippedRedirects = 0; // Number of redirects skipped for that namespace + $skippedRedirects = 0; // Number of redirects skipped for that namespace foreach ( $res as $row ) { if ( $this->skipRedirects && $row->page_is_redirect ) { $skippedRedirects++; @@ -415,6 +406,7 @@ class GenerateSitemap extends Maintenance { throw new MWException( __METHOD__ . " error opening file $file with flags $flags. Check permissions?" ); } + return $resource; } @@ -457,6 +449,7 @@ class GenerateSitemap extends Maintenance { */ function sitemapFilename( $namespace, $count ) { $ext = $this->compress ? '.gz' : ''; + return "sitemap-{$this->identifier}-NS_$namespace-$count.xml$ext"; }