MediaWiki REL1_31
RaggettWrapper.php
Go to the documentation of this file.
1<?php
2namespace MediaWiki\Tidy;
3
6
20
24 protected $mTokens;
25
29 protected $mMarkerIndex;
30
35 public function getWrapped( $text ) {
36 $this->mTokens = [];
37 $this->mMarkerIndex = 0;
38
39 // Replace <mw:editsection> elements with placeholders
40 $wrappedtext = preg_replace_callback( ParserOutput::EDITSECTION_REGEX,
41 [ $this, 'replaceCallback' ], $text );
42 // ...and <mw:toc> markers
43 $wrappedtext = preg_replace_callback( '/<\\/?mw:toc>/',
44 [ $this, 'replaceCallback' ], $wrappedtext );
45 // ... and <math> tags
46 $wrappedtext = preg_replace_callback( '/<math(.*?)<\\/math>/s',
47 [ $this, 'replaceCallback' ], $wrappedtext );
48 // Modify inline Microdata <link> and <meta> elements so they say <html-link> and <html-meta> so
49 // we can trick Tidy into not stripping them out by including them in tidy's new-empty-tags config
50 $wrappedtext = preg_replace( '!<(link|meta)([^>]*?)(/{0,1}>)!', '<html-$1$2$3', $wrappedtext );
51 // Similar for inline <style> tags, but those aren't empty.
52 $wrappedtext = preg_replace_callback( '!<style([^>]*)>(.*?)</style>!s', function ( $m ) {
53 return '<html-style' . $m[1] . '>'
54 . $this->replaceCallback( [ $m[2] ] )
55 . '</html-style>';
56 }, $wrappedtext );
57
58 // Preserve empty li elements (T49673) by abusing Tidy's datafld hack
59 // The whitespace class is as in TY_(InitMap)
60 $wrappedtext = preg_replace( "!<li>([ \r\n\t\f]*)</li>!",
61 '<li datafld="" class="mw-empty-elt">\1</li>', $wrappedtext );
62
63 // Wrap the whole thing in a doctype and body for Tidy.
64 $wrappedtext = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"' .
65 ' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html>' .
66 '<head><title>test</title></head><body>' . $wrappedtext . '</body></html>';
67
68 return $wrappedtext;
69 }
70
75 private function replaceCallback( array $m ) {
76 $marker = Parser::MARKER_PREFIX . "-item-{$this->mMarkerIndex}" . Parser::MARKER_SUFFIX;
77 $this->mMarkerIndex++;
78 $this->mTokens[$marker] = $m[0];
79 return $marker;
80 }
81
86 public function postprocess( $text ) {
87 // Revert <html-{link,meta,style}> back to <{link,meta,style}>
88 $text = preg_replace( '!<html-(link|meta)([^>]*?)(/{0,1}>)!', '<$1$2$3', $text );
89 $text = preg_replace( '!<(/?)html-(style)([^>]*)>!', '<$1$2$3>', $text );
90
91 // Remove datafld
92 $text = str_replace( '<li datafld=""', '<li', $text );
93
94 // Restore the contents of placeholder tokens
95 $text = strtr( $text, $this->mTokens );
96
97 return $text;
98 }
99
100}
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
Class used to hide mw:editsection tokens from Tidy so that it doesn't break them or break on them.
PHP Parser - Processes wiki markup (which uses a more user-friendly syntax, such as "[[link]]" for ma...
Definition Parser.php:70
const MARKER_PREFIX
Definition Parser.php:135
the array() calling protocol came about after MediaWiki 1.4rc1.
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