Commit graph

48 commits

Author SHA1 Message Date
daniel
0dc7ba02b4 Apply content wrapping in ParserOutput::getText()
Instead of applying wrapping the the parser and unwrapping in
ParserOutput::getText(), turn this around and apply wrapping in getText(),
and only if desired.

This avoids search&replace logic for unwrapping, and it also makes it a lot
easier to merge the output of multiple slots for MCR output.

This changes behavior in two hopefully irrelevant ways:
1) the limit report comments will be inside the wrapper div, instead of
following it.
2) if HTML with a wrapper div is explicitly injected into a ParserOutput
object, it will not be possible to unwrap the text.

Bug: T174035
Change-Id: I1641b7995af9bd297f1acd610d583fbf874f34e0
2018-08-29 16:46:25 +02:00
Aryeh Gregor
90d4f56fe4 Mass conversion of $wgContLang to service
Brought to you by vim macros.

Bug: T200246
Change-Id: I79e919f4553e3bd3eb714073fed7a43051b4fb2a
2018-08-11 22:44:29 -06:00
C. Scott Ananian
0935e47a72 Remove most uses of deprecated Language::truncate()
The Language::truncate() function was split into
Language::truncateForVisual() (which measures characters) and
Language::truncateForDatabase() (which measures bytes) in 1.31, but
the patch which soft-deprecated Language::truncate() didn't actually
remove all the uses in the codebase.  Replace most of those old uses
now, which should actually improve the situation for
non-latin-alphabet users who were getting unfairly squeezed in a
number of places.

Bug: T197492
Change-Id: I2291c69d9df17c1a9e4ab1b7d4cbc73bc51d3ebb
2018-07-09 13:36:27 -04:00
Umherirrender
130ec2523d Fix PhanTypeMismatchDeclaredParam
Auto fix MediaWiki.Commenting.FunctionComment.DefaultNullTypeParam sniff

Change-Id: I865323fd0295aabd06f3e3c75e0e5043fb31069e
2018-07-07 00:34:30 +00: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
addshore
c9231ac8c4 Make $mText an explicit member variable in TextContent
Change-Id: I1e1f652e4ef6d02bc76105407cb23975625560cd
2017-10-11 18:05:49 +00: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
Brad Jorsch
96b6afb31d TextContent: Normalize newlines in preSaveTransform()
This does the same normalization of newlines that
Parser::preSaveTransform() does. This should be appropriate for any text
content type, especially considering that EditPage uses
WebRequest::getText() which does a less-strict version of this same
transformation.

This also cleans up the code for doing that newline replacement
to be a bit less verbose.

Bug: T142805
Change-Id: I462afcda502f031a8b0360d982ce2398a0383a96
2016-08-16 10:21:32 -04:00
Thiemo Mättig
0965bf5991 Add missing null type hints to Content::isCountable and implementations
Change-Id: I6e3128dddd296f6d33da23332b8ff8393837b61b
2016-02-25 14:13:22 +01:00
Reedy
4d9143c7f5 Add lots of @throws
Change-Id: I09d0c13070f966fcf23d2638d8fc1328279a5995
2014-12-24 13:49:20 +00:00
Yuri Astrakhan
2beb4fc172 When cloning TextContent, include model
The model id should be preserved when cloning values
on save.

Change-Id: I397d36af30cf1401023b761e8c41f0dc83e76c12
2014-09-16 02:58:36 -04:00
umherirrender
7ff005407e Remove colon after @deprecated/@param/@todo/@note
Change-Id: I4e66dad85eecf7e8e03ac760af900395e1bc11b6
2014-07-24 11:30:25 +02:00
Stephan Muggli
7982cf183f Return value directly when using getter
It is not necessary to save the value in a variable

Change-Id: Ia58c94bb19e22476821451bddc2f66e556b773f6
2014-05-23 16:05:29 +02:00
daniel
48d5e5b3c9 Introduce 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.

This, together with I76412f9d, is a (hopefully) fixed version of the
reverted Ibfb2cbefea44.

Change-Id: I979e2438689648ba4c959d8083197ef14ce524e8
2014-05-10 14:27:33 +02: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
daniel
12f4689cc8 TextContent: Document parameters to convert()
Mostly extracted from I979e2438.

Change-Id: I764aae970a2ad90a54aa9816d81070d0899fd10a
2014-05-05 18:27:35 +02:00
Bartosz Dziewoński
c3f7f91705 Documentation cleanup in Content-related files
Mostly extracted from I979e2438.

Change-Id: I6562d111c15425957eaaad31ded175811d7abf1c
2014-05-05 17:04:10 +02:00
umherirrender
23bb3d1cb4 Follow-Ups to "Fixed some @params documentation"
Fix of inline comments of the following patch sets:
Follow-Up: I0056b4a8df243cfc0c5f25378de48f7a35170aca
Follow-Up: I7f605aa9e117b5fd80d9b1440864fe526d2b14a5
Follow-Up: I3622f216a2ca8ac1b5e51892be9f98665f65bc36
Follow-Up: I6627ba0e76d3577c40bf2473e0f78a5ad7368634
Follow-Up: Id75b5ecf648ca50f955b3bde3307c82c4366b102
Follow-Up: I4ca5231119f33039d91da3b57a41cd40719a576b

Change-Id: Id9bbe84b2820e9db44af5783411e955f55f643d4
2014-04-23 13:39:49 +02: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
Brian Wolff
7ebbd71744 Make the warning from TextContent::__construct show caller.
Having the warning point to itself isn't very useful.

Bug: 44898
Change-Id: Ia3e73477d323d17c9e97c2dd863255cc2e191f7f
2013-12-20 01:49:55 -07:00
Brad Jorsch
99da9b9bfe Fix TextContent::preSaveTransform() return type
TextContent::preSaveTransform should return an object of the same class
as $this, not a WikitextContent.

