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.normal_unless[:mediawiki][:sites][new_resource.name] = {}
33 node.normal[:mediawiki][:sites][new_resource.name][:directory] = site_directory
34 node.normal[:mediawiki][:sites][new_resource.name][:version] = new_resource.version
36 node.normal_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 = "REL#{new_resource.version}".tr(".", "_")
90 git "#{mediawiki_directory}/vendor" do
92 repository "https://gerrit.wikimedia.org/r/p/mediawiki/vendor.git"
93 revision mediawiki_reference
94 user node[:mediawiki][:user]
95 group node[:mediawiki][:group]
98 git mediawiki_directory do
100 repository "https://gerrit.wikimedia.org/r/p/mediawiki/core.git"
101 revision mediawiki_reference
102 user node[:mediawiki][:user]
103 group node[:mediawiki][:group]
104 notifies :sync, "git[#{mediawiki_directory}/vendor]", :immediately
105 notifies :run, "execute[#{mediawiki_directory}/maintenance/install.php]", :immediately
106 notifies :run, "execute[#{mediawiki_directory}/maintenance/update.php]"
109 # Safety catch if git doesn't update but install.php hasn't run
110 ruby_block "catch-installer-localsettings-run" do
116 ::File.exist?("#{mediawiki_directory}/LocalSettings-install.php")
118 notifies :run, "execute[#{mediawiki_directory}/maintenance/install.php]", :immediately
121 directory "#{mediawiki_directory}/images" do
123 group node[:mediawiki][:group]
127 directory "#{mediawiki_directory}/cache" do
129 group node[:mediawiki][:group]
133 directory "#{mediawiki_directory}/LocalSettings.d" do
134 user node[:mediawiki][:user]
135 group node[:mediawiki][:group]
139 template "#{mediawiki_directory}/LocalSettings.php" do
141 source "LocalSettings.php.erb"
142 owner node[:mediawiki][:user]
143 group node[:mediawiki][:group]
145 variables :name => new_resource.name,
146 :directory => mediawiki_directory,
147 :database_params => new_resource.database_params,
148 :mediawiki => new_resource.mediawiki_params
149 notifies :run, "execute[#{mediawiki_directory}/maintenance/update.php]"
152 template "/etc/cron.d/mediawiki-#{cron_name}" do
154 source "mediawiki.cron.erb"
158 variables :name => new_resource.name, :directory => site_directory,
159 :user => node[:mediawiki][:user]
162 template "/etc/cron.daily/mediawiki-#{cron_name}-backup" do
164 source "mediawiki-backup.cron.erb"
168 variables :name => new_resource.name, :directory => site_directory,
169 :database_params => new_resource.database_params
172 mediawiki_skin "CologneBlue" do # ~FC005
173 site new_resource.name
177 mediawiki_skin "Modern" do
178 site new_resource.name
182 mediawiki_skin "MonoBook" do
183 site new_resource.name
187 mediawiki_skin "Vector" do
188 site new_resource.name
192 mediawiki_extension "Cite" do
193 site new_resource.name
197 mediawiki_extension "CiteThisPage" do
198 site new_resource.name
202 if new_resource.private_accounts || new_resource.private
203 mediawiki_extension "ConfirmEdit" do
204 site new_resource.name
209 mediawiki_extension "ConfirmEdit" do
210 site new_resource.name
211 template "mw-ext-ConfirmEdit.inc.php.erb"
212 variables :public_key => new_resource.recaptcha_public_key,
213 :private_key => new_resource.recaptcha_private_key
218 mediawiki_extension "Gadgets" do
219 site new_resource.name
223 mediawiki_extension "ImageMap" do
224 site new_resource.name
228 mediawiki_extension "InputBox" do
229 site new_resource.name
233 mediawiki_extension "Interwiki" do
234 site new_resource.name
238 mediawiki_extension "Nuke" do
239 site new_resource.name
243 mediawiki_extension "ParserFunctions" do
244 site new_resource.name
245 template "mw-ext-ParserFunctions.inc.php.erb"
249 mediawiki_extension "PdfHandler" do
250 site new_resource.name
251 template "mw-ext-PdfHandler.inc.php.erb"
255 mediawiki_extension "Poem" do
256 site new_resource.name
260 mediawiki_extension "Renameuser" do
261 site new_resource.name
265 mediawiki_extension "SimpleAntiSpam" do
266 site new_resource.name
271 mediawiki_extension "SpamBlacklist" do
272 site new_resource.name
273 template "mw-ext-SpamBlacklist.inc.php.erb"
277 mediawiki_extension "SyntaxHighlight_GeSHi" do
278 site new_resource.name
279 template "mw-ext-SyntaxHighlight.inc.php.erb"
283 mediawiki_extension "TitleBlacklist" do
284 site new_resource.name
285 template "mw-ext-TitleBlacklist.inc.php.erb"
289 mediawiki_extension "WikiEditor" do
290 site new_resource.name
294 # MediaWiki Language Extension Bundle
295 # FIXME: should automatically resolve tag
296 mw_lang_ext_bundle_tag = "2017.01"
298 mediawiki_extension "Babel" do
299 site new_resource.name
300 template "mw-ext-Babel.inc.php.erb"
301 # tag mw_lang_ext_bundle_tag
302 tag mw_lang_ext_bundle_tag
306 mediawiki_extension "cldr" do
307 site new_resource.name
308 template "mw-ext-cldr.inc.php.erb"
309 tag mw_lang_ext_bundle_tag
313 mediawiki_extension "CleanChanges" do
314 site new_resource.name
315 template "mw-ext-CleanChanges.inc.php.erb"
316 tag mw_lang_ext_bundle_tag
320 mediawiki_extension "LocalisationUpdate" do
321 site new_resource.name
322 template "mw-ext-LocalisationUpdate.inc.php.erb"
323 tag mw_lang_ext_bundle_tag
327 # LocalisationUpdate Update Cron
328 # template "/etc/cron.d/mediawiki-#{name}-LocalisationUpdate" do
329 # cookbook "mediawiki"
330 # source "mediawiki-LocalisationUpdate.cron.erb"
334 # variables :name => name, :directory => site_directory, :user => node[:mediawiki][:user]
337 # mediawiki_extension "Translate" do
338 # site new_resource.name
339 # template "mw-ext-Translate.inc.php.erb"
340 # tag mw_lang_ext_bundle_tag
344 mediawiki_extension "UniversalLanguageSelector" do
345 site new_resource.name
346 tag mw_lang_ext_bundle_tag
350 mediawiki_extension "AntiSpoof" do
351 site new_resource.name
352 template "mw-ext-AntiSpoof.inc.php.erb"
356 mediawiki_extension "AbuseFilter" do
357 site new_resource.name
358 template "mw-ext-AbuseFilter.inc.php.erb"
362 mediawiki_extension "CheckUser" do
363 site new_resource.name
364 template "mw-ext-CheckUser.inc.php.erb"
368 mediawiki_extension "DismissableSiteNotice" do
369 site new_resource.name
373 mediawiki_extension "Elastica" do
374 site new_resource.name
378 mediawiki_extension "CirrusSearch" do
379 site new_resource.name
380 template "mw-ext-CirrusSearch.inc.php.erb"
384 mediawiki_extension "osmtaginfo" do
385 site new_resource.name
386 template "mw-ext-osmtaginfo.inc.php.erb"
387 repository "git://github.com/Firefishy/osmtaginfo.git"
392 mediawiki_extension "SimpleMap" do
393 site new_resource.name
394 template "mw-ext-SimpleMap.inc.php.erb"
395 repository "git://github.com/Firefishy/SimpleMap.git"
400 mediawiki_extension "SlippyMap" do
401 site new_resource.name
402 template "mw-ext-SlippyMap.inc.php.erb"
403 repository "git://github.com/Firefishy/SlippyMap.git"
408 mediawiki_extension "Mantle" do
409 site new_resource.name
414 mediawiki_extension "MobileFrontend" do
415 site new_resource.name
416 template "mw-ext-MobileFrontend.inc.php.erb"
420 mediawiki_extension "DisableAccount" do
421 site new_resource.name
422 template "mw-ext-DisableAccount.inc.php.erb"
426 mediawiki_extension "VisualEditor" do
427 site new_resource.name
428 template "mw-ext-VisualEditor.inc.php.erb"
432 cookbook_file "#{site_directory}/cc-wiki.png" do
434 owner node[:mediawiki][:user]
435 group node[:mediawiki][:group]
440 cookbook_file "#{site_directory}/googled06a989d1ccc8364.html" do
442 owner node[:mediawiki][:user]
443 group node[:mediawiki][:group]
448 cookbook_file "#{site_directory}/googlefac54c35e800caab.html" do
450 owner node[:mediawiki][:user]
451 group node[:mediawiki][:group]
456 ports = new_resource.ssl_enabled ? [80, 443] : [80]
458 ssl_certificate new_resource.name do
459 domains [new_resource.name] + Array(new_resource.aliases)
460 only_if { new_resource.ssl_enabled }
463 apache_site new_resource.name do
465 template "apache.erb"
466 directory site_directory
467 variables :aliases => Array(new_resource.aliases),
468 :private => new_resource.private,
469 :ssl_enabled => new_resource.ssl_enabled,
474 # FIXME: needs to run one
475 execute "#{mediawiki_directory}/extensions/CirrusSearch/maintenance/updateSearchIndexConfig.php" do
477 command "php extensions/CirrusSearch/maintenance/updateSearchIndexConfig.php"
478 cwd mediawiki_directory
479 user node[:mediawiki][:user]
480 group node[:mediawiki][:group]
485 mediawiki_directory = "#{site_directory}/w"
487 template "#{mediawiki_directory}/LocalSettings.php" do
489 source "LocalSettings.php.erb"
490 owner node[:mediawiki][:user]
491 group node[:mediawiki][:group]
493 variables :name => new_resource.name,
494 :directory => mediawiki_directory,
495 :database_params => new_resource.database_params,
496 :mediawiki => new_resource.mediawiki_params
497 notifies :run, "execute[#{mediawiki_directory}/maintenance/update.php]"
500 execute "#{mediawiki_directory}/maintenance/update.php" do
502 command "php maintenance/update.php --quick"
503 cwd mediawiki_directory
504 user node[:mediawiki][:user]
505 group node[:mediawiki][:group]
510 apache_site new_resource.name do
515 directory site_directory do
520 mysql_database new_resource.database_name do
524 mysql_user "#{new_resource.database_user}@localhost" do
530 new_resource.directory || "/srv/#{new_resource.name}"
534 new_resource.name.tr(".", "_")