2 import distutils.version
8 from wizard import app, install, resolve, shell, util
9 from wizard.app import php
11 def make_filename_regex(var):
12 return 'LocalSettings.php', php.re_var(var)
14 seed = util.dictmap(make_filename_regex, {
15 'WIZARD_IP': 'IP', # obsolete, remove after we're done
16 'WIZARD_SITENAME': 'wgSitename',
17 'WIZARD_SCRIPTPATH': 'wgScriptPath',
18 'WIZARD_EMERGENCYCONTACT': ('wgEmergencyContact', 'wgPasswordSender'),
19 'WIZARD_DBSERVER': 'wgDBserver',
20 'WIZARD_DBNAME': 'wgDBname',
21 'WIZARD_DBUSER': 'wgDBuser',
22 'WIZARD_DBPASSWORD': 'wgDBpassword',
23 'WIZARD_SECRETKEY': ('wgSecretKey', 'wgProxyKey'),
26 class Application(app.Application):
27 parametrized_files = ['LocalSettings.php'] + php.parametrized_files
28 deprecated_keys = set(['WIZARD_IP']) | php.deprecated_keys
29 extractors = app.make_extractors(seed)
30 extractors.update(php.extractors)
31 substitutions = app.make_substitutions(seed)
32 substitutions.update(php.substitutions)
33 install_schema = install.ArgSchema("mysql", "admin", "email", "title")
34 def checkConfig(self, deployment):
35 return os.path.isfile("LocalSettings.php")
36 def detectVersion(self, deployment):
37 return self.detectVersionFromFile("includes/DefaultSettings.php", php.re_var("wgVersion"))
38 def checkWeb(self, deployment, out=None):
39 page = deployment.fetch("/index.php?title=Main_Page")
42 return page.find("<!-- Served") != -1
43 def prepareMerge(self, deployment):
44 resolve.fix_newlines("LocalSettings.php")
45 def install(self, version, options):
47 os.unlink("LocalSettings.php")
51 os.chmod("config", 0777) # XXX: vaguely sketchy
54 'Sitename': options.title,
55 'EmergencyContact': options.email,
57 'DBserver': options.mysql_host,
58 'DBname': options.mysql_db,
59 'DBuser': options.mysql_user,
60 'DBpassword': options.mysql_password,
61 'DBpassword2': options.mysql_password,
62 'defaultEmail': options.email,
63 'SysopName': options.admin_name,
64 'SysopPass': options.admin_password,
65 'SysopPass2': options.admin_password,
67 result = install.fetch(options, '/config/index.php', post=postdata)
68 result_etree = lxml.etree.parse(StringIO.StringIO(result), lxml.etree.HTMLParser())
69 selector = lxml.cssselect.CSSSelector(".error")
70 error_messages = [e.text for e in selector(result_etree)]
71 if options.verbose or options.debug: print result
72 if result.find("Installation successful") == -1:
73 if not error_messages:
74 raise app.InstallFailure()
76 raise app.RecoverableInstallFailure(error_messages)
77 os.rename('config/LocalSettings.php', 'LocalSettings.php')
78 def upgrade(self, d, version, options):
80 if not os.path.isfile("AdminSettings.php"):
81 sh.call("git", "checkout", "-q", "mediawiki-" + str(version), "--", "AdminSettings.php")
83 result = sh.eval("php", "maintenance/update.php", "--quick", log=True)
84 except shell.CallError as e:
85 raise app.UpgradeFailure("Update script returned non-zero exit code\nSTDOUT: %s\nSTDERR: %s" % (e.stdout, e.stderr))
86 results = result.rstrip().split()
87 if not results or not results[-1] == "Done.":
88 raise app.UpgradeFailure(result)
89 def backup(self, deployment, backup_dir, options):
90 app.backup_database(backup_dir, deployment)
91 def restore(self, deployment, backup_dir, options):
92 app.restore_database(backup_dir, deployment)
94 Application.resolutions = {
95 'LocalSettings.php': [
100 ## The URL base path to the directory containing the wiki;
101 ## defaults for all runtime URL paths are based off of this.
102 ## For more information on customizing the URLs please see:
103 ## http://www.mediawiki.org/wiki/Manual:Short_URL
105 $wgScriptExtension = ".php";
107 ## UPO means: this is also a user preference option
115 # MySQL specific settings
118 """, ["\n# MySQL specific settings", 1]),
121 ## is writable, then uncomment this:
124 ## is writable, then set this to true:
125 $wgEnableUploads = false;
131 $wgMathPath = "{$wgUploadPath}/math";
132 $wgMathDirectory = "{$wgUploadDirectory}/math";
133 $wgTmpDirectory = "{$wgUploadDirectory}/tmp";
138 # order of these rules is important
141 $configdate = gmdate( 'YmdHis', @filemtime( __FILE__ ) );
142 $wgCacheEpoch = max( $wgCacheEpoch, $configdate );
146 $wgCacheEpoch = max( $wgCacheEpoch, gmdate( 'YmdHis', @filemtime( __FILE__ ) ) );
151 $configdate = gmdate( 'YmdHis', @filemtime( __FILE__ ) );
152 $wgCacheEpoch = max( $wgCacheEpoch, $configdate );
155 $wgCacheEpoch = max( $wgCacheEpoch, gmdate( 'YmdHis', @filemtime( __FILE__ ) ) );
162 # When you make changes to this configuration file, this will make
163 # sure that cached pages are cleared.
164 $wgCacheEpoch = max( $wgCacheEpoch, gmdate( 'YmdHis', @filemtime( __FILE__ ) ) );
172 # When you make changes to this configuration file, this will make
173 # sure that cached pages are cleared.
174 $wgCacheEpoch = max( $wgCacheEpoch, gmdate( 'YmdHis', @filemtime( __FILE__ ) ) );
181 # When you make changes to this configuration file, this will make
182 # sure that cached pages are cleared.
183 $wgCacheEpoch = max( $wgCacheEpoch, gmdate( 'YmdHis', @filemtime( __FILE__ ) ) );