Commit graph

27 commits

Author SHA1 Message Date
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
Umherirrender
07b499fbcf build: Update mediawiki/mediawiki-phan-config to 0.11.0
Addition and remove of suppression needs to be done with the version
update.

Change-Id: I3288b3cefa744b507eadebb67b8ab08c86517c1c
2021-09-07 17:19:05 +02: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
ZabeMath
60606a2986 Avoid using User::getBoolOption()
User::getBoolOption() is deprecated and should be replaced with UserOptionsLookup::getBoolOption()

Bug: T277600
Change-Id: Ife3c721237258d50852bbf764def74657cc70428
2021-03-27 22:51:03 +01:00
C. Scott Ananian
770ace8723 content: Add hidden preference to disable PST on CSS/JS content
Test Plan:
* Logged-in, preview a change adding {{subst:CURRENTYEAR}}
  to User:You/common.css, User:You/common.js and Main_Page.
* Observe that it expands to 2020 in all cases.
* Run `(new mw.Api).saveOption('pst-cssjs', '0')`
* Try again. Observe that the first two are now left unchanged.

Bug: T236828
Change-Id: Ic13e2ff3b90f0c3587cdb1e97fffcd96be650e0e
2020-08-12 02:14:30 +00:00
Thiemo Kreuz
70027add5d Make use of the preg_match() return value, if possible
Instead of checking if the resulting $matches array is complete, we can
safely assume it is, as long as the preg_match() call returned a
non-false value.

Note that some of these used empty() before and are actually bogus
because of this! empty() considers the string "0" to be empty. In case
of a ==0== headline that's an actual bug.

I'm also removing the `= []` initialization before the preg_match.
I understand why it was added: to make it a little more obvious that the
variable is guaranteed to be initialized. But:
* This is guaranteed by the preg_match anyway.
* Neither initializing it with null or an empty array makes much sense
  because the code below assumes so much more, e.g. that specific
  elements exist, and are arrays. Again, these guarantees are all given
  by the preg_match.

I find the additional initialization more distracting than helpful.

Change-Id: I22b192b59038d9fa51a7e6f04d8d76634ae3de73
2020-07-14 19:26:35 +00:00
daniel
272db6afde Replace "@stable for calling" by "@stable to call"
For compliance with the new version of the table interface policy
(T255803).

This patch was created by an automated search & replace operation
on the includes/ directory.

Bug: T257789
Change-Id: If560596f5e1e0a3da91afc36e656e7c27f040968
2020-07-13 08:55:28 +00:00
daniel
bd5c3d06a2 Annotate newable classes
This annotates classes that can safely be instantiated by
extensions, per the Stable Interface Policy.

Bug: T247862
Change-Id: Ia280f559874fc0750265ddeb7f831e65fd7d7d6a
2020-07-07 15:38:57 +02:00
Fomafix
025a5fb71a Let Html::element do the HTML encoding
This change avoids an unnecessary HTML encoding of `"` to `"` and
`>` to `>`.

Change-Id: Ieb135edacb84982908d9462bae3c287f54761f1f
2019-11-19 06:59:55 +01:00
Aryeh Gregor
e6df285854 Remove all $wgParser use from core
Bug: T160811

Change-Id: I0556c04d33386d0339e02e2bf7a1ee74d97c2abd
2019-04-17 15:16:50 +03: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
Kunal Mehta
674e486cb5 Recognize CSS/JS redirects with non-ASCII targets
The regex in JavaScriptContent and CssContent was trying to pass
urlencoded stuff to Title::newFromText(), which would fail. Make sure we
urldecode it first.

Bug: T208264
Change-Id: I189c4c308da2875839ad8c1061332500f0e6d244
2018-10-31 23:09:50 -07:00
Fomafix
1472f02b36 Phabricator: Use Tddddd instead of Bug ddddd in comments
Change-Id: Ic9fe03cab270bd6be738af346164ad5d31a0d780
2018-10-04 09:15:02 +02:00
Kunal Mehta
ad9f14d662 Support redirects in JavaScriptContent
When a JavaScript page is moved, a "redirect" in the form of
mw.loader.load(...) will be left behind, so any other
JavaScript loading the page that way will still work, albeit
with an extra HTTP request.

This also implements Content::getRedirectTarget(), so redirects
are marked properly in the database, and users viewing them
are redirected properly. A magic "/* #REDIRECT */" comment
must be in front of the mw.loader.load call. This is done so
that pages which currently are just one mw.loader.load call
aren't turned into redirects.

Bug: 71200
Bug: 33973
Change-Id: I10fdff087a901da56fad64531f0e382f90ebcf37
2015-07-20 15:36:49 +00:00
Kunal Mehta
87cddceefe Fix subclassing of CssContent and JavaScriptContent
We need to be able to set a different content model via the
constructor, so make it an optional parameter.

