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(".", "_")
42 :directory => "#{site_directory}/w",
44 :sitename => params[:sitename] || "OpenStreetMap Wiki",
45 :metanamespace => params[:metanamespace] || "OpenStreetMap",
46 :logo => params[:logo] || "$wgStylePath/common/images/wiki.png",
47 :email_contact => params[:email_contact] || "",
48 :email_sender => params[:email_sender] || "",
49 :email_sender_name => params[:email_sender_name] || "MediaWiki Mail",
50 :commons => params[:commons] || TRUE,
51 :skin => params[:skin] || "vector",
52 :site_notice => params[:site_notice] || "",
53 :site_readonly => params[:site_readonly] || FALSE,
54 :site_admin_user => "Admin",
55 :site_admin_pw => params[:admin_password],
56 :enable_ssl => params[:enable_ssl] || FALSE,
57 :private => params[:private] || FALSE
62 node.set_unless[:mediawiki][:sites][name] = {}
63 node.set[:mediawiki][:sites][name][:site_directory] = site_directory
64 node.set[:mediawiki][:sites][name][:directory] = mediawiki[:directory]
65 node.set[:mediawiki][:sites][name][:version] = mediawiki_version
66 node.set_unless[:mediawiki][:sites][name][:wgSecretKey] = random_password(64)
70 mysql_user "#{database_params[:username]}@localhost" do
71 password database_params[:password]
74 mysql_database database_params[:name] do
75 permissions "#{database_params[:username]}@localhost" => :all
78 ruby_block "rename-installer-localsettings" do
81 ::File.rename("#{mediawiki[:directory]}/LocalSettings.php","#{mediawiki[:directory]}/LocalSettings-install.php")
85 execute "#{mediawiki[:directory]}/maintenance/install.php" do
87 #Use metanamespace as Site Name to ensure correct set namespace
88 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]}'"
89 cwd mediawiki[:directory]
90 user node[:mediawiki][:user]
91 group node[:mediawiki][:group]
93 File.exists?("#{mediawiki[:directory]}/LocalSettings-install.php")
95 notifies :create, 'ruby_block[rename-installer-localsettings]', :immediately
98 execute "#{mediawiki[:directory]}/maintenance/update.php" do
100 command "php maintenance/update.php --quick"
101 cwd mediawiki[:directory]
102 user node[:mediawiki][:user]
103 group node[:mediawiki][:group]
106 directory "#{site_directory}" do
107 owner node[:mediawiki][:user]
108 group node[:mediawiki][:group]
112 directory "#{mediawiki[:directory]}" do
113 owner node[:mediawiki][:user]
114 group node[:mediawiki][:group]
118 git "#{mediawiki[:directory]}" do
120 repository mediawiki_repository
121 reference mediawiki_reference
123 user node[:mediawiki][:user]
124 group node[:mediawiki][:group]
125 notifies :run, resources(:execute => "#{mediawiki[:directory]}/maintenance/install.php"), :immediately
126 notifies :run, resources(:execute => "#{mediawiki[:directory]}/maintenance/update.php")
129 #Safety catch if git doesn't update but install.php hasn't run
130 ruby_block "catch-installer-localsettings-run" do
135 File.exists?("#{mediawiki[:directory]}/LocalSettings-install.php")
137 notifies :run, resources(:execute => "#{mediawiki[:directory]}/maintenance/install.php"), :immediately
141 directory "#{mediawiki[:directory]}/images" do
147 directory "#{mediawiki[:directory]}/cache" do
153 directory "#{mediawiki[:directory]}/LocalSettings.d" do
154 user node[:mediawiki][:user]
155 group node[:mediawiki][:group]
159 template "#{mediawiki[:directory]}/LocalSettings.php" do
161 source "LocalSettings.php.erb"
162 owner node[:mediawiki][:user]
163 group node[:mediawiki][:group]
167 :database_params => database_params,
168 :mediawiki => mediawiki
170 notifies :run, resources(:execute => "#{mediawiki[:directory]}/maintenance/update.php")
173 template "/etc/cron.d/mediawiki-#{cron_name}" do
175 source "mediawiki.cron.erb"
181 :directory => site_directory,
182 :user => node[:mediawiki][:user]
186 template "/etc/cron.daily/mediawiki-#{cron_name}-backup" do
188 source "mediawiki-backup.cron.erb"
194 :directory => site_directory,
195 :database_params => database_params
199 #MediaWiki Default Extension
201 mediawiki_extension "Cite" do
203 template "mw-ext-Cite.inc.php.erb"
206 mediawiki_extension "ConfirmEdit" do
208 template "mw-ext-ConfirmEdit.inc.php.erb"
211 mediawiki_extension "Gadgets" do
215 mediawiki_extension "ImageMap" do
219 mediawiki_extension "InputBox" do
223 mediawiki_extension "Interwiki" do
227 # "LocalisationUpdate" part of Language Extension Bundle, bundled per site
229 mediawiki_extension "Nuke" do
233 mediawiki_extension "ParserFunctions" do
235 template "mw-ext-ParserFunctions.inc.php.erb"
238 mediawiki_extension "PdfHandler" do
240 template "mw-ext-PdfHandler.inc.php.erb"
243 mediawiki_extension "Poem" do
247 mediawiki_extension "Renameuser" do
251 mediawiki_extension "SimpleAntiSpam" do
255 mediawiki_extension "SpamBlacklist" do
257 template "mw-ext-SpamBlacklist.inc.php.erb"
260 mediawiki_extension "SyntaxHighlight_GeSHi" do
264 mediawiki_extension "TitleBlacklist" do
266 template "mw-ext-TitleBlacklist.inc.php.erb"
269 mediawiki_extension "WikiEditor" do
273 # MediaWiki Language Extension Bundle
274 #fixme should automatically resolve tag
275 mw_lang_ext_bundle_tag = "2014.09"
277 mediawiki_extension "Babel" do
279 template "mw-ext-Babel.inc.php.erb"
280 tag mw_lang_ext_bundle_tag
283 mediawiki_extension "cldr" do
285 tag mw_lang_ext_bundle_tag
288 mediawiki_extension "CleanChanges" do
290 template "mw-ext-CleanChanges.inc.php.erb"
291 tag mw_lang_ext_bundle_tag
294 mediawiki_extension "LocalisationUpdate" do
296 template "mw-ext-LocalisationUpdate.inc.php.erb"
297 tag mw_lang_ext_bundle_tag
300 #LocalisationUpdate Update Cron
301 #template "/etc/cron.d/mediawiki-#{name}-LocalisationUpdate" do
302 # cookbook "mediawiki"
303 # source "mediawiki-LocalisationUpdate.cron.erb"
309 # :directory => site_directory,
310 # :user => node[:mediawiki][:user]
314 #mediawiki_extension "Translate" do
316 # template "mw-ext-Translate.inc.php.erb"
317 # tag mw_lang_ext_bundle_tag
320 mediawiki_extension "UniversalLanguageSelector" do
322 tag mw_lang_ext_bundle_tag
325 # Global Extra Mediawiki Extensions
327 mediawiki_extension "AntiSpoof" do
331 mediawiki_extension "AbuseFilter" do
333 template "mw-ext-AbuseFilter.inc.php.erb"
336 mediawiki_extension "CheckUser" do
338 template "mw-ext-CheckUser.inc.php.erb"
341 mediawiki_extension "DismissableSiteNotice" do
345 mediawiki_extension "Elastica" do
349 mediawiki_extension "CirrusSearch" do
351 template "mw-ext-CirrusSearch.inc.php.erb"
354 #OSM specifc extensions
356 mediawiki_extension "osmtaginfo" do
358 repository "git://github.com/Firefishy/osmtaginfo.git"
361 mediawiki_extension "SimpleMap" do
363 repository "git://github.com/Firefishy/SimpleMap.git"
367 mediawiki_extension "SlippyMap" do
369 repository "git://github.com/Firefishy/SlippyMap.git"
373 cookbook_file "#{site_directory}/cc-wiki.png" do
375 owner node[:mediawiki][:user]
376 group node[:mediawiki][:group]
381 cookbook_file "#{site_directory}/googled06a989d1ccc8364.html" do
383 owner node[:mediawiki][:user]
384 group node[:mediawiki][:group]
389 cookbook_file "#{site_directory}/googlefac54c35e800caab.html" do
391 owner node[:mediawiki][:user]
392 group node[:mediawiki][:group]
399 template "apache.erb"
400 directory site_directory
403 :mediawiki => mediawiki
405 notifies :reload, "service[apache2]"
408 #Fixme - Needs to run once
409 execute "#{mediawiki[:directory]}/extensions/CirrusSearch/maintenance/updateSearchIndexConfig.php" do
411 command "php extensions/CirrusSearch/maintenance/updateSearchIndexConfig.php"
412 cwd mediawiki[:directory]
413 user node[:mediawiki][:user]
414 group node[:mediawiki][:group]