]> scripts.mit.edu Git - wizard.git/blob - wizard/app/mediawiki.py
Fill out missing documentation.
[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 install(self, version, options):
44         util.soft_unlink("LocalSettings.php")
45         os.chmod("config", 0777) # XXX: vaguely sketchy
46
47         postdata = {
48             'Sitename': options.title,
49             'EmergencyContact': options.email,
50             'LanguageCode': 'en',
51             'DBserver': options.dsn.host,
52             'DBname': options.dsn.database,
53             'DBuser': options.dsn.username,
54             'DBpassword': options.dsn.password,
55             'DBpassword2': options.dsn.password,
56             'defaultEmail': options.email,
57             'SysopName': options.admin_name,
58             'SysopPass': options.admin_password,
59             'SysopPass2': options.admin_password,
60             }
61         result = install.fetch(options, '/config/index.php', post=postdata)
62         result_etree = lxml.etree.parse(StringIO.StringIO(result), lxml.etree.HTMLParser())
63         selector = lxml.cssselect.CSSSelector(".error")
64         error_messages = [e.text for e in selector(result_etree)]
65         logging.debug("Installation output:\n\n" + result)
66         if result.find("Installation successful") == -1:
67             if not error_messages:
68                 raise app.InstallFailure()
69             else:
70                 raise app.RecoverableInstallFailure(error_messages)
71         os.rename('config/LocalSettings.php', 'LocalSettings.php')
72         php.ini_replace_vars()
73
74     def upgrade(self, d, version, options):
75         if not os.path.isfile("AdminSettings.php"):
76             shell.call("git", "checkout", "-q", "mediawiki-" + str(version), "--", "AdminSettings.php")
77         try:
78             result = shell.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)
88     def remove(self, deployment, options):
89         app.remove_database(deployment)
90     def researchFilter(self, filename, added, deleted):
91         if filename == "LocalSettings.php":
92             return added == deleted == 10 or added == deleted == 9
93         elif filename == "AdminSettings.php":
94             return added == 0 and deleted == 20
95         elif filename == "config/index.php" or filename == "config/index.php5":
96             return added == 0
97         return False
98
99 Application.resolutions = {
100 'LocalSettings.php': [
101     ("""
102 <<<<<<<
103 ***1***
104 =======
105 ## The URL base path to the directory containing the wiki;
106 ## defaults for all runtime URL paths are based off of this.
107 ## For more information on customizing the URLs please see:
108 ## http://www.mediawiki.org/wiki/Manual:Short_URL
109 ***2***
110 $wgScriptExtension  = ".php";
111
112 ## UPO means: this is also a user preference option
113 >>>>>>>
114 """, [-1]),
115     ("""
116 <<<<<<<
117 ***1***
118 =======
119
120 # MySQL specific settings
121 $wgDBprefix         = "";
122 >>>>>>>
123 """, ["\n# MySQL specific settings", 1]),
124     ("""
125 <<<<<<<
126 ## is writable, then uncomment this:
127 ***1***
128 =======
129 ## is writable, then set this to true:
130 $wgEnableUploads       = false;
131 >>>>>>>
132 """, [-1]),
133     ("""
134 <<<<<<<
135 ***1***
136 $wgMathPath         = "{$wgUploadPath}/math";
137 $wgMathDirectory    = "{$wgUploadDirectory}/math";
138 $wgTmpDirectory     = "{$wgUploadDirectory}/tmp";
139 =======
140 $wgUseTeX           = false;
141 >>>>>>>
142 """, [1]),
143     # order of these rules is important
144     ("""
145 <<<<<<<
146 $configdate = gmdate( 'YmdHis', @filemtime( __FILE__ ) );
147 $wgCacheEpoch = max( $wgCacheEpoch, $configdate );
148 ***1***
149 ?>
150 =======
151 $wgCacheEpoch = max( $wgCacheEpoch, gmdate( 'YmdHis', @filemtime( __FILE__ ) ) );
152 >>>>>>>
153 """, [0, 1]),
154     ("""
155 <<<<<<<
156 $configdate = gmdate( 'YmdHis', @filemtime( __FILE__ ) );
157 $wgCacheEpoch = max( $wgCacheEpoch, $configdate );
158 ***1***
159 =======
160 $wgCacheEpoch = max( $wgCacheEpoch, gmdate( 'YmdHis', @filemtime( __FILE__ ) ) );
161 >>>>>>>
162 """, [0, 1]),
163     ("""
164 <<<<<<<
165 ?>
166 =======
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__ ) ) );
170 >>>>>>>
171 """, [0]),
172     ("""
173 <<<<<<<
174 ***1***
175 ?>
176 =======
177 # When you make changes to this configuration file, this will make
178 # sure that cached pages are cleared.
179 $wgCacheEpoch = max( $wgCacheEpoch, gmdate( 'YmdHis', @filemtime( __FILE__ ) ) );
180 >>>>>>>
181 """, [1, 0]),
182     ("""
183 <<<<<<<
184 ***1***
185 =======
186 # When you make changes to this configuration file, this will make
187 # sure that cached pages are cleared.
188 $wgCacheEpoch = max( $wgCacheEpoch, gmdate( 'YmdHis', @filemtime( __FILE__ ) ) );
189 >>>>>>>
190 """, [1, 0]),
191     ]
192 }
193