*/
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.
// Description ...
if ( $this->mDescription ) {
- $this->output( "\n" . $this->mDescription . "\n" );
+ $this->output( "\n" . wordwrap( $this->mDescription, $screenWidth ) . "\n" );
}
$output = "\nUsage: php " . basename( $this->mSelf );