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 = "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 mediawiki_extension "ConfirmEdit" do
203 site new_resource.name
204 template "mw-ext-ConfirmEdit.inc.php.erb"
205 variables :public_key => new_resource.recaptcha_public_key,
206 :private_key => new_resource.recaptcha_private_key
210 mediawiki_extension "Gadgets" do
211 site new_resource.name
215 mediawiki_extension "ImageMap" do
216 site new_resource.name
220 mediawiki_extension "InputBox" do
221 site new_resource.name
225 mediawiki_extension "Interwiki" do
226 site new_resource.name
230 mediawiki_extension "Nuke" do
231 site new_resource.name
235 mediawiki_extension "ParserFunctions" do
236 site new_resource.name
237 template "mw-ext-ParserFunctions.inc.php.erb"
241 mediawiki_extension "PdfHandler" do
242 site new_resource.name
243 template "mw-ext-PdfHandler.inc.php.erb"
247 mediawiki_extension "Poem" do
248 site new_resource.name
252 mediawiki_extension "Renameuser" do
253 site new_resource.name
257 mediawiki_extension "SimpleAntiSpam" do
258 site new_resource.name
263 mediawiki_extension "SpamBlacklist" do
264 site new_resource.name
265 template "mw-ext-SpamBlacklist.inc.php.erb"
269 mediawiki_extension "SyntaxHighlight_GeSHi" do
270 site new_resource.name
274 mediawiki_extension "TitleBlacklist" do
275 site new_resource.name
276 template "mw-ext-TitleBlacklist.inc.php.erb"
280 mediawiki_extension "WikiEditor" do
281 site new_resource.name
285 # MediaWiki Language Extension Bundle
286 # FIXME: should automatically resolve tag
287 mw_lang_ext_bundle_tag = "2015.10"
289 mediawiki_extension "Babel" do
290 site new_resource.name
291 template "mw-ext-Babel.inc.php.erb"
292 tag mw_lang_ext_bundle_tag
296 mediawiki_extension "cldr" do
297 site new_resource.name
298 tag mw_lang_ext_bundle_tag
302 mediawiki_extension "CleanChanges" do
303 site new_resource.name
304 template "mw-ext-CleanChanges.inc.php.erb"
305 tag mw_lang_ext_bundle_tag
309 mediawiki_extension "LocalisationUpdate" do
310 site new_resource.name
311 template "mw-ext-LocalisationUpdate.inc.php.erb"
312 tag mw_lang_ext_bundle_tag
316 # LocalisationUpdate Update Cron
317 # template "/etc/cron.d/mediawiki-#{name}-LocalisationUpdate" do
318 # cookbook "mediawiki"
319 # source "mediawiki-LocalisationUpdate.cron.erb"
323 # variables :name => name, :directory => site_directory, :user => node[:mediawiki][:user]
326 # mediawiki_extension "Translate" do
327 # site new_resource.name
328 # template "mw-ext-Translate.inc.php.erb"
329 # tag mw_lang_ext_bundle_tag
333 mediawiki_extension "UniversalLanguageSelector" do
334 site new_resource.name
335 tag mw_lang_ext_bundle_tag
339 mediawiki_extension "AntiSpoof" do
340 site new_resource.name
344 mediawiki_extension "AbuseFilter" do
345 site new_resource.name
346 template "mw-ext-AbuseFilter.inc.php.erb"
350 mediawiki_extension "CheckUser" do
351 site new_resource.name
352 template "mw-ext-CheckUser.inc.php.erb"
356 mediawiki_extension "DismissableSiteNotice" do
357 site new_resource.name
361 mediawiki_extension "Elastica" do
362 site new_resource.name
366 mediawiki_extension "CirrusSearch" do
367 site new_resource.name
368 template "mw-ext-CirrusSearch.inc.php.erb"
372 mediawiki_extension "osmtaginfo" do
373 site new_resource.name
374 repository "git://github.com/Firefishy/osmtaginfo.git"
380 mediawiki_extension "SimpleMap" do
381 site new_resource.name
382 repository "git://github.com/Firefishy/SimpleMap.git"
388 mediawiki_extension "SlippyMap" do
389 site new_resource.name
390 repository "git://github.com/Firefishy/SlippyMap.git"
396 mediawiki_extension "Mantle" do
397 site new_resource.name
402 mediawiki_extension "MobileFrontend" do
403 site new_resource.name
404 template "mw-ext-MobileFrontend.inc.php.erb"
408 mediawiki_extension "DisableAccount" do
409 site new_resource.name
410 template "mw-ext-DisableAccount.inc.php.erb"
414 cookbook_file "#{site_directory}/cc-wiki.png" do
416 owner node[:mediawiki][:user]
417 group node[:mediawiki][:group]
422 cookbook_file "#{site_directory}/googled06a989d1ccc8364.html" do
424 owner node[:mediawiki][:user]
425 group node[:mediawiki][:group]
430 cookbook_file "#{site_directory}/googlefac54c35e800caab.html" do
432 owner node[:mediawiki][:user]
433 group node[:mediawiki][:group]
438 ports = new_resource.ssl_enabled ? [80, 443] : [80]
440 apache_site new_resource.name do
442 template "apache.erb"
443 directory site_directory
444 variables :aliases => Array(new_resource.aliases),
445 :private => new_resource.private,
447 :ssl_certificate => new_resource.ssl_certificate,
448 :ssl_certificate_chain => new_resource.ssl_certificate_chain
452 # FIXME: needs to run one
453 execute "#{mediawiki_directory}/extensions/CirrusSearch/maintenance/updateSearchIndexConfig.php" do
455 command "php extensions/CirrusSearch/maintenance/updateSearchIndexConfig.php"
456 cwd mediawiki_directory
457 user node[:mediawiki][:user]
458 group node[:mediawiki][:group]
463 mediawiki_directory = "#{site_directory}/w"
465 template "#{mediawiki_directory}/LocalSettings.php" do
467 source "LocalSettings.php.erb"
468 owner node[:mediawiki][:user]
469 group node[:mediawiki][:group]
471 variables :name => new_resource.name,
472 :directory => mediawiki_directory,
473 :database_params => new_resource.database_params,
474 :mediawiki => new_resource.mediawiki_params
475 notifies :run, "execute[#{mediawiki_directory}/maintenance/update.php]"
478 execute "#{mediawiki_directory}/maintenance/update.php" do
480 command "php maintenance/update.php --quick"
481 cwd mediawiki_directory
482 user node[:mediawiki][:user]
483 group node[:mediawiki][:group]
488 apache_site new_resource.name do
493 directory site_directory do
498 mysql_database new_resource.database_name do
502 mysql_user "#{new_resource.database_user}@localhost" do
508 new_resource.directory || "/srv/#{new_resource.name}"
512 new_resource.name.tr(".", "_")