2 import distutils.version
9 from wizard import app, install, resolve, shell, util
10 from wizard.app import php
12 def make_filename_regex(var):
13 """See :ref:`versioning config <seed>` for more information."""
14 return 'LocalSettings.php', php.re_var(var)
16 seed = util.dictmap(make_filename_regex, {
17 'WIZARD_IP': 'IP', # obsolete, remove after we're done
18 'WIZARD_SITENAME': 'wgSitename',
19 'WIZARD_SCRIPTPATH': 'wgScriptPath',
20 'WIZARD_EMERGENCYCONTACT': ('wgEmergencyContact', 'wgPasswordSender'),
21 'WIZARD_DBSERVER': 'wgDBserver',
22 'WIZARD_DBNAME': 'wgDBname',
23 'WIZARD_DBUSER': 'wgDBuser',
24 'WIZARD_DBPASSWORD': 'wgDBpassword',
25 'WIZARD_SECRETKEY': ('wgSecretKey', 'wgProxyKey'),
28 class Application(app.Application):
30 parametrized_files = ['LocalSettings.php'] + php.parametrized_files
31 deprecated_keys = set(['WIZARD_IP']) | php.deprecated_keys
32 extractors = app.make_extractors(seed)
33 extractors.update(php.extractors)
34 substitutions = app.make_substitutions(seed)
35 substitutions.update(php.substitutions)
36 install_schema = install.ArgSchema("db", "admin", "email", "title")
37 def checkConfig(self, deployment):
38 return os.path.isfile("LocalSettings.php")
39 def detectVersion(self, deployment):
40 return self.detectVersionFromFile("includes/DefaultSettings.php", php.re_var("wgVersion"))
41 def checkWeb(self, deployment):
42 return self.checkWebPage(deployment, "/index.php?title=Main_Page", "<!-- Served")
43 def prepareMerge(self, deployment):
44 resolve.fix_newlines("LocalSettings.php")
45 def install(self, version, options):
46 util.soft_unlink("LocalSettings.php")
47 os.chmod("config", 0777) # XXX: vaguely sketchy
50 'Sitename': options.title,
51 'EmergencyContact': options.email,
53 'DBserver': options.dsn.host,
54 'DBname': options.dsn.database,
55 'DBuser': options.dsn.username,
56 'DBpassword': options.dsn.password,
57 'DBpassword2': options.dsn.password,
58 'defaultEmail': options.email,
59 'SysopName': options.admin_name,
60 'SysopPass': options.admin_password,
61 'SysopPass2': options.admin_password,
63 result = install.fetch(options, '/config/index.php', post=postdata)
64 result_etree = lxml.etree.parse(StringIO.StringIO(result), lxml.etree.HTMLParser())
65 selector = lxml.cssselect.CSSSelector(".error")
66 error_messages = [e.text for e in selector(result_etree)]
67 logging.debug("Installation output:\n\n" + result)
68 if result.find("Installation successful") == -1:
69 if not error_messages:
70 raise app.InstallFailure()
72 raise app.RecoverableInstallFailure(error_messages)
73 os.rename('config/LocalSettings.php', 'LocalSettings.php')
74 php.ini_replace_vars()
76 def upgrade(self, d, version, options):
77 if not os.path.isfile("AdminSettings.php"):
78 shell.call("git", "checkout", "-q", "mediawiki-" + str(version), "--", "AdminSettings.php")
80 result = shell.eval("php", "maintenance/update.php", "--quick", log=True)
81 except shell.CallError as e:
82 raise app.UpgradeFailure("Update script returned non-zero exit code\nSTDOUT: %s\nSTDERR: %s" % (e.stdout, e.stderr))
83 results = result.rstrip().split()
84 if not results or not results[-1] == "Done.":
85 raise app.UpgradeFailure(result)
86 def backup(self, deployment, backup_dir, options):
87 app.backup_database(backup_dir, deployment)
88 def restore(self, deployment, backup_dir, options):
89 app.restore_database(backup_dir, deployment)
90 def remove(self, deployment, options):
91 app.remove_database(deployment)
92 def researchFilter(self, filename, added, deleted):
93 if filename == "LocalSettings.php":
94 return added == deleted == 10 or added == deleted == 9
95 elif filename == "AdminSettings.php":
96 return added == 0 and deleted == 20
97 elif filename == "config/index.php" or filename == "config/index.php5":
101 Application.resolutions = {
102 'LocalSettings.php': [
107 ## The URL base path to the directory containing the wiki;
108 ## defaults for all runtime URL paths are based off of this.
109 ## For more information on customizing the URLs please see:
110 ## http://www.mediawiki.org/wiki/Manual:Short_URL
112 $wgScriptExtension = ".php";
114 ## UPO means: this is also a user preference option
122 # MySQL specific settings
125 """, ["\n# MySQL specific settings", 1]),
128 ## is writable, then uncomment this:
131 ## is writable, then set this to true:
132 $wgEnableUploads = false;
138 $wgMathPath = "{$wgUploadPath}/math";
139 $wgMathDirectory = "{$wgUploadDirectory}/math";
140 $wgTmpDirectory = "{$wgUploadDirectory}/tmp";
145 # order of these rules is important
148 $configdate = gmdate( 'YmdHis', @filemtime( __FILE__ ) );
149 $wgCacheEpoch = max( $wgCacheEpoch, $configdate );
153 $wgCacheEpoch = max( $wgCacheEpoch, gmdate( 'YmdHis', @filemtime( __FILE__ ) ) );
158 $configdate = gmdate( 'YmdHis', @filemtime( __FILE__ ) );
159 $wgCacheEpoch = max( $wgCacheEpoch, $configdate );
162 $wgCacheEpoch = max( $wgCacheEpoch, gmdate( 'YmdHis', @filemtime( __FILE__ ) ) );
169 # When you make changes to this configuration file, this will make
170 # sure that cached pages are cleared.
171 $wgCacheEpoch = max( $wgCacheEpoch, gmdate( 'YmdHis', @filemtime( __FILE__ ) ) );
179 # When you make changes to this configuration file, this will make
180 # sure that cached pages are cleared.
181 $wgCacheEpoch = max( $wgCacheEpoch, gmdate( 'YmdHis', @filemtime( __FILE__ ) ) );
188 # When you make changes to this configuration file, this will make
189 # sure that cached pages are cleared.
190 $wgCacheEpoch = max( $wgCacheEpoch, gmdate( 'YmdHis', @filemtime( __FILE__ ) ) );