Commit graph

21 commits

Author SHA1 Message Date
daniel
f5623b6082 content: Document use cases for JsonContent
This also marks JsonContentHandler as stable to extend, which
was missing from the parent patch.

Bug: T275976
Change-Id: Ied8c2930017bc9ec28e522a774da1050b2b1ffde
2022-02-08 22:39:45 +00:00
Martin Urbanec
231073cd80 content: Mark JsonContent as stable to extend
Bug: T275976
Change-Id: Ib567e3cddbed93e41ca2636b39e28b352066af14
2022-02-06 05:59:58 +00:00
Roman Stolar
a68e641f9d Move Content::getParserOutput & AbstractContent::fillParserOutput to ContentHandler
Update/Create override classes of ContentHandler.
Soft-deprecate and remove method from Content and classes that override them.

Bug: T287158
Change-Id: Idfcfbfe1a196cd69a04ca357281d08bb3d097ce2
2021-09-29 13:10:51 +03:00
Petr Pchelko
b782a7e66d Move Content::preSaveTransform to ContentHandler
Create ContentTransformer to access ContentHandler::preSaveTransform through the service.
Prepare object to hold a data that required for ContentHandler::preSaveTranform params.

This will require making a semi-backwards-incompatible
change no matter what, we don't really have a great way
of hard-deprecating overriding methods.

However, with the ContentHandler calling Content and
Content calling ContentHandler, and with the ProxyContent
trick to stop infinite recursion, it doesn't matter whether
callers use Content or ContentHandler. This will allow us
to naturally convert all callers. But won't really allow
hard-deprecation.

Bug: T287156
Change-Id: If6a2025868ceca3a3b6f11baec39695e47292e40
2021-07-29 18:06:02 +03:00
Lucas Werkmeister
6e074668bc JsonContent: align object key cells at the top
The default middle vertical align can make it hard to find the object
key for long tables (where the value is itself a long object or array).
Move it to the top, and add position: sticky to make it stay on screen
as the top of the table is scrolled out of view. (position: sticky is
not supported in Internet Explorer, but in that case this should
gracefully degrade to keeping the object key at the top, which is no
worse than the previous behavior, where the object key might be out of
view in all browsers.)

The extra <span> is necessary because putting position: sticky on the
table cell itself doesn’t work.

Change-Id: Ib38710e5cc2b75971a26eabf7f144378790d3661
2020-01-13 12:50:07 +01:00
Ed Sanders
3535a5f327 JsonContent: Add missing prefix to selector
Change-Id: I977f6c565b93949a310d1207411f893cf83af996
2019-04-15 02:49:47 +00:00
James D. Forrester
631d2df664 Drop JsonContent->getJsonData(), deprecated in 1.25 and unused
Change-Id: I2cac3a1d2cda799c302ca2364fb91916c3240c11
2019-02-09 07:50:28 +00:00
daniel
54c70c3551 Deprecate Content::getNativeData, add TextContent::getText
getNativeData() is under-specified - callers can do nothing with the
value returned by getNativeData without knowing the concrete Content
class. And if they know the concrete class, they can and should use
a specialized getter instead, anyway.

Basically, getNativeData is overly generic, an example of polymorphism
done poorly. Let's fix it now.

Bug: T155582
Change-Id: Id2c61dcd38ab30416a25746e3680edb8791ae8e8
2019-01-16 11:57:50 -08:00
Thiemo Mättig
ef470ebf7f Remove @param comments that literally repeat what the code says
These comments do not add anything. I argue they are worse than having
no comments, because I have to read them first to understand they
actually don't explain anything. Removing them makes room for actual
improvements in the future (if needed).

Change-Id: Iee70aad681b3385e9af282d5581c10addbb91ac4
2018-01-10 14:14:26 +01:00
Umherirrender
5544cef16b Add missing type to @param documentation
Change-Id: I6b2c9c7af9a281fe457099cc3a336a60a25e74aa
2017-08-11 20:37:35 +02:00
Umherirrender
a9007e8baf Add missing & to @param documentation to match functon call
Change-Id: I81e68310abcbc59964b22e0e74842d509f6b1fb9
2017-08-11 18:47:46 +02:00
Kunal Mehta
85034abca5 content: Refactor normalization of line endings code
The code that normalizes line endings ("\r\n" and "\r" to "\n") and
trims trailing whitespace is buried in Parser::preSaveTransform(), and
was duplicated to TextContent in 96b6afb31d, as non-wikitext content
models should still be normalizing line endings.

This splits the duplicated code into
TextContent::normalizeLineEndings(), and utilize it in the Parser.
Additionally, expand the documentation of
TextContent::preSaveTransform() to document that subclasses should make
sure they normalize line endings during the PST stage.

And remove a useless rtrim() call from WikitextContent that did nothing.

Change-Id: I9094c671d4bbd23d75436f8f1d682d6dd6e6d2fc
2016-08-23 11:09:59 -07:00
Siebrand Mazeland
5b119a0e44 Replace uses of join() by implode()
All of core uses implode() consistently now.

Change-Id: Iba50898c64c43f356d1caf8869f484e90d9ff651
2016-03-08 18:24:16 +00:00
Kunal Mehta
3167a7162c JsonContent: Call member functions with '$this->', not 'self::'
Change-Id: I7dab69ff77c98439f90e7d79f31d0e9128728683
2016-02-22 11:48:35 -08:00
Kunal Mehta
6e9b4f0e9c Convert all array() syntax to []
Per wikitech-l consensus:
 https://lists.wikimedia.org/pipermail/wikitech-l/2016-February/084821.html

Notes:
* Disabled CallTimePassByReference due to false positives (T127163)

Change-Id: I2c8ce713ce6600a0bb7bf67537c87044c7a45c4b
2016-02-17 01:33:00 -08:00
Bartosz Dziewoński
d7389bd865 JsonContent: Pass FormatJson::UTF8_OK when beautifying JSON
Currently it is not beautiful at all.

Change-Id: I82a07238b4213212b8e4a7150e35486f6dc90bc6
2015-03-16 21:53:33 +01:00
Timo Tijhof
7c340aed29 JsonContent: Support non-object values as root structure
* Remove is_object restriction from isValid.
* Implement rootValueTable to support rendering of other
  root structures.

Also:
* Minor method documentation tweaks.
* Document why quotes are not escaped for strings in value cells.

Bug: T86270
Change-Id: Ic1d10393912fcefa22d675fd4aa2baf437d2a05a
2015-01-16 20:57:07 +00:00
wctaiwan
a90b4c5809 Let subclasses specify content model in JsonContent
This is needed for extensions that subclass JsonContent.

Follows up Ifed379ba4674a8289b55
Change-Id: I2f4f9cb343c2ab3ee802b584d3c79d0fafadf9e7
2015-01-10 00:11:37 -05:00
Timo Tijhof
e4f84af980 content: Refactor and fix various bugs in JsonContent
Follows-up d2a82fcb60. These issues weren't previously exposed
as nothing uses JsonContent by default in core, and the extensions
using it (e.g. EventLogging) lock it down very early. As are
most of these methods were never really put to use (they were
called after the extension does its superset of checking, or
too early and WikiPage ignores it).

Bug fixes

* Empty JSON object was converted to an array by PST conversion.
  The beautifyJSON method is intended for prettify purposes but
  actually modified the content stored in the database and made
  it no longer roundtrip ({} != []).

  We can't change getJsonData to return an object since it's
  a public method and people use it as an array. So we can't cast
  it to a PHP object as that would break back-compat.

  Turns out the class doesn't even support non-objects anyway (a
  primitive in JSON can trivially cause a fatal as it wasn't
  consistently considered invalid, though it didn't actually fatal
  due to some lucky spaghetti code in WikiPage).

* Fix beautifyJSON by checking for empty objects to prevent
  implicit {} to [] conversion.

* Add isValid() check to fillParserOutput() as it's called early
  on. Otherwise it throws a warning that 'foreach' (in objectTable)
  iterates over null. In practice it doesn't matter since the
  entire parser output is rejected when WikiPage eventually
  checks isValid (through Content::prepareSave).

* Consider all non- (PHP) array values invalid instead of just
  non-null values.

Enhancements

* Display message "Empty object" instead of a completely blank page
  for an empty object.

* Display message "Empty object" or "Empty array" instead of an
  empty table cell.

* Render arrays as a list of values (without indices).

* Remove italics from table cells for values. The monospace font
  should be enough. It also offsets it from the "Empty"
  placeholders (which are italicised).

Refactoring and clean up

* Use FormatJson::parse so that we can use Status to distinguish
  between null parse result and thus reliably cache it.

  Ideally we wouldn't need to cache it, but right now this code
  is pulled apart and called in so many strange ways that we end
  up calling this several times.

* Improve fairly meaningless test (testBeautifyJson) that was
  calling FormatJson in its data provider, exactly what the method
  being tested did. It also provided the test with data that could
  never end up in normal usage (a PHP-style associated array with
  implied numerical indices).

* Document that this class rejects non-array values.

* Document the problem with WikiPage assumming PST can run on any
  content. WikiPage fundamentally still assumes wikitext, in that
  there's no concept of invalid content.

* Fix incorrect documentation for getJsonData's return value
  (It may return null.)

* Fix incorrect documentation for beautifyJSON's return value.
  (It never returned boolean.)

Bug: T76553
Change-Id: Ifed379ba4674a8289b554a95953951886bf2cbfd
2014-12-17 23:04:24 +00:00
Ori Livneh
f109074bfe Simplify JsonContent::beautifyJSON()
Change-Id: I406d5c2967615f818c9ac42abc19ab8a49e1da8d
2014-12-16 21:45:49 -08:00
Yuri Astrakhan
3a28ee5acb CSS/JSON/JavaScript ContentHandler refactoring
* All content handlers that deal with code/data tend to have
English as their page language & pageview language, so moved common
code to the abstract CodeContentHandler class.

* Renamed JSONContent & JSONContentHandler into JsonContent*

Change-Id: I46819a0572ef5becc211d0d82471ff7102edaa3c
2014-09-15 08:24:15 +00:00
Renamed from includes/content/JSONContent.php (Browse further)