MediaWiki  1.33.0
RemexStripTagHandler.php
Go to the documentation of this file.
1 <?php
2 
3 use RemexHtml\Tokenizer\Attributes;
4 use RemexHtml\Tokenizer\TokenHandler;
5 use RemexHtml\Tokenizer\Tokenizer;
6 
10 class 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 }
RemexStripTagHandler\error
error( $text, $pos)
Definition: RemexStripTagHandler.php:22
RemexStripTagHandler\isBlockLevelTag
isBlockLevelTag( $tagName)
Detect block level tags.
Definition: RemexStripTagHandler.php:105
RemexStripTagHandler\endTag
endTag( $name, $sourceStart, $sourceLength)
Definition: RemexStripTagHandler.php:35
RemexStripTagHandler\comment
comment( $text, $sourceStart, $sourceLength)
Definition: RemexStripTagHandler.php:45
RemexStripTagHandler
Definition: RemexStripTagHandler.php:10
RemexStripTagHandler\characters
characters( $text, $start, $length, $sourceStart, $sourceLength)
Definition: RemexStripTagHandler.php:25
RemexStripTagHandler\startDocument
startDocument(Tokenizer $t, $fns, $fn)
Definition: RemexStripTagHandler.php:16
RemexStripTagHandler\$BLOCK_LEVEL_TAGS
static $BLOCK_LEVEL_TAGS
Definition: RemexStripTagHandler.php:55
php
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:35
RemexStripTagHandler\$text
$text
Definition: RemexStripTagHandler.php:11
RemexStripTagHandler\doctype
doctype( $name, $public, $system, $quirks, $sourceStart, $sourceLength)
Definition: RemexStripTagHandler.php:42
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
$name
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:271
RemexStripTagHandler\startTag
startTag( $name, Attributes $attrs, $selfClose, $sourceStart, $sourceLength)
Definition: RemexStripTagHandler.php:28
text
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
Definition: All_system_messages.txt:1267
$t
$t
Definition: testCompression.php:69
RemexStripTagHandler\endDocument
endDocument( $pos)
Definition: RemexStripTagHandler.php:19
RemexStripTagHandler\getResult
getResult()
Definition: RemexStripTagHandler.php:12