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 = "2016.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
301 reference "740782459d34e756a932ea1ceddde432a1295197"
305 mediawiki_extension "cldr" do
306 site new_resource.name
307 template "mw-ext-cldr.inc.php.erb"
308 tag mw_lang_ext_bundle_tag
312 mediawiki_extension "CleanChanges" do
313 site new_resource.name
314 template "mw-ext-CleanChanges.inc.php.erb"
315 tag mw_lang_ext_bundle_tag
319 mediawiki_extension "LocalisationUpdate" do
320 site new_resource.name
321 template "mw-ext-LocalisationUpdate.inc.php.erb"
322 tag mw_lang_ext_bundle_tag
326 # LocalisationUpdate Update Cron
327 # template "/etc/cron.d/mediawiki-#{name}-LocalisationUpdate" do
328 # cookbook "mediawiki"
329 # source "mediawiki-LocalisationUpdate.cron.erb"
333 # variables :name => name, :directory => site_directory, :user => node[:mediawiki][:user]
336 # mediawiki_extension "Translate" do
337 # site new_resource.name
338 # template "mw-ext-Translate.inc.php.erb"
339 # tag mw_lang_ext_bundle_tag
343 mediawiki_extension "UniversalLanguageSelector" do
344 site new_resource.name
345 tag mw_lang_ext_bundle_tag
349 mediawiki_extension "AntiSpoof" do
350 site new_resource.name
351 template "mw-ext-AntiSpoof.inc.php.erb"
355 mediawiki_extension "AbuseFilter" do
356 site new_resource.name
357 template "mw-ext-AbuseFilter.inc.php.erb"
361 mediawiki_extension "CheckUser" do
362 site new_resource.name
363 template "mw-ext-CheckUser.inc.php.erb"
367 mediawiki_extension "DismissableSiteNotice" do
368 site new_resource.name
372 mediawiki_extension "Elastica" do
373 site new_resource.name
377 mediawiki_extension "CirrusSearch" do
378 site new_resource.name
379 template "mw-ext-CirrusSearch.inc.php.erb"
383 mediawiki_extension "osmtaginfo" do
384 site new_resource.name
385 template "mw-ext-osmtaginfo.inc.php.erb"
386 repository "git://github.com/Firefishy/osmtaginfo.git"
391 mediawiki_extension "SimpleMap" do
392 site new_resource.name
393 template "mw-ext-SimpleMap.inc.php.erb"
394 repository "git://github.com/Firefishy/SimpleMap.git"
399 mediawiki_extension "SlippyMap" do
400 site new_resource.name
401 template "mw-ext-SlippyMap.inc.php.erb"
402 repository "git://github.com/Firefishy/SlippyMap.git"
407 mediawiki_extension "Mantle" do
408 site new_resource.name
413 mediawiki_extension "MobileFrontend" do
414 site new_resource.name
415 template "mw-ext-MobileFrontend.inc.php.erb"
419 mediawiki_extension "DisableAccount" do
420 site new_resource.name
421 template "mw-ext-DisableAccount.inc.php.erb"
425 mediawiki_extension "VisualEditor" do
426 site new_resource.name
427 template "mw-ext-VisualEditor.inc.php.erb"
431 cookbook_file "#{site_directory}/cc-wiki.png" do
433 owner node[:mediawiki][:user]
434 group node[:mediawiki][:group]
439 cookbook_file "#{site_directory}/googled06a989d1ccc8364.html" do
441 owner node[:mediawiki][:user]
442 group node[:mediawiki][:group]
447 cookbook_file "#{site_directory}/googlefac54c35e800caab.html" do
449 owner node[:mediawiki][:user]
450 group node[:mediawiki][:group]
455 ports = new_resource.ssl_enabled ? [80, 443] : [80]
457 apache_site new_resource.name do
459 template "apache.erb"
460 directory site_directory
461 variables :aliases => Array(new_resource.aliases),
462 :private => new_resource.private,
464 :ssl_certificate => new_resource.ssl_certificate,
465 :ssl_certificate_chain => new_resource.ssl_certificate_chain
469 # FIXME: needs to run one
470 execute "#{mediawiki_directory}/extensions/CirrusSearch/maintenance/updateSearchIndexConfig.php" do
472 command "php extensions/CirrusSearch/maintenance/updateSearchIndexConfig.php"
473 cwd mediawiki_directory
474 user node[:mediawiki][:user]
475 group node[:mediawiki][:group]
480 mediawiki_directory = "#{site_directory}/w"
482 template "#{mediawiki_directory}/LocalSettings.php" do
484 source "LocalSettings.php.erb"
485 owner node[:mediawiki][:user]
486 group node[:mediawiki][:group]
488 variables :name => new_resource.name,
489 :directory => mediawiki_directory,
490 :database_params => new_resource.database_params,
491 :mediawiki => new_resource.mediawiki_params
492 notifies :run, "execute[#{mediawiki_directory}/maintenance/update.php]"
495 execute "#{mediawiki_directory}/maintenance/update.php" do
497 command "php maintenance/update.php --quick"
498 cwd mediawiki_directory
499 user node[:mediawiki][:user]
500 group node[:mediawiki][:group]
505 apache_site new_resource.name do
510 directory site_directory do
515 mysql_database new_resource.database_name do
519 mysql_user "#{new_resource.database_user}@localhost" do
525 new_resource.directory || "/srv/#{new_resource.name}"
529 new_resource.name.tr(".", "_")