Ori.livneh has uploaded a new change for review. https://gerrit.wikimedia.org/r/68941
Change subject: Support inter-page JSON references ...................................................................... Support inter-page JSON references Doesn't quite adhere to the JSON Reference draft spec. WIP. Change-Id: I2b5aae432d8f8259d0bc170f69f363faa5dc27b1 --- M includes/JsonSchemaContent.php 1 file changed, 37 insertions(+), 0 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/EventLogging refs/changes/41/68941/1 diff --git a/includes/JsonSchemaContent.php b/includes/JsonSchemaContent.php index 1ba47d5..7c12f1b 100644 --- a/includes/JsonSchemaContent.php +++ b/includes/JsonSchemaContent.php @@ -15,8 +15,39 @@ */ class JsonSchemaContent extends TextContent { + const DEFAULT_RECURSION_LIMIT = 3; + function __construct( $text ) { parent::__construct( $text, 'JsonSchema' ); + } + + /** + * Resolve a JSON reference to a schema. + * @param string $ref Schema reference with format 'Title/Revision'. + */ + static function resolve( $ref ) { + list( $title, $revId ) = explode( '/', $ref ); + $rs = new RemoteSchema( $title, $revId ); + return $rs->get(); + } + + /** + * Recursively resolve references in a schema. + * @param array $schema Schema object to expand. + * @param int $recursionLimit Maximum recursion limit. + * @return array: Expanded schema object. + */ + static function expand( $schema, $recursionLimit = JsonSchemaContent::DEFAULT_RECURSION_LIMIT ) { + return array_map( function ( $value ) { + if ( is_array( $value ) && $recursionLimit > 0 ) { + if ( isset( $value['$ref'] ) ) { + $value = JsonSchemaContent::resolve( $value['$ref'] ); + } + return JsonSchemaContent::expand( $value, $recursionLimit - 1 ); + } else { + return $value; + } + }, $schema ); } /** @@ -87,6 +118,12 @@ $th = Xml::elementClean( 'th', array(), $key ); if ( is_array( $val ) ) { $td = Xml::tags( 'td', array(), self::objectTable( $val ) ); + } elseif ( $key === '$ref' ) { + list( , $revId ) = explode( '/', $val ); + $title = Revision::newFromId( $revId )->getTitle(); + $link = Linker::link( $title, htmlspecialchars( $val ), array(), + array( 'oldid' => $revId ) ); + $td = Xml::tags( 'td', array( 'class' => 'value' ), $link ); } else { if ( is_string( $val ) ) { $val = '"' . $val . '"'; -- To view, visit https://gerrit.wikimedia.org/r/68941 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I2b5aae432d8f8259d0bc170f69f363faa5dc27b1 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/EventLogging Gerrit-Branch: master Gerrit-Owner: Ori.livneh <o...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits