Commit graph

480 commits

Author SHA1 Message Date
Bartosz Dziewoński
add6c49e01 Fix edit API adding empty section title when creating new pages
WikitextContent methods replaceSection() (used when adding a section
to an existing page) and addSectionHeader() (used when creating a new
page) behaved inconsistently - the former would omit the heading
syntax when the section title was empty, but the latter would not.
They both omit it now.

Some callers of addSectionHeader() handled this case, but others did
not, which caused T311489. (I am removing the checks now, since the
change makes them redundant.)

Bug: T311489
Change-Id: Icd59bcf2b75bf50865f19fac92bddabe0c183dcc
2022-07-05 21:06:06 +00:00
Tim Starling
e2c26e1774 Migrate risky callers of MediaWikiServices::getParser()
Don't call MediaWikiServices::getParser() from ContentHandler.
Always use ParserFactory::getInstance().

Bug: T310948
Change-Id: I5fcdc28111e0c5c7d4a76e69b3978402433ebad9
2022-07-05 14:09:36 +10:00
Tim Starling
f270881ca2 Deprecate Parser::getFreshParser()
Following up on the comment I made at Ibbc1423166f4804a5122, make Parser
instance management a ParserFactory responsibility. It is weird for
Parser to have a ParserFactory proxy aspect.

* Add ParserFactory::getMainInstance(), which is equivalent to the old
  MediaWikiServices::getParser() and $wgParser.
* Add ParserFactory::getInstance(), which is equivalent to
  $wgParser->getFreshInstance(), returning the main instance if it is
  free, or a new instance otherwise. The naming is supposed to encourage
  it as the default way to get a parser, which will help with the linked
  bug.
* Deprecate Parser::getFreshParser() and migrate all core callers.

I left the entry in ServiceWiring.php so that it's not immediately
necessary to migrate ObjectFactory specs that ask for Parser.

Bug: T310948
Change-Id: I762b191e978c2d1bbc9f332c9cfa047888ce2e67
2022-07-05 14:09:36 +10:00
Matěj Suchánek
1865180ae7 Do minor code cleanup
Remove dead code and fix typos. Should cause no change in behavior.

Change-Id: I5d293b842bc93a28b8bcd799a31b5e6e30fe692e
2022-06-24 13:52:42 +02:00
Matěj Suchánek
47cbe9ed89 Remove ContentHandler::cleanupHandlersCache
It has been deprecated since 1.35 and it is unused.

Change-Id: I3a9e207d1e4cd8d2d3386934926299427d11785f
2022-06-20 12:12:09 +02:00
Derick Alangi
d01e3ed739 Replace deprecated calls ParserOptions::newCanonical( 'canonical' )
This is a quick find & replace of calls to the deprecated method
ParserOptions::newCanonical() when the context is the string literal
'canonical'. This can be safely replaced by called newFromAnon().

Change-Id: If7bb68459b11e0c5f5de188f10fdae85ad1a78bf
2022-06-16 14:22:24 +01:00
DannyS712
0e3942092e Remove deprecated WikiPage::doEditContent()
Bug: T286139
Change-Id: I17b144f62a3e8f42d221d6476651dbd4c7554524
2022-06-03 21:43:31 +00:00
Umherirrender
f07295ade1 content: Remove UnknownContent/UnknownContentHandler class alias
Renamed in a67cad6 in 1.36
The fallback content is designed for internal use only

Change-Id: I6977a9cf1eab0e701fd6969b1a2b5d1dfcecfdfa
2022-05-29 06:20:45 +00:00
Bartosz Dziewoński
f7705d976a ParserObserver: Only report duplicate parse if the content is the same
Bug: T303596
Change-Id: Ib3b00a8cfabeb12723ac6a441495d72fd0c0ca92
2022-05-14 02:13:25 +02:00
Matěj Suchánek
e47c441078 Fix many typos in comments
Found using IntelliJ's "Typo" code inspection.

Change-Id: I746220ebe6e1e39f6cb503390ec9053e6518cf16
2022-05-10 12:46:11 +00:00
daniel
66f3ab254c Remove support for $wgMaxRedirect
Redirect chains have never worked as intended.

Bug: T296430
Change-Id: If0e514c57b8f3d857d956a581f1b549518ecb099
2022-05-06 10:52:56 +02:00
Brian Wolff
bec8dada48 Clarify generate-html and make ParserOutput behave as expected
Previously:
* It was unclear that generate-html is an optional optimization
* Most of MediaWiki core was doing $parserOutput->setText('') if
html wasn't generated. However this is wrong and will cause
$parserOutput->hasText() to return true and also potentially cause
cache pollution if a content handler both does that and supports
parser cache (Like MassMessage; see T299896)
* The default value of mText in the constructor was '', and most
of the time MW used that default. This doesn't seem right. If
setText() is never called, the ParserOutput should not be considered
to have text
* It was impossible to set mText to null, as $parserOutput->setText(null)
was a no-op. Docs implied you were supposed to do this, so it was very
confusing.

This patch clarifies docs, changes the default value for ParserOutput::$mText
from '' to null, and makes $parserOutput->setText(null) do what you
expect it to. The last two are arguably breaking changes, although
the previous behaviours were unexpected, mostly undocumented and
based on a code search do not appear to be relied on.

It seems like the main reason this only broke MassMessage is most
content handlers either don't support generateHtml, or they don't
support parser cache.

Bug: T306591
Change-Id: I49cdf21411c6b02ac9a221a13393bebe17c7871e
Depends-On: I68ad491735b2df13951399312a4f9c37b63a08fa
2022-05-03 11:23:08 +02:00
Aryeh Gregor
7b791474a5 Use MainConfigNames instead of string literals, #4
Now largely automated:

VARS=$(grep -o "'[A-Za-z0-9_]*'" includes/MainConfigNames.php | \
  tr "\n" '|' | sed "s/|$/\n/;s/'//g")
sed -i -E "s/'($VARS)'/MainConfigNames::\1/g" \
  $(grep -ERIl "'($VARS)'" includes/)

Then git add -p with lots of error-prone manual checking. Then
semi-manually add all the necessary "use" lines:

vim $(grep -L 'use MediaWiki\\MainConfigNames;' \
  $(git diff --cached --name-only --diff-filter=M HEAD^))

I didn't bother fixing lines that were over 100 characters unless they
were over 120 and triggered phpcs.

Bug: T305805
Change-Id: I74e0ab511abecb276717ad4276a124760a268147
2022-04-26 19:03:37 +03:00
Aryeh Gregor
4a52bf553f Use MainConfigNames instead of string literals, #3
This edition brought to you by:

grep -ERIn $(grep -o "'[A-Za-z0-9_]*'" includes/MainConfigNames.php | tr
"\n" '|' | sed 's/|$/\n/') includes/

I only corrected a fraction of the results provided by that command. I'm
submitting the partial patch now so it doesn't bitrot.

Bug: T305805
Change-Id: If1918c0b3d88cdf90403921e4310740e206d6962
2022-04-26 14:31:26 +03:00
Timo Tijhof
e3659dfef9 page: Improve class documentation briefs
* Indicate whether a class is a service (to be found via MediaWikiServices)
  or a lower-level class for certain backend logic.

* Indicate how to create / where to get instances of non-service classes,
  e.g. point to the relevant service.

* Remove copy-pasta text in file docblock that is unrelated,
  and incorporate any relevant text into the class docblock instead.

Change-Id: Ia3b9b8c22da4d7160c5e14ae6a6a7c9dca30e9db
2022-04-12 00:49:41 +00:00
David Causse
2eca69ca63 Clarify the return type of ContentHandler::getParserOutputForIndexing()
it may be null in some cases.

Bug: T305169
Change-Id: I00bf78e6d46392244cbf95344f782ffe3c55dbb6
2022-04-05 10:38:48 +02:00
Amir Sarabadani
a087f79319 ParserOutputAccess: Allow calling getPO with option of not saving in PC
This is needed to make sure CirrusSearch doesn't overwhelm parsercache.

Follows-up I23c053df4c (T302620).

Bug: T285993
Change-Id: Ia5fc3b063c45cb43fdee16f44da2270847773945
2022-04-01 14:02:07 +00:00
Umherirrender
1f71eccf63 phan: Disable null_casts_as_any_type setting
Make phan stricter about null types by setting null_casts_as_any_type to
false (the default in mediawiki-phan-config)
Remaining false positive issues are suppressed.
The suppression and the setting change can only be done together

Bug: T242536
Bug: T301991
Change-Id: I0f295382b96fb3be8037a01c10487d9d591e7e01
2022-03-21 18:25:07 +00:00
jenkins-bot
6fd4c95f5e Merge "Use updated ObjectFactory namespace" 2022-03-12 00:19:53 +00:00
Alexander Vorwerk
9b09bf3112 Use updated ObjectFactory namespace
Depends-On: I99c5e5664d2401c36a9890f148eba7c25e6e8324
Depends-On: I48ab818b2965da14af15ef370aa83ad9455badd9
Depends-On: I018371e4b77911e56152ca7b2df734afc73f58a5
Change-Id: I04ebdb52102f6191d49a9cc70b1f98308299e72f
2022-03-09 23:04:51 +00:00
jenkins-bot
0200221a93 Merge "Fix various documentation related to null types (part II)" 2022-03-09 22:42:42 +00:00
Umherirrender
d30b3d8926 Fix various documentation related to scalar types
Found by phan strict checks

