]> scripts.mit.edu Git - wizard.git/blobdiff - wizard/app/mediawiki.py
Set admin e-mail address properly on MediaWiki >= 1.18.0
[wizard.git] / wizard / app / mediawiki.py
index 12d0c483c7532f02e0bb317772773aa5787ea926..5194d712f8d76b18c74e086248f1b12a497e8ad3 100644 (file)
@@ -24,7 +24,9 @@ def make_filename_regex(var):
 seed = util.dictmap(make_filename_regex, {
         'WIZARD_IP': 'IP', # obsolete, remove after we're done
         'WIZARD_SITENAME': 'wgSitename',
+        'WIZARD_META_NAMESPACE': 'wgMetaNamespace',
         'WIZARD_SCRIPTPATH': 'wgScriptPath',
+        'WIZARD_SERVER': 'wgServer',
         'WIZARD_EMERGENCYCONTACT': ('wgEmergencyContact', 'wgPasswordSender'),
         'WIZARD_DBSERVER': 'wgDBserver',
         'WIZARD_DBNAME': 'wgDBname',
@@ -35,6 +37,7 @@ seed = util.dictmap(make_filename_regex, {
         })
 
 class Application(app.Application):
+    fullname = "MediaWiki"
     database = "mysql"
     parametrized_files = ['LocalSettings.php'] + php.parametrized_files
     deprecated_keys = set(['WIZARD_IP']) | php.deprecated_keys
@@ -54,30 +57,59 @@ class Application(app.Application):
     def checkWeb(self, deployment):
         return self.checkWebPage(deployment, "/index.php?title=Main_Page", outputs=["<!-- Served"])
     def install(self, version, options):
+        php.ini_replace_vars()
         if version >= distutils.version.LooseVersion("1.17.0"):
-            self.install_1_17_0(options)
+            # The --email option was added in 1.16.3 and removed in 1.18.0
+            has_email = version < distutils.version.LooseVersion("1.18.0")
+            self.install_1_17_0(options, has_email)
         else:
             self.install_old(options)
-    def install_1_17_0(self, options):
+    def install_1_17_0(self, options, has_email):
         util.soft_unlink("LocalSettings.php")
+        if os.path.exists("math"):
+            with util.ChangeDirectory("math"):
+                shell.call("make")
         try:
-            result = shell.eval(
-                    "php", "maintenance/install.php",
-                    "--dbname", options.dsn.database,
-                    "--dbpass", options.dsn.password,
-                    "--dbserver", options.dsn.host,
-                    "--dbuser", options.dsn.username,
+            dbpass_fd, out_fd = os.pipe()
+            os.write(out_fd, options.dsn.password)
+            os.close(out_fd)
+            pass_fd, out_fd = os.pipe()
+            os.write(out_fd, options.admin_password)
+            os.close(out_fd)
+
+            args = (
+                "php", "-c", ".", "maintenance/install.php",
+                "--dbname", options.dsn.database,
+                "--dbpassfile", "php://fd/%d" % (dbpass_fd,),
+                "--dbserver", options.dsn.host,
+                "--dbuser", options.dsn.username,
+                "--passfile", "php://fd/%d" % (pass_fd,),
+                "--server", "https://" + options.web_host,
+                "--scriptpath", options.web_path,
+            )
+            if has_email:
+                args += (
                     "--email", options.email,
-                    "--pass", options.admin_password,
-                    options.title, options.admin_name,
-                    log=True)
+                )
+            args += (options.title, options.admin_name,)
+            result = shell.eval(
+                *args,
+                log=True,
+                close_fds=False)
+            if not has_email:
+                shell.eval(
+                    "php", "-c", ".", "maintenance/resetUserEmail.php",
+                    "--no-reset-password",
+                    options.admin_name, options.email,
+                    log=True,
+                )
         except shell.CallError as e:
-            raise app.RecoverableInstallFailure("Install script returned non-zero exit code\nSTDOUT: %s\nSTDERR: %s" % (e.stdout, e.stderr))
+            raise app.RecoverableInstallFailure(["Install script returned non-zero exit code\nSTDOUT: %s\nSTDERR: %s" % (e.stdout, e.stderr)])
         logging.debug("Install script output:\n\n" + result)
         # See [Note: Maintenance script exit codes]
         results = result.rstrip().split()
         if not results or not results[-1] == "done":
-            raise app.RecoverableInstallFailure(result)
+            raise app.RecoverableInstallFailure([result])
 
     def install_old(self, options):
         util.soft_unlink("LocalSettings.php")
@@ -108,11 +140,13 @@ class Application(app.Application):
             else:
                 raise app.RecoverableInstallFailure(error_messages)
         os.rename('config/LocalSettings.php', 'LocalSettings.php')
-        php.ini_replace_vars()
 
     def upgrade(self, d, version, options):
         if not os.path.isfile("AdminSettings.php"):
             shell.call("git", "checkout", "-q", "mediawiki-" + str(version), "--", "AdminSettings.php")
+        if os.path.exists("math"):
+            with util.ChangeDirectory("math"):
+                shell.call("make")
         try:
             result = shell.eval("php", "maintenance/update.php", "--quick", log=True)
         except shell.CallError as e: