MediaWiki REL1_33
RemexStripTagHandler.php
Go to the documentation of this file.
1<?php
2
3use RemexHtml\Tokenizer\Attributes;
4use RemexHtml\Tokenizer\TokenHandler;
5use RemexHtml\Tokenizer\Tokenizer;
6
10class RemexStripTagHandler implements TokenHandler {
11 private $text = '';
12 public function getResult() {
13 return $this->text;
14 }
15
16 function startDocument( Tokenizer $t, $fns, $fn ) {
17 // Do nothing.
18 }
19 function endDocument( $pos ) {
20 // Do nothing.
21 }
22 function error( $text, $pos ) {
23 // Do nothing.
24 }
25 function characters( $text, $start, $length, $sourceStart, $sourceLength ) {
26 $this->text .= substr( $text, $start, $length );
27 }
28 function startTag( $name, Attributes $attrs, $selfClose, $sourceStart, $sourceLength ) {
29 // Inject whitespace for typical block-level tags to
30 // prevent merging unrelated<br>words.
31 if ( $this->isBlockLevelTag( $name ) ) {
32 $this->text .= ' ';
33 }
34 }
35 function endTag( $name, $sourceStart, $sourceLength ) {
36 // Inject whitespace for typical block-level tags to
37 // prevent merging unrelated<br>words.
38 if ( $this->isBlockLevelTag( $name ) ) {
39 $this->text .= ' ';
40 }
41 }
42 function doctype( $name, $public, $system, $quirks, $sourceStart, $sourceLength ) {
43 // Do nothing.
44 }
45 function comment( $text, $sourceStart, $sourceLength ) {
46 // Do nothing.
47 }
48
49 // Per https://developer.mozilla.org/en-US/docs/Web/HTML/Block-level_elements
50 // retrieved on sept 12, 2018. <br> is not block level but was added anyways.
51 // The following is a complete list of all HTML block level elements
52 // (although "block-level" is not technically defined for elements that are
53 // new in HTML5).
54 // Structured as tag => true to allow O(1) membership test.
55 private static $BLOCK_LEVEL_TAGS = [
56 'address' => true,
57 'article' => true,
58 'aside' => true,
59 'blockquote' => true,
60 'br' => true,
61 'canvas' => true,
62 'dd' => true,
63 'div' => true,
64 'dl' => true,
65 'dt' => true,
66 'fieldset' => true,
67 'figcaption' => true,
68 'figure' => true,
69 'footer' => true,
70 'form' => true,
71 'h1' => true,
72 'h2' => true,
73 'h3' => true,
74 'h4' => true,
75 'h5' => true,
76 'h6' => true,
77 'header' => true,
78 'hgroup' => true,
79 'hr' => true,
80 'li' => true,
81 'main' => true,
82 'nav' => true,
83 'noscript' => true,
84 'ol' => true,
85 'output' => true,
86 'p' => true,
87 'pre' => true,
88 'section' => true,
89 'table' => true,
90 'td' => true,
91 'tfoot' => true,
92 'th' => true,
93 'tr' => true,
94 'ul' => true,
95 'video' => true,
96 ];
97
105 private function isBlockLevelTag( $tagName ) {
106 $key = strtolower( trim( $tagName ) );
107 return isset( self::$BLOCK_LEVEL_TAGS[$key] );
108 }
109}
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
This list may contain false positives That usually means there is additional text with links below the first Each row contains links to the first and second as well as the first line of the second redirect text
doctype( $name, $public, $system, $quirks, $sourceStart, $sourceLength)
endTag( $name, $sourceStart, $sourceLength)
startDocument(Tokenizer $t, $fns, $fn)
comment( $text, $sourceStart, $sourceLength)
isBlockLevelTag( $tagName)
Detect block level tags.
characters( $text, $start, $length, $sourceStart, $sourceLength)
startTag( $name, Attributes $attrs, $selfClose, $sourceStart, $sourceLength)
Allows to change the fields on the form that will be generated $name
Definition hooks.txt:271
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