Change-Id: If41d16b473baddd92cc4261cdc2bfbe65fedcb19
2022-03-09 20:49:51 +00:00
Umherirrender
d7248d63fb Fix various documentation related to null types (part II)
The functions returning null or the class property is set explict null.
Some function should not accept null or return null.

Found by phan strict checks

Change-Id: Ie50f23249282cdb18caa332f562a3945a58d86ff
2022-03-08 23:45:31 +00:00
Amir Sarabadani
89ef0a943d ContentHandler: Use ParserOutputAccess for accessing ParserOutput
This utilizes class cache to avoid duplicate parses

Bug: T302620
Change-Id: I23c053df4cca5b701d2edafc07c484702f2cc85e
2022-02-25 20:08:55 +01:00
Amir Sarabadani
3dc1b21110 ContentHandler: Avoding saving in ParserCache in search index jobs
This is adding a lot of PC entries for pages that possibly won't ever
be visited. This is similar to what Refreshlinks job does and doesn't
save at all.

Bug: T285993
Change-Id: I68c14932d568795ab54074e073eab2a80517ed70
2022-02-10 01:07:44 +00:00
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
Tim Starling
c5ef6e3091 PHP 8.1: add ENT_COMPAT to some htmlspecialchars() calls
In PHP 8.1 the default $flags argument to htmlspecialchars() has changed
from ENT_COMPAT to ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401. This
breaks some tests.

I changed all the calls that break unit tests, and some others
based on a quick code review. A lot of callers just use the default for
convenience, and were already over-quoting, so the default should still
be good enough for them.

Change-Id: Ie9fbeae6f0417c6cf29dceaf429243a135f9fecb
2022-01-25 16:30:44 +11:00
C. Scott Ananian
75480cf1e0 Narrow the signature of ParserOutput::addModules() and ::addModuleStyles()
We always implicitly converted a string argument to an array anyway; just
ask the caller to do this instead so that we can have a simpler and
more straight-forward method signature which matches the plural form
of the method name.

Part of the ParserOutput API cleanup / Parsoid unification discussed
in T287216.

In a number of places we also rename $out to $parserOutput, to make it
easier for codesearch (and human readers) to distinguish between
ParserOutput and OutputPage methods.

Code search:

https://codesearch.wmcloud.org/deployed/?q=p%28arser%29%3F%28Out%7Cout%29%28put%29%3F-%3EaddModule%28Style%29%3Fs%5C%28&i=nope&files=&excludeFiles=&repos=
https://codesearch.wmcloud.org/deployed/?q=arser-%3EgetOutput%5C%28%5C%29-%3EaddModule%28Style%29%3Fs%5C%28&i=nope&files=&excludeFiles=&repos=

Bug: T296123
Depends-On: Iedea960bd450474966eb60ff8dfbf31c127025b6
Depends-On: I7900c5746a9ea75ce4918ffd97d45128038ab3f0
Depends-On: If29dc1d696b3a4c249fa9b150cedf2a502796ea1
Depends-On: I8f1bc7233a00382123a9b1b0bb549bd4dbc4a095
Depends-On: I52dda72aee6c7784a8961488c437863e31affc17
Depends-On: Ia1dcc86cb64f6aa39c68403d37bd76f970e55b97
Depends-On: Ib89ef9c900514d50173e13ab49d17c312b729900
Depends-On: If54244a0278d532c8553029c487c916068e1300f
Depends-On: I8d9b34f5d1ed5b1534bb29f5cd6edcdc086b71ca
Depends-On: I068f9f8e85e88a5c457d40e6a92f09b7eddd6b81
Depends-On: Iced2fc7b4f3cda5296532f22d233875bbc2f5d1b
Depends-On: If14866f76703aa62d33e197bb18a5eacde7a55c0
Depends-On: I9b7fe5acee73c3a378153c0820b46816164ebf21
Depends-On: I95858c08bce0d90709ac7771a910f73d78cc8be4
Depends-On: If9a70e8f8545d4f9ee3b605ad849dbd7de742fc1
Depends-On: I982c81e1ad73b58a90649648e19501cf9172d493
Depends-On: I53a8fd22b22c93bba703233b62377c49ba9f5562
Depends-On: Ic532bca4348b17882716fcb2ca8656a04766c095
Depends-On: If34330acf97d2c4e357b693b086264a718738fb1
Change-Id: Ie4d6bbe258cc483d5693f7a27dbccb60d8f37e2c
2022-01-20 13:14:20 -05:00
Tim Starling
d636ae57c1 In WikitextContentHandler always use getFreshParser()
Make it safe to parse articles while in the parser, by always calling
getFreshParser() from WikitextContentHandler.

