X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=maintenance%2FgenerateSitemap.php;h=87af5b83cc7d5bd85a5c07520c8dd0305f6b5bf3;hb=584fd0c75b8ed34c710d5c3747c4bee4aeb9d179;hp=c43851e6f2ac5edc1d424c37e2d9615643707b33;hpb=519309a43c9613b545b7bfa0f99bbdcc94849acb;p=lhc%2Fweb%2Fwiklou.git diff --git a/maintenance/generateSitemap.php b/maintenance/generateSitemap.php index c43851e6f2..87af5b83cc 100644 --- a/maintenance/generateSitemap.php +++ b/maintenance/generateSitemap.php @@ -89,21 +89,21 @@ class GenerateSitemap extends Maintenance { * * @var array */ - public $limit = array(); + public $limit = []; /** * Key => value entries of namespaces and their priorities * * @var array */ - public $priorities = array(); + public $priorities = []; /** * A one-dimensional array of namespaces in the wiki * * @var array */ - public $namespaces = array(); + public $namespaces = []; /** * When this sitemap batch was generated @@ -113,7 +113,7 @@ class GenerateSitemap extends Maintenance { public $timestamp; /** - * A database slave object + * A database replica DB object * * @var object */ @@ -145,7 +145,7 @@ class GenerateSitemap extends Maintenance { */ public function __construct() { parent::__construct(); - $this->mDescription = "Creates a sitemap for the site"; + $this->addDescription( 'Creates a sitemap for the site' ); $this->addOption( 'fspath', 'The file system path to save to, e.g. /tmp/sitemap; defaults to current directory', @@ -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 .= '/'; @@ -189,7 +196,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->dbr = wfGetDB( DB_SLAVE ); + $this->dbr = $this->getDB( DB_REPLICA ); $this->generateNamespaces(); $this->timestamp = wfTimestamp( TS_ISO_8601, wfTimestampNow() ); $this->findex = fopen( "{$this->fspath}sitemap-index-{$this->identifier}.xml", 'wb' ); @@ -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 */ @@ -268,13 +258,13 @@ class GenerateSitemap extends Maintenance { } $res = $this->dbr->select( 'page', - array( 'page_namespace' ), - array(), + [ 'page_namespace' ], + [], __METHOD__, - array( + [ 'GROUP BY' => 'page_namespace', 'ORDER BY' => 'page_namespace', - ) + ] ); foreach ( $res as $row ) { @@ -316,13 +306,13 @@ class GenerateSitemap extends Maintenance { */ function getPageRes( $namespace ) { return $this->dbr->select( 'page', - array( + [ 'page_namespace', 'page_title', 'page_touched', 'page_is_redirect' - ), - array( 'page_namespace' => $namespace ), + ], + [ 'page_namespace' => $namespace ], __METHOD__ ); } @@ -558,7 +548,7 @@ class GenerateSitemap extends Maintenance { // bug 17961: make a title with the longest possible URL in this namespace $title = Title::makeTitle( $namespace, str_repeat( "\xf0\xa8\xae\x81", 63 ) . "\xe5\x96\x83" ); - $this->limit = array( + $this->limit = [ strlen( $this->openFile() ), strlen( $this->fileEntry( $title->getCanonicalURL(), @@ -566,7 +556,7 @@ class GenerateSitemap extends Maintenance { $this->priority( $namespace ) ) ), strlen( $this->closeFile() ) - ); + ]; } }