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
282 mediawiki_extension "TitleBlacklist" do
283 site new_resource.name
284 template "mw-ext-TitleBlacklist.inc.php.erb"
288 mediawiki_extension "WikiEditor" do
289 site new_resource.name
293 # MediaWiki Language Extension Bundle
294 # FIXME: should automatically resolve tag
295 mw_lang_ext_bundle_tag = "2015.10"
297 mediawiki_extension "Babel" do
298 site new_resource.name
299 template "mw-ext-Babel.inc.php.erb"
300 tag mw_lang_ext_bundle_tag
304 mediawiki_extension "cldr" do
305 site new_resource.name
306 template "mw-ext-cldr.inc.php.erb"
307 tag mw_lang_ext_bundle_tag
311 mediawiki_extension "CleanChanges" do
312 site new_resource.name
313 template "mw-ext-CleanChanges.inc.php.erb"
314 tag mw_lang_ext_bundle_tag
318 mediawiki_extension "LocalisationUpdate" do
319 site new_resource.name
320 template "mw-ext-LocalisationUpdate.inc.php.erb"
321 tag mw_lang_ext_bundle_tag
325 # LocalisationUpdate Update Cron
326 # template "/etc/cron.d/mediawiki-#{name}-LocalisationUpdate" do
327 # cookbook "mediawiki"
328 # source "mediawiki-LocalisationUpdate.cron.erb"
332 # variables :name => name, :directory => site_directory, :user => node[:mediawiki][:user]
335 # mediawiki_extension "Translate" do
336 # site new_resource.name
337 # template "mw-ext-Translate.inc.php.erb"
338 # tag mw_lang_ext_bundle_tag
342 mediawiki_extension "UniversalLanguageSelector" do
343 site new_resource.name
344 tag mw_lang_ext_bundle_tag
348 mediawiki_extension "AntiSpoof" do
349 site new_resource.name
350 template "mw-ext-AntiSpoof.inc.php.erb"
354 mediawiki_extension "AbuseFilter" do
355 site new_resource.name
356 template "mw-ext-AbuseFilter.inc.php.erb"
360 mediawiki_extension "CheckUser" do
361 site new_resource.name
362 template "mw-ext-CheckUser.inc.php.erb"
366 mediawiki_extension "DismissableSiteNotice" do
367 site new_resource.name
371 mediawiki_extension "Elastica" do
372 site new_resource.name
376 mediawiki_extension "CirrusSearch" do
377 site new_resource.name
378 template "mw-ext-CirrusSearch.inc.php.erb"
382 mediawiki_extension "osmtaginfo" do
383 site new_resource.name
384 template "mw-ext-osmtaginfo.inc.php.erb"
385 repository "git://github.com/Firefishy/osmtaginfo.git"
390 mediawiki_extension "SimpleMap" do
391 site new_resource.name
392 template "mw-ext-SimpleMap.inc.php.erb"
393 repository "git://github.com/Firefishy/SimpleMap.git"
398 mediawiki_extension "SlippyMap" do
399 site new_resource.name
400 template "mw-ext-SlippyMap.inc.php.erb"
401 repository "git://github.com/Firefishy/SlippyMap.git"
406 mediawiki_extension "Mantle" do
407 site new_resource.name
412 mediawiki_extension "MobileFrontend" do
413 site new_resource.name
414 template "mw-ext-MobileFrontend.inc.php.erb"
418 mediawiki_extension "DisableAccount" do
419 site new_resource.name
420 template "mw-ext-DisableAccount.inc.php.erb"
424 mediawiki_extension "VisualEditor" do
425 site new_resource.name
426 template "mw-ext-VisualEditor.inc.php.erb"
430 cookbook_file "#{site_directory}/cc-wiki.png" do
432 owner node[:mediawiki][:user]
433 group node[:mediawiki][:group]
438 cookbook_file "#{site_directory}/googled06a989d1ccc8364.html" do
440 owner node[:mediawiki][:user]
441 group node[:mediawiki][:group]
446 cookbook_file "#{site_directory}/googlefac54c35e800caab.html" do
448 owner node[:mediawiki][:user]
449 group node[:mediawiki][:group]
454 ports = new_resource.ssl_enabled ? [80, 443] : [80]
456 apache_site new_resource.name do
458 template "apache.erb"
459 directory site_directory
460 variables :aliases => Array(new_resource.aliases),
461 :private => new_resource.private,
463 :ssl_certificate => new_resource.ssl_certificate,
464 :ssl_certificate_chain => new_resource.ssl_certificate_chain
468 # FIXME: needs to run one
469 execute "#{mediawiki_directory}/extensions/CirrusSearch/maintenance/updateSearchIndexConfig.php" do
471 command "php extensions/CirrusSearch/maintenance/updateSearchIndexConfig.php"
472 cwd mediawiki_directory
473 user node[:mediawiki][:user]
474 group node[:mediawiki][:group]
479 mediawiki_directory = "#{site_directory}/w"
481 template "#{mediawiki_directory}/LocalSettings.php" do
483 source "LocalSettings.php.erb"
484 owner node[:mediawiki][:user]
485 group node[:mediawiki][:group]
487 variables :name => new_resource.name,
488 :directory => mediawiki_directory,
489 :database_params => new_resource.database_params,
490 :mediawiki => new_resource.mediawiki_params
491 notifies :run, "execute[#{mediawiki_directory}/maintenance/update.php]"
494 execute "#{mediawiki_directory}/maintenance/update.php" do
496 command "php maintenance/update.php --quick"
497 cwd mediawiki_directory
498 user node[:mediawiki][:user]
499 group node[:mediawiki][:group]
504 apache_site new_resource.name do
509 directory site_directory do
514 mysql_database new_resource.database_name do
518 mysql_user "#{new_resource.database_user}@localhost" do
524 new_resource.directory || "/srv/#{new_resource.name}"
528 new_resource.name.tr(".", "_")