Commit graph

19 commits

Author SHA1 Message Date
James D. Forrester 5293a6d3da Add 'suggested' status type for parameters
This is a status for parameters which are not 'required' but are recommended
to be high value, if not always used, by downstream template users. This
commit does not add GUI-related changes to address this, as the interface
probably needs moving from checkbox- to dropdown-based status setting given
that there are now four, rather than three, mutually-exclusive statuses.

Change-Id: I104976e76d5ad6d586d9c818418ba6e16af53506
2014-04-28 11:45:44 -07:00
Timo Tijhof eb236e81de Fix tests to pass after 58a161f in mediawiki/core
Status::getHtml now wraps the html in <p> tags, unwrapping
them for now, classic parseinline style..

Change-Id: Ic9b651cbd76752346ea7cbf230af49f09ef3ec12
2013-12-10 22:13:10 +01:00
Siebrand Mazeland c705e026bd Update ternary notation
Change-Id: I04f8a1158b6135e5387244c104ace3518416bd54
2013-12-04 09:47:08 +01:00
Timo Tijhof 6cdb47d097 Drop type prefixes because all values are strings in HTML (and wikitext)
Change-Id: I8655393320064dd8d6f8f06abff6d5abc0baa795
2013-11-07 19:39:24 +00:00
Timo Tijhof 50bbd93e6a Fix roundtrip issues (normalised output for API must be valid input)
For example, in case of failure we were defaulting to an empty
object, even though that is invalid input.

Change-Id: I00b4ce26b04ec408b5e86b9a2242cf942300ad41
2013-11-07 19:39:20 +00:00
Timo Tijhof a800a46c7f Add Root#paramOrder to spec and implemention thereof
* Detail the new property in the spec.
* The property is optional (as all new properties have to be
  for backwards compatibility).
* Validate value if present, and for normalisation fill it
  with inferred order from the JSON parser. This means the API
  output will always contain #paramOrder, however the strict
  specification for it is optional and users must still account
  for absence of this property.

Bug: 53608
Change-Id: I7bcd7c9146f5ae75c4bad22b0a9cd4400f196c8c
2013-11-07 20:34:45 +01:00
Timo Tijhof 46509ebd2a Require Set#params to be non-empty and improve error
* An empty array for a Set is invalid and the implementation now
  enforces this.
* Add new error message for invalid value. When Sets contain a
  reference to a key that doesn't exist, it should say that that
  reference in the Set is invalid instead of saying that Params
  is invalid for not having it.
  > { params: {}, sets: [ { params: [ "quux" ] } ] }
  - Required property "params.quux" not found.
  + Invalid value for property "sets.0.params[1]".

Also:
* Abstracted handling of $case and the different assertions
  on it in a helper function so that we don't have to repeat
  it everywhere.
* Use the same hack as in other tests to display the status error
  message in the phpunit output (true === isGood ?: getHtml).
  Maybe use '' === getHtml instead, though that is also evil
  since Status fatals if you call getMessage/getHtml for a good
  Status object.

Change-Id: I06a6615f728cd287a4839e09eedc2d0eeb537949
2013-10-30 00:10:38 +00:00
Timo Tijhof 4615338a51 Implement getInterfaceTextInLanguage and use API and Parser
Fallback for user language and content language is easiest to
resolve server-side. Also saves sending a lot of data to the
client that it doesn't need. Similar to how ResourceLoader only
sends 1 set of message values.

