2 # Cookbook Name:: mediawiki
3 # Provider:: mediawiki_site
5 # Copyright 2015, OpenStreetMap Foundation
7 # Licensed under the Apache License, Version 2.0 (the "License");
8 # you may not use this file except in compliance with the License.
9 # You may obtain a copy of the License at
11 # http://www.apache.org/licenses/LICENSE-2.0
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
20 require "securerandom"
22 include Chef::Mixin::EditFile
31 node.set_unless[:mediawiki][:sites][new_resource.name] = {}
33 node.set[:mediawiki][:sites][new_resource.name][:directory] = site_directory
34 node.set[:mediawiki][:sites][new_resource.name][:version] = new_resource.version
36 node.set_unless[:mediawiki][:sites][new_resource.name][:wgSecretKey] = SecureRandom.base64(48)
38 mysql_user "#{new_resource.database_user}@localhost" do
39 password new_resource.database_password
42 mysql_database new_resource.database_name do
43 permissions "#{new_resource.database_user}@localhost" => :all
46 mediawiki_directory = "#{site_directory}/w"
48 ruby_block "rename-installer-localsettings" do
51 ::File.rename("#{mediawiki_directory}/LocalSettings.php", "#{mediawiki_directory}/LocalSettings-install.php")
55 execute "#{mediawiki_directory}/maintenance/install.php" do
57 # Use metanamespace as Site Name to ensure correct set namespace
58 command "php maintenance/install.php --server '#{name}' --dbtype 'mysql' --dbname '#{new_resource.database_name}' --dbuser '#{new_resource.database_user}' --dbpass '#{new_resource.database_password}' --dbserver 'localhost' --scriptpath /w --pass '#{new_resource.admin_password}' '#{new_resource.metanamespace}' '#{new_resource.admin_user}'"
59 cwd mediawiki_directory
60 user node[:mediawiki][:user]
61 group node[:mediawiki][:group]
63 ::File.exist?("#{mediawiki_directory}/LocalSettings-install.php")
65 notifies :create, "ruby_block[rename-installer-localsettings]", :immediately
68 execute "#{mediawiki_directory}/maintenance/update.php" do
70 command "php maintenance/update.php --quick"
71 cwd mediawiki_directory
72 user node[:mediawiki][:user]
73 group node[:mediawiki][:group]
76 directory site_directory do
77 owner node[:mediawiki][:user]
78 group node[:mediawiki][:group]
82 directory mediawiki_directory do
83 owner node[:mediawiki][:user]
84 group node[:mediawiki][:group]
88 mediawiki_reference = "refs/heads/REL#{new_resource.version}".tr(".", "_")
92 repository "git://github.com/wikimedia/mediawiki-core"
93 reference mediawiki_reference
95 user node[:mediawiki][:user]
96 group node[:mediawiki][:group]
97 notifies :run, "execute[#{mediawiki_directory}/maintenance/install.php]", :immediately
98 notifies :run, "execute[#{mediawiki_directory}/maintenance/update.php]"
101 # Safety catch if git doesn't update but install.php hasn't run
102 ruby_block "catch-installer-localsettings-run" do
108 ::File.exist?("#{mediawiki_directory}/LocalSettings-install.php")
110 notifies :run, "execute[#{mediawiki_directory}/maintenance/install.php]", :immediately
113 directory "#{mediawiki_directory}/images" do
115 group node[:mediawiki][:group]
119 directory "#{mediawiki_directory}/cache" do
121 group node[:mediawiki][:group]
125 directory "#{mediawiki_directory}/LocalSettings.d" do
126 user node[:mediawiki][:user]
127 group node[:mediawiki][:group]
131 template "#{mediawiki_directory}/LocalSettings.php" do
133 source "LocalSettings.php.erb"
134 owner node[:mediawiki][:user]
135 group node[:mediawiki][:group]
137 variables :name => new_resource.name,
138 :directory => mediawiki_directory,
139 :database_params => new_resource.database_params,
140 :mediawiki => new_resource.mediawiki_params
141 notifies :run, "execute[#{mediawiki_directory}/maintenance/update.php]"
144 template "/etc/cron.d/mediawiki-#{cron_name}" do
146 source "mediawiki.cron.erb"
150 variables :name => new_resource.name, :directory => site_directory,
151 :user => node[:mediawiki][:user]
154 template "/etc/cron.daily/mediawiki-#{cron_name}-backup" do
156 source "mediawiki-backup.cron.erb"
160 variables :name => new_resource.name, :directory => site_directory,
161 :database_params => new_resource.database_params
164 mediawiki_extension "Cite" do
165 site new_resource.name
166 template "mw-ext-Cite.inc.php.erb"
170 mediawiki_extension "ConfirmEdit" do
171 site new_resource.name
172 template "mw-ext-ConfirmEdit.inc.php.erb"
173 variables :public_key => new_resource.recaptcha_public_key,
174 :private_key => new_resource.recaptcha_private_key
178 mediawiki_extension "Gadgets" do
179 site new_resource.name
183 mediawiki_extension "ImageMap" do
184 site new_resource.name
188 mediawiki_extension "InputBox" do
189 site new_resource.name
193 mediawiki_extension "Interwiki" do
194 site new_resource.name
198 mediawiki_extension "Nuke" do
199 site new_resource.name
203 mediawiki_extension "ParserFunctions" do
204 site new_resource.name
205 template "mw-ext-ParserFunctions.inc.php.erb"
209 mediawiki_extension "PdfHandler" do
210 site new_resource.name
211 template "mw-ext-PdfHandler.inc.php.erb"
215 mediawiki_extension "Poem" do
216 site new_resource.name
220 mediawiki_extension "Renameuser" do
221 site new_resource.name
225 mediawiki_extension "SimpleAntiSpam" do
226 site new_resource.name
230 mediawiki_extension "SpamBlacklist" do
231 site new_resource.name
232 template "mw-ext-SpamBlacklist.inc.php.erb"
236 mediawiki_extension "SyntaxHighlight_GeSHi" do
237 site new_resource.name
241 mediawiki_extension "TitleBlacklist" do
242 site new_resource.name
243 template "mw-ext-TitleBlacklist.inc.php.erb"
247 mediawiki_extension "WikiEditor" do
248 site new_resource.name
252 # MediaWiki Language Extension Bundle
253 # FIXME: should automatically resolve tag
254 mw_lang_ext_bundle_tag = "2015.03"
256 mediawiki_extension "Babel" do
257 site new_resource.name
258 template "mw-ext-Babel.inc.php.erb"
259 tag mw_lang_ext_bundle_tag
263 mediawiki_extension "cldr" do
264 site new_resource.name
265 tag mw_lang_ext_bundle_tag
269 mediawiki_extension "CleanChanges" do
270 site new_resource.name
271 template "mw-ext-CleanChanges.inc.php.erb"
272 tag mw_lang_ext_bundle_tag
276 mediawiki_extension "LocalisationUpdate" do
277 site new_resource.name
278 template "mw-ext-LocalisationUpdate.inc.php.erb"
279 tag mw_lang_ext_bundle_tag
283 # LocalisationUpdate Update Cron
284 # template "/etc/cron.d/mediawiki-#{name}-LocalisationUpdate" do
285 # cookbook "mediawiki"
286 # source "mediawiki-LocalisationUpdate.cron.erb"
290 # variables :name => name, :directory => site_directory, :user => node[:mediawiki][:user]
293 # mediawiki_extension "Translate" do
294 # site new_resource.name
295 # template "mw-ext-Translate.inc.php.erb"
296 # tag mw_lang_ext_bundle_tag
300 mediawiki_extension "UniversalLanguageSelector" do
301 site new_resource.name
302 tag mw_lang_ext_bundle_tag
306 mediawiki_extension "AntiSpoof" do
307 site new_resource.name
311 mediawiki_extension "AbuseFilter" do
312 site new_resource.name
313 template "mw-ext-AbuseFilter.inc.php.erb"
317 mediawiki_extension "CheckUser" do
318 site new_resource.name
319 template "mw-ext-CheckUser.inc.php.erb"
323 mediawiki_extension "DismissableSiteNotice" do
324 site new_resource.name
328 mediawiki_extension "Elastica" do
329 site new_resource.name
333 mediawiki_extension "CirrusSearch" do
334 site new_resource.name
335 template "mw-ext-CirrusSearch.inc.php.erb"
339 mediawiki_extension "osmtaginfo" do
340 site new_resource.name
341 repository "git://github.com/Firefishy/osmtaginfo.git"
346 mediawiki_extension "SimpleMap" do
347 site new_resource.name
348 repository "git://github.com/Firefishy/SimpleMap.git"
353 mediawiki_extension "SlippyMap" do
354 site new_resource.name
355 repository "git://github.com/Firefishy/SlippyMap.git"
360 cookbook_file "#{site_directory}/cc-wiki.png" do
362 owner node[:mediawiki][:user]
363 group node[:mediawiki][:group]
368 cookbook_file "#{site_directory}/googled06a989d1ccc8364.html" do
370 owner node[:mediawiki][:user]
371 group node[:mediawiki][:group]
376 cookbook_file "#{site_directory}/googlefac54c35e800caab.html" do
378 owner node[:mediawiki][:user]
379 group node[:mediawiki][:group]
384 apache_site new_resource.name do
386 template "apache.erb"
387 directory site_directory
388 variables :aliases => Array(new_resource.aliases),
389 :private => new_resource.private,
390 :ssl_enabled => new_resource.ssl_enabled,
391 :ssl_certificate => new_resource.ssl_certificate,
392 :ssl_certificate_chain => new_resource.ssl_certificate_chain
396 # FIXME: needs to run one
397 execute "#{mediawiki_directory}/extensions/CirrusSearch/maintenance/updateSearchIndexConfig.php" do
399 command "php extensions/CirrusSearch/maintenance/updateSearchIndexConfig.php"
400 cwd mediawiki_directory
401 user node[:mediawiki][:user]
402 group node[:mediawiki][:group]
407 apache_site new_resource.name do
412 directory site_directory do
417 mysql_database new_resource.database_name do
421 mysql_user "#{new_resource.database_user}@localhost" do
427 new_resource.directory || "/srv/#{new_resource.name}"
431 new_resource.name.tr(".", "_")