1 | <?php |
||
23 | class ContentParser { |
||
24 | |||
25 | /** @var Title */ |
||
26 | protected $title; |
||
27 | |||
28 | /** @var Parser */ |
||
29 | protected $parser = null; |
||
30 | |||
31 | /** @var ParserOutput */ |
||
32 | protected $parserOutput = null; |
||
33 | |||
34 | /** @var Revision */ |
||
35 | protected $revision = null; |
||
36 | |||
37 | /** @var array */ |
||
38 | protected $errors = array(); |
||
39 | |||
40 | /** |
||
41 | * @var boolean |
||
42 | */ |
||
43 | private $enabledToUseContentHandler = true; |
||
44 | |||
45 | /** |
||
46 | * @var boolean |
||
47 | */ |
||
48 | private $skipInTextAnnotationParser = false; |
||
49 | |||
50 | /** |
||
51 | * @note Injecting new Parser() alone will not yield an expected result and |
||
52 | * doing new Parser( $GLOBALS['wgParserConf'] brings no benefits therefore |
||
53 | * we stick to the GLOBAL as fallback if no parser is injected. |
||
54 | * |
||
55 | * @since 1.9 |
||
56 | * |
||
57 | * @param Title $title |
||
58 | * @param Parser|null $parser |
||
59 | */ |
||
60 | 53 | public function __construct( Title $title, Parser $parser = null ) { |
|
68 | |||
69 | /** |
||
70 | * @since 2.3 |
||
71 | * |
||
72 | * @return Parser $parser |
||
73 | */ |
||
74 | public function setParser( Parser $parser ) { |
||
77 | |||
78 | /** |
||
79 | * @since 1.9.1 |
||
80 | * |
||
81 | * @return ContentParser |
||
82 | */ |
||
83 | 10 | public function setRevision( Revision $revision = null ) { |
|
87 | |||
88 | /** |
||
89 | * @bug 62856 and #212 |
||
90 | * |
||
91 | * @since 2.0 |
||
92 | */ |
||
93 | 1 | public function forceToUseParser() { |
|
96 | |||
97 | /** |
||
98 | * @since 1.9 |
||
99 | * |
||
100 | * @return Title |
||
101 | */ |
||
102 | 52 | public function getTitle() { |
|
105 | |||
106 | /** |
||
107 | * @since 1.9 |
||
108 | * |
||
109 | * @return ParserOutput|null |
||
110 | */ |
||
111 | 48 | public function getOutput() { |
|
114 | |||
115 | /** |
||
116 | * @since 1.9 |
||
117 | * |
||
118 | * @return array |
||
119 | */ |
||
120 | 3 | public function getErrors() { |
|
123 | |||
124 | public function skipInTextAnnotationParser() { |
||
127 | |||
128 | /** |
||
129 | * Generates or fetches the ParserOutput object from an appropriate source |
||
130 | * |
||
131 | * @since 1.9 |
||
132 | * |
||
133 | * @param string|null $text |
||
134 | * |
||
135 | * @return ContentParser |
||
136 | */ |
||
137 | 52 | public function parse( $text = null ) { |
|
149 | |||
150 | 16 | protected function parseText( $text ) { |
|
160 | |||
161 | /** |
||
162 | * @note Revision ID must be passed to the parser output to |
||
163 | * get revision variables correct |
||
164 | * |
||
165 | * @note If no content is available create an empty object |
||
166 | */ |
||
167 | 32 | protected function fetchFromContent() { |
|
188 | |||
189 | 4 | protected function fetchFromParser() { |
|
206 | |||
207 | 4 | protected function msgForNullRevision( $fname = __METHOD__ ) { |
|
211 | |||
212 | 18 | protected function makeParserOptions() { |
|
228 | |||
229 | 52 | protected function getRevision() { |
|
244 | |||
245 | 29 | protected function hasContentHandler() { |
|
248 | |||
249 | } |
||
250 |
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: