35 return $svg->getMetadata();
45 const NS_SVG =
'http://www.w3.org/2000/svg';
69 $this->reader =
new XMLReader();
73 if ( $size ===
false ) {
74 throw new MWException(
"Error getting filesize of SVG." );
77 if ( $size > $wgSVGMetadataCutoff ) {
78 $this->
debug(
"SVG is $size bytes, which is bigger than $wgSVGMetadataCutoff. Truncating." );
79 $contents = file_get_contents(
$source,
false, null, -1, $wgSVGMetadataCutoff );
80 if ( $contents ===
false ) {
83 $this->reader->XML( $contents, null, LIBXML_NOERROR | LIBXML_NOWARNING );
85 $this->reader->open(
$source, null, LIBXML_NOERROR | LIBXML_NOWARNING );
96 $oldDisable = libxml_disable_entity_loader(
true );
97 $this->reader->setParserProperty( XMLReader::SUBST_ENTITIES,
true );
99 $this->metadata[
'width'] = self::DEFAULT_WIDTH;
100 $this->metadata[
'height'] = self::DEFAULT_HEIGHT;
105 $this->metadata[
'originalWidth'] =
'100%';
106 $this->metadata[
'originalHeight'] =
'100%';
111 MediaWiki\suppressWarnings();
117 MediaWiki\restoreWarnings();
118 libxml_disable_entity_loader( $oldDisable );
121 MediaWiki\restoreWarnings();
122 libxml_disable_entity_loader( $oldDisable );
138 $keepReading = $this->reader->read();
141 while ( $keepReading && $this->reader->nodeType != XMLReader::ELEMENT ) {
142 $keepReading = $this->reader->read();
145 if ( $this->reader->localName !=
'svg' || $this->reader->namespaceURI != self::NS_SVG ) {
146 throw new MWException(
"Expected <svg> tag, got " .
147 $this->reader->localName .
" in NS " . $this->reader->namespaceURI );
149 $this->
debug(
"<svg> tag is correct." );
152 $exitDepth = $this->reader->depth;
153 $keepReading = $this->reader->read();
154 while ( $keepReading ) {
155 $tag = $this->reader->localName;
156 $type = $this->reader->nodeType;
157 $isSVG = ( $this->reader->namespaceURI == self::NS_SVG );
159 $this->
debug(
"$tag" );
161 if ( $isSVG &&
$tag ==
'svg' &&
$type == XMLReader::END_ELEMENT
162 && $this->reader->depth <= $exitDepth
165 } elseif ( $isSVG &&
$tag ==
'title' ) {
167 } elseif ( $isSVG &&
$tag ==
'desc' ) {
169 } elseif ( $isSVG &&
$tag ==
'metadata' &&
$type == XMLReader::ELEMENT ) {
171 } elseif ( $isSVG &&
$tag ==
'script' ) {
175 $this->metadata[
'animated'] =
true;
176 } elseif (
$tag !==
'#text' ) {
177 $this->
debug(
"Unhandled top-level XML tag $tag" );
184 $keepReading = $this->reader->next();
187 $this->reader->close();
201 $this->
debug(
"Read field $metafield" );
202 if ( !$metafield || $this->reader->nodeType != XMLReader::ELEMENT ) {
205 $keepReading = $this->reader->read();
206 while ( $keepReading ) {
207 if ( $this->reader->localName ==
$name
208 && $this->reader->namespaceURI == self::NS_SVG
209 && $this->reader->nodeType == XMLReader::END_ELEMENT
212 } elseif ( $this->reader->nodeType == XMLReader::TEXT ) {
213 $this->metadata[$metafield] = trim( $this->reader->value );
215 $keepReading = $this->reader->read();
225 private function readXml( $metafield = null ) {
226 $this->
debug(
"Read top level metadata" );
227 if ( !$metafield || $this->reader->nodeType != XMLReader::ELEMENT ) {
231 if ( method_exists( $this->reader,
'readInnerXML' ) ) {
232 $this->metadata[$metafield] = trim( $this->reader->readInnerXml() );
234 throw new MWException(
"The PHP XMLReader extension does not come " .
235 "with readInnerXML() method. Your libxml is probably out of " .
236 "date (need 2.6.20 or later)." );
238 $this->reader->next();
248 $this->
debug(
"animate filter for tag $name" );
249 if ( $this->reader->nodeType != XMLReader::ELEMENT ) {
252 if ( $this->reader->isEmptyElement ) {
255 $exitDepth = $this->reader->depth;
256 $keepReading = $this->reader->read();
257 while ( $keepReading ) {
258 if ( $this->reader->localName ==
$name && $this->reader->depth <= $exitDepth
259 && $this->reader->nodeType == XMLReader::END_ELEMENT
262 } elseif ( $this->reader->namespaceURI == self::NS_SVG
263 && $this->reader->nodeType == XMLReader::ELEMENT
265 $sysLang = $this->reader->getAttribute(
'systemLanguage' );
266 if ( !is_null( $sysLang ) && $sysLang !==
'' ) {
268 $langList = explode(
',', $sysLang );
269 foreach ( $langList
as $langItem ) {
270 $langItem = trim( $langItem );
272 $this->languages[$langItem] = self::LANG_FULL_MATCH;
280 $dash = strpos( $langItem,
'-' );
283 $itemPrefix = substr( $langItem, 0, $dash );
285 $this->languagePrefixes[$itemPrefix] = self::LANG_PREFIX_MATCH;
290 switch ( $this->reader->localName ) {
298 case 'animateMotion':
300 case 'animateTransform':
301 $this->
debug(
"HOUSTON WE HAVE ANIMATION" );
302 $this->metadata[
'animated'] =
true;
306 $keepReading = $this->reader->read();
312 $this->
debug(
"FAILURE: $err" );
313 wfDebug(
"SVGReader XML error: $err\n" );
317 if ( $this->mDebug ) {
318 wfDebug(
"SVGReader: $data\n" );
328 $defaultWidth = self::DEFAULT_WIDTH;
329 $defaultHeight = self::DEFAULT_HEIGHT;
334 if ( $this->reader->getAttribute(
'viewBox' ) ) {
336 $viewBox = preg_split(
'/\s+/', trim( $this->reader->getAttribute(
'viewBox' ) ) );
337 if ( count( $viewBox ) == 4 ) {
340 if ( $viewWidth > 0 && $viewHeight > 0 ) {
341 $aspect = $viewWidth / $viewHeight;
342 $defaultHeight = $defaultWidth / $aspect;
346 if ( $this->reader->getAttribute(
'width' ) ) {
347 $width = $this->
scaleSVGUnit( $this->reader->getAttribute(
'width' ), $defaultWidth );
348 $this->metadata[
'originalWidth'] = $this->reader->getAttribute(
'width' );
350 if ( $this->reader->getAttribute(
'height' ) ) {
351 $height = $this->
scaleSVGUnit( $this->reader->getAttribute(
'height' ), $defaultHeight );
352 $this->metadata[
'originalHeight'] = $this->reader->getAttribute(
'height' );
355 if ( !isset( $width ) && !isset( $height ) ) {
356 $width = $defaultWidth;
357 $height = $width / $aspect;
358 } elseif ( isset( $width ) && !isset( $height ) ) {
359 $height = $width / $aspect;
360 } elseif ( isset( $height ) && !isset( $width ) ) {
361 $width = $height * $aspect;
364 if ( $width > 0 && $height > 0 ) {
365 $this->metadata[
'width'] = intval( round( $width ) );
366 $this->metadata[
'height'] = intval( round( $height ) );
379 static $unitLength = [
391 if ( preg_match(
'/^\s*(\d+(?:\.\d+)?)(em|ex|px|pt|pc|cm|mm|in|%|)\s*$/', $length,
$matches ) ) {
394 if ( $unit ==
'%' ) {
395 return $length * 0.01 * $viewportSize;
397 return $length * $unitLength[$unit];
401 return floatval( $length );
readXml($metafield=null)
Read an XML snippet from an element.
$wgSVGMetadataCutoff
Don't read SVG metadata beyond this point.
animateFilterAndLang($name)
Filter all children, looking for animated elements.
static isWellFormedLanguageTag($code, $lenient=false)
Returns true if a language code string is a well-formed language tag according to RFC 5646...
div flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException'returning false will NOT prevent logging $e
handleSVGAttribs()
Parse the attributes of an SVG element.
when a variable name is used in a it is silently declared as a new local masking the global
readField($name, $metafield=null)
Read a textelement from an element.
wfDebug($text, $dest= 'all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books $tag
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
__construct($source)
Constructor.
static scaleSVGUnit($length, $viewportSize=512)
Return a rounded pixel equivalent for a labeled CSS/SVG length.
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
do that in ParserLimitReportFormat instead use this to modify the parameters of the image and a DIV can begin in one section and end in another Make sure your code can handle that case gracefully See the EditSectionClearerLink extension for an example zero but section is usually empty its values are the globals values before the output is cached one of or reset my talk my contributions etc etc otherwise the built in rate limiting checks are if enabled allows for interception of redirect as a string mapping parameter names to values & $type
Allows to change the fields on the form that will be generated $name