I think ideally this should be a ParserFactory responsibility, with
Parser instances stored by ParserFactory instead of directly by
ServiceContainer, but this fixes the bug, follows existing conventions,
and does not reduce performance in the usual case.

Bug: T299149
Change-Id: Ibbc1423166f4804a5122de10293ea26f5704d96d
2022-01-14 09:36:02 +11:00
jenkins-bot
289e2cb656 Merge "rdbms: Hard-deprecate legacy cruft from introduction of ResultWrapper" 2022-01-12 06:17:27 +00:00
TChin
47adb6d65a Refactor global variables to use MediaWikiServices instead
Automatically refactors wg prefixed globals to use MediaWikiServices config using Rector. Doesn't include files that set globals or files that fail CI.

Rector Gist: https://gist.github.com/tchin25/7cc54f6d23aedef010b22e4dfbead228

* This patch uses a modified source code rector library for our specific use case and the rector will have different effects without it.

A writeup for future reference is here: https://meta.wikimedia.org/wiki/User:TChin_(WMF)/Using_Rector_On_MediaWiki

Change-Id: I1a691f01cd82e60bf41207d32501edb4b9835e37
2022-01-10 13:55:53 -05:00
Amir Sarabadani
87e1a6a2be rdbms: Hard-deprecate legacy cruft from introduction of ResultWrapper
Bug: T286694
Change-Id: Ifc58dd478592be49dd55caddfc9aeb536da1e1d6
2022-01-06 07:17:38 +01:00
jenkins-bot
a498712d6b Merge "Fix typos in comments (C-D)" 2021-12-30 14:42:56 +00:00
Siddharth VP
191cadb6a5 Fix typos in comments (C-D)
Change-Id: I568fb93b53feb83f026d485136dd0d116d677f4f
2021-12-30 18:00:02 +05:30
Siddharth VP
0d9b49beff Fix typos in comments (A-B)
Change-Id: I852453fbeeebdc4e34c0b35c0fdca4b4ab74fde9
2021-12-26 16:43:47 +05:30
Bartosz Dziewoński
275dec4f18 SECURITY: Fix use of EditFilterMergedContent hook when changing content model
The logic in ContentModelChange class now matches the
EditFilterMergedContentHookConstraint class.

Now it aborts processing when an extension has set the status,
but did not return false from its hook handler.

CVE-2021-44856

Bug: T271037
Change-Id: Ic9d5fba7218d3cc8afc499199616754888610b70
2021-12-15 16:12:39 +00:00
Derick Alangi
8fe9e0317f Introduce Redirect(Lookup&Store) services to handle redirects
The concept of a redirect chain didn't really work for a value of
max redirect > 1. In the ideal world, we just want to have a source
which points to target (source -> target) discarding the concept of
a redirect chain completely.

Having something like: source -> target -> target1 -> target2 doesn't
really work well with the current database design.

NOTE: Support for $wgMaxRedirect will be removed soon hence
deprecation without interfaces for replacement.

Bug: T290639
Change-Id: I469de6f85e405e8ddbe7abaa5b99b77cb9cf415d
2021-12-01 19:14:22 +01:00
jenkins-bot
1fc7c9443a Merge "Hard-deprecate Content::prepareSave." 2021-11-23 11:20:21 +00:00
Reedy
2a2bb1e9bd Remove or replace usages of "sane"
Bug: T254646
Change-Id: I096b2cf738a1395a14f1d47bcbed0c2c686c2581
2021-11-22 13:35:17 +00:00
C. Scott Ananian
d8a7c01b67 Allow inserting new sections named '0'
This bug has apparently existed since sometime before b6fe213226
in 2012 (!).

Bug: T296112
Change-Id: Ic50965647117b91562493444d62dfdd2bbb5260e
2021-11-19 22:13:58 -05:00
jenkins-bot
fef2689b0a Merge "Deprecate $hasHistory param to ContentHandler::getAutoDeleteReason()" 2021-11-15 16:57:35 +00:00
Daimona Eaytoy
1ccd95dca4 Deprecate $hasHistory param to ContentHandler::getAutoDeleteReason()
Unused except for DeleteAction, which now uses a custom query (similar
to the one in ContentHandler::getAutoDeleteReason). Passing the
parameter is hence hard-deprecated, and it will be removed in 1.39.

