From: Antoine Musso Date: Sat, 19 Jul 2008 12:53:59 +0000 (+0000) Subject: Fix #12441 : generateSitemap.php --fspath parameter required a trailing slash X-Git-Tag: 1.31.0-rc.0~46446 X-Git-Url: https://git.cyclocoop.org/%28%28?a=commitdiff_plain;h=1095879e3b0a32ab5ea1d462033456edc53583d0;p=lhc%2Fweb%2Fwiklou.git Fix #12441 : generateSitemap.php --fspath parameter required a trailing slash --- diff --git a/RELEASE-NOTES b/RELEASE-NOTES index ae5c03f343..bc8aa4655b 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -441,6 +441,8 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN its existance. * Accesskeys for minor edit/watch checkboxes on edit now work in Firefox 3 * (bug 12384) Comments in maintenance/*php +* (bug 12441) ./maintenance/generateSitemap.php fix -fspath requiring + a trailing slash. === API changes in 1.13 === diff --git a/maintenance/generateSitemap.php b/maintenance/generateSitemap.php index 0405868969..cc3f523a9a 100644 --- a/maintenance/generateSitemap.php +++ b/maintenance/generateSitemap.php @@ -148,16 +148,34 @@ class GenerateSitemap { $this->url_limit = 50000; $this->size_limit = pow( 2, 20 ) * 10; - $this->fspath = isset( $fspath ) ? $fspath : ''; + $this->fspath = self::init_path( $fspath ); + $this->compress = $compress; $this->stderr = fopen( 'php://stderr', 'wt' ); $this->dbr = wfGetDB( DB_SLAVE ); $this->generateNamespaces(); $this->timestamp = wfTimestamp( TS_ISO_8601, wfTimestampNow() ); + + $this->findex = fopen( "{$this->fspath}sitemap-index-" . wfWikiID() . ".xml", 'wb' ); } + /** + * Create directory if it does not exist and return pathname with a trailing slash + */ + private static function init_path( $fspath ) { + if( !isset( $fspath ) ) { + return null; + } + # Create directory if needed + if( $fspath && !is_dir( $fspath ) ) { + mkdir( $fspath, 0755 ) or die("Can not create directory $fspath.\n"); + } + + return realpath( $fspath ). DIRECTORY_SEPARATOR ; + } + /** * Generate a one-dimensional array of existing namespaces */ @@ -260,7 +278,7 @@ class GenerateSitemap { $this->file = $this->open( $this->fspath . $filename, 'wb' ); $this->write( $this->file, $this->openFile() ); fwrite( $this->findex, $this->indexEntry( $filename ) ); - $this->debug( "\t$filename" ); + $this->debug( "\t$this->fspath$filename" ); $length = $this->limit[0]; $i = 1; } @@ -457,7 +475,7 @@ if ( in_array( '--help', $argv ) ) { Usage: php generateSitemap.php [options] --help show this message - --fspath= The file system path to save to, e.g /tmp/sitemap/ + --fspath= The file system path to save to, e.g /tmp/sitemap --server= The protocol and server name to use in URLs, e.g. http://en.wikipedia.org. This is sometimes necessary because