2 import distutils.version
5 from wizard import app, install, resolve, shell, util
6 from wizard.app import php
8 def make_filename_regex(var):
9 return 'LocalSettings.php', php.re_var(var)
11 seed = util.dictmap(make_filename_regex, {
12 'WIZARD_IP': 'IP', # obsolete, remove after we're done
13 'WIZARD_SITENAME': 'wgSitename',
14 'WIZARD_SCRIPTPATH': 'wgScriptPath',
15 'WIZARD_EMERGENCYCONTACT': ('wgEmergencyContact', 'wgPasswordSender'),
16 'WIZARD_DBSERVER': 'wgDBserver',
17 'WIZARD_DBNAME': 'wgDBname',
18 'WIZARD_DBUSER': 'wgDBuser',
19 'WIZARD_DBPASSWORD': 'wgDBpassword',
20 'WIZARD_SECRETKEY': ('wgSecretKey', 'wgProxyKey'),
23 class Application(app.Application):
24 parametrized_files = ['LocalSettings.php', 'php.ini']
25 deprecated_keys = set(['WIZARD_IP']) | php.deprecated_keys
26 extractors = app.make_extractors(seed)
27 extractors.update(php.extractors)
28 substitutions = app.make_substitutions(seed)
29 substitutions.update(php.substitutions)
30 install_schema = install.ArgSchema("mysql", "admin", "email", "title")
31 def checkConfig(self, deployment):
32 return os.path.isfile(os.path.join(deployment.location, "LocalSettings.php"))
33 def detectVersion(self, deployment):
34 contents = deployment.read("includes/DefaultSettings.php")
35 regex = php.re_var("wgVersion")
36 match = regex.search(contents)
37 if not match: return None
38 return distutils.version.LooseVersion(match.group(2)[1:-1])
39 def checkWeb(self, deployment, out=None):
40 page = deployment.fetch("/index.php?title=Main_Page")
43 return page.find("<!-- Served") != -1
44 def prepareMerge(self, deployment):
45 resolve.fix_newlines("LocalSettings.php")
46 def install(self, version, options):
48 os.unlink("LocalSettings.php")
52 os.chmod("config", 0777) # XXX: vaguely sketchy
55 'Sitename': options.title,
56 'EmergencyContact': options.email,
58 'DBserver': options.mysql_host,
59 'DBname': options.mysql_db,
60 'DBuser': options.mysql_user,
61 'DBpassword': options.mysql_password,
62 'DBpassword2': options.mysql_password,
63 'defaultEmail': options.email,
64 'SysopName': options.admin_name,
65 'SysopPass': options.admin_password,
66 'SysopPass2': options.admin_password,
68 result = install.fetch(options, '/config/index.php', post=postdata)
69 if options.verbose or options.debug: print result
70 if result.find("Installation successful") == -1:
71 raise install.Failure()
72 os.rename('config/LocalSettings.php', 'LocalSettings.php')
73 def upgrade(self, d, version, options):
75 if not os.path.isfile("AdminSettings.php"):
76 sh.call("git", "checkout", "-q", "mediawiki-" + str(version), "--", "AdminSettings.php")
78 result = sh.eval("php", "maintenance/update.php", "--quick", log=True)
79 except shell.CallError as e:
80 raise app.UpgradeFailure("Update script returned non-zero exit code\nSTDOUT: %s\nSTDERR: %s" % (e.stdout, e.stderr))
81 results = result.rstrip().split()
82 if not results or not results[-1] == "Done.":
83 raise app.UpgradeFailure(result)
84 def backup(self, deployment, backup_dir, options):
85 app.backup_database(backup_dir, deployment)
86 def restore(self, deployment, backup_dir, options):
87 app.restore_database(backup_dir, deployment)
89 Application.resolutions = {
90 'LocalSettings.php': [
95 ## The URL base path to the directory containing the wiki;
96 ## defaults for all runtime URL paths are based off of this.
97 ## For more information on customizing the URLs please see:
98 ## http://www.mediawiki.org/wiki/Manual:Short_URL
100 $wgScriptExtension = ".php";
102 ## UPO means: this is also a user preference option
110 # MySQL specific settings
113 """, ["\n# MySQL specific settings", 1]),
116 ## is writable, then uncomment this:
119 ## is writable, then set this to true:
120 $wgEnableUploads = false;
126 $wgMathPath = "{$wgUploadPath}/math";
127 $wgMathDirectory = "{$wgUploadDirectory}/math";
128 $wgTmpDirectory = "{$wgUploadDirectory}/tmp";
133 # order of these rules is important
136 $configdate = gmdate( 'YmdHis', @filemtime( __FILE__ ) );
137 $wgCacheEpoch = max( $wgCacheEpoch, $configdate );
141 $wgCacheEpoch = max( $wgCacheEpoch, gmdate( 'YmdHis', @filemtime( __FILE__ ) ) );
146 $configdate = gmdate( 'YmdHis', @filemtime( __FILE__ ) );
147 $wgCacheEpoch = max( $wgCacheEpoch, $configdate );
150 $wgCacheEpoch = max( $wgCacheEpoch, gmdate( 'YmdHis', @filemtime( __FILE__ ) ) );
157 # When you make changes to this configuration file, this will make
158 # sure that cached pages are cleared.
159 $wgCacheEpoch = max( $wgCacheEpoch, gmdate( 'YmdHis', @filemtime( __FILE__ ) ) );
167 # When you make changes to this configuration file, this will make
168 # sure that cached pages are cleared.
169 $wgCacheEpoch = max( $wgCacheEpoch, gmdate( 'YmdHis', @filemtime( __FILE__ ) ) );
176 # When you make changes to this configuration file, this will make
177 # sure that cached pages are cleared.
178 $wgCacheEpoch = max( $wgCacheEpoch, gmdate( 'YmdHis', @filemtime( __FILE__ ) ) );