MediaWiki  master
RemexCompatFormatter.php
Go to the documentation of this file.
1 <?php
2 
3 namespace MediaWiki\Tidy;
4 
8 
12 class RemexCompatFormatter extends HtmlFormatter {
13  private static $markedEmptyElements = [
14  'li' => true,
15  'p' => true,
16  'tr' => true,
17  ];
18 
19  public function __construct( $options = [] ) {
20  parent::__construct( $options );
21  $this->attributeEscapes["\u{00A0}"] = '&#160;';
22  unset( $this->attributeEscapes["&"] );
23  $this->textEscapes["\u{00A0}"] = '&#160;';
24  unset( $this->textEscapes["&"] );
25  }
26 
27  public function startDocument( $fragmentNamespace, $fragmentName ) {
28  return '';
29  }
30 
31  public function element( SerializerNode $parent, SerializerNode $node, $contents ) {
32  $data = $node->snData;
33  if ( $data && $data->isPWrapper ) {
34  if ( $data->nonblankNodeCount ) {
35  return "<p>$contents</p>";
36  } else {
37  return $contents;
38  }
39  }
40 
41  $name = $node->name;
42  $attrs = $node->attrs;
43  if ( isset( self::$markedEmptyElements[$name] ) && $attrs->count() === 0
44  && strspn( $contents, "\t\n\f\r " ) === strlen( $contents )
45  ) {
46  return "<{$name} class=\"mw-empty-elt\">$contents</{$name}>";
47  }
48 
49  $s = "<$name";
50  foreach ( $attrs->getValues() as $attrName => $attrValue ) {
51  $encValue = strtr( $attrValue, $this->attributeEscapes );
52  $s .= " $attrName=\"$encValue\"";
53  }
54  if ( $node->namespace === HTMLData::NS_HTML && isset( $this->voidElements[$name] ) ) {
55  $s .= ' />';
56  return $s;
57  }
58 
59  $s .= '>';
60  if ( $node->namespace === HTMLData::NS_HTML
61  && isset( $contents[0] ) && $contents[0] === "\n"
62  && isset( $this->prefixLfElements[$name] )
63  ) {
64  $s .= "\n$contents</$name>";
65  } else {
66  $s .= "$contents</$name>";
67  }
68  return $s;
69  }
70 }
$data
Utility to generate mapping file used in mw.Title (phpCharToUpper.json)
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped & $options
Definition: hooks.txt:1982
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
Definition: distributors.txt:9
element(SerializerNode $parent, SerializerNode $node, $contents)
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
$parent
Definition: pageupdater.txt:71
startDocument( $fragmentNamespace, $fragmentName)
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:271