MediaWiki REL1_32
RaggettWrapper.php
Go to the documentation of this file.
1<?php
2namespace MediaWiki\Tidy;
3
6
21
25 protected $mTokens;
26
30 protected $mMarkerIndex;
31
36 public function getWrapped( $text ) {
37 $this->mTokens = [];
38 $this->mMarkerIndex = 0;
39
40 // Replace <mw:editsection> elements with placeholders
41 $wrappedtext = preg_replace_callback( ParserOutput::EDITSECTION_REGEX,
42 [ $this, 'replaceCallback' ], $text );
43 // ...and <mw:toc> markers
44 $wrappedtext = preg_replace_callback( '/<\\/?mw:toc>/',
45 [ $this, 'replaceCallback' ], $wrappedtext );
46 // ... and <math> tags
47 $wrappedtext = preg_replace_callback( '/<math(.*?)<\\/math>/s',
48 [ $this, 'replaceCallback' ], $wrappedtext );
49 // Modify inline Microdata <link> and <meta> elements so they say <html-link> and <html-meta> so
50 // we can trick Tidy into not stripping them out by including them in tidy's new-empty-tags config
51 $wrappedtext = preg_replace( '!<(link|meta)([^>]*?)(/{0,1}>)!', '<html-$1$2$3', $wrappedtext );
52 // Similar for inline <style> tags, but those aren't empty.
53 $wrappedtext = preg_replace_callback( '!<style([^>]*)>(.*?)</style>!s', function ( $m ) {
54 return '<html-style' . $m[1] . '>'
55 . $this->replaceCallback( [ $m[2] ] )
56 . '</html-style>';
57 }, $wrappedtext );
58
59 // Preserve empty li elements (T49673) by abusing Tidy's datafld hack
60 // The whitespace class is as in TY_(InitMap)
61 $wrappedtext = preg_replace( "!<li>([ \r\n\t\f]*)</li>!",
62 '<li datafld="" class="mw-empty-elt">\1</li>', $wrappedtext );
63
64 // Wrap the whole thing in a doctype and body for Tidy.
65 $wrappedtext = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"' .
66 ' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html>' .
67 '<head><title>test</title></head><body>' . $wrappedtext . '</body></html>';
68
69 return $wrappedtext;
70 }
71
76 private function replaceCallback( array $m ) {
77 $marker = Parser::MARKER_PREFIX . "-item-{$this->mMarkerIndex}" . Parser::MARKER_SUFFIX;
78 $this->mMarkerIndex++;
79 $this->mTokens[$marker] = $m[0];
80 return $marker;
81 }
82
87 public function postprocess( $text ) {
88 // Revert <html-{link,meta,style}> back to <{link,meta,style}>
89 $text = preg_replace( '!<html-(link|meta)([^>]*?)(/{0,1}>)!', '<$1$2$3', $text );
90 $text = preg_replace( '!<(/?)html-(style)([^>]*)>!', '<$1$2$3>', $text );
91
92 // Remove datafld
93 $text = str_replace( '<li datafld=""', '<li', $text );
94
95 // Restore the contents of placeholder tokens
96 $text = strtr( $text, $this->mTokens );
97
98 return $text;
99 }
100
101}
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:68
const MARKER_PREFIX
Definition Parser.php:133
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
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))