Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
90.91% covered (success)
90.91%
10 / 11
66.67% covered (warning)
66.67%
2 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
DublinCore
90.91% covered (success)
90.91%
10 / 11
66.67% covered (warning)
66.67%
2 / 3
5.02
0.00% covered (danger)
0.00%
0 / 1
 init
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
1
 addMetadata
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
3
 getAllowedParameterNames
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
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\Generator\Plugins;
23
24use MediaWiki\Extension\WikiSEO\Generator\AbstractBaseGenerator;
25use MediaWiki\Extension\WikiSEO\Generator\GeneratorInterface;
26use OutputPage;
27
28class DublinCore extends AbstractBaseGenerator implements GeneratorInterface {
29
30    /**
31     * Valid Tags for this generator
32     *
33     * @var array
34     */
35    protected $tags = [
36        'author',
37        'description',
38        'dc.identifier.wikidata',
39        'locale',
40        'site_name',
41        'title',
42    ];
43
44    /**
45     * Tag name conversions for this generator
46     *
47     * @var array
48     */
49    protected $conversions = [
50        'author'      => 'DC.creator',
51        'description' => 'DC.description',
52        'locale'      => 'DC.language',
53        'title'       => 'DC.title',
54        'site_name'   => 'DC.publisher',
55    ];
56
57    /**
58     * @inheritDoc
59     */
60    public function init( array $metadata, OutputPage $out ): void {
61        $this->metadata = $metadata;
62        $this->outputPage = $out;
63
64        $out->addLink( [
65            'rel' => 'schema.DC',
66            'href' => 'http://purl.org/dc/clients/1.1/',
67        ] );
68    }
69
70    /**
71     * @inheritDoc
72     */
73    public function addMetadata(): void {
74        foreach ( $this->tags as $tag ) {
75            if ( array_key_exists( $tag, $this->metadata ) ) {
76                $tagName = $this->conversions[$tag] ?? $tag;
77
78                $this->outputPage->addMeta( $tagName, $this->metadata[$tag] );
79            }
80        }
81    }
82
83    /**
84     * @inheritDoc
85     */
86    public function getAllowedParameterNames(): array {
87        return $this->tags;
88    }
89}