Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 12 |
|
0.00% |
0 / 6 |
CRAP | |
0.00% |
0 / 1 |
WBMIHooksHelper | |
0.00% |
0 / 12 |
|
0.00% |
0 / 6 |
42 | |
0.00% |
0 / 1 |
getPropertyType | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
getMediaInfoViewRegex | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
getMediaInfoCaptionsRegex | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
getMediaInfoStatementsRegex | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
getStructuredDataHeaderRegex | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
getMaxCaptionLength | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace Wikibase\MediaInfo; |
4 | |
5 | use MediaWiki\Config\ConfigException; |
6 | use Wikibase\DataModel\Entity\PropertyId; |
7 | use Wikibase\DataModel\Services\Lookup\PropertyDataTypeLookupException; |
8 | use Wikibase\MediaInfo\View\MediaInfoEntityStatementsView; |
9 | use Wikibase\MediaInfo\View\MediaInfoEntityTermsView; |
10 | use Wikibase\MediaInfo\View\MediaInfoView; |
11 | use Wikibase\Repo\WikibaseRepo; |
12 | |
13 | /** |
14 | * Helpers for MediaInfo hooks |
15 | * |
16 | * @license GPL-2.0-or-later |
17 | */ |
18 | class 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 | /** |
32 | * @return string |
33 | */ |
34 | public static function getMediaInfoViewRegex() { |
35 | $tag = MediaInfoView::MEDIAINFOVIEW_CUSTOM_TAG; |
36 | return '/<' . $tag . '[^>]*>(.*)<\/' . $tag . '>/is'; |
37 | } |
38 | |
39 | /** |
40 | * @return string |
41 | */ |
42 | public static function getMediaInfoCaptionsRegex() { |
43 | $tag = MediaInfoEntityTermsView::CAPTIONS_CUSTOM_TAG; |
44 | return '/<' . $tag . '>(.*)<\/' . $tag . '>/is'; |
45 | } |
46 | |
47 | /** |
48 | * @return string |
49 | */ |
50 | public static function getMediaInfoStatementsRegex() { |
51 | $tag = MediaInfoEntityStatementsView::STATEMENTS_CUSTOM_TAG; |
52 | return '/<' . $tag . '>(.*)<\/' . $tag . '>/is'; |
53 | } |
54 | |
55 | /** |
56 | * @return string |
57 | */ |
58 | public static function getStructuredDataHeaderRegex() { |
59 | return '#<h1\b[^>]*\bclass=(\'|")mw-slot-header\\1[^>]*>' . |
60 | WikibaseMediaInfoHooks::MEDIAINFO_SLOT_HEADER_PLACEHOLDER . '</h1>#iU'; |
61 | } |
62 | |
63 | /** |
64 | * @return int |
65 | */ |
66 | public static function getMaxCaptionLength() { |
67 | $settings = WikibaseRepo::getSettings(); |
68 | return $settings->getSetting( 'string-limits' )['multilang']['length']; |
69 | } |
70 | } |