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]
90 directory extension_directory do
95 file "#{mediawiki_directory}/LocalSettings.d/Ext-#{new_resource.extension}.inc.php" do
102 node[:mediawiki][:sites][new_resource.site][:directory]
105 def mediawiki_directory
106 "#{site_directory}/w"
109 def extension_directory
110 "#{mediawiki_directory}/extensions/#{new_resource.extension}"
113 def extension_version
114 new_resource.version || node[:mediawiki][:sites][new_resource.site][:version]
117 def default_repository
118 "https://github.com/wikimedia/mediawiki-extensions-#{new_resource.extension}.git"
123 notifies :update, "mediawiki_site[#{site}]" if update_site