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 :directory, :kind_of => String
27 property :version, :kind_of => String, :default => "1.39"
28 property :database_name, :kind_of => String, :required => true
29 property :database_user, :kind_of => String, :required => [:create, :update]
30 property :database_password, :kind_of => String, :required => [:create, :update]
31 property :sitename, :kind_of => String, :default => "OpenStreetMap Wiki"
32 property :metanamespace, :kind_of => String, :default => "OpenStreetMap"
33 property :logo, :kind_of => String, :default => "$wgStylePath/common/images/wiki.png"
34 property :email_contact, :kind_of => String, :default => ""
35 property :email_sender, :kind_of => String, :default => ""
36 property :email_sender_name, :kind_of => String, :default => "MediaWiki Mail"
37 property :commons, :kind_of => [TrueClass, FalseClass], :default => true
38 property :skin, :kind_of => String, :default => "vector"
39 property :site_notice, :kind_of => [String, TrueClass, FalseClass], :default => false
40 property :site_readonly, :kind_of => [String, TrueClass, FalseClass], :default => false
41 property :admin_user, :kind_of => String, :default => "Admin"
42 property :admin_password, :kind_of => String, :required => [:create]
43 property :private_accounts, :kind_of => [TrueClass, FalseClass], :default => false
44 property :private_site, :kind_of => [TrueClass, FalseClass], :default => false
45 property :hcaptcha_public_key, :kind_of => String, :default => ""
46 property :hcaptcha_private_key, :kind_of => String, :default => ""
47 property :extra_file_extensions, :kind_of => [String, Array], :default => []
48 property :fpm_max_children, :kind_of => Integer, :default => 5
49 property :fpm_start_servers, :kind_of => Integer, :default => 2
50 property :fpm_min_spare_servers, :kind_of => Integer, :default => 1
51 property :fpm_max_spare_servers, :kind_of => Integer, :default => 3
52 property :fpm_request_terminate_timeout, :kind_of => Integer, :default => 300
53 property :fpm_prometheus_port, :kind_of => Integer
54 property :reload_apache, :kind_of => [TrueClass, FalseClass], :default => true
57 node.default[:mediawiki][:sites][new_resource.site] = {
58 :directory => site_directory,
59 :version => new_resource.version
62 mysql_user "#{new_resource.database_user}@localhost" do
63 password new_resource.database_password
67 mysql_database new_resource.database_name do
68 permissions "#{new_resource.database_user}@localhost" => :all
71 mediawiki_directory = "#{site_directory}/w"
73 declare_resource :directory, site_directory do
74 owner node[:mediawiki][:user]
75 group node[:mediawiki][:group]
79 declare_resource :directory, mediawiki_directory do
80 owner node[:mediawiki][:user]
81 group node[:mediawiki][:group]
85 git mediawiki_directory do
87 repository "https://gerrit.wikimedia.org/r/mediawiki/core.git"
88 revision mediawiki_reference
90 user node[:mediawiki][:user]
91 group node[:mediawiki][:group]
94 template "#{mediawiki_directory}/composer.local.json" do
96 source "composer.local.json.erb"
97 owner node[:mediawiki][:user]
98 group node[:mediawiki][:group]
102 execute "#{mediawiki_directory}/composer.json" do
103 command "composer update --no-dev"
104 cwd mediawiki_directory
105 user node[:mediawiki][:user]
106 group node[:mediawiki][:group]
107 environment "COMPOSER_HOME" => site_directory
108 not_if { ::File.exist?("#{mediawiki_directory}/composer.lock") }
111 execute "#{mediawiki_directory}/maintenance/install.php" do
112 # Use metanamespace as Site Name to ensure correct set namespace
113 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}'"
114 cwd mediawiki_directory
115 user node[:mediawiki][:user]
116 group node[:mediawiki][:group]
117 not_if { ::File.exist?("#{mediawiki_directory}/LocalSettings.php") }
120 declare_resource :directory, "#{mediawiki_directory}/images" do
122 group node[:mediawiki][:group]
126 declare_resource :directory, "#{mediawiki_directory}/cache" do
128 group node[:mediawiki][:group]
132 declare_resource :directory, "#{mediawiki_directory}/LocalSettings.d" do
133 user node[:mediawiki][:user]
134 group node[:mediawiki][:group]
138 template "#{mediawiki_directory}/LocalSettings.php" do
140 source "LocalSettings.php.erb"
141 owner node[:mediawiki][:user]
142 group node[:mediawiki][:group]
144 variables :name => new_resource.site,
145 :directory => mediawiki_directory,
146 :database_params => database_params,
147 :mediawiki => mediawiki_params,
148 :secret_key => secret_key
151 service "mediawiki-sitemap@#{new_resource.site}.timer" do
152 action [:enable, :start]
153 only_if { ::File.exist?("#{mediawiki_directory}/LocalSettings.php") }
156 service "mediawiki-jobs@#{new_resource.site}.timer" do
157 action [:enable, :start]
158 only_if { ::File.exist?("#{mediawiki_directory}/LocalSettings.php") }
161 service "mediawiki-email-jobs@#{new_resource.site}.timer" do
162 action [:enable, :start]
163 only_if { ::File.exist?("#{mediawiki_directory}/LocalSettings.php") }
166 service "mediawiki-refresh-links@#{new_resource.site}.timer" do
167 action [:enable, :start]
168 only_if { ::File.exist?("#{mediawiki_directory}/LocalSettings.php") }
171 template "/etc/cron.daily/mediawiki-#{cron_name}-backup" do
173 source "mediawiki-backup.cron.erb"
177 variables :name => new_resource.site,
178 :directory => site_directory,
179 :database_params => database_params
180 only_if { ::File.exist?("#{mediawiki_directory}/LocalSettings.php") }
183 # MobileFrontend extension is required by MinervaNeue skin
184 mediawiki_extension "MobileFrontend" do
185 site new_resource.site
186 template "mw-ext-MobileFrontend.inc.php.erb"
190 # MobileFrontend extension is required by MinervaNeue skin
191 mediawiki_skin "MinervaNeue" do
192 site new_resource.site
197 mediawiki_skin "CologneBlue" do
198 site new_resource.site
203 mediawiki_skin "Modern" do
204 site new_resource.site
209 mediawiki_skin "MonoBook" do
210 site new_resource.site
215 mediawiki_skin "Vector" do
216 site new_resource.site
221 mediawiki_extension "Cite" do
222 site new_resource.site
226 mediawiki_extension "CiteThisPage" do
227 site new_resource.site
231 if new_resource.private_accounts || new_resource.private_site
232 mediawiki_extension "ConfirmEdit" do
233 site new_resource.site
238 mediawiki_extension "ConfirmEdit" do
239 site new_resource.site
240 template "mw-ext-ConfirmEdit.inc.php.erb"
241 variables :public_key => new_resource.hcaptcha_public_key,
242 :private_key => new_resource.hcaptcha_private_key
247 mediawiki_extension "Gadgets" do
248 site new_resource.site
252 mediawiki_extension "ImageMap" do
253 site new_resource.site
257 mediawiki_extension "InputBox" do
258 site new_resource.site
262 mediawiki_extension "Interwiki" do
263 site new_resource.site
264 template "mw-ext-Interwiki.inc.php.erb"
268 mediawiki_extension "Nuke" do
269 site new_resource.site
273 mediawiki_extension "ParserFunctions" do
274 site new_resource.site
275 template "mw-ext-ParserFunctions.inc.php.erb"
279 mediawiki_extension "PdfHandler" do
280 site new_resource.site
281 template "mw-ext-PdfHandler.inc.php.erb"
285 mediawiki_extension "Poem" do
286 site new_resource.site
290 mediawiki_extension "Renameuser" do
291 site new_resource.site
295 mediawiki_extension "SimpleAntiSpam" do
296 site new_resource.site
301 mediawiki_extension "SpamBlacklist" do
302 site new_resource.site
303 template "mw-ext-SpamBlacklist.inc.php.erb"
307 mediawiki_extension "SyntaxHighlight_GeSHi" do
308 site new_resource.site
309 template "mw-ext-SyntaxHighlight.inc.php.erb"
313 mediawiki_extension "TitleBlacklist" do
314 site new_resource.site
315 template "mw-ext-TitleBlacklist.inc.php.erb"
319 mediawiki_extension "WikiEditor" do
320 site new_resource.site
324 mediawiki_extension "Babel" do
325 site new_resource.site
326 template "mw-ext-Babel.inc.php.erb"
330 mediawiki_extension "CategoryTree" do
331 site new_resource.site
335 mediawiki_extension "cldr" do
336 site new_resource.site
337 template "mw-ext-cldr.inc.php.erb"
341 mediawiki_extension "CleanChanges" do
342 site new_resource.site
343 template "mw-ext-CleanChanges.inc.php.erb"
347 mediawiki_extension "LocalisationUpdate" do
348 site new_resource.site
349 template "mw-ext-LocalisationUpdate.inc.php.erb"
353 # mediawiki_extension "Translate" do
354 # site new_resource.site
355 # template "mw-ext-Translate.inc.php.erb"
359 mediawiki_extension "UniversalLanguageSelector" do
360 site new_resource.site
361 template "mw-ext-UniversalLanguageSelector.inc.php.erb"
365 mediawiki_extension "AntiSpoof" do
366 site new_resource.site
367 template "mw-ext-AntiSpoof.inc.php.erb"
371 mediawiki_extension "AbuseFilter" do
372 site new_resource.site
373 template "mw-ext-AbuseFilter.inc.php.erb"
377 mediawiki_extension "CheckUser" do
378 site new_resource.site
379 template "mw-ext-CheckUser.inc.php.erb"
383 mediawiki_extension "DismissableSiteNotice" do
384 site new_resource.site
388 mediawiki_extension "Elastica" do
389 site new_resource.site
393 mediawiki_extension "CirrusSearch" do
394 site new_resource.site
395 template "mw-ext-CirrusSearch.inc.php.erb"
399 mediawiki_extension "osmtaginfo" do
400 site new_resource.site
401 repository "https://github.com/openstreetmap/osmtaginfo.git"
406 mediawiki_extension "OSMCALWikiWidget" do
407 site new_resource.site
408 repository "https://github.com/thomersch/OSMCALWikiWidget.git"
413 mediawiki_extension "DisableAccount" do
414 site new_resource.site
415 template "mw-ext-DisableAccount.inc.php.erb"
419 mediawiki_extension "VisualEditor" do
420 site new_resource.site
421 template "mw-ext-VisualEditor.inc.php.erb"
422 variables :version => new_resource.version
426 mediawiki_extension "TemplateData" do
427 site new_resource.site
431 if new_resource.commons
432 mediawiki_extension "QuickInstantCommons" do
433 site new_resource.site
437 mediawiki_extension "QuickInstantCommons" do
438 site new_resource.site
444 cookbook_file "#{site_directory}/cc-wiki.png" do
446 owner node[:mediawiki][:user]
447 group node[:mediawiki][:group]
452 cookbook_file "#{site_directory}/googled06a989d1ccc8364.html" do
454 owner node[:mediawiki][:user]
455 group node[:mediawiki][:group]
460 cookbook_file "#{site_directory}/googlefac54c35e800caab.html" do
462 owner node[:mediawiki][:user]
463 group node[:mediawiki][:group]
468 ssl_certificate new_resource.site do
469 domains [new_resource.site] + Array(new_resource.aliases)
472 php_fpm new_resource.site do
473 pm_max_children new_resource.fpm_max_children
474 pm_start_servers new_resource.fpm_start_servers
475 pm_min_spare_servers new_resource.fpm_min_spare_servers
476 pm_max_spare_servers new_resource.fpm_max_spare_servers
477 request_terminate_timeout new_resource.fpm_request_terminate_timeout
478 php_admin_values "open_basedir" => "#{site_directory}/:/usr/share/php/:/dev/null:/tmp/"
479 php_values "memory_limit" => "500M",
480 "max_execution_time" => "240",
481 "upload_max_filesize" => "70M",
482 "post_max_size" => "100M"
483 prometheus_port new_resource.fpm_prometheus_port
486 apache_site new_resource.site do
488 template "apache.erb"
489 directory site_directory
490 variables :aliases => Array(new_resource.aliases),
491 :private_site => new_resource.private_site
495 # FIXME: needs to run one
496 execute "#{mediawiki_directory}/extensions/CirrusSearch/maintenance/updateSearchIndexConfig.php" do
498 command "php extensions/CirrusSearch/maintenance/updateSearchIndexConfig.php"
499 cwd mediawiki_directory
500 user node[:mediawiki][:user]
501 group node[:mediawiki][:group]
506 mediawiki_directory = "#{site_directory}/w"
508 execute "#{mediawiki_directory}/composer.json" do
509 command "composer update --no-dev"
510 cwd mediawiki_directory
511 user node[:mediawiki][:user]
512 group node[:mediawiki][:group]
513 environment "COMPOSER_HOME" => site_directory
516 template "#{mediawiki_directory}/LocalSettings.php" do
518 source "LocalSettings.php.erb"
519 owner node[:mediawiki][:user]
520 group node[:mediawiki][:group]
522 variables :name => new_resource.site,
523 :directory => mediawiki_directory,
524 :database_params => database_params,
525 :mediawiki => mediawiki_params,
526 :secret_key => secret_key
529 execute "#{mediawiki_directory}/maintenance/update.php" do
531 command "php maintenance/update.php --quick"
532 cwd mediawiki_directory
533 user node[:mediawiki][:user]
534 group node[:mediawiki][:group]
540 apache_site new_resource.site do
545 declare_resource :directory, site_directory do
550 mysql_database new_resource.database_name do
554 mysql_user "#{new_resource.database_user}@localhost" do
560 include OpenStreetMap::Mixin::PersistentToken
563 new_resource.directory || "/srv/#{new_resource.site}"
566 def mediawiki_reference
567 shell_out!("git", "ls-remote", "--refs", "--sort=-version:refname",
568 "https://gerrit.wikimedia.org/r/mediawiki/core.git",
569 "refs/tags/#{new_resource.version}.*")
578 new_resource.site.tr(".", "_")
583 :host => "localhost",
584 :name => new_resource.database_name,
585 :username => new_resource.database_user,
586 :password => new_resource.database_password
592 :sitename => new_resource.sitename,
593 :metanamespace => new_resource.metanamespace,
594 :logo => new_resource.logo,
595 :email_contact => new_resource.email_contact,
596 :email_sender => new_resource.email_sender,
597 :email_sender_name => new_resource.email_sender_name,
598 :commons => new_resource.commons,
599 :skin => new_resource.skin,
600 :site_notice => new_resource.site_notice,
601 :site_readonly => new_resource.site_readonly,
602 :extra_file_extensions => new_resource.extra_file_extensions,
603 :private_accounts => new_resource.private_accounts,
604 :private_site => new_resource.private_site
609 persistent_token("mediawiki", new_resource.site, "wgSecretKey")
614 notifies :update, "mediawiki_site[#{site}]"
615 notifies :reload, "service[apache2]" if reload_apache