Also escalate the exception logging from wfDebug to error, since we want
to know what exceptions are being caught.

Bug: T288282
Change-Id: I91ed9574da68bc7ff36e968f016da390b6d295ed
2021-11-11 23:14:42 +00:00
Roman Stolar
56e5616e96 Hard-deprecate Content::prepareSave.
Use ContentHandler::validateSave instead.

Bug: T287159
Depends-On: I3d847d1714224b2e5903d3b1e8f1c218d850c17b
Depends-On: Ie71d1b590560b1210dd4599afb17ad41a2ec687e
Depends-On: I4b9287372a95f4b6178dc321105081552d040ef8
Change-Id: Iee3dd92747019ae18830fc9d0e904afc2d1939e4
2021-11-11 14:01:19 +00:00
Roman Stolar
5461404d69 Move Content::prepareSave to ContentHandler
Update method name in ContentHandler, soft-deprecate method on Content.
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.
Replace all callers of Content::prepareSave in core.

Add tests for ContentHandler::validateSave.

Bug: T287159
Change-Id: I7f23e6e97b1c7d27a6aaefdb88b19b2fc6e8b3a8
2021-11-11 15:40:42 +02:00
Roman Stolar
957697e1e0 Hard-deprecate Content::getParserOutput and AbstractContent::fillParserOutput.
Use ContentRenderer::getParserOutput instead.
Extensions defining a content model should override ContentHandler::fillParserOutput.
Update tests.

Bug: T287158
Change-Id: I1c71a8429806f1813a39f5807256b2eb9fb9901f
2021-10-29 14:04:22 +03:00
Roman Stolar
fa5237eb48 Replace Content::getParserOutput call to ContentRenderer::getParserOutput
Bug: T287158
Change-Id: I8a13f45027e08e2d8ddefa140dd47a0c55094934
2021-10-20 12:11:24 +03:00
C. Scott Ananian
06ab90f163 Add new ParserOutput::{get,set}OutputFlag() interface
This is a uniform mechanism to access a number of bespoke boolean
flags in ParserOutput.  It allows extensibility in core (by adding new
field names to ParserOutputFlags) without exposing new getter/setter
methods to Parsoid.  It replaces the ParserOutput::{get,set}Flag()
interface which (a) doesn't allow access to certain flags, and (b) is
typically called with a string rather than a constant, and (c) has a
very generic name.  (Note that Parser::setOutputFlag() already called
these "output flags".)

In the future we might unify the representation so that we store
everything in $mFlags and don't have explicit properties in
ParserOutput, but those representation details should be invisible to
the clients of this API.  (We might also use a proper enumeration
for ParserOutputFlags, when PHP supports this.)

There is some overlap with ParserOutput::{get,set}ExtensionData(), but
I've left those methods as-is because (a) they allow for non-boolean
data, unlike the *Flag() methods, and (b) it seems worthwhile to
distingush properties set by extensions from properties used by core.

Code search:
https://codesearch.wmcloud.org/search/?q=%5BOo%5Dut%28put%29%3F%28%5C%28%5C%29%29%3F-%3E%28g%7Cs%29etFlag%5C%28&i=nope&files=&excludeFiles=&repos=

Bug: T292868
Change-Id: I39bc58d207836df6f328c54be9e3330719cebbeb
2021-10-15 14:25:54 -04:00
Lucas Werkmeister
97661702dc Fix reference to moved flag in phpdoc
$generateHtml is now wrapped in the ContentParseParams, referring to it
by its old name is confusing.

Bug: T287158
Change-Id: I31e0a596881ecd7d3bea709ab3f8029779cb7f02
2021-10-12 11:57:38 +02:00
C. Scott Ananian
af5d13c5de Rename ParserOutput::{get,set,unset}Property to {get,set,unset}PageProperty
The ::getProperty() naming is too generic and doesn't clearly indicate
that these are "page properties" (which have their own table in the DB).
As part of refactoring a clean API out of ParserOutput which can be used
by Parsoid, clean up the naming here.

Soft-deprecation in this patch, there are a handful of external users
which need to be cleaned up before we hard-deprecate.

Bug: T287216
Change-Id: Ie963eea5aa0f0e984ced7c4dfa0fd65d57313cfa
2021-10-08 10:07:17 -04:00