Commit graph

63 commits

Author SHA1 Message Date
C. Scott Ananian 5812413f11 Extend 'format' spec to include custom format strings.
Thanks to Thiemo Mättig for the suggestion and specification at
Wikimania 2016 in Esino Lario.

This is an extended version of Thiemo's original specification.  This
version also allows specification of "own line" properties for
templates; that is, whether the template should be preceded/followed
by a newline, as requested by James Forrester.

Bug: T138492
Bug: T135667
Change-Id: Idc6b2680330e6bf5caec2bf6fc86a705d25bc649
2016-09-01 14:14:47 -07:00
Kunal Mehta 7280f40cc6 build: Updating mediawiki/mediawiki-codesniffer to 0.7.1
Also added "composer fix" command.

Change-Id: I7d2e62235f08ecb03f92e5eafccd84b79434c9d1
2016-05-09 17:00:14 -07:00
Alex Monk 84b1ddf44c Localise names of types in HTML rendering
Reuses some messages, renaming them in the process.
Changes undefined on the client to unknown.

Bug: T61745
Change-Id: I2cf5c25acbe1c854c33b2eb3f23dc74393a456d4
2016-04-06 19:00:58 +00:00
Bartosz Dziewoński 8e55adab59 [BREAKING CHANGE] Change default format to null instead of 'inline'
Don't enforce 'inline' as the default format if none is specified.
Instead preserve the unspecified value as 'null'. This allows
third-party tools to provide a better default experience when changing
existing content (e.g. by using smart detection to follow the format
already used).

Bug: T128337
Change-Id: I911c7999e3731c0125fc058118f8d7287d8f88f4
2016-03-01 22:53:27 +00:00
Alex Monk 3d4e71956c Make 'required' bold in the TD documentation block
Bug: T104674
Change-Id: Ie3bb75a3e1df9096f911615ecf362fe16625d8ed
2016-02-21 01:59:03 +00:00
cenarium ab4ede9015 TemplateDataBlob: Avoid encoding and compressing json twice
The json and compressed json are saved in-class to avoid
reencoding and compressing twice (this is called both in
parse and to set the 'templatedata' property). In case
of status failure, they are set to null since the data
is reinitialized.

Change-Id: I3976e48b9c2cc914960271485e7c8c59ba36aa57
2016-02-04 00:00:29 +01:00
Alex Monk 11f874975e Update filename of specification in TemplateDataBlob::parse comment
Change-Id: Ibddd3834ea870eb6e817458dd495b5dea762e60a
2016-01-12 19:44:17 +00:00
Brian Wolff 8f781417a9 Use ucfirst from lang object, not php's ucfirst.
Change-Id: I302cc7dc32331bf313b6211056c5a246b7961a39
2015-11-15 21:38:18 -05:00
Ed Sanders c069153411 Display format icon and message inside parameters table caption
Change-Id: Id9d6620ed766645384d31c63aacd7c8167c1ce19
2015-11-13 12:35:07 -08:00
eranroz 01821eae64 Introduce new 'format' template property
Adding format data, which defines the preferred source format
to use when using templates.

Possible formats:
* Inline - all parameters in a single line
* Block - each parameter is in its own line

Bug: T64147
Change-Id: Id856c4a38890526060d0619432f06174d66f7792
2015-11-11 23:52:17 +00:00
James D. Forrester 017fa53e65 Add a url type for URLs
Bug: T54880
Change-Id: I722fcbc957825c2aaea32d9350480d29a388bb68
2015-09-30 22:15:19 +00:00
James D. Forrester 62d3138216 Add a wiki-template-name type for template names
Bug: T88900
Change-Id: Ia1c87072f453df4b756de6725c4b3ab1dda84497
2015-09-17 12:28:11 -07:00
Timo Tijhof 402d95ff6b HtmlView: Move "default", "example", and "autovalue" under description
The table is getting too wide. The sortability isn't that useful
for these columns either.

Change-Id: I080b427f524d0146c9ef5d2e067e83463511fd06
2015-04-28 17:05:00 +01:00
Timo Tijhof 65b101e60c Add example property to HTML rendering
Follows-up ec0467c65a.

Bug: T53049
Change-Id: I07dd73b7e2ba0994f29e1b9e619c5cbf347d4d9d
2015-04-28 16:48:13 +01:00
Moriel Schottlender ec0467c65a Add an example property to parameters
The example is optional and can be translated.

