Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 27
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
SeoLua
0.00% covered (danger)
0.00%
0 / 27
0.00% covered (danger)
0.00%
0 / 2
20
0.00% covered (danger)
0.00%
0 / 1
 register
0.00% covered (danger)
0.00%
0 / 13
0.00% covered (danger)
0.00%
0 / 1
2
 set
0.00% covered (danger)
0.00%
0 / 14
0.00% covered (danger)
0.00%
0 / 1
12
1<?php
2/**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16 *
17 * @file
18 */
19
20declare( strict_types=1 );
21
22namespace MediaWiki\Extension\WikiSEO;
23
24use MediaWiki\MediaWikiServices;
25use Scribunto_LuaLibraryBase;
26
27class SeoLua extends Scribunto_LuaLibraryBase {
28    /**
29     * Registers the callable lua methods
30     *
31     * @return array
32     */
33    public function register(): array {
34        $lib = [
35            'set' => [ $this, 'set' ],
36        ];
37
38        return $this->getEngine()->registerInterface(
39            sprintf(
40                '%s%s%s',
41                __DIR__,
42                DIRECTORY_SEPARATOR,
43                'mw.ext.seo.lua'
44            ),
45            $lib,
46            []
47        );
48    }
49
50    /**
51     * Validates function arguments through Validator::validateParams
52     * All validated params are written to the page props, which in turn are picked up by WikiSEO
53     * through the onBeforePageDisplay Hook
54     *
55     * @see Validator::validateParams()
56     * @see Hooks::onBeforePageDisplay()
57     */
58    public function set(): void {
59        $args = func_get_args();
60
61        if ( !isset( $args[0] ) ) {
62            return;
63        }
64
65        $args = $args[0];
66
67        $validated = Validator::validateParams( $args );
68
69        MediaWikiServices::getInstance()->getHookContainer()->run(
70            'WikiSEOLuaPreAddPageProps',
71            [
72                &$validated,
73            ]
74        );
75
76        $out = $this->getParser()->getOutput();
77        foreach ( $validated as $metaKey => $value ) {
78            $out->setPageProperty( $metaKey, $value );
79        }
80    }
81}