Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 5
CRAP
0.00% covered (danger)
0.00%
0 / 1
Utils
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 5
30
0.00% covered (danger)
0.00%
0 / 1
 escapeWtEntities
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 decodeWtEntities
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 parseMediaDimensions
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 entityEncodeAll
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 validateMediaParam
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2declare( strict_types = 1 );
3
4namespace Wikimedia\Parsoid\Ext;
5
6use Wikimedia\Parsoid\Utils\Utils as U;
7
8/**
9 * This class provides sundry helpers needed by extensions.
10 */
11class Utils {
12    /**
13     * Entity-escape anything that would decode to a valid wikitext entity.
14     *
15     * Note that HTML5 allows certain "semicolon-less" entities, like
16     * `&para`; these aren't allowed in wikitext and won't be escaped
17     * by this function.
18     *
19     * @param string $text
20     * @return string
21     */
22    public static function escapeWtEntities( string $text ): string {
23        return U::escapeWtEntities( $text );
24    }
25
26    /**
27     * Decode HTML5 entities in wikitext.
28     *
29     * NOTE that wikitext only allows semicolon-terminated entities, while
30     * HTML allows a number of "legacy" entities to be decoded without
31     * a terminating semicolon.  This function deliberately does not
32     * decode these HTML-only entity forms.
33     *
34     * @param string $text
35     * @return string
36     */
37    public static function decodeWtEntities( string $text ): string {
38        return U::decodeWtEntities( $text );
39    }
40
41    /**
42     * Parse media dimensions
43     * @param string $str media dimension string to parse
44     * @param bool $onlyOne If set, returns null if multiple dimenstions are present
45     * @return array{x:int,y?:int}|null
46     */
47    public static function parseMediaDimensions( string $str, bool $onlyOne = false ): ?array {
48        return U::parseMediaDimensions( $str, $onlyOne );
49    }
50
51    /**
52     * Encode all characters as entity references.  This is done to make
53     * characters safe for wikitext (regardless of whether they are
54     * HTML-safe). Typically only called with single-codepoint strings.
55     * @param string $s
56     * @return string
57     */
58    public static function entityEncodeAll( string $s ): string {
59        return U::entityEncodeAll( $s );
60    }
61
62    /**
63     * Validate media parameters
64     * More generally, this is defined by the media handler in core
65     * @param ?int $num
66     * @return bool
67     */
68    public static function validateMediaParam( ?int $num ): bool {
69        return U::validateMediaParam( $num );
70    }
71}