Bug: T53049
Change-Id: I9e2d66a805e25409532a742521886233ce3de569
2015-04-09 19:23:42 +01:00
Moriel Schottlender ff77f32e38 [BREAKING CHANGE] Change "default" property to InterfaceText
Default should be InterfaceText and support languages.

Bug: T54966
Change-Id: I7be3a8be72df3e5d80300bd72fcd7197e43155aa
2015-04-02 08:53:51 +01:00
Moriel Schottlender aed0e38edf Make elseif into else because it is
Following up on I2bc79421be330, the condition was always true in
case the first one wasn't. This is just a beautification fixup.

Change-Id: I7463207f02de2116b96173d88199d46ce70ca174
2015-03-03 18:30:32 -08:00
Moriel Schottlender 7b741d3af4 Add paramOrder by default to TemplateData blobs
Make sure that paramOrder is initialized as an array even if the
params property of the TemplateData object is empty.

Bug: T91470
Change-Id: I2bc79421be33053e7e21170528fbbd1c01eaf4bb
2015-03-03 18:08:13 -08:00
Moriel Schottlender 4757a83f88 Display a message when no parameters are defined
If no parameters are defined in the TemplateData, have the table
display a specific message noting that.

Bug: T53429
Change-Id: I3c9ae31ef9eafab7f94325fcd58e14a3e45c9818
2015-02-18 17:43:16 -08:00
Moriel Schottlender ba0349866f Display TemplateData parameter table according to param order
Have the parameter order in the display table appear according to
the paramOrder setting. If the setting isn't explicitly set in the
TemplateData string, the parameters will be in order of appearance.

Change-Id: Ibbd5a7b28f722c51788b9ed0f5ac577902ce4b7a
2015-02-18 16:53:59 -08:00
Ricordisamoa 9639d78e4f Show "no description" in italic grey also for deprecated parameters
Timo Tijhof's initial commit b7080c5f90
inexplicably caused the "mw-templatedata-doc-muted" class to be added
to the description field only when $paramObj->deprecated was false.

Bug: T69794
Change-Id: Iad86f5dbc48046faa09f39c339fce95db3331208
2015-01-16 23:58:05 +01:00
Ori Livneh 74b46c14d8 MWException -> Exception
Change-Id: I9ed1d8c331787718ed85ef61fdda4714247fc72b
2015-01-09 19:05:53 -08:00
jenkins-bot 9322c4262d Merge "Implement new "maps" property in Root" 2014-11-19 03:48:41 +00:00
glaisher fae0586c00 Add "sortable" class to display table
This will make the display table sortable; table which appears when
<templatedata> tag is used on a page.

Bug: 50435
Change-Id: If72a44eab3229139791ea2d06ef6a74e2ce2e0c9
2014-11-15 22:21:30 +05:00
Marielle Volz d6cac31082 Implement new "maps" property in Root
Add "maps" as an allowed root value to template data JSON.

Maps allow applications to map equivalencies between their
application-specific parameters and valid template parameters.

Each Map has arbitrary keys (from the consuming application) that
are mapped to one or more template parameters.

* Added root.maps to TemplateDataBlob
  * Validates that values are strings or arrays
  * Validates that values are valid params
* Added templatedata-invalid-param to i18n/en.json
  * Richer error message for when invalid value is a param
* Fixed existing tests to work with new "maps" property
* Added two new tests for maps
  * Test for invalid value (!string or !array)
  * Test for invalid parameter
* Added specification for root.maps property and Map object

Change-Id: I3bf5e002ad6c1632e02c4c2e393b244c51f77177
2014-11-08 20:29:51 +00:00
Moriel Schottlender 4f3e647758 Implement new 'autovalue' parameter property
Add an 'autovalue' parameter property to the TemplateData spec. And
implement it in the validation for the API and in the editor.

Also added tests to make sure all parameter attributes preserve
their values before and after parsing, including the 'autovalue'
parameter.

