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 template "mw-ext-cldr.inc.php.erb"
299 tag mw_lang_ext_bundle_tag
303 mediawiki_extension "CleanChanges" do
304 site new_resource.name
305 template "mw-ext-CleanChanges.inc.php.erb"
306 tag mw_lang_ext_bundle_tag
310 mediawiki_extension "LocalisationUpdate" do
311 site new_resource.name
312 template "mw-ext-LocalisationUpdate.inc.php.erb"
313 tag mw_lang_ext_bundle_tag
317 # LocalisationUpdate Update Cron
318 # template "/etc/cron.d/mediawiki-#{name}-LocalisationUpdate" do
319 # cookbook "mediawiki"
320 # source "mediawiki-LocalisationUpdate.cron.erb"
324 # variables :name => name, :directory => site_directory, :user => node[:mediawiki][:user]
327 # mediawiki_extension "Translate" do
328 # site new_resource.name
329 # template "mw-ext-Translate.inc.php.erb"
330 # tag mw_lang_ext_bundle_tag
334 mediawiki_extension "UniversalLanguageSelector" do
335 site new_resource.name
336 tag mw_lang_ext_bundle_tag
340 mediawiki_extension "AntiSpoof" do
341 site new_resource.name
342 template "mw-ext-AntiSpoof.inc.php.erb"
346 mediawiki_extension "AbuseFilter" do
347 site new_resource.name
348 template "mw-ext-AbuseFilter.inc.php.erb"
352 mediawiki_extension "CheckUser" do
353 site new_resource.name
354 template "mw-ext-CheckUser.inc.php.erb"
358 mediawiki_extension "DismissableSiteNotice" do
359 site new_resource.name
363 mediawiki_extension "Elastica" do
364 site new_resource.name
368 mediawiki_extension "CirrusSearch" do
369 site new_resource.name
370 template "mw-ext-CirrusSearch.inc.php.erb"
374 mediawiki_extension "osmtaginfo" do
375 site new_resource.name
376 repository "git://github.com/Firefishy/osmtaginfo.git"
382 mediawiki_extension "SimpleMap" do
383 site new_resource.name
384 repository "git://github.com/Firefishy/SimpleMap.git"
390 mediawiki_extension "SlippyMap" do
391 site new_resource.name
392 repository "git://github.com/Firefishy/SlippyMap.git"
398 mediawiki_extension "Mantle" do
399 site new_resource.name
404 mediawiki_extension "MobileFrontend" do
405 site new_resource.name
406 template "mw-ext-MobileFrontend.inc.php.erb"
410 mediawiki_extension "DisableAccount" do
411 site new_resource.name
412 template "mw-ext-DisableAccount.inc.php.erb"
416 cookbook_file "#{site_directory}/cc-wiki.png" do
418 owner node[:mediawiki][:user]
419 group node[:mediawiki][:group]
424 cookbook_file "#{site_directory}/googled06a989d1ccc8364.html" do
426 owner node[:mediawiki][:user]
427 group node[:mediawiki][:group]
432 cookbook_file "#{site_directory}/googlefac54c35e800caab.html" do
434 owner node[:mediawiki][:user]
435 group node[:mediawiki][:group]
440 ports = new_resource.ssl_enabled ? [80, 443] : [80]
442 apache_site new_resource.name do
444 template "apache.erb"
445 directory site_directory
446 variables :aliases => Array(new_resource.aliases),
447 :private => new_resource.private,
449 :ssl_certificate => new_resource.ssl_certificate,
450 :ssl_certificate_chain => new_resource.ssl_certificate_chain
454 # FIXME: needs to run one
455 execute "#{mediawiki_directory}/extensions/CirrusSearch/maintenance/updateSearchIndexConfig.php" do
457 command "php extensions/CirrusSearch/maintenance/updateSearchIndexConfig.php"
458 cwd mediawiki_directory
459 user node[:mediawiki][:user]
460 group node[:mediawiki][:group]
465 mediawiki_directory = "#{site_directory}/w"
467 template "#{mediawiki_directory}/LocalSettings.php" do
469 source "LocalSettings.php.erb"
470 owner node[:mediawiki][:user]
471 group node[:mediawiki][:group]
473 variables :name => new_resource.name,
474 :directory => mediawiki_directory,
475 :database_params => new_resource.database_params,
476 :mediawiki => new_resource.mediawiki_params
477 notifies :run, "execute[#{mediawiki_directory}/maintenance/update.php]"
480 execute "#{mediawiki_directory}/maintenance/update.php" do
482 command "php maintenance/update.php --quick"
483 cwd mediawiki_directory
484 user node[:mediawiki][:user]
485 group node[:mediawiki][:group]
490 apache_site new_resource.name do
495 directory site_directory do
500 mysql_database new_resource.database_name do
504 mysql_user "#{new_resource.database_user}@localhost" do
510 new_resource.directory || "/srv/#{new_resource.name}"
514 new_resource.name.tr(".", "_")