Puppet Class: mediawiki

Defined in:
puppet/modules/mediawiki/manifests/init.pp

Overview

Class: mediawiki

MediaWiki is a free software open source wiki package written in PHP, originally for use on Wikipedia.

Parameters

wiki_name

The name of your site (example: 'devwiki').

admin_user

User name for the initial admin account (example: 'admin').

admin_pass

Initial password for admin account (example: 'secret123').

admin_email

Email address for initial admin account.

db_name

Logical MySQL database name (example: 'devwiki').

dir

The system path to which MediaWiki files have been installed (example: '/srv/mediawiki').

cache_dir

Root directory to use for caching interface messages (l10n cache). Note that each instance of mediawiki::wiki will create its own subdirectory. (example: '/var/cache/mediawiki').

settings_dir

Directory to use for configuration fragments. (example: '/srv/mediawiki/settings.d').

upload_dir

The file system path of the folder where files will be uploaded (example: '/srv/mediawiki/images').

page_dir

The file system path of the folder where the content of vagrant-managed pages is stored (example: '/srv/pages').

branch

Branch to check out (example: 'master').

git_depth

Git cloning depth - undef for normal, a number for a shallow clone with that many revisions.

server_url

Full base URL of host (example: 'mywiki.net:8080').

Parameters:

  • wiki_name (Any)
  • admin_user (Any)
  • admin_pass (Any)
  • admin_email (Any)
  • db_name (Any)
  • dir (Any)
  • cache_dir (Any)
  • settings_dir (Any)
  • upload_dir (Any)
  • page_dir (Any)
  • composer_fragment_dir (Any)
  • parallel_composer_jobs (Any)
  • branch (Any) (defaults to: undef)
  • git_depth (Any) (defaults to: undef)
  • server_url (Any) (defaults to: undef)


54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
# File 'puppet/modules/mediawiki/manifests/init.pp', line 54

