diff options
author | Pierre Schmitz <pierre@archlinux.de> | 2013-12-08 09:55:49 +0100 |
---|---|---|
committer | Pierre Schmitz <pierre@archlinux.de> | 2013-12-08 09:55:49 +0100 |
commit | 4ac9fa081a7c045f6a9f1cfc529d82423f485b2e (patch) | |
tree | af68743f2f4a47d13f2b0eb05f5c4aaf86d8ea37 /maintenance/generateSitemap.php | |
parent | af4da56f1ad4d3ef7b06557bae365da2ea27a897 (diff) |
Update to MediaWiki 1.22.0
Diffstat (limited to 'maintenance/generateSitemap.php')
-rw-r--r-- | maintenance/generateSitemap.php | 40 |
1 files changed, 23 insertions, 17 deletions
diff --git a/maintenance/generateSitemap.php b/maintenance/generateSitemap.php index adea97ea..0b21a1fe 100644 --- a/maintenance/generateSitemap.php +++ b/maintenance/generateSitemap.php @@ -26,7 +26,7 @@ * @see http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd */ -require_once( __DIR__ . '/Maintenance.php' ); +require_once __DIR__ . '/Maintenance.php'; /** * Maintenance script that generates a sitemap for the site. @@ -167,7 +167,7 @@ class GenerateSitemap extends Maintenance { } $this->identifier = $this->getOption( 'identifier', wfWikiID() ); $this->compress = $this->getOption( 'compress', 'yes' ) !== 'no'; - $this->skipRedirects = $this->getOption( 'skip-redirects', false ) !== false ; + $this->skipRedirects = $this->getOption( 'skip-redirects', false ) !== false; $this->dbr = wfGetDB( DB_SLAVE ); $this->generateNamespaces(); $this->timestamp = wfTimestamp( TS_ISO_8601, wfTimestampNow() ); @@ -231,7 +231,7 @@ class GenerateSitemap extends Maintenance { wfMkdirParents( $fspath, null, __METHOD__ ) or die( "Can not create directory $fspath.\n" ); } - return realpath( $fspath ) . DIRECTORY_SEPARATOR ; + return realpath( $fspath ) . DIRECTORY_SEPARATOR; } /** @@ -255,8 +255,9 @@ class GenerateSitemap extends Maintenance { ) ); - foreach ( $res as $row ) + foreach ( $res as $row ) { $this->namespaces[] = $row->page_namespace; + } } /** @@ -319,7 +320,7 @@ class GenerateSitemap extends Maintenance { $this->output( "$namespace ($fns)\n" ); $skippedRedirects = 0; // Number of redirects skipped for that namespace foreach ( $res as $row ) { - if ($this->skipRedirects && $row->page_is_redirect ) { + if ( $this->skipRedirects && $row->page_is_redirect ) { $skippedRedirects++; continue; } @@ -346,7 +347,9 @@ class GenerateSitemap extends Maintenance { if ( $wgContLang->hasVariants() ) { $variants = $wgContLang->getVariants(); foreach ( $variants as $vCode ) { - if ( $vCode == $wgContLang->getCode() ) continue; // we don't want default variant + if ( $vCode == $wgContLang->getCode() ) { + continue; // we don't want default variant + } $entry = $this->fileEntry( $title->getCanonicalURL( '', $vCode ), $date, $this->priority( $namespace ) ); $length += strlen( $entry ); $this->write( $this->file, $entry ); @@ -354,7 +357,7 @@ class GenerateSitemap extends Maintenance { } } - if ($this->skipRedirects && $skippedRedirects > 0) { + if ( $this->skipRedirects && $skippedRedirects > 0 ) { $this->output( " skipped $skippedRedirects redirect(s)\n" ); } @@ -374,8 +377,8 @@ class GenerateSitemap extends Maintenance { */ function open( $file, $flags ) { $resource = $this->compress ? gzopen( $file, $flags ) : fopen( $file, $flags ); - if( $resource === false ) { - wfDebugDieBacktrace( __METHOD__ . " error opening file $file with flags $flags. Check permissions?" ); + if ( $resource === false ) { + throw new MWException( __METHOD__ . " error opening file $file with flags $flags. Check permissions?" ); } return $resource; } @@ -384,23 +387,25 @@ class GenerateSitemap extends Maintenance { * gzwrite() / fwrite() wrapper */ function write( &$handle, $str ) { - if( $handle === true || $handle === false ) { - wfDebugDieBacktrace( __METHOD__ . " was passed a boolean as a file handle.\n" ); + if ( $handle === true || $handle === false ) { + throw new MWException( __METHOD__ . " was passed a boolean as a file handle.\n" ); } - if ( $this->compress ) + if ( $this->compress ) { gzwrite( $handle, $str ); - else + } else { fwrite( $handle, $str ); + } } /** * gzclose() / fclose() wrapper */ function close( &$handle ) { - if ( $this->compress ) + if ( $this->compress ) { gzclose( $handle ); - else + } else { fclose( $handle ); + } } /** @@ -485,7 +490,8 @@ class GenerateSitemap extends Maintenance { function fileEntry( $url, $date, $priority ) { return "\t<url>\n" . - "\t\t<loc>$url</loc>\n" . + // bug 34666: $url may contain bad characters such as ampersands. + "\t\t<loc>" . htmlspecialchars( $url ) . "</loc>\n" . "\t\t<lastmod>$date</lastmod>\n" . "\t\t<priority>$priority</priority>\n" . "\t</url>\n"; @@ -516,4 +522,4 @@ class GenerateSitemap extends Maintenance { } $maintClass = "GenerateSitemap"; -require_once( RUN_MAINTENANCE_IF_MAIN ); +require_once RUN_MAINTENANCE_IF_MAIN; |