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 do
92 repository "https://gerrit.wikimedia.org/r/p/mediawiki/core.git"
93 revision mediawiki_reference
94 user node[:mediawiki][:user]
95 group node[:mediawiki][:group]
96 notifies :run, "execute[#{mediawiki_directory}/maintenance/install.php]", :immediately
97 notifies :run, "execute[#{mediawiki_directory}/maintenance/update.php]"
100 # Safety catch if git doesn't update but install.php hasn't run
101 ruby_block "catch-installer-localsettings-run" do
107 ::File.exist?("#{mediawiki_directory}/LocalSettings-install.php")
109 notifies :run, "execute[#{mediawiki_directory}/maintenance/install.php]", :immediately
112 directory "#{mediawiki_directory}/images" do
114 group node[:mediawiki][:group]
118 directory "#{mediawiki_directory}/cache" do
120 group node[:mediawiki][:group]
124 directory "#{mediawiki_directory}/LocalSettings.d" do
125 user node[:mediawiki][:user]
126 group node[:mediawiki][:group]
130 template "#{mediawiki_directory}/LocalSettings.php" do
132 source "LocalSettings.php.erb"
133 owner node[:mediawiki][:user]
134 group node[:mediawiki][:group]
136 variables :name => new_resource.name,
137 :directory => mediawiki_directory,
138 :database_params => new_resource.database_params,
139 :mediawiki => new_resource.mediawiki_params
140 notifies :run, "execute[#{mediawiki_directory}/maintenance/update.php]"
143 template "/etc/cron.d/mediawiki-#{cron_name}" do
145 source "mediawiki.cron.erb"
149 variables :name => new_resource.name, :directory => site_directory,
150 :user => node[:mediawiki][:user]
153 template "/etc/cron.daily/mediawiki-#{cron_name}-backup" do
155 source "mediawiki-backup.cron.erb"
159 variables :name => new_resource.name, :directory => site_directory,
160 :database_params => new_resource.database_params
163 mediawiki_skin "CologneBlue" do # ~FC005
164 site new_resource.name
168 mediawiki_skin "Modern" do
169 site new_resource.name
173 mediawiki_skin "MonoBook" do
174 site new_resource.name
178 mediawiki_skin "Vector" do
179 site new_resource.name
183 mediawiki_extension "Cite" do
184 site new_resource.name
185 template "mw-ext-Cite.inc.php.erb"
189 mediawiki_extension "ConfirmEdit" do
190 site new_resource.name
191 template "mw-ext-ConfirmEdit.inc.php.erb"
192 variables :public_key => new_resource.recaptcha_public_key,
193 :private_key => new_resource.recaptcha_private_key
197 mediawiki_extension "Gadgets" do
198 site new_resource.name
202 mediawiki_extension "ImageMap" do
203 site new_resource.name
207 mediawiki_extension "InputBox" do
208 site new_resource.name
212 mediawiki_extension "Interwiki" do
213 site new_resource.name
217 mediawiki_extension "Nuke" do
218 site new_resource.name
222 mediawiki_extension "ParserFunctions" do
223 site new_resource.name
224 template "mw-ext-ParserFunctions.inc.php.erb"
228 mediawiki_extension "PdfHandler" do
229 site new_resource.name
230 template "mw-ext-PdfHandler.inc.php.erb"
234 mediawiki_extension "Poem" do
235 site new_resource.name
239 mediawiki_extension "Renameuser" do
240 site new_resource.name
244 mediawiki_extension "SimpleAntiSpam" do
245 site new_resource.name
249 mediawiki_extension "SpamBlacklist" do
250 site new_resource.name
251 template "mw-ext-SpamBlacklist.inc.php.erb"
255 mediawiki_extension "SyntaxHighlight_GeSHi" do
256 site new_resource.name
260 mediawiki_extension "TitleBlacklist" do
261 site new_resource.name
262 template "mw-ext-TitleBlacklist.inc.php.erb"
266 mediawiki_extension "WikiEditor" do
267 site new_resource.name
271 # MediaWiki Language Extension Bundle
272 # FIXME: should automatically resolve tag
273 mw_lang_ext_bundle_tag = "2015.03"
275 mediawiki_extension "Babel" do
276 site new_resource.name
277 template "mw-ext-Babel.inc.php.erb"
278 tag mw_lang_ext_bundle_tag
282 mediawiki_extension "cldr" do
283 site new_resource.name
284 tag mw_lang_ext_bundle_tag
288 mediawiki_extension "CleanChanges" do
289 site new_resource.name
290 template "mw-ext-CleanChanges.inc.php.erb"
291 tag mw_lang_ext_bundle_tag
295 mediawiki_extension "LocalisationUpdate" do
296 site new_resource.name
297 template "mw-ext-LocalisationUpdate.inc.php.erb"
298 tag mw_lang_ext_bundle_tag
302 # LocalisationUpdate Update Cron
303 # template "/etc/cron.d/mediawiki-#{name}-LocalisationUpdate" do
304 # cookbook "mediawiki"
305 # source "mediawiki-LocalisationUpdate.cron.erb"
309 # variables :name => name, :directory => site_directory, :user => node[:mediawiki][:user]
312 # mediawiki_extension "Translate" do
313 # site new_resource.name
314 # template "mw-ext-Translate.inc.php.erb"
315 # tag mw_lang_ext_bundle_tag
319 mediawiki_extension "UniversalLanguageSelector" do
320 site new_resource.name
321 tag mw_lang_ext_bundle_tag
325 mediawiki_extension "AntiSpoof" do
326 site new_resource.name
330 mediawiki_extension "AbuseFilter" do
331 site new_resource.name
332 template "mw-ext-AbuseFilter.inc.php.erb"
336 mediawiki_extension "CheckUser" do
337 site new_resource.name
338 template "mw-ext-CheckUser.inc.php.erb"
342 mediawiki_extension "DismissableSiteNotice" do
343 site new_resource.name
347 mediawiki_extension "Elastica" do
348 site new_resource.name
352 mediawiki_extension "CirrusSearch" do
353 site new_resource.name
354 template "mw-ext-CirrusSearch.inc.php.erb"
358 mediawiki_extension "osmtaginfo" do
359 site new_resource.name
360 repository "git://github.com/Firefishy/osmtaginfo.git"
365 mediawiki_extension "SimpleMap" do
366 site new_resource.name
367 repository "git://github.com/Firefishy/SimpleMap.git"
372 mediawiki_extension "SlippyMap" do
373 site new_resource.name
374 repository "git://github.com/Firefishy/SlippyMap.git"
379 mediawiki_extension "Mantle" do
380 site new_resource.name
384 mediawiki_extension "MobileFrontend" do
385 site new_resource.name
386 template "mw-ext-MobileFrontend.inc.php.erb"
390 cookbook_file "#{site_directory}/cc-wiki.png" do
392 owner node[:mediawiki][:user]
393 group node[:mediawiki][:group]
398 cookbook_file "#{site_directory}/googled06a989d1ccc8364.html" do
400 owner node[:mediawiki][:user]
401 group node[:mediawiki][:group]
406 cookbook_file "#{site_directory}/googlefac54c35e800caab.html" do
408 owner node[:mediawiki][:user]
409 group node[:mediawiki][:group]
414 ports = new_resource.ssl_enabled ? [80, 443] : [80]
416 apache_site new_resource.name do
418 template "apache.erb"
419 directory site_directory
420 variables :aliases => Array(new_resource.aliases),
421 :private => new_resource.private,
423 :ssl_certificate => new_resource.ssl_certificate,
424 :ssl_certificate_chain => new_resource.ssl_certificate_chain
428 # FIXME: needs to run one
429 execute "#{mediawiki_directory}/extensions/CirrusSearch/maintenance/updateSearchIndexConfig.php" do
431 command "php extensions/CirrusSearch/maintenance/updateSearchIndexConfig.php"
432 cwd mediawiki_directory
433 user node[:mediawiki][:user]
434 group node[:mediawiki][:group]
439 mediawiki_directory = "#{site_directory}/w"
441 template "#{mediawiki_directory}/LocalSettings.php" do
443 source "LocalSettings.php.erb"
444 owner node[:mediawiki][:user]
445 group node[:mediawiki][:group]
447 variables :name => new_resource.name,
448 :directory => mediawiki_directory,
449 :database_params => new_resource.database_params,
450 :mediawiki => new_resource.mediawiki_params
451 notifies :run, "execute[#{mediawiki_directory}/maintenance/update.php]"
454 execute "#{mediawiki_directory}/maintenance/update.php" do
456 command "php maintenance/update.php --quick"
457 cwd mediawiki_directory
458 user node[:mediawiki][:user]
459 group node[:mediawiki][:group]
464 apache_site new_resource.name do
469 directory site_directory do
474 mysql_database new_resource.database_name do
478 mysql_user "#{new_resource.database_user}@localhost" do
484 new_resource.directory || "/srv/#{new_resource.name}"
488 new_resource.name.tr(".", "_")