Bug: 51428
Change-Id: Iffb376a804d39388d2b5b6ea3583ef2a292eea41
2014-09-19 16:36:29 -07:00
Max Semenik 4551fd29f7 HHVM compatibility: objects don't have array-like interface
Bug: 66937
Change-Id: I6da1eb76afc26ebf724c089d7137c4e5106fbe7c
2014-07-18 00:30:19 +00:00
James D. Forrester d333467ec2 Use <code> rather than <tt> elements for HTML5-ification
Apparently some Blackbery devices just silently chomp content inside HTML4-style
elements, so let's use the HTML5 version (which is meant to be preferred anyway).

Bug: 67084
Change-Id: I7e07fc2193b290a0e5c3912a678f53045ff1de32
2014-06-25 16:08:10 +00:00
James D. Forrester 3f05967d94 Add 'date' type support for ISO 8601 date-times
Change-Id: Ida5b09fb763bef12f92cf687b5170b5f5b5840a2
2014-05-23 18:50:00 -07:00
James D. Forrester 759f0eef20 Add 'boolean' type support
Bug: 55331
Change-Id: I2508e3cc6e04f1eb382e6ec18c636bebdfccbf99
2014-05-20 20:40:05 +02:00
Trevor Parscal 96f73a6ec1 Convert $status into a Message object before calling methods on it
Change-Id: I0f6b7715c4713b425467d8a3e72b6fd9f87a9c74
2014-04-29 16:33:49 -07:00
James D. Forrester fb34a07c02 Add a wiki-file-name type for file names
Bug: 52652
Change-Id: Ibe8d143abbb607eb71549536aaac6555528813cc
2014-04-28 13:21:53 -07:00
jenkins-bot 4f7fa2f424 Merge "Add 'suggested' status type for parameters" 2014-04-28 18:56:16 +00:00
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
Trevor Parscal 404b0dd579 Obey specified behaviour and allow Param#deprecated to be boolean true
Specified as {boolean|InterfaceText}, which means both false and true
must be valid values.

Bug: 53412
Change-Id: I0272c7acc85caed0b73a427e86f851792964214f
2014-04-25 23:42:57 +00:00
Timo Tijhof 0a03f37581 Specify "content" and "unbalanced-wikitext" as a valid parameter types
Bug: 51374
Change-Id: I711998193cc542b72213b56046529b53ebb17d73
2013-11-07 19:39:29 +00: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 ddd6b2761e Localize default "empty" value and status (deprecated, optional, required)
* Fixed 'should be not be'  in other 'qqq' messages.
* Fixed absence of ->text() in other wfMessage uses
  (defaulted to parse, which was wrong as these are Html::element
  uses that take text input, so it was being double escaped).

Bug: 50370
Change-Id: Iba1a10f14e258a588435cd03017177acfb96d0f3
2013-10-07 18:54:56 +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
Timo Tijhof f8eb557a64 Account for absence of template description in #getHtml
The description property is optional and is explicitly set to
null by the parser in normalisation if there is none.

The HTML rendering of parameter descriptions (as oppposed to the
description of the template as a whole) already covered for this.
Used the same logic for the template parameter.

Also fixed:
* Localize the text "no description"
* Use !== null instead of isset() since the property is always
  set, we just need to know whether it is null or an object.

Bug: 54422
Change-Id: I86a40dbd1225feb54123e77a856b4ad6d525461b
2013-09-25 20:23:46 +00: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
Timo Tijhof 1f5705aa23 Fix phpcs errors
Configuration for phpcs was changed to now require spacing
of ternary to be at the end of the previous line.

Change-Id: I8a358053a9ccf4ec83bfd8db1383fce12d9d9f2f
2013-09-04 15:49:27 -07:00
jenkins-bot 18663c27eb Merge "Use ParserOptions language instead of RequestContext language" 2013-08-02 19:33:21 +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 088d67b61f Use ParserOptions language instead of RequestContext language
The context user language is correctly set to that of the user
who is saving the page.

Parser options are set to the default language during saving and
only changed to the user language when viewing the page with
a uselang that is not the default wiki language.

As a result we were saving the user language (e.g. French) on
en.wikipedia.org as the canonical version on-save and only changing
it to the correct language for non-English viewers.

To test:
* Wiki set to 'en', user preference language to 'nl'
* Save a page with templatedata
* View it logged-out without a uselang query

Was 'nl', is now 'en'.

Bug: 52419
Change-Id: Ic8b5b63450c9f80b85a95d16cc81ce62fc96b77f
2013-08-01 23:18:00 +02:00