2 # Cookbook Name:: mediawiki
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.
20 default_action :create
22 property :extension, :kind_of => String, :name_attribute => true
23 property :site, :kind_of => String, :required => true
24 property :source, :kind_of => String
25 property :template, :kind_of => String
26 property :template_cookbook, :kind_of => String, :default => "mediawiki"
27 property :variables, :kind_of => Hash, :default => {}
28 property :version, :kind_of => String
29 property :repository, :kind_of => String
30 property :tag, :kind_of => String
31 property :reference, :kind_of => String
32 property :compose, :kind_of => [TrueClass, FalseClass], :default => false
33 property :update_site, :kind_of => [TrueClass, FalseClass], :default => true
36 if new_resource.source
37 remote_directory extension_directory do
39 source new_resource.source
40 owner node[:mediawiki][:user]
41 group node[:mediawiki][:group]
43 files_owner node[:mediawiki][:user]
44 files_group node[:mediawiki][:group]
48 extension_repository = new_resource.repository || default_repository
49 extension_reference = if new_resource.reference
50 new_resource.reference
51 elsif new_resource.tag
52 "refs/tags/#{new_resource.tag}"
54 "REL#{extension_version}".tr(".", "_")
57 git extension_directory do
59 repository extension_repository
60 reference extension_reference
61 enable_submodules true
62 user node[:mediawiki][:user]
63 group node[:mediawiki][:group]
64 ignore_failure extension_repository.start_with?("git://github.com/wikimedia/mediawiki-extensions")
68 if new_resource.template # ~FC023
69 declare_resource :template, "#{mediawiki_directory}/LocalSettings.d/Ext-#{new_resource.extension}.inc.php" do
70 cookbook new_resource.template_cookbook
71 source new_resource.template
72 user node[:mediawiki][:user]
73 group node[:mediawiki][:group]
75 variables new_resource.variables
78 file "#{mediawiki_directory}/LocalSettings.d/Ext-#{new_resource.extension}.inc.php" do
79 content "<?php wfLoadExtension( '#{new_resource.extension}' );\n"
80 user node[:mediawiki][:user]
81 group node[:mediawiki][:group]
86 if new_resource.compose # ~FC023
87 execute "composer-#{new_resource.extension}" do
89 command "composer install --no-dev"
90 cwd extension_directory
91 user node[:mediawiki][:user]
92 group node[:mediawiki][:group]
93 subscribes :run, "git[#{extension_directory}]"
99 directory extension_directory do
104 file "#{mediawiki_directory}/LocalSettings.d/Ext-#{new_resource.extension}.inc.php" do
111 node[:mediawiki][:sites][new_resource.site][:directory]
114 def mediawiki_directory
115 "#{site_directory}/w"
118 def extension_directory
119 "#{mediawiki_directory}/extensions/#{new_resource.extension}"
122 def extension_version
123 new_resource.version || node[:mediawiki][:sites][new_resource.site][:version]
126 def default_repository
127 "git://github.com/wikimedia/mediawiki-extensions-#{new_resource.extension}.git"
133 notifies :update, "mediawiki_site[#{site}]"
135 site_directory = node[:mediawiki][:sites][site][:directory]
137 notifies :create, "template[#{site_directory}/w/LocalSettings.php]"
138 notifies :run, "execute[#{site_directory}/w/maintenance/update.php]"