3 # Resource:: mediawiki_extension
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 :extension, :kind_of => String, :name_property => true
25 property :site, :kind_of => String, :required => true
26 property :source, :kind_of => String
27 property :template, :kind_of => String
28 property :template_cookbook, :kind_of => String, :default => "mediawiki"
29 property :variables, :kind_of => Hash, :default => {}
30 property :version, :kind_of => String
31 property :repository, :kind_of => String
32 property :tag, :kind_of => String
33 property :reference, :kind_of => String
34 property :update_site, :kind_of => [TrueClass, FalseClass], :default => true
37 if new_resource.source
38 remote_directory extension_directory do
40 source new_resource.source
41 owner node[:mediawiki][:user]
42 group node[:mediawiki][:group]
44 files_owner node[:mediawiki][:user]
45 files_group node[:mediawiki][:group]
49 extension_repository = new_resource.repository || default_repository
50 extension_reference = if new_resource.reference
51 new_resource.reference
52 elsif new_resource.tag
53 "refs/tags/#{new_resource.tag}"
55 "REL#{extension_version}".tr(".", "_")
58 git extension_directory do
60 repository extension_repository
61 reference extension_reference
63 enable_submodules true
64 user node[:mediawiki][:user]
65 group node[:mediawiki][:group]
66 ignore_failure extension_repository.start_with?("https://github.com/wikimedia/mediawiki-extensions")
70 if new_resource.template
71 declare_resource :template, "#{mediawiki_directory}/LocalSettings.d/Ext-#{new_resource.extension}.inc.php" do
72 cookbook new_resource.template_cookbook
73 source new_resource.template
74 user node[:mediawiki][:user]
75 group node[:mediawiki][:group]
77 variables new_resource.variables
80 file "#{mediawiki_directory}/LocalSettings.d/Ext-#{new_resource.extension}.inc.php" do
81 content "<?php wfLoadExtension( '#{new_resource.extension}' );\n"
82 user node[:mediawiki][:user]
83 group node[:mediawiki][:group]
88 execute "#{extension_directory}/composer.json" do
90 command "composer update --no-dev"
91 cwd mediawiki_directory
92 user node[:mediawiki][:user]
93 group node[:mediawiki][:group]
94 environment "COMPOSER_HOME" => site_directory
95 only_if { ::File.exist?("#{extension_directory}/composer.json") }
96 subscribes :run, "git[#{extension_directory}]"
101 directory extension_directory do
106 file "#{mediawiki_directory}/LocalSettings.d/Ext-#{new_resource.extension}.inc.php" do
113 node[:mediawiki][:sites][new_resource.site][:directory]
116 def mediawiki_directory
117 "#{site_directory}/w"
120 def extension_directory
121 "#{mediawiki_directory}/extensions/#{new_resource.extension}"
124 def extension_version
125 new_resource.version || node[:mediawiki][:sites][new_resource.site][:version]
128 def default_repository
129 "https://github.com/wikimedia/mediawiki-extensions-#{new_resource.extension}.git"
135 notifies :update, "mediawiki_site[#{site}]"
137 site_directory = node[:mediawiki][:sites][site][:directory]
139 notifies :create, "template[#{site_directory}/w/LocalSettings.php]"
140 notifies :run, "execute[#{site_directory}/w/maintenance/update.php]"