Apparently this was never noticed because most code paths rtrim the
input and TextContent::preSaveTransform returns $this if the rtrim is a
no-op on the input.

Bug: 58451
Change-Id: I9f8f78d52448d1ba055a654a12ff4fad86756110
2013-12-13 13:20:22 -05:00
Siebrand Mazeland
5bec2e90d1 Update documentation and break long lines
Also remove some superfluous newlines.

Change-Id: I904d6ddeb976434708d5a22df9e8abd2e6f60a6c
2013-11-20 06:02:37 +01:00
Siebrand Mazeland
3bbe32d6e9 Update formatting
Change-Id: Ieee4747cf2401d0d89a497a7637d32348192f481
2013-11-19 22:26:16 +01:00
Alex Monk
991c53d1be ContentHandler: TextContent::diff should compare to given object, not itself
Not sure this is actually used anywhere which might be why this has gone unnoticed.

Also fix the method's docs.

Change-Id: Ifa7a684fe98774cae546b385b09a950cfa7eff32
2013-11-16 20:51:20 +00: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
Tyler Anthony Romeo
4dcc7961df Fixed @param tags to conform with Doxygen format.
Doxygen expects parameter types to come before the
parameter name in @param tags. Used a quick regex
to switch everything around where possible. This
only fixes cases where a primitve variable (or a
primitive followed by other types) is the variable
type. Other cases will need to be fixed manually.

Change-Id: Ic59fd20856eb0489d70f3469a56ebce0efb3db13
2013-03-11 13:15:01 -04:00
Reedy
c3e4057e06 Kill off numerous unused variables
Change-Id: I7039f1328f37ee669b694f73ee282602186bffd1
2013-03-08 02:36:24 +00: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
daniel
ea4473037d Content::convert() for conv. betw. content models.
This is needed to fix bug 41706 and similar, watch for follow-ups.

Automatic, implicit conversion may be handy in several cases, especially
for converting between different text based content models. E.g. it should
be possible to create a diff between a JavaScript and a wikitext page. This
change lais the foundations for this ability.

Change-Id: Ie7d87b67b24ac9897cb5696220a7785b228d3c79
2012-11-06 17:39:10 +01:00
daniel
ee5527aa47 Warn when creating TextContent around false/null.
Instantiating a TextContent instance around a null or false value
instead of a string may indicate an error and should thus trigger
a warning and thereby make tests fail.

Change-Id: I0864bbf31040d0c5db96a90ff427dc9dd3ccbd67
2012-10-29 16:26:06 +01:00
aude
1024fb7e69 revert gerrit change 29597 for TextContent constructor
https://gerrit.wikimedia.org/r/#/c/29597/

use cases that pass non-strings to TextContent need to be handled differently
and handle the exceptions

Change-Id: Id3f88b0fb867fff0d16abcf570178cbbe86e89a1
2012-10-24 21:30:14 +00:00
aude
a17660fbd0 per bug 41244 and 41303, handle null or false params in TextContent constructor
Instead of throwing exception in these cases (which there are use cases for),
create an empty TextContent object.

Change-Id: Ice30ea78428d95805aa56cd3a35405aa67ad10ab
2012-10-23 15:42:20 +00:00
Antoine Musso
9362bb6c56 miscellaneous doxygen warnings
* @licence -> @license
* Protects inline HTML by using double quotes, our inline comments uses
  elements such as <h1> or <firstnameLastname@gmail.com>
* Commands in lowercase (@TODO -> @todo, @NOTE -> @note)
* removes @abstract and @static since doxygen detects them from PHP
  code.
* various undocumented function parameters
* typos in parameters declarations

Change-Id: I62ad6fc124c355bf31acc780b9614a59cf79a421
2012-10-22 14:00:08 +02:00
Demon
6d11551ea1 Merge "(Bug 41169) Apply rtrim on on preSaveTransfrom." 2012-10-18 18:45:36 +00:00
daniel
f4a1242db8 (Bug 41169) Apply rtrim on on preSaveTransfrom.
Wikitext should not have trailing whitespace.

Change-Id: I75eb1c4bef7217ec2b7440594e3fc4b68dc3c022
2012-10-18 19:40:29 +01:00
daniel
8b568be5e2 [Bug 41155] Record links on CSS/JS pages in the DB.
ContentHandler removed wikitext parsing for CSS and JS pages.
However, people seem to rely on links and categories embedded
in script comments.

Change-Id: I0736f15878fbd3292e75854bf16f04df656ce363
2012-10-18 20:21:04 +02:00
jeroendedauw
506456c138 Added docu headers to content(handler) files
Change-Id: I9981698a5e4d79db89892ce3f3e007dd5aee5fd1
2012-10-16 20:04:32 +02:00
daniel
41b0a79455 Support plain text content.
Made TextContent and TextContentHandler usable directly.
CONTENT_MODEL_TEXT is unused in core, but may be used by extensions.

Change-Id: I8963c968800b98e286cd917a1038a9905b3a0fef
2012-10-14 23:27:00 +00:00
daniel
0e507f630a Fix creation of pages in the MediaWiki namespace.
Creation of pages in the MediaWiki namespace failed with a "no such section"
error if the corresponding system message did not exist. Fixed now.

Change-Id: Ia6e879c66a6330ea2a63246b3aed51c9c6e1d49d
2012-10-09 14:58:25 +02:00
daniel
bb51a58e57 Cleanup of Wikidata branch.
This cleans up several issues raised in comments to I3b2dad3a,
mostly style and merge artifacts.

Change-Id: I99f5e300a671db1353db151cd187ffd2e4478d03
2012-10-08 17:34:47 +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