Change-Id: I8b31084e0cfbcca1b3785176eac492d837e0cb0f
2014-09-13 15:31:18 -07:00
Kunal Mehta
ccee80b8a6 Make it easier to subclass Content and ContentHandler subclasses
Currently the names of associated Content classes are hardcoded,
meaning that any extension that wishes to subclass these implementations
must also re-implement that function, usually copying it exactly
with just the class name changed. Using "static" avoids that issue.

For ContentHandlers, I added a TextContentHandler::getContentClass,
which should be used when creating new Content objects.

Change-Id: I70f1a3291aec3460120ec20121a23f4cb68e04d1
2014-08-16 23:04:08 -07:00
Bartosz Dziewoński
5fea642f16 Content: Deprecate and stop using getHighlightHtml()
That function was clearly a bad idea, everyone should just use
getHtml() instead. It was supposed to allow extensions to extend
the content formatting process, but actually doesn't.

A better hook-based solution follows in separate commit I979e2438.

Split off from original I979e2438 and rebased with minor changes
(updated documentation comments, etc.).

Co-Authored-By: daniel <daniel.kinzler@wikimedia.de>
Co-Authored-By: Bartosz Dziewoński <matma.rex@gmail.com>
Change-Id: I76412f9d28bb145fb5975f59e538f6560e50472f
2014-05-09 10:18:00 +00:00
Thiemo Mättig
6806400129 Added and updated Doxygen comments in content handler and diff namespaces
Reasons for touching this are:
* "@param type $var" were mixed in a lot of places. Both works but the
  MediaWiki coding conventions suggest that specific order.
* Things like String and Bool aren't objects and shouldn't be uppercase.
* Tried to fill missing types in "@param $var".
* Tried to fill missing descriptions in "@return type" when I could.
* Removed duplicate descriptions if a @see is sufficend.
* Removed useless descriptions ("isUsefull returns true if usefull").
* Removed useless @return void.
* Replaces mixed[] with array (does have the exact same meaning).
* Tried to find better replacements for "varargs", phpDocumentor
  suggest $var,...
* Order should be @since, @param, @throws, @return, @see. This is the
  order Doxygen renders this.

There is always more to do but I think this is already much better
than before. Please feel free to put more change sets on top of mine
or request more changes by adding comments.

Change-Id: I05262ce06caabf79f68772302524ac91bbead1c6
2014-03-06 11:17:41 +01:00
Ori.livneh
6ec90a1acd Revert "Introducing ContentGetParserOutput hook."
This change removed getHtml(), but not the call to it from fillParserOutput.
It has a few other issues that I'll flag in-line after deploying the revert.

This reverts commit fda090a7e7

Bug: 49398
Change-Id: Idcef8d4cedc7c03f72bc1743e0f89cc5ed4ad7a7
2013-06-10 19:13:00 +00:00
daniel
fda090a7e7 Introducing ContentGetParserOutput hook.
This hooks allows extensions to override the normal model-specific rendering
of page content. A typical use would be to provide syntax highlighting for
pages that contain scripts. In that sense, ContentGetParserOutput is a
generalization of the old ShowRawCssJs hook.

Change-Id: Ibfb2cbefea44eeee9f2a027f47e7721bf177ba0f
2013-06-04 15:57:04 +00:00
Timo Tijhof
4bd5471ca3 docs: Remove odd colons after @todo
Most were this way already:
https://doc.wikimedia.org/mediawiki-core/master/php/html/todo.html

Ran a find/replace on the odd ones. Also made them all
lower case.

Change-Id: I70c6a69344ddebc603e9a1c1d87e3cc4f4f4c560
2013-05-15 06:23:40 +00:00
umherirrender
926d2ee143 Remove spaces between parentheses in function calls
Change-Id: If8ec665a01b566fa5189dfcc810b2d9a17f371e1
2013-03-17 16:13:22 +01:00
umherirrender
d63121016d fix some spacing
Added/removed spaces around logical/arithmetic operator
Reduced multiple empty lines to one empty line
Removed wrong tabs before comments at end of line
Removed too many spaces in assigments

Change-Id: I2bba4e72f9b5f88c53324d7b70e6042f1aad8f6b
2013-03-07 17:53:21 +01:00
Alexandre Emsenhuber
ddf601f7d3 Improve documentation of content handler stuff
- Split file and class documentation
- Add some missing file/class descriptions
- Add missing @ingroup Content

Change-Id: I7f7e3056570ca13a92f36a408c9b961c938f09a1
2012-12-20 20:44:47 +01:00
jeroendedauw
506456c138 Added docu headers to content(handler) files
Change-Id: I9981698a5e4d79db89892ce3f3e007dd5aee5fd1
2012-10-16 20:04:32 +02:00
daniel
7db9491d89 set mediawiki version number
Change-Id: I3479776bd3bb25c4d75d07e62ede2ad989025c5b
2012-10-05 15:03:24 +02:00
daniel
2b1016eb9d Split Content.php into one file per class.
Change-Id: Ib49d9ec729613dcc43d38d46cb133ff9df459d79
2012-09-24 22:51:53 +02:00