* Added a new hook, 'UploadVerifyUpload', which can be used to reject a file
upload. Unlike 'UploadVerifyFile' it provides information about upload comment
and the file description page, but does not run for uploads to stash.
+* (T141604) Extensions can now provide a better error message when their
+ maintenance scripts are run without the extension being installed.
=== External library changes in 1.28 ===
*/
private $config;
+ /**
+ * @see Maintenance::requireExtension
+ * @var array
+ */
+ private $requiredExtensions = [];
+
/**
* Used to read the options in the order they were passed.
* Useful for option chaining (Ex. dumpBackup.php). It will
$this->config = $config;
}
+ /**
+ * Indicate that the specified extension must be
+ * loaded before the script can run.
+ *
+ * This *must* be called in the constructor.
+ *
+ * @since 1.28
+ * @param string $name
+ */
+ protected function requireExtension( $name ) {
+ $this->requiredExtensions[] = $name;
+ }
+
+ /**
+ * Verify that the required extensions are installed
+ *
+ * @since 1.28
+ */
+ public function checkRequiredExtensions() {
+ $registry = ExtensionRegistry::getInstance();
+ $missing = [];
+ foreach ( $this->requiredExtensions as $name ) {
+ if ( !$registry->isLoaded( $name ) ) {
+ $missing[] = $name;
+ }
+ }
+
+ if ( $missing ) {
+ $joined = implode( ', ', $missing );
+ $msg = "The following extensions are required to be installed "
+ . "for this script to run: $joined. Please enable them and then try again.";
+ $this->error( $msg, 1 );
+ }
+
+ }
+
/**
* Run a child maintenance script. Pass all of the current arguments
* to it.
// Initialize main config instance
$maintenance->setConfig( ConfigFactory::getDefaultInstance()->makeConfig( 'main' ) );
+// Sanity-check required extensions are installed
+$maintenance->checkRequiredExtensions();
+
// Do the work
$maintenance->execute();