Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 12
0.00% covered (danger)
0.00%
0 / 6
CRAP
0.00% covered (danger)
0.00%
0 / 1
WBMIHooksHelper
0.00% covered (danger)
0.00%
0 / 12
0.00% covered (danger)
0.00%
0 / 6
42
0.00% covered (danger)
0.00%
0 / 1
 getPropertyType
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 getMediaInfoViewRegex
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 getMediaInfoCaptionsRegex
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 getMediaInfoStatementsRegex
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 getStructuredDataHeaderRegex
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 getMaxCaptionLength
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace Wikibase\MediaInfo;
4
5use MediaWiki\Config\ConfigException;
6use Wikibase\DataModel\Entity\PropertyId;
7use Wikibase\DataModel\Services\Lookup\PropertyDataTypeLookupException;
8use Wikibase\MediaInfo\View\MediaInfoEntityStatementsView;
9use Wikibase\MediaInfo\View\MediaInfoEntityTermsView;
10use Wikibase\MediaInfo\View\MediaInfoView;
11use Wikibase\Repo\WikibaseRepo;
12
13/**
14 * Helpers for MediaInfo hooks
15 *
16 * @license GPL-2.0-or-later
17 */
18class WBMIHooksHelper {
19
20    /**
21     * @param PropertyId $id
22     * @return string
23     * @throws ConfigException
24     * @throws PropertyDataTypeLookupException
25     */
26    public static function getPropertyType( PropertyId $id ) {
27        $propertyDataTypeLookup = WikibaseRepo::getPropertyDataTypeLookup();
28        return $propertyDataTypeLookup->getDataTypeIdForProperty( $id );
29    }
30
31    public static function getMediaInfoViewRegex() {
32        $tag = MediaInfoView::MEDIAINFOVIEW_CUSTOM_TAG;
33        return '/<' . $tag . '[^>]*>(.*)<\/' . $tag . '>/is';
34    }
35
36    public static function getMediaInfoCaptionsRegex() {
37        $tag = MediaInfoEntityTermsView::CAPTIONS_CUSTOM_TAG;
38        return '/<' . $tag . '>(.*)<\/' . $tag . '>/is';
39    }
40
41    public static function getMediaInfoStatementsRegex() {
42        $tag = MediaInfoEntityStatementsView::STATEMENTS_CUSTOM_TAG;
43        return '/<' . $tag . '>(.*)<\/' . $tag . '>/is';
44    }
45
46    public static function getStructuredDataHeaderRegex() {
47        return '#<h1\b[^>]*\bclass=(\'|")mw-slot-header\\1[^>]*>' .
48            WikibaseMediaInfoHooks::MEDIAINFO_SLOT_HEADER_PLACEHOLDER . '</h1>#iU';
49    }
50
51    public static function getMaxCaptionLength() {
52        $settings = WikibaseRepo::getSettings();
53        return $settings->getSetting( 'string-limits' )['multilang']['length'];
54    }
55}