MediaWiki REL1_32
RemexDriverTest.php
Go to the documentation of this file.
1<?php
2
4 static private $remexTidyTestData = [
5 // Tests from Html5Depurate
6 [
7 'Empty string',
8 "",
9 ""
10 ],
11 [
12 'Simple p-wrap',
13 "x",
14 "<p>x</p>"
15 ],
16 [
17 'No p-wrap of blank node',
18 " ",
19 " "
20 ],
21 [
22 'p-wrap terminated by div',
23 "x<div></div>",
24 "<p>x</p><div></div>"
25 ],
26 [
27 'p-wrap not terminated by span',
28 "x<span></span>",
29 "<p>x<span></span></p>"
30 ],
31 [
32 'An element is non-blank and so gets p-wrapped',
33 "<span></span>",
34 "<p><span></span></p>"
35 ],
36 [
37 'The blank flag is set after a block-level element',
38 "<div></div> ",
39 "<div></div> "
40 ],
41 [
42 'Blank detection between two block-level elements',
43 "<div></div> <div></div>",
44 "<div></div> <div></div>"
45 ],
46 [
47 'But p-wrapping of non-blank content works after an element',
48 "<div></div>x",
49 "<div></div><p>x</p>"
50 ],
51 [
52 'p-wrapping between two block-level elements',
53 "<div></div>x<div></div>",
54 "<div></div><p>x</p><div></div>"
55 ],
56 [
57 'p-wrap inside blockquote',
58 "<blockquote>x</blockquote>",
59 "<blockquote><p>x</p></blockquote>"
60 ],
61 [
62 'A comment is blank for p-wrapping purposes',
63 "<!-- x -->",
64 "<!-- x -->"
65 ],
66 [
67 'A comment is blank even when a p-wrap was opened by a text node',
68 " <!-- x -->",
69 " <!-- x -->"
70 ],
71 [
72 'A comment does not open a p-wrap',
73 "<!-- x -->x",
74 "<!-- x --><p>x</p>"
75 ],
76 [
77 'A comment does not close a p-wrap',
78 "x<!-- x -->",
79 "<p>x<!-- x --></p>"
80 ],
81 [
82 'Empty li',
83 "<ul><li></li></ul>",
84 "<ul><li class=\"mw-empty-elt\"></li></ul>"
85 ],
86 [
87 'li with element',
88 "<ul><li><span></span></li></ul>",
89 "<ul><li><span></span></li></ul>"
90 ],
91 [
92 'li with text',
93 "<ul><li>x</li></ul>",
94 "<ul><li>x</li></ul>"
95 ],
96 [
97 'Empty tr',
98 "<table><tbody><tr></tr></tbody></table>",
99 "<table><tbody><tr class=\"mw-empty-elt\"></tr></tbody></table>"
100 ],
101 [
102 'Empty p',
103 "<p>\n</p>",
104 "<p class=\"mw-empty-elt\">\n</p>"
105 ],
106 [
107 'No p-wrapping of an inline element which contains a block element (T150317)',
108 "<small><div>x</div></small>",
109 "<small><div>x</div></small>"
110 ],
111 [
112 'p-wrapping of an inline element which contains an inline element',
113 "<small><b>x</b></small>",
114 "<p><small><b>x</b></small></p>"
115 ],
116 [
117 'p-wrapping is enabled in a blockquote in an inline element',
118 "<small><blockquote>x</blockquote></small>",
119 "<small><blockquote><p>x</p></blockquote></small>"
120 ],
121 [
122 'All bare text should be p-wrapped even when surrounded by block tags',
123 "<small><blockquote>x</blockquote></small>y<div></div>z",
124 "<small><blockquote><p>x</p></blockquote></small><p>y</p><div></div><p>z</p>"
125 ],
126 [
127 'Split tag stack 1',
128 "<small>x<div>y</div>z</small>",
129 "<p><small>x</small></p><small><div>y</div></small><p><small>z</small></p>"
130 ],
131 [
132 'Split tag stack 2',
133 "<small><div>y</div>z</small>",
134 "<small><div>y</div></small><p><small>z</small></p>"
135 ],
136 [
137 'Split tag stack 3',
138 "<small>x<div>y</div></small>",
139 "<p><small>x</small></p><small><div>y</div></small>"
140 ],
141 [
142 'Split tag stack 4 (modified to use splittable tag)',
143 "a<code>b<i>c<div>d</div></i>e</code>",
144 "<p>a<code>b<i>c</i></code></p><code><i><div>d</div></i></code><p><code>e</code></p>"
145 ],
146 [
147 "Split tag stack regression check 1",
148 "x<span><div>y</div></span>",
149 "<p>x</p><span><div>y</div></span>"
150 ],
151 [
152 "Split tag stack regression check 2 (modified to use splittable tag)",
153 "a<code><i><div>d</div></i>e</code>",
154 "<p>a</p><code><i><div>d</div></i></code><p><code>e</code></p>"
155 ],
156 // Simple tests from pwrap.js
157 [
158 'Simple pwrap test 1',
159 'a',
160 '<p>a</p>'
161 ],
162 [
163 '<span> is not a splittable tag, but gets p-wrapped in simple wrapping scenarios',
164 '<span>a</span>',
165 '<p><span>a</span></p>'
166 ],
167 [
168 'Simple pwrap test 3',
169 'x <div>a</div> <div>b</div> y',
170 '<p>x </p><div>a</div> <div>b</div><p> y</p>'
171 ],
172 [
173 'Simple pwrap test 4',
174 'x<!--c--> <div>a</div> <div>b</div> <!--c-->y',
175 '<p>x<!--c--> </p><div>a</div> <div>b</div> <!--c--><p>y</p>'
176 ],
177 // Complex tests from pwrap.js
178 [
179 'Complex pwrap test 1',
180 '<i>x<div>a</div>y</i>',
181 '<p><i>x</i></p><i><div>a</div></i><p><i>y</i></p>'
182 ],
183 [
184 'Complex pwrap test 2',
185 'a<small>b</small><i>c<div>d</div>e</i>f',
186 '<p>a<small>b</small><i>c</i></p><i><div>d</div></i><p><i>e</i>f</p>'
187 ],
188 [
189 'Complex pwrap test 3',
190 'a<small>b<i>c<div>d</div></i>e</small>',
191 '<p>a<small>b<i>c</i></small></p><small><i><div>d</div></i></small><p><small>e</small></p>'
192 ],
193 [
194 'Complex pwrap test 4',
195 'x<small><div>y</div></small>',
196 '<p>x</p><small><div>y</div></small>'
197 ],
198 [
199 'Complex pwrap test 5',
200 'a<small><i><div>d</div></i>e</small>',
201 '<p>a</p><small><i><div>d</div></i></small><p><small>e</small></p>'
202 ],
203 // phpcs:disable Generic.Files.LineLength
204 [
205 'Complex pwrap test 6',
206 '<i>a<div>b</div>c<b>d<div>e</div>f</b>g</i>',
207 // PHP 5 does not allow concatenation in initialisation of a class static variable
208 '<p><i>a</i></p><i><div>b</div></i><p><i>c<b>d</b></i></p><i><b><div>e</div></b></i><p><i><b>f</b>g</i></p>'
209 ],
210 // phpcs:enable
211 /* FIXME the second <b> causes a stack split which clones the <i> even
212 * though no <p> is actually generated
213 [
214 'Complex pwrap test 7',
215 '<i><b><font><div>x</div></font></b><div>y</div><b><font><div>z</div></font></b></i>',
216 '<i><b><font><div>x</div></font></b><div>y</div><b><font><div>z</div></font></b></i>'
217 ],
218 */
219 // New local tests
220 [
221 'Blank text node after block end',
222 '<small>x<div>y</div> <b>z</b></small>',
223 '<p><small>x</small></p><small><div>y</div></small><p><small> <b>z</b></small></p>'
224 ],
225 [
226 'Text node fostering (FIXME: wrap missing)',
227 '<table>x</table>',
228 'x<table></table>'
229 ],
230 [
231 'Blockquote fostering',
232 '<table><blockquote>x</blockquote></table>',
233 '<blockquote><p>x</p></blockquote><table></table>'
234 ],
235 [
236 'Block element fostering',
237 '<table><div>x',
238 '<div>x</div><table></table>'
239 ],
240 [
241 'Formatting element fostering (FIXME: wrap missing)',
242 '<table><b>x',
243 '<b>x</b><table></table>'
244 ],
245 [
246 'AAA clone of p-wrapped element (FIXME: empty b)',
247 '<b>x<p>y</b>z</p>',
248 '<p><b>x</b></p><b></b><p><b>y</b>z</p>',
249 ],
250 [
251 'AAA with fostering (FIXME: wrap missing)',
252 '<table><b>1<p>2</b>3</p>',
253 '<b>1</b><p><b>2</b>3</p><table></table>'
254 ],
255 [
256 'AAA causes reparent of p-wrapped text node (T178632)',
257 '<i><blockquote>x</i></blockquote>',
258 '<i></i><blockquote><p><i>x</i></p></blockquote>',
259 ],
260 [
261 'p-wrap ended by reparenting (T200827)',
262 '<i><blockquote><p></i>',
263 '<i></i><blockquote><p><i></i></p><p><i></i></p></blockquote>',
264 ],
265 ];
266
267 public function provider() {
269 }
270
278 public function testTidy( $desc, $input, $expected ) {
279 $r = new MediaWiki\Tidy\RemexDriver( [] );
280 $result = $r->tidy( $input );
281 $this->assertEquals( $expected, $result, $desc );
282 }
283
284 public function html5libProvider() {
285 $files = json_decode( file_get_contents( __DIR__ . '/html5lib-tests.json' ), true );
286 $tests = [];
287 foreach ( $files as $file => $fileTests ) {
288 foreach ( $fileTests as $i => $test ) {
289 $tests[] = [ "$file:$i", $test['data'] ];
290 }
291 }
292 return $tests;
293 }
294
302 public function testHtml5Lib( $desc, $input ) {
303 $r = new MediaWiki\Tidy\RemexDriver( [] );
304 $result = $r->tidy( $input );
305 $this->assertTrue( true, $desc );
306 }
307}
testHtml5Lib( $desc, $input)
This is a quick and dirty test to make sure none of the html5lib tests generate exceptions.
testTidy( $desc, $input, $expected)
provider MediaWiki\Tidy\RemexCompatFormatter MediaWiki\Tidy\RemexCompatMunger MediaWiki\Tidy\RemexDri...
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
The index of the header message $result[1]=The index of the body text message $result[2 through n]=Parameters passed to body text message. Please note the header message cannot receive/use parameters. 'ImgAuthModifyHeaders':Executed just before a file is streamed to a user via img_auth.php, allowing headers to be modified beforehand. $title:LinkTarget object & $headers:HTTP headers(name=> value, names are case insensitive). Two headers get special handling:If-Modified-Since(value must be a valid HTTP date) and Range(must be of the form "bytes=(\d*-\d*)") will be honored when streaming the file. 'ImportHandleLogItemXMLTag':When parsing a XML tag in a log item. Return false to stop further processing of the tag $reader:XMLReader object $logInfo:Array of information 'ImportHandlePageXMLTag':When parsing a XML tag in a page. Return false to stop further processing of the tag $reader:XMLReader object & $pageInfo:Array of information 'ImportHandleRevisionXMLTag':When parsing a XML tag in a page revision. Return false to stop further processing of the tag $reader:XMLReader object $pageInfo:Array of page information $revisionInfo:Array of revision information 'ImportHandleToplevelXMLTag':When parsing a top level XML tag. Return false to stop further processing of the tag $reader:XMLReader object 'ImportHandleUnknownUser':When a user doesn 't exist locally, this hook is called to give extensions an opportunity to auto-create it. If the auto-creation is successful, return false. $name:User name 'ImportHandleUploadXMLTag':When parsing a XML tag in a file upload. Return false to stop further processing of the tag $reader:XMLReader object $revisionInfo:Array of information 'ImportLogInterwikiLink':Hook to change the interwiki link used in log entries and edit summaries for transwiki imports. & $fullInterwikiPrefix:Interwiki prefix, may contain colons. & $pageTitle:String that contains page title. 'ImportSources':Called when reading from the $wgImportSources configuration variable. Can be used to lazy-load the import sources list. & $importSources:The value of $wgImportSources. Modify as necessary. See the comment in DefaultSettings.php for the detail of how to structure this array. 'InfoAction':When building information to display on the action=info page. $context:IContextSource object & $pageInfo:Array of information 'InitializeArticleMaybeRedirect':MediaWiki check to see if title is a redirect. & $title:Title object for the current page & $request:WebRequest & $ignoreRedirect:boolean to skip redirect check & $target:Title/string of redirect target & $article:Article object 'InternalParseBeforeLinks':during Parser 's internalParse method before links but after nowiki/noinclude/includeonly/onlyinclude and other processings. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InternalParseBeforeSanitize':during Parser 's internalParse method just before the parser removes unwanted/dangerous HTML tags and after nowiki/noinclude/includeonly/onlyinclude and other processings. Ideal for syntax-extensions after template/parser function execution which respect nowiki and HTML-comments. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InterwikiLoadPrefix':When resolving if a given prefix is an interwiki or not. Return true without providing an interwiki to continue interwiki search. $prefix:interwiki prefix we are looking for. & $iwData:output array describing the interwiki with keys iw_url, iw_local, iw_trans and optionally iw_api and iw_wikiid. 'InvalidateEmailComplete':Called after a user 's email has been invalidated successfully. $user:user(object) whose email is being invalidated 'IRCLineURL':When constructing the URL to use in an IRC notification. Callee may modify $url and $query, URL will be constructed as $url . $query & $url:URL to index.php & $query:Query string $rc:RecentChange object that triggered url generation 'IsFileCacheable':Override the result of Article::isFileCacheable()(if true) & $article:article(object) being checked 'IsTrustedProxy':Override the result of IP::isTrustedProxy() & $ip:IP being check & $result:Change this value to override the result of IP::isTrustedProxy() 'IsUploadAllowedFromUrl':Override the result of UploadFromUrl::isAllowedUrl() $url:URL used to upload from & $allowed:Boolean indicating if uploading is allowed for given URL 'isValidEmailAddr':Override the result of Sanitizer::validateEmail(), for instance to return false if the domain name doesn 't match your organization. $addr:The e-mail address entered by the user & $result:Set this and return false to override the internal checks 'isValidPassword':Override the result of User::isValidPassword() $password:The password entered by the user & $result:Set this and return false to override the internal checks $user:User the password is being validated for 'Language::getMessagesFileName':$code:The language code or the language we 're looking for a messages file for & $file:The messages file path, you can override this to change the location. 'LanguageGetMagic':DEPRECATED since 1.16! Use $magicWords in a file listed in $wgExtensionMessagesFiles instead. Use this to define synonyms of magic words depending of the language & $magicExtensions:associative array of magic words synonyms $lang:language code(string) 'LanguageGetNamespaces':Provide custom ordering for namespaces or remove namespaces. Do not use this hook to add namespaces. Use CanonicalNamespaces for that. & $namespaces:Array of namespaces indexed by their numbers 'LanguageGetSpecialPageAliases':DEPRECATED! Use $specialPageAliases in a file listed in $wgExtensionMessagesFiles instead. Use to define aliases of special pages names depending of the language & $specialPageAliases:associative array of magic words synonyms $lang:language code(string) 'LanguageGetTranslatedLanguageNames':Provide translated language names. & $names:array of language code=> language name $code:language of the preferred translations 'LanguageLinks':Manipulate a page 's language links. This is called in various places to allow extensions to define the effective language links for a page. $title:The page 's Title. & $links:Array with elements of the form "language:title" in the order that they will be output. & $linkFlags:Associative array mapping prefixed links to arrays of flags. Currently unused, but planned to provide support for marking individual language links in the UI, e.g. for featured articles. 'LanguageSelector':Hook to change the language selector available on a page. $out:The output page. $cssClassName:CSS class name of the language selector. 'LinkBegin':DEPRECATED since 1.28! Use HtmlPageLinkRendererBegin instead. Used when generating internal and interwiki links in Linker::link(), before processing starts. Return false to skip default processing and return $ret. See documentation for Linker::link() for details on the expected meanings of parameters. $skin:the Skin object $target:the Title that the link is pointing to & $html:the contents that the< a > tag should have(raw HTML) $result
Definition hooks.txt:2042
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition injection.txt:37
if(is_array($mode)) switch( $mode) $input