class mediawiki(
    $wiki_name,
    $admin_user,
    $admin_pass,
    $admin_email,
    $db_name,
    $dir,
    $cache_dir,
    $settings_dir,
    $upload_dir,
    $page_dir,
    $composer_fragment_dir,
    $parallel_composer_jobs,
    $branch     = undef,
    $git_depth  = undef,
    $server_url = undef,
) {
    Exec {
      environment => "MW_INSTALL_PATH=${dir}",
    }

    include ::mwv
    require ::php

    require ::service

    include ::mediawiki::apache
    include ::mediawiki::jobrunner
    include ::mediawiki::multiwiki
    include ::mediawiki::mwrepl
    include ::mediawiki::ready_service
    include ::mediawiki::psysh

    require_package('parallel', 'firejail')

    $managed_settings_dir = "${settings_dir}/puppet-managed"

    git::clone { 'mediawiki/core':
        # T152801 - avoid using gerrit for the initial cloning
        temp_remote => 'https://github.com/wikimedia/mediawiki.git',
        directory   => $dir,
        branch      => $branch,
        depth       => $git_depth,
    }

    mediawiki::skin { 'Vector':
        settings => {
            wgVectorDefaultSkinVersion                    => '2',
            wgVectorDefaultSkinVersionForExistingAccounts => '2',
            wgVectorDefaultSkinVersionForNewAccounts      => '2',
        },
    }

    file { $settings_dir:
        ensure => directory,
        owner  => $::share_owner,
        group  => $::share_group,
    }

    file { $cache_dir:
        ensure => directory,
        owner  => 'vagrant',
        group  => 'www-data',
        mode   => '0775',
    }

    file { $managed_settings_dir:
        ensure  => directory,
        owner   => $::share_owner,
        group   => $::share_group,
        mode    => undef,
        recurse => true,
        purge   => true,
        force   => true,
        source  => 'puppet:///modules/mediawiki/mediawiki-settings.d-empty',
    }

    # Needed by ::mediawiki::import::text
    file { [$page_dir, "${page_dir}/wiki"]:
        ensure => directory,
    }

    mediawiki::wiki { $wiki_name:
        db_name      => $db_name,
        upload_dir   => $upload_dir,
        upload_path  => '/images',
        server_url   => $server_url,
        primary_wiki => true,
        require      => [
            Git::Clone['mediawiki/core'],
            Php::Composer::Install[$dir],
        ],
    }

    mediawiki::user { "admin_user_in_steward_suppress_on_${db_name}":
        username => $admin_user,
        password => $admin_pass,
        wiki     => $db_name,
        groups   => [
            'steward',
            'suppress',
        ],
        require  => MediaWiki::Wiki[$wiki_name],
    }

    mediawiki::group { "${wiki_name}_suppress":
        wiki              => $wiki_name,
        group_name        => 'suppress',
        grant_permissions => [
            'deletelogentry',
            'deleterevision',
            'hideuser',
            'suppressrevision',
            'suppressionlog',
            'viewsuppressed',
        ],
    }

    env::var { 'MW_INSTALL_PATH':
        value => $dir,
    }

    [
        'mediawiki-vagrant.png',
        'mediawiki-vagrant-1.5x.png',
        'mediawiki-vagrant-2x.png',
        'mediawiki-vagrant.svg',
        'mediawiki-vagrant.50px.png',
    ].each |$file| {
        file { "${mediawiki::apache::docroot}/${file}":
            source => "puppet:///modules/mediawiki/${file}",
        }
    }

    file { '/usr/local/bin/run-mediawiki-tests':
        source => 'puppet:///modules/mediawiki/run-mediawiki-tests',
        mode   => '0755',
    }

    file { '/usr/local/bin/run-git-update':
        content => template('mediawiki/run-git-update.erb'),
        mode    => '0755',
    }

    file { '/usr/local/bin/import-mediawiki-dump':
        source => 'puppet:///modules/mediawiki/import-mediawiki-dump',
        mode   => '0755',
    }

    file { '/usr/local/bin/export-mediawiki-dump':
        source => 'puppet:///modules/mediawiki/export-mediawiki-dump',
        mode   => '0755',
    }

    exec { 'update_all_databases':
        command     => '/usr/local/bin/foreachwiki update.php --quick --doshared',
        cwd         => $dir,
        user        => 'www-data',
        refreshonly => true,
        require     => Exec["composer update ${dir}"],
    }

    # Make sure settings which will affect update_all_databases are
    # in place before db updates run.
    Mediawiki::Settings <| |> -> Exec['update_all_databases']

    # Make sure all wikis are defined before db updates run.
    Mediawiki::Wiki <| |> -> Exec['update_all_databases']

    # Ensure that vendor directory exists before db updates run.
    Php::Composer::Install <| |> -> Exec['update_all_databases']
    Php::Composer::Prefer_source <| |> -> Exec['update_all_databases']

    php::composer::install { $dir:
        require => Git::Clone['mediawiki/core'],
        timeout => 900,
    }

    # Needed by mediawiki::composer::require
    file { $composer_fragment_dir:
        ensure  => directory,
        recurse => true,
        purge   => true,
        notify  => Exec["composer update ${dir}"],
    }

    file { "${dir}/composer.local.json":
        owner   => $::share_owner,
        group   => $::share_group,
        mode    => '0664',
        source  => 'puppet:///modules/mediawiki/composer.local.json',
        require => Git::Clone['mediawiki/core'],
    }

    exec { "composer update ${dir}":
        command     => '/usr/local/bin/composer update --no-progress',
        cwd         => $::mediawiki::dir,
        environment => [
            "COMPOSER_HOME=${::php::composer::home}",
            "COMPOSER_CACHE_DIR=${::php::composer::cache_dir}",
            'COMPOSER_NO_INTERACTION=1',
        ],
        refreshonly => true,
        require     => [
            Php::Composer::Install[$::mediawiki::dir],
            File["${dir}/composer.local.json"],
        ],
    }

    env::profile_script { 'add mediawiki vendor bin to path':
        content => "export PATH=\$PATH:${dir}/vendor/bin",
    }

    mediawiki::import::text { 'Main_Page':
        source => 'puppet:///modules/mediawiki/main_page.wiki',
    }

    mediawiki::import::text { 'Template:Main_Page':
        source => 'puppet:///modules/mediawiki/main_page_template.wiki',
    }

    file { '/etc/logrotate.d/mediawiki_shared_log_groups':
        source => 'puppet:///modules/mediawiki/wiki/logrotate.d-mediawiki-shared-log-groups',
        owner  => 'root',
        group  => 'root',
        mode   => '0444',
    }
}