From db1350ef6122054be50df7473f48229da689db0f Mon Sep 17 00:00:00 2001 From: Reedy Date: Fri, 5 Jan 2024 18:07:37 +0000 Subject: [PATCH] installer: Minor cleanup * Minor comment tweaks Change-Id: I76b44fcd88f27f6182f2b245301298a182e870f5 --- includes/installer/InstallDocFormatter.php | 8 ++---- includes/installer/InstallException.php | 11 ++++---- includes/installer/MysqlInstaller.php | 2 +- includes/installer/MysqlUpdater.php | 4 +-- includes/installer/Pingback.php | 2 +- includes/installer/SqliteInstaller.php | 32 ++++++++++------------ includes/installer/SqliteUpdater.php | 2 +- 7 files changed, 28 insertions(+), 33 deletions(-) diff --git a/includes/installer/InstallDocFormatter.php b/includes/installer/InstallDocFormatter.php index eb96e05941d..71e85279ff7 100644 --- a/includes/installer/InstallDocFormatter.php +++ b/includes/installer/InstallDocFormatter.php @@ -25,9 +25,7 @@ class InstallDocFormatter { private $text; public static function format( $text ) { - $obj = new self( $text ); - - return $obj->execute(); + return ( new self( $text ) )->execute(); } protected function __construct( $text ) { @@ -66,12 +64,10 @@ class InstallDocFormatter { ); // add links to manual to every global variable mentioned - $text = preg_replace( + return preg_replace( '/\$wg[a-z0-9_]+/i', "{$linkStart}https://www.mediawiki.org/wiki/Manual:$0{$linkEnd}", $text ); - - return $text; } } diff --git a/includes/installer/InstallException.php b/includes/installer/InstallException.php index ab6e51a003b..7ccf4df86ec 100644 --- a/includes/installer/InstallException.php +++ b/includes/installer/InstallException.php @@ -20,31 +20,32 @@ namespace MediaWiki\Installer; +use MediaWiki\Status\Status; use Throwable; /** - * Exception thrown if an error occur which installation + * Exception thrown if an error occurs during installation * @ingroup Exception */ class InstallException extends \MWException { /** - * @var \MediaWiki\Status\Status State when an exception occurs + * @var Status The state when an exception occurs */ private $status; /** - * @param \MediaWiki\Status\Status $status State when an exception occurs + * @param Status $status The state when an exception occurs * @param string $message The Exception message to throw * @param int $code The Exception code * @param Throwable|null $previous The previous throwable used for the exception chaining */ - public function __construct( \MediaWiki\Status\Status $status, $message = '', $code = 0, + public function __construct( Status $status, $message = '', $code = 0, Throwable $previous = null ) { parent::__construct( $message, $code, $previous ); $this->status = $status; } - public function getStatus(): \MediaWiki\Status\Status { + public function getStatus(): Status { return $this->status; } } diff --git a/includes/installer/MysqlInstaller.php b/includes/installer/MysqlInstaller.php index 48b6479d3d7..8b37d9b0914 100644 --- a/includes/installer/MysqlInstaller.php +++ b/includes/installer/MysqlInstaller.php @@ -437,7 +437,7 @@ class MysqlInstaller extends DatabaseInstaller { } // Validate engines and charsets - // This is done pre-submit already so it's just for security + // This is done pre-submit already, so it's just for security $engines = $this->getEngines(); if ( !in_array( $this->getVar( '_MysqlEngine' ), $engines ) ) { $this->setVar( '_MysqlEngine', reset( $engines ) ); diff --git a/includes/installer/MysqlUpdater.php b/includes/installer/MysqlUpdater.php index 9ec1d795c60..16c46504ee8 100644 --- a/includes/installer/MysqlUpdater.php +++ b/includes/installer/MysqlUpdater.php @@ -159,7 +159,7 @@ class MysqlUpdater extends DatabaseUpdater { } /** - * Check whether an index contain a field + * Check whether an index contains a field * * @param string $table Table name * @param string $index Index name to check @@ -238,7 +238,7 @@ class MysqlUpdater extends DatabaseUpdater { } /** - * Drop a default value from a field + * Drops the default value from a field * * @since 1.36 * @param string $table diff --git a/includes/installer/Pingback.php b/includes/installer/Pingback.php index 7ea547886dd..fa2d027d5b8 100644 --- a/includes/installer/Pingback.php +++ b/includes/installer/Pingback.php @@ -140,7 +140,7 @@ class Pingback { if ( $timestamp === false ) { return false; } - // send heartbeat ping if last ping was over a month ago + // send heartbeat ping if the last ping was over a month ago if ( ConvertibleTimestamp::time() - (int)$timestamp > 60 * 60 * 24 * 30 ) { return false; } diff --git a/includes/installer/SqliteInstaller.php b/includes/installer/SqliteInstaller.php index e87cb48487c..843524488bf 100644 --- a/includes/installer/SqliteInstaller.php +++ b/includes/installer/SqliteInstaller.php @@ -144,23 +144,21 @@ class SqliteInstaller extends DatabaseInstaller { if ( !is_readable( $dir ) ) { return Status::newFatal( 'config-sqlite-dir-unwritable', $dir ); } - } else { + } elseif ( !is_writable( dirname( $dir ) ) ) { // Check the parent directory if $dir not exists - if ( !is_writable( dirname( $dir ) ) ) { - $webserverGroup = Installer::maybeGetWebserverPrimaryGroup(); - if ( $webserverGroup !== null ) { - return Status::newFatal( - 'config-sqlite-parent-unwritable-group', - $dir, dirname( $dir ), basename( $dir ), - $webserverGroup - ); - } else { - return Status::newFatal( - 'config-sqlite-parent-unwritable-nogroup', - $dir, dirname( $dir ), basename( $dir ) - ); - } + $webserverGroup = Installer::maybeGetWebserverPrimaryGroup(); + if ( $webserverGroup !== null ) { + return Status::newFatal( + 'config-sqlite-parent-unwritable-group', + $dir, dirname( $dir ), basename( $dir ), + $webserverGroup + ); } + + return Status::newFatal( + 'config-sqlite-parent-unwritable-nogroup', + $dir, dirname( $dir ), basename( $dir ) + ); } return Status::newGood(); } @@ -384,8 +382,8 @@ EOT; public function getLocalSettings() { $dir = LocalSettingsGenerator::escapePhpString( $this->getVar( 'wgSQLiteDataDir' ) ); // These tables have frequent writes and are thus split off from the main one. - // Since the code using these tables only uses transactions for writes then set - // them to using BEGIN IMMEDIATE. This avoids frequent lock errors on first write. + // Since the code using these tables only uses transactions for writes, then set + // them to using BEGIN IMMEDIATE. This avoids frequent lock errors on the first write action. return "# SQLite-specific settings \$wgSQLiteDataDir = \"{$dir}\"; \$wgObjectCaches[CACHE_DB] = [ diff --git a/includes/installer/SqliteUpdater.php b/includes/installer/SqliteUpdater.php index c5fbc43fc70..4290d01966f 100644 --- a/includes/installer/SqliteUpdater.php +++ b/includes/installer/SqliteUpdater.php @@ -141,7 +141,7 @@ class SqliteUpdater extends DatabaseUpdater { } /** - * Check whether an index contain a field + * Check whether an index contains a field * * @param string $table Table name * @param string $index Index name to check