]> scripts.mit.edu Git - wizard.git/blob - wizard/app/mediawiki.py
Add more testing documentation on prompting of Ian Smith.
[wizard.git] / wizard / app / mediawiki.py
1 import re
2 import distutils.version
3 import os
4 import lxml.cssselect
5 import lxml.etree
6 import StringIO
7 import logging
8
9 from wizard import app, install, resolve, shell, util
10 from wizard.app import php
11
12 def make_filename_regex(var):
13     """See :ref:`versioning config <seed>` for more information."""
14     return 'LocalSettings.php', php.re_var(var)
15
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'),
26         })
27
28 class Application(app.Application):
29     database = "mysql"
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
48
49         postdata = {
50             'Sitename': options.title,
51             'EmergencyContact': options.email,
52             'LanguageCode': 'en',
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,
62             }
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()
71             else:
72                 raise app.RecoverableInstallFailure(error_messages)
73         os.rename('config/LocalSettings.php', 'LocalSettings.php')
74         php.ini_replace_vars()
75
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")
79         try:
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":
98             return added == 0
99         return False
100
101 Application.resolutions = {
102 'LocalSettings.php': [
103     ("""
104 <<<<<<<
105 ***1***
106 =======
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
111 ***2***
112 $wgScriptExtension  = ".php";
113
114 ## UPO means: this is also a user preference option
115 >>>>>>>
116 """, [-1]),
117     ("""
118 <<<<<<<
119 ***1***
120 =======
121
122 # MySQL specific settings
123 $wgDBprefix         = "";
124 >>>>>>>
125 """, ["\n# MySQL specific settings", 1]),
126     ("""
127 <<<<<<<
128 ## is writable, then uncomment this:
129 ***1***
130 =======
131 ## is writable, then set this to true:
132 $wgEnableUploads       = false;
133 >>>>>>>
134 """, [-1]),
135     ("""
136 <<<<<<<
137 ***1***
138 $wgMathPath         = "{$wgUploadPath}/math";
139 $wgMathDirectory    = "{$wgUploadDirectory}/math";
140 $wgTmpDirectory     = "{$wgUploadDirectory}/tmp";
141 =======
142 $wgUseTeX           = false;
143 >>>>>>>
144 """, [1]),
145     # order of these rules is important
146     ("""
147 <<<<<<<
148 $configdate = gmdate( 'YmdHis', @filemtime( __FILE__ ) );
149 $wgCacheEpoch = max( $wgCacheEpoch, $configdate );
150 ***1***
151 ?>
152 =======
153 $wgCacheEpoch = max( $wgCacheEpoch, gmdate( 'YmdHis', @filemtime( __FILE__ ) ) );
154 >>>>>>>
155 """, [0, 1]),
156     ("""
157 <<<<<<<
158 $configdate = gmdate( 'YmdHis', @filemtime( __FILE__ ) );
159 $wgCacheEpoch = max( $wgCacheEpoch, $configdate );
160 ***1***
161 =======
162 $wgCacheEpoch = max( $wgCacheEpoch, gmdate( 'YmdHis', @filemtime( __FILE__ ) ) );
163 >>>>>>>
164 """, [0, 1]),
165     ("""
166 <<<<<<<
167 ?>
168 =======
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__ ) ) );
172 >>>>>>>
173 """, [0]),
174     ("""
175 <<<<<<<
176 ***1***
177 ?>
178 =======
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__ ) ) );
182 >>>>>>>
183 """, [1, 0]),
184     ("""
185 <<<<<<<
186 ***1***
187 =======
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__ ) ) );
191 >>>>>>>
192 """, [1, 0]),
193     ]
194 }
195