3 # Definition:: mediawiki_site
5 # Copyright 2012, 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 define :mediawiki_site, :action => [ :create, :enable ] do
23 #/etc/cron.d names cannot contain a dot
24 cron_name = name.tr(".", "_")
26 aliases = Array(params[:aliases])
28 site_directory = params[:directory] || "/srv/#{name}"
31 :host => params[:database_host] || "localhost",
32 :name => params[:database_name],
33 :username => params[:database_username],
34 :password => params[:database_password]
37 mediawiki_repository = "git://github.com/wikimedia/mediawiki-core"
38 mediawiki_version = params[:version] || "1.22"
39 mediawiki_reference = "refs/heads/REL#{mediawiki_version}".tr(".", "_")
41 passwords = data_bag_item("mediawiki", "passwords")
44 :directory => "#{site_directory}/w",
46 :sitename => params[:sitename] || "OpenStreetMap Wiki",
47 :metanamespace => params[:metanamespace] || "OpenStreetMap",
48 :logo => params[:logo] || "$wgStylePath/common/images/wiki.png",
49 :email_contact => params[:email_contact] || "",
50 :email_sender => params[:email_sender] || "",
51 :email_sender_name => params[:email_sender_name] || "MediaWiki Mail",
52 :commons => params[:commons] || TRUE,
53 :skin => params[:skin] || "vector",
54 :site_notice => params[:site_notice] || "",
55 :site_readonly => params[:site_readonly] || FALSE,
56 :site_admin_user => "Admin",
57 :site_admin_pw => passwords["mediawiki-admin-user"],
58 :enable_ssl => params[:enable_ssl] || FALSE
63 node.set_unless[:mediawiki][:sites][name] = {}
64 node.set[:mediawiki][:sites][name][:site_directory] = site_directory
65 node.set[:mediawiki][:sites][name][:directory] = mediawiki[:directory]
66 node.set[:mediawiki][:sites][name][:version] = mediawiki_version
67 node.set_unless[:mediawiki][:sites][name][:wgSecretKey] = random_password(64)
71 mysql_user "#{database_params[:username]}@localhost" do
72 password database_params[:password]
75 mysql_database database_params[:name] do
76 permissions "#{database_params[:username]}@localhost" => :all
79 ruby_block "rename-installer-localsettings" do
82 ::File.rename("#{mediawiki[:directory]}/LocalSettings.php","#{mediawiki[:directory]}/LocalSettings-install.php")
86 execute "#{mediawiki[:directory]}/maintenance/install.php" do
88 #Use metanamespace as Site Name to ensure correct set namespace
89 command "php maintenance/install.php --server '#{name}' --dbtype 'mysql' --dbname '#{database_params[:name]}' --dbuser '#{database_params[:username]}' --dbpass '#{database_params[:password]}' --dbserver '#{database_params[:host]}' --scriptpath /w --pass '#{mediawiki[:site_admin_pw]}' '#{mediawiki[:metanamespace]}' '#{mediawiki[:site_admin_user]}'"
90 cwd mediawiki[:directory]
91 user node[:mediawiki][:user]
92 group node[:mediawiki][:group]
94 File.exists?("#{mediawiki[:directory]}/LocalSettings-install.php")
96 notifies :create, 'ruby_block[rename-installer-localsettings]', :immediately
99 execute "#{mediawiki[:directory]}/maintenance/update.php" do
101 command "php maintenance/update.php --quick"
102 cwd mediawiki[:directory]
103 user node[:mediawiki][:user]
104 group node[:mediawiki][:group]
107 directory "#{site_directory}" do
108 owner node[:mediawiki][:user]
109 group node[:mediawiki][:group]
113 directory "#{mediawiki[:directory]}" do
114 owner node[:mediawiki][:user]
115 group node[:mediawiki][:group]
119 git "#{mediawiki[:directory]}" do
121 repository mediawiki_repository
122 reference mediawiki_reference
124 user node[:mediawiki][:user]
125 group node[:mediawiki][:group]
126 notifies :run, resources(:execute => "#{mediawiki[:directory]}/maintenance/install.php"), :immediately
127 notifies :run, resources(:execute => "#{mediawiki[:directory]}/maintenance/update.php")
130 #Safety catch if git doesn't update but install.php hasn't run
131 ruby_block "catch-installer-localsettings-run" do
136 File.exists?("#{mediawiki[:directory]}/LocalSettings-install.php")
138 notifies :run, resources(:execute => "#{mediawiki[:directory]}/maintenance/install.php"), :immediately
142 directory "#{mediawiki[:directory]}/images" do
148 directory "#{mediawiki[:directory]}/cache" do
154 directory "#{mediawiki[:directory]}/LocalSettings.d" do
155 user node[:mediawiki][:user]
156 group node[:mediawiki][:group]
160 template "#{mediawiki[:directory]}/LocalSettings.php" do
162 source "LocalSettings.php.erb"
163 owner node[:mediawiki][:user]
164 group node[:mediawiki][:group]
168 :database_params => database_params,
169 :mediawiki => mediawiki
171 notifies :run, resources(:execute => "#{mediawiki[:directory]}/maintenance/update.php")
174 template "/etc/cron.d/mediawiki-#{cron_name}" do
176 source "mediawiki.cron.erb"
182 :directory => site_directory,
183 :user => node[:mediawiki][:user]
187 template "/etc/cron.daily/mediawiki-#{cron_name}-backup" do
189 source "mediawiki-backup.cron.erb"
195 :directory => site_directory,
196 :database_params => database_params
200 #MediaWiki Default Extension
202 mediawiki_extension "Cite" do
204 template "mw-ext-Cite.inc.php.erb"
207 mediawiki_extension "ConfirmEdit" do
209 template "mw-ext-ConfirmEdit.inc.php.erb"
212 mediawiki_extension "Gadgets" do
216 mediawiki_extension "ImageMap" do
220 mediawiki_extension "InputBox" do
224 mediawiki_extension "Interwiki" do
228 # "LocalisationUpdate" part of Language Extension Bundle, bundled per site
230 mediawiki_extension "Nuke" do
234 mediawiki_extension "ParserFunctions" do
236 template "mw-ext-ParserFunctions.inc.php.erb"
239 mediawiki_extension "PdfHandler" do
241 template "mw-ext-PdfHandler.inc.php.erb"
244 mediawiki_extension "Poem" do
248 mediawiki_extension "Renameuser" do
252 mediawiki_extension "SimpleAntiSpam" do
256 mediawiki_extension "SpamBlacklist" do
258 template "mw-ext-SpamBlacklist.inc.php.erb"
261 mediawiki_extension "SyntaxHighlight_GeSHi" do
265 mediawiki_extension "TitleBlacklist" do
267 template "mw-ext-TitleBlacklist.inc.php.erb"
270 mediawiki_extension "WikiEditor" do
274 # MediaWiki Language Extension Bundle
275 #fixme should automatically resolve tag
276 mw_lang_ext_bundle_tag = "2014.09"
278 mediawiki_extension "Babel" do
280 template "mw-ext-Babel.inc.php.erb"
281 tag mw_lang_ext_bundle_tag
284 mediawiki_extension "cldr" do
286 tag mw_lang_ext_bundle_tag
289 mediawiki_extension "CleanChanges" do
291 template "mw-ext-CleanChanges.inc.php.erb"
292 tag mw_lang_ext_bundle_tag
295 mediawiki_extension "LocalisationUpdate" do
297 template "mw-ext-LocalisationUpdate.inc.php.erb"
298 tag mw_lang_ext_bundle_tag
301 #LocalisationUpdate Update Cron
302 #template "/etc/cron.d/mediawiki-#{name}-LocalisationUpdate" do
303 # cookbook "mediawiki"
304 # source "mediawiki-LocalisationUpdate.cron.erb"
310 # :directory => site_directory,
311 # :user => node[:mediawiki][:user]
315 #mediawiki_extension "Translate" do
317 # template "mw-ext-Translate.inc.php.erb"
318 # tag mw_lang_ext_bundle_tag
321 mediawiki_extension "UniversalLanguageSelector" do
323 tag mw_lang_ext_bundle_tag
326 # Global Extra Mediawiki Extensions
328 mediawiki_extension "AntiSpoof" do
332 mediawiki_extension "AbuseFilter" do
334 template "mw-ext-AbuseFilter.inc.php.erb"
337 mediawiki_extension "CheckUser" do
339 template "mw-ext-CheckUser.inc.php.erb"
342 mediawiki_extension "DismissableSiteNotice" do
346 mediawiki_extension "Elastica" do
350 mediawiki_extension "CirrusSearch" do
352 template "mw-ext-CirrusSearch.inc.php.erb"
355 #OSM specifc extensions
357 mediawiki_extension "osmtaginfo" do
359 repository "git://github.com/Firefishy/osmtaginfo.git"
362 mediawiki_extension "SimpleMap" do
364 repository "git://github.com/Firefishy/SimpleMap.git"
368 mediawiki_extension "SlippyMap" do
370 repository "git://github.com/Firefishy/SlippyMap.git"
374 cookbook_file "#{site_directory}/cc-wiki.png" do
376 owner node[:mediawiki][:user]
377 group node[:mediawiki][:group]
382 cookbook_file "#{site_directory}/googled06a989d1ccc8364.html" do
384 owner node[:mediawiki][:user]
385 group node[:mediawiki][:group]
390 cookbook_file "#{site_directory}/googlefac54c35e800caab.html" do
392 owner node[:mediawiki][:user]
393 group node[:mediawiki][:group]
400 template "apache.erb"
401 directory site_directory
404 :mediawiki => mediawiki
406 notifies :reload, "service[apache2]"
409 #Fixme - Needs to run once
410 execute "#{mediawiki[:directory]}/extensions/CirrusSearch/maintenance/updateSearchIndexConfig.php" do
412 command "php extensions/CirrusSearch/maintenance/updateSearchIndexConfig.php"
413 cwd mediawiki[:directory]
414 user node[:mediawiki][:user]
415 group node[:mediawiki][:group]