Harej has uploaded a new change for review. https://gerrit.wikimedia.org/r/316196
Change subject: When a CollaborationListContent page does not meet the schema, instead of throwing an exception it returns the offending JSON. ...................................................................... When a CollaborationListContent page does not meet the schema, instead of throwing an exception it returns the offending JSON. This introduces a new top-level property in the object called "displaymode" which is currently optional but will be required soon. The options are "normal" (the default), "error" (used for outputting the error) and "members" (not currently used but will replace the ismemberlist bool). Bug: T148085 Change-Id: I4f76f8f43405cf81eb84108a848a76e0255a76b7 --- M i18n/en.json M i18n/qqq.json M includes/content/CollaborationListContent.php M includes/content/CollaborationListContentHandler.php M includes/content/CollaborationListContentSchema.php 5 files changed, 36 insertions(+), 9 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/CollaborationKit refs/changes/96/316196/1 diff --git a/i18n/en.json b/i18n/en.json old mode 100644 new mode 100755 index 22e18d9..172cf4e --- a/i18n/en.json +++ b/i18n/en.json @@ -35,6 +35,7 @@ "collaborationkit-createhubfeature-freetext": "Generic wiki page", "collaborationkit-createhubfeature-articlelist": "List of pages", "collaborationkit-list-isempty": "This list has no items in it.", + "collaborationkit-list-invalid": "This content does not meet the requirements of the CollaborationListContent schema. This may happen as a result of a software update. The content is reproduced below.", "collaborationkit-list-notlist": "[[$1]] is not a CollaborationKit list page", "collaborationkit-list-taglist": "'''{{PLURAL:$2|Tagged:|Tags:}}''' $1 ", "collaborationkit-list-toomanytags": "You are not allowed to specify more than {{PLURAL:$1|one tag|$1 tags}}", diff --git a/i18n/qqq.json b/i18n/qqq.json old mode 100644 new mode 100755 index a83df17..09e8229 --- a/i18n/qqq.json +++ b/i18n/qqq.json @@ -35,6 +35,7 @@ "collaborationkit-createhubfeature-invalidcontenttype": "Error message on Special:CreateHubFeature in the unlikely event that an invalid content type is specified for a feature", "collaborationkit-createhubfeature-editsummary": "Edit summary used by Special:CreateHubFeature when creating a new feature", "collaborationkit-list-isempty": "Shown on lists that are empty immediately after the description", + "collaborationkit-list-invalid": "Message shown on lists that do not comply with the JSON Schema before showing the offending content", "collaborationkit-list-notlist": "Error when <nowiki>{{#transcludelist:page}}</nowiki> is given a page that is not a CollaborationKit list page. $1 Name of page given.", "collaborationkit-list-taglist": "Box for showing tags a specific item has on a list. $1 = comma separated list of tags. $2 = number of tags", "collaborationkit-list-toomanytags": "Error if <nowiki>{{#transcludelist:...}}</nowiki> is given more than the allowed number of tag arguments. $1 - number of tags allowed. $2 - number of tags given.", diff --git a/includes/content/CollaborationListContent.php b/includes/content/CollaborationListContent.php old mode 100644 new mode 100755 index b45422b..b2d6b70 --- a/includes/content/CollaborationListContent.php +++ b/includes/content/CollaborationListContent.php @@ -22,6 +22,8 @@ protected $options; /** @var $items Array List of items */ protected $items; + /** @var $displaymode String The variety of list */ + protected $displaymode; function __construct( $text, $type = 'CollaborationListContent' ) { parent::__construct( $text, $type ); @@ -41,6 +43,10 @@ return false; } $data = $status->value; + // TODO: The schema should be checking for required fields but for some reason that doesn't work + if ( !isset( $data->description ) || !isset( $data->items ) || !isset( $data->options ) ) { + return false; + } $jsonAsArray = json_decode( json_encode( $data ), true ); try { EventLogging::schemaValidate( $jsonAsArray, $listSchema ); @@ -109,13 +115,16 @@ if ( $this->decoded ) { return; } - if ( !$this->isValid() ) { - throw new Exception( "Can't decode invalid content" ); - } $data = $this->getData()->value; - $this->description = $data->description; - $this->options = $data->options; - $this->items = $data->items; + if ( !$this->isValid() ) { + $this->displaymode = 'error'; + $this->errortext = FormatJson::encode( $data, true, FormatJson::ALL_OK ); + } else { + $this->displaymode = 'normal'; // For now, while this field is still optional + $this->description = $data->description; + $this->options = $data->options; + $this->items = $data->items; + } $this->decoded = true; } @@ -182,6 +191,14 @@ $maxItems = $options['maxItems']; $includeDesc = $options['includeDesc']; + // If this is an error-type list (i.e. a schema-violating blob), + // just return the plain JSON. + + if ( $this->displaymode == 'error' ) { + $errorWikitext = wfMessage( 'collaborationkit-list-invalid' ) . '<br /><pre>' . $this->errortext . '</pre>'; + return $errorWikitext; + } + // Hack to force style loading even when we don't have a Parser reference. $text = "<collaborationkitloadliststyles/>\n"; diff --git a/includes/content/CollaborationListContentHandler.php b/includes/content/CollaborationListContentHandler.php old mode 100644 new mode 100755 index b0a98b0..674638e --- a/includes/content/CollaborationListContentHandler.php +++ b/includes/content/CollaborationListContentHandler.php @@ -45,9 +45,7 @@ $text = FormatJson::encode( $data ); } $content = new CollaborationListContent( $text ); - if ( !$content->isValid() ) { - throw new MWContentSerializationException( 'The collaborationlist content is invalid.' ); - } + // Deliberately not validating at this step; validation is done later. return $content; } diff --git a/includes/content/CollaborationListContentSchema.php b/includes/content/CollaborationListContentSchema.php old mode 100644 new mode 100755 index 0766013..6dfa7ce --- a/includes/content/CollaborationListContentSchema.php +++ b/includes/content/CollaborationListContentSchema.php @@ -3,6 +3,16 @@ 'type' => 'object', 'required' => [ 'description', 'items', 'options' ], 'properties' => [ + 'displaymode' => [ + 'enum' => [ + 0 => 'normal', + 1 => 'members', + 2 => 'error' + ] + ], + 'errortext' => [ + 'type' => 'string' + ], 'description' => [ 'type' => 'string' ], -- To view, visit https://gerrit.wikimedia.org/r/316196 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I4f76f8f43405cf81eb84108a848a76e0255a76b7 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/CollaborationKit Gerrit-Branch: master Gerrit-Owner: Harej <jamesmh...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits