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 :variables, :kind_of => Hash, :default => {}
27 property :version, :kind_of => String
28 property :repository, :kind_of => String
29 property :tag, :kind_of => String
30 property :reference, :kind_of => String
31 property :compose, :kind_of => [TrueClass, FalseClass], :default => false
32 property :update_site, :kind_of => [TrueClass, FalseClass], :default => true
35 if new_resource.source
36 remote_directory extension_directory do
38 source new_resource.source
39 owner node[:mediawiki][:user]
40 group node[:mediawiki][:group]
42 files_owner node[:mediawiki][:user]
43 files_group node[:mediawiki][:group]
47 extension_repository = new_resource.repository || default_repository
48 extension_reference = if new_resource.reference
49 new_resource.reference
50 elsif new_resource.tag
51 "refs/tags/#{new_resource.tag}"
53 "REL#{extension_version}".tr(".", "_")
56 git extension_directory do
58 repository extension_repository
59 reference extension_reference
60 enable_submodules true
61 user node[:mediawiki][:user]
62 group node[:mediawiki][:group]
63 ignore_failure extension_repository.start_with?("git://github.com/wikimedia/mediawiki-extensions")
67 if new_resource.template # ~FC023
68 declare_resource :template, "#{mediawiki_directory}/LocalSettings.d/Ext-#{new_resource.extension}.inc.php" do
70 source new_resource.template
71 user node[:mediawiki][:user]
72 group node[:mediawiki][:group]
74 variables new_resource.variables
77 extension_script = "#{extension_directory}/#{new_resource.extension}.php"
79 file "#{mediawiki_directory}/LocalSettings.d/Ext-#{new_resource.extension}.inc.php" do
80 content "<?php wfLoadExtension( '#{new_resource.extension}' );\n"
81 user node[:mediawiki][:user]
82 group node[:mediawiki][:group]
84 only_if { ::File.exist?(extension_script) }
88 if new_resource.compose # ~FC023
89 execute "composer-#{new_resource.extension}" do
91 command "composer install --no-dev"
92 cwd extension_directory
93 user node[:mediawiki][:user]
94 group node[:mediawiki][:group]
95 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 "git://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]"