Bug: 50431
Bug: 52922
Change-Id: If8317ed6522a05d5a48a210ff43c97277b950a97
2013-10-07 19:26:59 +02:00
MatmaRex 7bf85a39a1 Remove all references to TemplateInfo
Change-Id: I5ffc8f75140a2c372fc1c64509b13a534fe07479
2013-09-12 11:41:07 +02:00
Antoine Musso 8dc157bc09 Test gzdecode() in TemplateDataBlob::newFromDatabase()
gzdecode() has been introduced in PHP 5.4 although gzencode() has been
there for a while.  Wikimedia is still using PHP 5.3, so the
TemplateDataBlob::newFromDatabase() would trigger a fatal error whenever
it is passed compressed JSON :-(

The test does not fix the root cause (that needs a fallback function in
the TemplateData extension), but it does highlight the issue in PHP 5.3.x.

Updated a @return comment, correcting the class being returned.

bug: 54058
Change-Id: I8357b474165f4317982b9c924cf0afe68650d677
2013-09-12 04:14:40 +00:00
MatmaRex d66b4c6090 Store compressed JSON since size is limited
We only have 65535 bytes, let's use them wisely.

Prior to Ib2db241a in core (1.22wmf12) even binary page properties
were sometimes shown as plaintext (e.g. on Special:PagesWithProp).
Thus this introduces a "soft dependency" on that change.

No backwards-incompatible changes were made in public methods.
Added two new ones:

* Add TemplateDataBlob#getJSONForDatabase which returns compressed
  JSON, use it where applicable.
* Add TemplateDataBlob::newFromDatabase which accept compressed and
  uncompressed JSON, use it where applicable.

Use a long pseudorandom string in the test.

Bug: 51740
Change-Id: Ie66b0dd6b6dab6f8648e78595c41e52d9c704d57
2013-09-04 22:52:02 +00:00
MatmaRex 6281fe626f Bail when JSON length exceeds database limits
This might not be necessary on non-MySQL databases, but I'm sure that
at least their limits aren't lower than MySQL's, so let's stay on the
safe side.

Bug: 51740
Change-Id: I9c7115a951f126844bc70755bff12e8cd5fc2be1
2013-08-01 23:39:47 +02:00
Timo Tijhof 70ab71d6a3 phpcs: Resolve style violations
Change-Id: Ie5d4d84b8d7b6bc88e7a5a1559579e504dd1bd20
2013-05-16 15:31:25 +00:00
Timo Tijhof 708bbad12d Implement Sets
Change-Id: I93a0ba7287fec6e5566994d03dff1d8eaeeb8430
2013-05-16 01:35:31 +02:00
Timo Tijhof 1a38b42241 tests: Reformat tests, evaluate status in addition to I/O
Previously we only compared output, we now evaluate
status as well.

For example test {} => {} was misleading since the reason
it roundtripped was because it is *invalid* and we replace
invalid blobs with an empty object in blob storage.

But in the API this'll never get used because getStatus
will have a fatal error in it. Which overrides the data.
The tests were previously looking in the data whilst ignoring
the return status.

Change-Id: I9809f126c1615c9bc9c28ce2d8bb7953058cbf6e
2013-05-16 01:25:09 +02:00
Timo Tijhof 5e50116d6d TemplateDataBlob: Implement 'type' and 'label'
InterfaceText now defaults to null instead of {en:""} which
was awkward to deal with in the frontend.

As specified:
- label is InterfaceText
- type is a string and must be a one of the recognized types

Updated example for the hypothetical variant of Template:Unsigned
and removed other no longer needed example.

HTML output has been revised per conversation with Trevor,
James and Timo:
- Not sortable.
- Add label to html output.
- Aliases in the main parameter column (one per line),
  but muted in styling.
- Add type to html output.

The css module styles content from the server, not content
generated by javascript. Moved module to position => top to
fix flash of unstyled content.

Change-Id: I16d3f9e460c5513935b9b55fe4cec0092b38e6c2
2013-05-09 02:49:56 +00:00
Timo Tijhof 61ab90278a TemplateDataBlob: Convert 'clones' to 'inherits'
Before

{
  a: {
    ...,
    clones: ['a2', 'a3']
  },
  a2: {
    some: 'thing'
  },
  a3: {
    other: 'thing'
  }
}

After

{
  a: {
    ...
  },
  a2: {
    inherits: 'a',
    some: 'thing'
  },
  a3: {
    inherits: 'a',
    other: 'thing'
  }
}

Change-Id: Ib17d9e299d503c35e3ee817d3cc4ecb56186b84c
2013-05-01 00:32:08 +02:00
Timo Tijhof 942c88f749 API: Update/Normalise before outputting
I ran into countless random exceptions and errors locally due to
cache I built up over time that was no longer valid. Though in
approved commits in the repository there is only 1 version as of
now, I'm sure we will make changes in the future that require a
cache invalidation since getHtml needs to be able to make
assumptions about what properties exist.

Also fixed a bug in the parse() method where the 'deprecated'
property is asserted the wrong way around. Added a test for it.

Change-Id: I5f61d6030578a711909435c8b996373e9aaa5178
2013-04-23 23:52:37 +00:00
Timo Tijhof ffd8899def Add unit tests and fix implemention accordingly
* Add unit tests for all types of invalid input we check for.
* Add unit tests for all types of input we expand or otherwise
  normalise.

* Implement InterfaceText expansion/normalisation.
* Fix bug that caused a string value in the root description property
  to be considered invalid (it only accepted an object, it should
  accept both).

Change-Id: I5a15080f1f924451a9dde8af96ea2922011981ec
2013-04-22 07:42:49 +00:00