X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fapi%2FApiFormatXml.php;h=e4dfda0f572c1faf39cb16372dc0d7a3c8be15dd;hb=fb4821adfc3ab95d9c5c0be1162139f99bfebf6c;hp=b4a478c240d9661b0300ae2c6e366e6fad8cb7d7;hpb=04ca989e86ff82b2a2336f91b0c19d72a592ba18;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/api/ApiFormatXml.php b/includes/api/ApiFormatXml.php index b4a478c240..e4dfda0f57 100644 --- a/includes/api/ApiFormatXml.php +++ b/includes/api/ApiFormatXml.php @@ -61,7 +61,7 @@ class ApiFormatXml extends ApiFormatBase { // This allows API output of other XML types like Atom, RSS, RSD. $result->addValue( null, 'xmlns', self::$namespace, ApiResult::NO_SIZE_CHECK ); } - $data = $result->getResultData( null, array( + $data = $result->getResultData( null, [ 'Custom' => function ( &$data, &$metadata ) { if ( isset( $metadata[ApiResult::META_TYPE] ) ) { // We want to use non-BC for BCassoc to force outputting of _idx. @@ -72,9 +72,9 @@ class ApiFormatXml extends ApiFormatBase { } } }, - 'BC' => array( 'nobool', 'no*', 'nosub' ), - 'Types' => array( 'ArmorKVP' => '_name' ), - ) ); + 'BC' => [ 'nobool', 'no*', 'nosub' ], + 'Types' => [ 'ArmorKVP' => '_name' ], + ] ); $this->printText( static::recXmlPrint( $this->mRootElemName, @@ -93,7 +93,7 @@ class ApiFormatXml extends ApiFormatBase { * @param array $attributes Additional attributes * @return string */ - public static function recXmlPrint( $name, $value, $indent, $attributes = array() ) { + public static function recXmlPrint( $name, $value, $indent, $attributes = [] ) { $retval = ''; if ( $indent !== null ) { if ( $name !== null ) { @@ -113,7 +113,7 @@ class ApiFormatXml extends ApiFormatBase { : '*'; $subelementKeys = isset( $value[ApiResult::META_SUBELEMENTS] ) ? $value[ApiResult::META_SUBELEMENTS] - : array(); + : []; if ( isset( $value[ApiResult::META_BC_SUBELEMENTS] ) ) { $subelementKeys = array_merge( $subelementKeys, $value[ApiResult::META_BC_SUBELEMENTS] @@ -121,20 +121,20 @@ class ApiFormatXml extends ApiFormatBase { } $preserveKeys = isset( $value[ApiResult::META_PRESERVE_KEYS] ) ? $value[ApiResult::META_PRESERVE_KEYS] - : array(); + : []; $indexedTagName = isset( $value[ApiResult::META_INDEXED_TAG_NAME] ) ? self::mangleName( $value[ApiResult::META_INDEXED_TAG_NAME], $preserveKeys ) : '_v'; $bcBools = isset( $value[ApiResult::META_BC_BOOLS] ) ? $value[ApiResult::META_BC_BOOLS] - : array(); + : []; $indexSubelements = isset( $value[ApiResult::META_TYPE] ) ? $value[ApiResult::META_TYPE] !== 'array' : false; $content = null; - $subelements = array(); - $indexedSubelements = array(); + $subelements = []; + $indexedSubelements = []; foreach ( $value as $k => $v ) { if ( ApiResult::isMetadataKey( $k ) && !in_array( $k, $preserveKeys, true ) ) { continue; @@ -152,11 +152,11 @@ class ApiFormatXml extends ApiFormatBase { } elseif ( is_array( $v ) || is_object( $v ) ) { $subelements[self::mangleName( $k, $preserveKeys )] = $v; } elseif ( in_array( $k, $subelementKeys, true ) || $name === null ) { - $subelements[self::mangleName( $k, $preserveKeys )] = array( + $subelements[self::mangleName( $k, $preserveKeys )] = [ 'content' => $v, ApiResult::META_CONTENT => 'content', ApiResult::META_TYPE => 'assoc', - ); + ]; } elseif ( is_bool( $oldv ) ) { if ( $oldv ) { $attributes[self::mangleName( $k, $preserveKeys )] = ''; @@ -168,16 +168,16 @@ class ApiFormatXml extends ApiFormatBase { if ( $content !== null ) { if ( $subelements || $indexedSubelements ) { - $subelements[self::mangleName( $contentKey, $preserveKeys )] = array( + $subelements[self::mangleName( $contentKey, $preserveKeys )] = [ 'content' => $content, ApiResult::META_CONTENT => 'content', ApiResult::META_TYPE => 'assoc', - ); + ]; $content = null; } elseif ( is_scalar( $content ) ) { // Add xml:space="preserve" to the element so XML parsers // will leave whitespace in the content alone - $attributes += array( 'xml:space' => 'preserve' ); + $attributes += [ 'xml:space' => 'preserve' ]; } } @@ -206,7 +206,7 @@ class ApiFormatXml extends ApiFormatBase { } foreach ( $indexedSubelements as $k => $v ) { $retval .= static::recXmlPrint( $indexedTagName, $v, $indent, - $indexSubelements ? array( '_idx' => $k ) : array() + $indexSubelements ? [ '_idx' => $k ] : [] ); } if ( $name !== null ) { @@ -232,7 +232,7 @@ class ApiFormatXml extends ApiFormatBase { * @param array $preserveKeys Names to not mangle * @return string Mangled name */ - private static function mangleName( $name, $preserveKeys = array() ) { + private static function mangleName( $name, $preserveKeys = [] ) { static $nsc = null, $nc = null; if ( in_array( $name, $preserveKeys, true ) ) { @@ -266,20 +266,20 @@ class ApiFormatXml extends ApiFormatBase { ); } - function addXslt() { + protected function addXslt() { $nt = Title::newFromText( $this->mXslt ); if ( is_null( $nt ) || !$nt->exists() ) { - $this->setWarning( 'Invalid or non-existent stylesheet specified' ); + $this->addWarning( 'apiwarn-invalidxmlstylesheet' ); return; } if ( $nt->getNamespace() != NS_MEDIAWIKI ) { - $this->setWarning( 'Stylesheet should be in the MediaWiki namespace.' ); + $this->addWarning( 'apiwarn-invalidxmlstylesheetns' ); return; } if ( substr( $nt->getText(), -4 ) !== '.xsl' ) { - $this->setWarning( 'Stylesheet should have .xsl extension.' ); + $this->addWarning( 'apiwarn-invalidxmlstylesheetext' ); return; } @@ -288,14 +288,14 @@ class ApiFormatXml extends ApiFormatBase { } public function getAllowedParams() { - return parent::getAllowedParams() + array( - 'xslt' => array( + return parent::getAllowedParams() + [ + 'xslt' => [ ApiBase::PARAM_HELP_MSG => 'apihelp-xml-param-xslt', - ), - 'includexmlnamespace' => array( + ], + 'includexmlnamespace' => [ ApiBase::PARAM_DFLT => false, ApiBase::PARAM_HELP_MSG => 'apihelp-xml-param-includexmlnamespace', - ), - ); + ], + ]; } }