2 import distutils.version
5 from wizard import app, deploy, install, shell, util
6 from wizard.app import php
8 def make_filename_regex(var):
9 return 'LocalSettings.php', re.compile('^(\$' + app.expand_re(var) + r'''\s*=\s*)(.*)(;)''', re.M)
11 make_extractor = app.filename_regex_extractor(make_filename_regex)
12 make_substitution = app.filename_regex_substitution(make_filename_regex)
14 'WIZARD_IP': 'IP', # obsolete, remove after we're done
15 'WIZARD_SITENAME': 'wgSitename',
16 'WIZARD_SCRIPTPATH': 'wgScriptPath',
17 'WIZARD_EMERGENCYCONTACT': ('wgEmergencyContact', 'wgPasswordSender'),
18 'WIZARD_DBSERVER': 'wgDBserver',
19 'WIZARD_DBNAME': 'wgDBname',
20 'WIZARD_DBUSER': 'wgDBuser',
21 'WIZARD_DBPASSWORD': 'wgDBpassword',
22 'WIZARD_SECRETKEY': ('wgSecretKey', 'wgProxyKey'),
25 class Application(deploy.Application):
26 parametrized_files = ['LocalSettings.php', 'php.ini']
27 deprecated_keys = set(['WIZARD_IP']) | php.deprecated_keys
30 if not self._extractors:
31 self._extractors = util.dictmap(make_extractor, seed)
32 self._extractors.update(php.extractors)
33 return self._extractors
35 def substitutions(self):
36 if not self._substitutions:
37 self._substitutions = util.dictkmap(make_substitution, seed)
38 self._substitutions.update(php.substitutions)
39 return self._substitutions
41 def install_handler(self):
42 handler = install.ArgHandler("mysql", "admin", "email")
43 handler.add(install.Arg("title", help="Title of your new MediaWiki install"))
45 def checkConfig(self, deployment):
46 return os.path.isfile(os.path.join(deployment.location, "LocalSettings.php"))
47 def detectVersion(self, deployment):
48 contents = deployment.read("includes/DefaultSettings.php")
49 regex = make_filename_regex("wgVersion")[1]
50 match = regex.search(contents)
51 if not match: return None
52 return distutils.version.LooseVersion(match.group(2)[1:-1])
53 def install(self, options):
55 os.unlink("LocalSettings.php")
59 os.chmod("config", 0777) # XXX: vaguely sketchy
62 'Sitename': options.title,
63 'EmergencyContact': options.email,
65 'DBserver': options.mysql_host,
66 'DBname': options.mysql_db,
67 'DBuser': options.mysql_user,
68 'DBpassword': options.mysql_password,
69 'DBpassword2': options.mysql_password,
70 'defaultEmail': options.email,
71 'SysopName': options.admin_name,
72 'SysopPass': options.admin_password,
73 'SysopPass2': options.admin_password,
75 result = install.fetch(options, 'config/index.php', post=postdata)
76 if options.verbose: print result
77 if result.find("Installation successful") == -1:
78 raise install.Failure()
79 os.rename('config/LocalSettings.php', 'LocalSettings.php')
80 def upgrade(self, options):
82 sh.call("php", "maintenance/update.php")