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.ini']
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 contents = deployment.read("includes/DefaultSettings.php")
38 regex = php.re_var("wgVersion")
39 match = regex.search(contents)
40 if not match: return None
41 return distutils.version.LooseVersion(match.group(2)[1:-1])
42 def checkWeb(self, deployment, out=None):
43 page = deployment.fetch("/index.php?title=Main_Page")
46 return page.find("<!-- Served") != -1
47 def prepareMerge(self, deployment):
48 resolve.fix_newlines("LocalSettings.php")
49 def install(self, version, options):
51 os.unlink("LocalSettings.php")
55 os.chmod("config", 0777) # XXX: vaguely sketchy
58 'Sitename': options.title,
59 'EmergencyContact': options.email,
61 'DBserver': options.mysql_host,
62 'DBname': options.mysql_db,
63 'DBuser': options.mysql_user,
64 'DBpassword': options.mysql_password,
65 'DBpassword2': options.mysql_password,
66 'defaultEmail': options.email,
67 'SysopName': options.admin_name,
68 'SysopPass': options.admin_password,
69 'SysopPass2': options.admin_password,
71 result = install.fetch(options, '/config/index.php', post=postdata)
72 result_etree = lxml.etree.parse(StringIO.StringIO(result), lxml.etree.HTMLParser())
73 selector = lxml.cssselect.CSSSelector(".error")
74 error_messages = [e.text for e in selector(result_etree)]
75 if options.verbose or options.debug: print result
76 if result.find("Installation successful") == -1:
77 if not error_messages:
78 raise install.Failure()
79 raise app.NonfatalFailure(error_messages)
80 os.rename('config/LocalSettings.php', 'LocalSettings.php')
81 def upgrade(self, d, version, options):
83 if not os.path.isfile("AdminSettings.php"):
84 sh.call("git", "checkout", "-q", "mediawiki-" + str(version), "--", "AdminSettings.php")
86 result = sh.eval("php", "maintenance/update.php", "--quick", log=True)
87 except shell.CallError as e:
88 raise app.UpgradeFailure("Update script returned non-zero exit code\nSTDOUT: %s\nSTDERR: %s" % (e.stdout, e.stderr))
89 results = result.rstrip().split()
90 if not results or not results[-1] == "Done.":
91 raise app.UpgradeFailure(result)
92 def backup(self, deployment, backup_dir, options):
93 app.backup_database(backup_dir, deployment)
94 def restore(self, deployment, backup_dir, options):
95 app.restore_database(backup_dir, deployment)
97 Application.resolutions = {
98 'LocalSettings.php': [
103 ## The URL base path to the directory containing the wiki;
104 ## defaults for all runtime URL paths are based off of this.
105 ## For more information on customizing the URLs please see:
106 ## http://www.mediawiki.org/wiki/Manual:Short_URL
108 $wgScriptExtension = ".php";
110 ## UPO means: this is also a user preference option
118 # MySQL specific settings
121 """, ["\n# MySQL specific settings", 1]),
124 ## is writable, then uncomment this:
127 ## is writable, then set this to true:
128 $wgEnableUploads = false;
134 $wgMathPath = "{$wgUploadPath}/math";
135 $wgMathDirectory = "{$wgUploadDirectory}/math";
136 $wgTmpDirectory = "{$wgUploadDirectory}/tmp";
141 # order of these rules is important
144 $configdate = gmdate( 'YmdHis', @filemtime( __FILE__ ) );
145 $wgCacheEpoch = max( $wgCacheEpoch, $configdate );
149 $wgCacheEpoch = max( $wgCacheEpoch, gmdate( 'YmdHis', @filemtime( __FILE__ ) ) );
154 $configdate = gmdate( 'YmdHis', @filemtime( __FILE__ ) );
155 $wgCacheEpoch = max( $wgCacheEpoch, $configdate );
158 $wgCacheEpoch = max( $wgCacheEpoch, gmdate( 'YmdHis', @filemtime( __FILE__ ) ) );
165 # When you make changes to this configuration file, this will make
166 # sure that cached pages are cleared.
167 $wgCacheEpoch = max( $wgCacheEpoch, gmdate( 'YmdHis', @filemtime( __FILE__ ) ) );
175 # When you make changes to this configuration file, this will make
176 # sure that cached pages are cleared.
177 $wgCacheEpoch = max( $wgCacheEpoch, gmdate( 'YmdHis', @filemtime( __FILE__ ) ) );
184 # When you make changes to this configuration file, this will make
185 # sure that cached pages are cleared.
186 $wgCacheEpoch = max( $wgCacheEpoch, gmdate( 'YmdHis', @filemtime( __FILE__ ) ) );