35 return $svg->getMetadata();
45 const NS_SVG =
'http://www.w3.org/2000/svg';
67 $this->reader =
new XMLReader();
71 if ( $size ===
false ) {
72 throw new MWException(
"Error getting filesize of SVG." );
76 $this->
debug(
"SVG is $size bytes, which is bigger than $wgSVGMetadataCutoff. Truncating." );
78 if ( $contents ===
false ) {
81 $this->reader->XML( $contents,
null, LIBXML_NOERROR | LIBXML_NOWARNING );
83 $this->reader->open(
$source,
null, LIBXML_NOERROR | LIBXML_NOWARNING );
94 $oldDisable = libxml_disable_entity_loader(
true );
95 $this->reader->setParserProperty( XMLReader::SUBST_ENTITIES,
true );
103 $this->metadata[
'originalWidth'] =
'100%';
104 $this->metadata[
'originalHeight'] =
'100%';
109 Wikimedia\suppressWarnings();
112 }
catch ( Exception
$e ) {
115 Wikimedia\restoreWarnings();
116 libxml_disable_entity_loader( $oldDisable );
119 Wikimedia\restoreWarnings();
120 libxml_disable_entity_loader( $oldDisable );
136 $keepReading = $this->reader->read();
139 while ( $keepReading && $this->reader->nodeType != XMLReader::ELEMENT ) {
140 $keepReading = $this->reader->read();
143 if ( $this->reader->localName !=
'svg' || $this->reader->namespaceURI != self::NS_SVG ) {
144 throw new MWException(
"Expected <svg> tag, got " .
145 $this->reader->localName .
" in NS " . $this->reader->namespaceURI );
147 $this->
debug(
"<svg> tag is correct." );
150 $exitDepth = $this->reader->depth;
151 $keepReading = $this->reader->read();
152 while ( $keepReading ) {
153 $tag = $this->reader->localName;
154 $type = $this->reader->nodeType;
155 $isSVG = ( $this->reader->namespaceURI ==
self::NS_SVG );
157 $this->
debug(
"$tag" );
159 if ( $isSVG && $tag ==
'svg' &&
$type == XMLReader::END_ELEMENT
160 && $this->reader->depth <= $exitDepth
163 } elseif ( $isSVG && $tag ==
'title' ) {
165 } elseif ( $isSVG && $tag ==
'desc' ) {
167 } elseif ( $isSVG && $tag ==
'metadata' &&
$type == XMLReader::ELEMENT ) {
169 } elseif ( $isSVG && $tag ==
'script' ) {
173 $this->metadata[
'animated'] =
true;
174 } elseif ( $tag !==
'#text' ) {
175 $this->
debug(
"Unhandled top-level XML tag $tag" );
182 $keepReading = $this->reader->next();
185 $this->reader->close();
198 private function readField( $name, $metafield =
null ) {
199 $this->
debug(
"Read field $metafield" );
200 if ( !$metafield || $this->reader->nodeType != XMLReader::ELEMENT ) {
203 $keepReading = $this->reader->read();
204 while ( $keepReading ) {
205 if ( $this->reader->localName ==
$name
206 && $this->reader->namespaceURI == self::NS_SVG
207 && $this->reader->nodeType == XMLReader::END_ELEMENT
210 } elseif ( $this->reader->nodeType == XMLReader::TEXT ) {
211 $this->metadata[$metafield] = trim( $this->reader->value );
213 $keepReading = $this->reader->read();
223 private function readXml( $metafield =
null ) {
224 $this->
debug(
"Read top level metadata" );
225 if ( !$metafield || $this->reader->nodeType != XMLReader::ELEMENT ) {
229 $this->metadata[$metafield] = trim( $this->reader->readInnerXml() );
231 $this->reader->next();
241 $this->
debug(
"animate filter for tag $name" );
242 if ( $this->reader->nodeType != XMLReader::ELEMENT ) {
245 if ( $this->reader->isEmptyElement ) {
248 $exitDepth = $this->reader->depth;
249 $keepReading = $this->reader->read();
250 while ( $keepReading ) {
251 if ( $this->reader->localName ==
$name && $this->reader->depth <= $exitDepth
252 && $this->reader->nodeType == XMLReader::END_ELEMENT
255 } elseif ( $this->reader->namespaceURI == self::NS_SVG
256 && $this->reader->nodeType == XMLReader::ELEMENT
258 $sysLang = $this->reader->getAttribute(
'systemLanguage' );
259 if ( !is_null( $sysLang ) && $sysLang !==
'' ) {
261 $langList = explode(
',', $sysLang );
262 foreach ( $langList
as $langItem ) {
263 $langItem = trim( $langItem );
264 if ( Language::isWellFormedLanguageTag( $langItem ) ) {
273 $dash = strpos( $langItem,
'-' );
276 $itemPrefix = substr( $langItem, 0, $dash );
277 if ( Language::isWellFormedLanguageTag( $itemPrefix ) ) {
283 switch ( $this->reader->localName ) {
291 case 'animateMotion':
293 case 'animateTransform':
294 $this->
debug(
"HOUSTON WE HAVE ANIMATION" );
295 $this->metadata[
'animated'] =
true;
299 $keepReading = $this->reader->read();
304 if ( $this->mDebug ) {
305 wfDebug(
"SVGReader: $data\n" );
321 if ( $this->reader->getAttribute(
'viewBox' ) ) {
323 $viewBox = preg_split(
'/\s*[\s,]\s*/', trim( $this->reader->getAttribute(
'viewBox' ) ) );
324 if ( count( $viewBox ) == 4 ) {
327 if ( $viewWidth > 0 && $viewHeight > 0 ) {
328 $aspect = $viewWidth / $viewHeight;
329 $defaultHeight = $defaultWidth / $aspect;
333 if ( $this->reader->getAttribute(
'width' ) ) {
334 $width = $this->
scaleSVGUnit( $this->reader->getAttribute(
'width' ), $defaultWidth );
335 $this->metadata[
'originalWidth'] = $this->reader->getAttribute(
'width' );
337 if ( $this->reader->getAttribute(
'height' ) ) {
338 $height = $this->
scaleSVGUnit( $this->reader->getAttribute(
'height' ), $defaultHeight );
339 $this->metadata[
'originalHeight'] = $this->reader->getAttribute(
'height' );
342 if ( !isset( $width ) && !isset( $height ) ) {
343 $width = $defaultWidth;
344 $height = $width / $aspect;
345 } elseif ( isset( $width ) && !isset( $height ) ) {
346 $height = $width / $aspect;
347 } elseif ( isset( $height ) && !isset( $width ) ) {
348 $width = $height * $aspect;
351 if ( $width > 0 && $height > 0 ) {
352 $this->metadata[
'width'] = intval( round( $width ) );
353 $this->metadata[
'height'] = intval( round( $height ) );
366 static $unitLength = [
379 '/^\s*([-+]?\d*(?:\.\d+|\d+)(?:[Ee][-+]?\d+)?)\s*(em|ex|px|pt|pc|cm|mm|in|%|)\s*$/',
385 if ( $unit ==
'%' ) {
386 return $length * 0.01 * $viewportSize;
388 return $length * $unitLength[$unit];
392 return floatval( $length );
$wgSVGMetadataCutoff
Don't read SVG metadata beyond this point.
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
static scaleSVGUnit( $length, $viewportSize=512)
Return a rounded pixel equivalent for a labeled CSS/SVG length.
handleSVGAttribs()
Parse the attributes of an SVG element.
readXml( $metafield=null)
Read an XML snippet from an element.
animateFilterAndLang( $name)
Filter all children, looking for animated elements.
readField( $name, $metafield=null)
Read a textelement from an element.
__construct( $source)
Creates an SVGReader drawing from the source provided.
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
$data
Utility to generate mapping file used in mw.Title (phpCharToUpper.json)
Allows to change the fields on the form that will be generated $name
returning false will NOT prevent logging $e
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
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))