Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
94.66% |
408 / 431 |
|
42.86% |
3 / 7 |
CRAP | |
0.00% |
0 / 1 |
Preprocessor_Hash | |
94.88% |
408 / 430 |
|
42.86% |
3 / 7 |
128.13 | |
0.00% |
0 / 1 |
__construct | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
newFrame | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
newCustomFrame | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
newPartNodeArray | |
0.00% |
0 / 14 |
|
0.00% |
0 / 1 |
12 | |||
preprocessToObj | |
95.24% |
20 / 21 |
|
0.00% |
0 / 1 |
5 | |||
buildDomTreeArrayFromText | |
98.45% |
381 / 387 |
|
0.00% |
0 / 1 |
112 | |||
addLiteral | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
3 |
1 | <?php |
2 | /** |
3 | * Preprocessor using PHP arrays |
4 | * |
5 | * This program is free software; you can redistribute it and/or modify |
6 | * it under the terms of the GNU General Public License as published by |
7 | * the Free Software Foundation; either version 2 of the License, or |
8 | * (at your option) any later version. |
9 | * |
10 | * This program is distributed in the hope that it will be useful, |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | * GNU General Public License for more details. |
14 | * |
15 | * You should have received a copy of the GNU General Public License along |
16 | * with this program; if not, write to the Free Software Foundation, Inc., |
17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
18 | * http://www.gnu.org/copyleft/gpl.html |
19 | * |
20 | * @file |
21 | * @ingroup Parser |
22 | */ |
23 | |
24 | namespace MediaWiki\Parser; |
25 | |
26 | use Wikimedia\ObjectCache\WANObjectCache; |
27 | |
28 | /** |
29 | * Differences from DOM schema: |
30 | * * attribute nodes are children |
31 | * * "<h>" nodes that aren't at the top are replaced with <possible-h> |
32 | * |
33 | * Nodes are stored in a recursive array data structure. A node store is an |
34 | * array where each element may be either a scalar (representing a text node) |
35 | * or a "descriptor", which is a two-element array where the first element is |
36 | * the node name and the second element is the node store for the children. |
37 | * |
38 | * Attributes are represented as children that have a node name starting with |
39 | * "@", and a single text node child. |
40 | * |
41 | * @todo: Consider replacing descriptor arrays with objects of a new class. |
42 | * Benchmark and measure resulting memory impact. |
43 | * |
44 | * @ingroup Parser |
45 | */ |
46 | // phpcs:ignore Squiz.Classes.ValidClassName.NotCamelCaps |
47 | class Preprocessor_Hash extends Preprocessor { |
48 | /** Cache format version */ |
49 | protected const CACHE_VERSION = 4; |
50 | |
51 | /** @var int|false Min wikitext size for which to cache DOM tree */ |
52 | protected $cacheThreshold; |
53 | |
54 | /** |
55 | * @see Preprocessor::__construct() |
56 | * @param Parser $parser |
57 | * @param WANObjectCache|null $wanCache |
58 | * @param array $options Additional options include: |
59 | * - cacheThreshold: min text size for which to cache DOMs. [Default: false] |
60 | */ |
61 | public function __construct( |
62 | Parser $parser, |
63 | ?WANObjectCache $wanCache = null, |
64 | array $options = [] |
65 | ) { |
66 | parent::__construct( $parser, $wanCache, $options ); |
67 | |
68 | $this->cacheThreshold = $options['cacheThreshold'] ?? false; |
69 | } |
70 | |
71 | /** |
72 | * @return PPFrame_Hash |
73 | */ |
74 | public function newFrame() { |