3 # Resource:: 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 # https://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.
22 default_action :create
24 property :site, :kind_of => String, :name_property => true
25 property :aliases, :kind_of => [String, Array]
26 property :version, :kind_of => String, :default => "1.39"
27 property :database_name, :kind_of => String, :required => true
28 property :database_user, :kind_of => String, :required => [:create, :update]
29 property :database_password, :kind_of => String, :required => [:create, :update]
30 property :sitename, :kind_of => String, :default => "OpenStreetMap Wiki"
31 property :metanamespace, :kind_of => String, :default => "OpenStreetMap"
32 property :logo, :kind_of => String, :default => "$wgStylePath/common/images/wiki.png"
33 property :email_contact, :kind_of => String, :default => ""
34 property :email_sender, :kind_of => String, :default => ""
35 property :email_sender_name, :kind_of => String, :default => "MediaWiki Mail"
36 property :commons, :kind_of => [TrueClass, FalseClass], :default => true
37 property :skin, :kind_of => String, :default => "vector"
38 property :site_notice, :kind_of => [String, TrueClass, FalseClass], :default => false
39 property :site_readonly, :kind_of => [String, TrueClass, FalseClass], :default => false
40 property :admin_user, :kind_of => String, :default => "Admin"
41 property :admin_password, :kind_of => String, :required => [:create]
42 property :private_accounts, :kind_of => [TrueClass, FalseClass], :default => false
43 property :private_site, :kind_of => [TrueClass, FalseClass], :default => false
44 property :hcaptcha_public_key, :kind_of => String, :default => ""
45 property :hcaptcha_private_key, :kind_of => String, :default => ""
46 property :extra_file_extensions, :kind_of => [String, Array], :default => []
47 property :fpm_max_children, :kind_of => Integer, :default => 5
48 property :fpm_start_servers, :kind_of => Integer, :default => 2
49 property :fpm_min_spare_servers, :kind_of => Integer, :default => 1
50 property :fpm_max_spare_servers, :kind_of => Integer, :default => 3
51 property :fpm_request_terminate_timeout, :kind_of => Integer, :default => 300
52 property :fpm_prometheus_port, :kind_of => Integer
53 property :reload_apache, :kind_of => [TrueClass, FalseClass], :default => true
56 node.default[:mediawiki][:sites][new_resource.site] = {
57 :directory => site_directory,
58 :version => new_resource.version
61 mysql_user "#{new_resource.database_user}@localhost" do
62 password new_resource.database_password
66 mysql_database new_resource.database_name do
67 permissions "#{new_resource.database_user}@localhost" => :all
70 mediawiki_directory = "#{site_directory}/w"
72 declare_resource :directory, site_directory do
73 owner node[:mediawiki][:user]
74 group node[:mediawiki][:group]
78 declare_resource :directory, mediawiki_directory do
79 owner node[:mediawiki][:user]
80 group node[:mediawiki][:group]
84 git mediawiki_directory do
86 repository "https://gerrit.wikimedia.org/r/mediawiki/core.git"
87 revision mediawiki_reference
89 user node[:mediawiki][:user]
90 group node[:mediawiki][:group]
93 template "#{mediawiki_directory}/composer.local.json" do
95 source "composer.local.json.erb"
96 owner node[:mediawiki][:user]
97 group node[:mediawiki][:group]
101 execute "#{mediawiki_directory}/composer.json" do
102 command "composer update --no-dev"
103 cwd mediawiki_directory
104 user node[:mediawiki][:user]
105 group node[:mediawiki][:group]
106 environment "COMPOSER_HOME" => site_directory
107 not_if { ::File.exist?("#{mediawiki_directory}/composer.lock") }
110 execute "#{mediawiki_directory}/maintenance/install.php" do
111 # Use metanamespace as Site Name to ensure correct set namespace
112 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}'"
113 cwd mediawiki_directory
114 user node[:mediawiki][:user]
115 group node[:mediawiki][:group]
116 not_if { ::File.exist?("#{mediawiki_directory}/LocalSettings.php") }
119 declare_resource :directory, "#{mediawiki_directory}/images" do
121 group node[:mediawiki][:group]
125 declare_resource :directory, "#{mediawiki_directory}/cache" do
127 group node[:mediawiki][:group]
131 declare_resource :directory, "#{mediawiki_directory}/LocalSettings.d" do
132 user node[:mediawiki][:user]
133 group node[:mediawiki][:group]
137 template "#{mediawiki_directory}/LocalSettings.php" do
139 source "LocalSettings.php.erb"
140 owner node[:mediawiki][:user]
141 group node[:mediawiki][:group]
143 variables :name => new_resource.site,
144 :directory => mediawiki_directory,
145 :database_params => database_params,
146 :mediawiki => mediawiki_params,
147 :secret_key => secret_key
150 service "mediawiki-sitemap@#{new_resource.site}.timer" do
151 action [:enable, :start]
152 only_if { ::File.exist?("#{mediawiki_directory}/LocalSettings.php") }
155 service "mediawiki-jobs@#{new_resource.site}.timer" do
156 action [:enable, :start]
157 only_if { ::File.exist?("#{mediawiki_directory}/LocalSettings.php") }
160 service "mediawiki-email-jobs@#{new_resource.site}.timer" do
161 action [:enable, :start]
162 only_if { ::File.exist?("#{mediawiki_directory}/LocalSettings.php") }
165 service "mediawiki-refresh-links@#{new_resource.site}.timer" do
166 action [:enable, :start]
167 only_if { ::File.exist?("#{mediawiki_directory}/LocalSettings.php") }
170 template "/etc/cron.daily/mediawiki-#{cron_name}-backup" do
172 source "mediawiki-backup.cron.erb"
176 variables :name => new_resource.site,
177 :directory => site_directory,
178 :database_params => database_params
179 only_if { ::File.exist?("#{mediawiki_directory}/LocalSettings.php") }
182 # MobileFrontend extension is required by MinervaNeue skin
183 mediawiki_extension "MobileFrontend" do
184 site new_resource.site
185 template "mw-ext-MobileFrontend.inc.php.erb"
189 # MobileFrontend extension is required by MinervaNeue skin
190 mediawiki_skin "MinervaNeue" do
191 site new_resource.site
196 mediawiki_skin "CologneBlue" do
197 site new_resource.site
202 mediawiki_skin "Modern" do
203 site new_resource.site
208 mediawiki_skin "MonoBook" do
209 site new_resource.site
214 mediawiki_skin "Vector" do
215 site new_resource.site
220 mediawiki_extension "Cite" do
221 site new_resource.site
225 mediawiki_extension "CiteThisPage" do
226 site new_resource.site
230 if new_resource.private_accounts || new_resource.private_site
231 mediawiki_extension "ConfirmEdit" do
232 site new_resource.site
237 mediawiki_extension "ConfirmEdit" do
238 site new_resource.site
239 template "mw-ext-ConfirmEdit.inc.php.erb"
240 variables :public_key => new_resource.hcaptcha_public_key,
241 :private_key => new_resource.hcaptcha_private_key
246 mediawiki_extension "Gadgets" do
247 site new_resource.site
251 mediawiki_extension "ImageMap" do
252 site new_resource.site
256 mediawiki_extension "InputBox" do
257 site new_resource.site
261 mediawiki_extension "Interwiki" do
262 site new_resource.site
263 template "mw-ext-Interwiki.inc.php.erb"
267 mediawiki_extension "Nuke" do
268 site new_resource.site
272 mediawiki_extension "ParserFunctions" do
273 site new_resource.site
274 template "mw-ext-ParserFunctions.inc.php.erb"
278 mediawiki_extension "PdfHandler" do
279 site new_resource.site
280 template "mw-ext-PdfHandler.inc.php.erb"
284 mediawiki_extension "Poem" do
285 site new_resource.site
289 mediawiki_extension "Renameuser" do
290 site new_resource.site
294 mediawiki_extension "SimpleAntiSpam" do
295 site new_resource.site
300 mediawiki_extension "SpamBlacklist" do
301 site new_resource.site
302 template "mw-ext-SpamBlacklist.inc.php.erb"
306 mediawiki_extension "SyntaxHighlight_GeSHi" do
307 site new_resource.site
308 template "mw-ext-SyntaxHighlight.inc.php.erb"
312 mediawiki_extension "TitleBlacklist" do
313 site new_resource.site
314 template "mw-ext-TitleBlacklist.inc.php.erb"
318 mediawiki_extension "WikiEditor" do
319 site new_resource.site
323 mediawiki_extension "Babel" do
324 site new_resource.site
325 template "mw-ext-Babel.inc.php.erb"
329 mediawiki_extension "CategoryTree" do
330 site new_resource.site
334 mediawiki_extension "cldr" do
335 site new_resource.site
336 template "mw-ext-cldr.inc.php.erb"
340 mediawiki_extension "CleanChanges" do
341 site new_resource.site
342 template "mw-ext-CleanChanges.inc.php.erb"
346 mediawiki_extension "LocalisationUpdate" do
347 site new_resource.site
348 template "mw-ext-LocalisationUpdate.inc.php.erb"
352 # mediawiki_extension "Translate" do
353 # site new_resource.site
354 # template "mw-ext-Translate.inc.php.erb"
358 mediawiki_extension "UniversalLanguageSelector" do
359 site new_resource.site
360 template "mw-ext-UniversalLanguageSelector.inc.php.erb"
364 mediawiki_extension "AntiSpoof" do
365 site new_resource.site
366 template "mw-ext-AntiSpoof.inc.php.erb"
370 mediawiki_extension "AbuseFilter" do
371 site new_resource.site
372 template "mw-ext-AbuseFilter.inc.php.erb"
376 mediawiki_extension "CheckUser" do
377 site new_resource.site
378 template "mw-ext-CheckUser.inc.php.erb"
382 mediawiki_extension "DismissableSiteNotice" do
383 site new_resource.site
387 mediawiki_extension "Elastica" do
388 site new_resource.site
392 mediawiki_extension "CirrusSearch" do
393 site new_resource.site
394 template "mw-ext-CirrusSearch.inc.php.erb"
398 mediawiki_extension "osmtaginfo" do
399 site new_resource.site
400 repository "https://github.com/openstreetmap/osmtaginfo.git"
405 mediawiki_extension "OSMCALWikiWidget" do
406 site new_resource.site
407 repository "https://github.com/thomersch/OSMCALWikiWidget.git"
412 mediawiki_extension "DisableAccount" do
413 site new_resource.site
414 template "mw-ext-DisableAccount.inc.php.erb"
418 mediawiki_extension "VisualEditor" do
419 site new_resource.site
420 template "mw-ext-VisualEditor.inc.php.erb"
421 variables :version => new_resource.version
425 mediawiki_extension "TemplateData" do
426 site new_resource.site
430 if new_resource.commons
431 mediawiki_extension "QuickInstantCommons" do
432 site new_resource.site
436 mediawiki_extension "QuickInstantCommons" do
437 site new_resource.site
443 cookbook_file "#{site_directory}/cc-wiki.png" do
445 owner node[:mediawiki][:user]
446 group node[:mediawiki][:group]
451 cookbook_file "#{site_directory}/googled06a989d1ccc8364.html" do
453 owner node[:mediawiki][:user]
454 group node[:mediawiki][:group]
459 cookbook_file "#{site_directory}/googlefac54c35e800caab.html" do
461 owner node[:mediawiki][:user]
462 group node[:mediawiki][:group]
467 ssl_certificate new_resource.site do
468 domains [new_resource.site] + Array(new_resource.aliases)
471 php_fpm new_resource.site do
472 pm_max_children new_resource.fpm_max_children
473 pm_start_servers new_resource.fpm_start_servers
474 pm_min_spare_servers new_resource.fpm_min_spare_servers
475 pm_max_spare_servers new_resource.fpm_max_spare_servers
476 request_terminate_timeout new_resource.fpm_request_terminate_timeout
477 php_admin_values "open_basedir" => "#{site_directory}/:/usr/share/php/:/dev/null:/tmp/"
478 php_values "memory_limit" => "500M",
479 "max_execution_time" => "240",
480 "upload_max_filesize" => "70M",
481 "post_max_size" => "100M"
482 prometheus_port new_resource.fpm_prometheus_port
485 apache_site new_resource.site do
487 template "apache.erb"
488 directory site_directory
489 variables :aliases => Array(new_resource.aliases),
490 :private_site => new_resource.private_site
494 # FIXME: needs to run one
495 execute "#{mediawiki_directory}/extensions/CirrusSearch/maintenance/updateSearchIndexConfig.php" do
497 command "php extensions/CirrusSearch/maintenance/updateSearchIndexConfig.php"
498 cwd mediawiki_directory
499 user node[:mediawiki][:user]
500 group node[:mediawiki][:group]
505 mediawiki_directory = "#{site_directory}/w"
507 execute "#{mediawiki_directory}/composer.json" do
508 command "composer update --no-dev"
509 cwd mediawiki_directory
510 user node[:mediawiki][:user]
511 group node[:mediawiki][:group]
512 environment "COMPOSER_HOME" => site_directory
515 template "#{mediawiki_directory}/LocalSettings.php" do
517 source "LocalSettings.php.erb"
518 owner node[:mediawiki][:user]
519 group node[:mediawiki][:group]
521 variables :name => new_resource.site,
522 :directory => mediawiki_directory,
523 :database_params => database_params,
524 :mediawiki => mediawiki_params,
525 :secret_key => secret_key
528 execute "#{mediawiki_directory}/maintenance/update.php" do
530 command "php maintenance/update.php --quick"
531 cwd mediawiki_directory
532 user node[:mediawiki][:user]
533 group node[:mediawiki][:group]
539 apache_site new_resource.site do
544 declare_resource :directory, site_directory do
549 mysql_database new_resource.database_name do
553 mysql_user "#{new_resource.database_user}@localhost" do
559 include OpenStreetMap::Mixin::PersistentToken
562 "/srv/#{new_resource.site}"
565 def mediawiki_reference
566 shell_out!("git", "ls-remote", "--refs", "--sort=-version:refname",
567 "https://gerrit.wikimedia.org/r/mediawiki/core.git",
568 "refs/tags/#{new_resource.version}.*")
577 new_resource.site.tr(".", "_")
582 :host => "localhost",
583 :name => new_resource.database_name,
584 :username => new_resource.database_user,
585 :password => new_resource.database_password
591 :sitename => new_resource.sitename,
592 :metanamespace => new_resource.metanamespace,
593 :logo => new_resource.logo,
594 :email_contact => new_resource.email_contact,
595 :email_sender => new_resource.email_sender,
596 :email_sender_name => new_resource.email_sender_name,
597 :commons => new_resource.commons,
598 :skin => new_resource.skin,
599 :site_notice => new_resource.site_notice,
600 :site_readonly => new_resource.site_readonly,
601 :extra_file_extensions => new_resource.extra_file_extensions,
602 :private_accounts => new_resource.private_accounts,
603 :private_site => new_resource.private_site
608 persistent_token("mediawiki", new_resource.site, "wgSecretKey")
613 notifies :update, "mediawiki_site[#{site}]"
614 notifies :reload, "service[apache2]" if reload_apache