Commit graph

401 commits

Author SHA1 Message Date
Umherirrender
f9195771f6 Use local variable for null checks
This helps phan to understand that the value is not-null after the check

Change-Id: Ifdac7ed99a873fed011d8357a657b30e59b8d1fa
2022-03-05 19:59:38 +01:00
Umherirrender
9efd9ca45e Add explicit casts between scalar types
* Some functions accept only string, cast ints and floats to string
* After preg_matches or explode() casts numbers to int to do maths
* Cast unix timestamps to int to do maths
* Cast return values from timestamp format function to int
* Cast bitwise operator to bool when needed as bool

* php internal functions like floor/round/ceil documented to return
  float, most cases the result is used as int, added casts

Found by phan strict checks

Change-Id: Icb2de32107f43817acc45fe296fb77acf65c1786
2022-03-01 18:19:33 +01:00
jenkins-bot
0607fc561a Merge "Don't double-escape the ellipses in Language::truncateForVisual()" 2022-02-10 22:47:33 +00:00
C. Scott Ananian
9e033de4f2 Don't double-escape the ellipses in Language::truncateForVisual()
It turns out this gets rid of a bunch of suppressed
"SecurityCheck-DoubleEscaped" that appear to have been accurate
warnings.

There seems to have been some confusion about how ::truncateForVisual()
is supposed to be used; in particular it is to be passed *unescaped*
output, because it is not (generally speaking) safe to truncate
HTML-escaped strings.  The goal of ::truncateForVisual() is to have
a specific number of codepoints in the output for display purposes,
the encoding of those codepoints is not an issue (htmlspecialchars
can be applied to the *return value*.)  If you need a specific number
of *bytes* you should be using ::truncateForDatabase().  If you want
a certain number of *HTML bytes* then the ::truncateHtml() method
is probably what you want.

Slightly refactor some code in RevDelLogItem to avoid a false positive.

Bug: T301205
Bug: T290624
Change-Id: I893362e049aedfa699043fcf27caf4815196f748
2022-02-10 17:09:18 -05:00
Amir Sarabadani
a965ceab7b DerivedPageDataUpdater: Set ParserOutput when it's passed to it
This fixes duplicate parsing in RefreshLinksJob

Bug: T301309
Change-Id: I3e75621a4e4fccd46836a6f9da5778aa521ca09a
2022-02-09 23:40:48 +01:00
Tim Starling
ca71e69fc6 Try not to discard Excimer timeout exceptions
Don't catch and discard exceptions from the RequestTimeout library,
except when the exception is properly handled and the code seems to be
trying to wrap things up.

In most cases the exception is rethrown. Ideally it should instead be
done by narrowing the catch, and this was feasible in a few cases. But
sometimes the exception being caught is an instance of the base class
(notably DateTime::__construct()). Often Exception is the root of the
hierarchy of exceptions being thrown and so is the obvious catch-all.

Notes on specific callers:

* In the case of ResourceLoader::respond(), exceptions were caught for API
  correctness, but processing continued. I added an outer try block for
  timeout handling so that termination would be more prompt.
* In LCStoreCDB the Exception being caught was Cdb\Exception not
  \Exception. I added an alias to avoid confusion.
* In ImageGallery I added a special exception class.
* In Message::__toString() the rationale for catching disappears
  in PHP 7.4.0+, so I added a PHP version check.
* In PoolCounterRedis, let the shutdown function do its thing, but
  rethrow the exception for logging.

Change-Id: I4c3770b9efc76a1ce42ed9f59329c36de04d657c
2022-02-02 16:27:44 +11:00
Aaron Schulz
c433c15087 Convert various callers to LoadBalancer::getConnectionRef()
Bug: T193565
Change-Id: I2e2ef6a1d841c632d1f3e53ca3f82a720af15d47
2022-01-27 01:02:44 +00:00
daniel
06c7ac58b1 Allow empty revisions to be created with pageUpdater.
This avoids application code re-implementing page update logic
for creating dummy revisions.

Change-Id: Ifbf2b65be259fcef5dfc30f3e49a6d36febb3aba
2022-01-25 17:15:40 +01:00
jenkins-bot
289e2cb656 Merge "rdbms: Hard-deprecate legacy cruft from introduction of ResultWrapper" 2022-01-12 06:17:27 +00:00
Umherirrender
95852cb22b Explicit cast TS_UNIX to int for arithmetic operations and int args
When the called function has a doc of int, it should be cast to be
explicit here.
Also cast for arithmetic operations to be explicit about the number

Change-Id: I905b78dfb66e66443e0e3203488bab5b548db543
2022-01-11 20:13:13 +01:00
jenkins-bot
c60409405b Merge "Move LinksUpdate and LinksDeletionUpdate into the new namespace" 2022-01-10 19:17:10 +00:00
jenkins-bot
7623cae28c Merge "Move the link updates from moveUnsafe() to LinksUpdate" 2022-01-10 19:17:04 +00:00
Siddharth VP
38295f9226 Fix typos in comments (N-R)
Change-Id: I2d1bdb7531ff5126114a391550c2615ea6e244b3
2022-01-09 23:14:44 +05:30
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
Tim Starling
682aad7557 Move LinksUpdate and LinksDeletionUpdate into the new namespace
Change-Id: I5cf7a08324d08aa89c23540222ba8eddc1ae2647
2022-01-04 15:35:57 +11:00
Tim Starling
87d8ccbd3e Move the link updates from moveUnsafe() to LinksUpdate
Since LinksUpdate was already run after a page move, it was just a
matter of propagating a move flag down to it, and resolving the
differences between the move case and the edit case.

This should be faster since it avoids writing to the links tables twice
on a page move.

Change-Id: Ifaa4051a736b01cda82fbd890325e0751ce041f8
2022-01-04 15:35:57 +11:00
Siddharth VP
191cadb6a5 Fix typos in comments (C-D)
Change-Id: I568fb93b53feb83f026d485136dd0d116d677f4f
2021-12-30 18:00:02 +05:30
jenkins-bot
a09e60d0c3 Merge "Introduced PreparedUpdate to replace PreparedEdit" 2021-12-20 20:41:14 +00:00
daniel
cbfcf9e8a8 Introduced PreparedUpdate to replace PreparedEdit
PreparedUpdate represents an in-progress edit. It can be used to access
information about the edit from hooks that do to have access to the
PageUpdater. Ideally, the PreparedUpdate or PageUpdater would be passed
to the hook as a parameter. Handlers of legacy hooks may use
WikiPage::prepareUpdate() to access it.

Bug: T242249
Needed-By: I23324a31e06e7e6f28077085c0ade05db63e9a35
Change-Id: Id5ba40a21cc4547205adf2f3a1f725c3a69c24d8
2021-12-20 21:19:52 +01:00
Thiemo Kreuz
b4c63c64ae Remove some more comments that literally repeat the code
Nothing to learn from these.

You can find a longer explanation in the comments in I93751e6.

Change-Id: I195aae70fc282b58be5b18160783f27d38605d15
2021-12-09 19:01:36 +01:00
Matěj Suchánek
3eb46360f0 Drop obsolete comment
The type hint has already been reduced.

Change-Id: Ifa59399e2e8f292361b7dacd88923708809d5d26
2021-12-04 10:41:43 +01:00
Aaron Schulz
b1ab76471f edit: Make PreparedEdit->timestamp lazy to avoid eager parse
Avoid triggering a parse in DerivedPageDataUpdater::getPreparedEdit().

Defer the internal getOutput() call till when something actually tries
to access the timestamp property.

Bug: T277788
Change-Id: I899d9966214b36ebcd660aaf7c2da399e35be92e
2021-12-01 12:34:36 +00:00
Reedy
7bf779524a Remove or replace usages of "sanity"
Bug: T254646
Change-Id: I2b120f0b9c9e1dc1a6c216bfefa3f2463efe1001
2021-11-19 23:19:42 +00:00
jenkins-bot
34ce0ad77c Merge "Drop User methods which were deprecated since 1.35" 2021-11-15 15:57:50 +00:00
vladshapik
9b92c1088f Drop User methods which were deprecated since 1.35
The following User methods, deprecated in 1.35, have been removed:
  - ::isIP,
  - ::isIPRange,
  - ::isValidUserName,
  - ::isUsableName,
  - ::isCreatableName,
  - ::getCanonicalName,
  - ::addAutopromoteOnceGroups,
  - ::getDefaultOptions,
  - ::getDefaultOption,
  - ::getOptions,
  - ::getBoolOption,
  - ::getIntOption,
  - ::setOption
  - ::listOptionKinds
  - ::getOptionKinds,
  - ::resetOptions,
  - ::getEffectiveGroups,
  - ::getAutomaticGroups,
  - ::getFormerGroups
User::GETOPTIONS_EXCLUDE_DEFAULTS has been removed, since it is used only in the description of User::getOptions.

Bug: T277511
Depends-On: Ida05c22f81b30d9b46678e8ede3d531c38855d83
Change-Id: I72bbc2336f8ddbc66ce67226cd2d5baaa2f807d8
2021-11-12 15:35:50 +02:00
jenkins-bot
bb728b803a Merge "Move Content::prepareSave to ContentHandler" 2021-11-11 15:31: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
jenkins-bot
76c52330ba Merge "doc: Cleanup @param documentation" 2021-11-05 17:41:33 +00:00
Umherirrender
171775e07b doc: Cleanup @param documentation
No extra sign needed between variable and description

Change-Id: Iaaaf62a3ffba7967aef8c31b121121b2830b74c4
2021-11-04 22:32:39 +01:00
Petr Pchelko
3a1d030efb PageUpdater: apply tags even if RC suppressed.
Sometimes we apply tag to a revision even if we
suppress the RecentChange, for example when leaving
redirects after page moves.

Bug: T291967
Change-Id: I7330d3b56cd2280dd23ec0ccb4e1c4807c534739
2021-11-04 13:39:04 -07:00
jenkins-bot
b2af67d496 Merge "Allow populateContentTables to continue when there are bad blobs" 2021-11-03 17:29:30 +00:00
Thiemo Kreuz
62d45967c0 Replace some more isset() with shorter ?? syntax
Change-Id: Ie119167bc2584f047e29174f95c39b65f99a64a6
2021-11-02 10:39:38 +01:00
Umherirrender
5018000e35 Change User::isAnon to !User::isRegistered in PageEditStash
Also use another variable for the full user object to make clear which
parts needs it and which part is fine with an UserIdentity

Change-Id: I8422159a462cc54b54006a44e7b46079919691ad
2021-10-19 20:05:35 +02:00
jenkins-bot
6fd447783a Merge "Make PageEditStash::checkCache() accept an UserIdentity" 2021-10-18 19:20:11 +00:00
Cindy Cicalese
d80f7ade32 Allow populateContentTables to continue when there are bad blobs
When encountering missing or null text blobs, populateContentTables
would fail, leaving the data migration to slots incomplete. This
patch allows the script to continue, reporting the bad blobs without
failing.

This patch and I041d5c67bf241bb7cf2e31e0a4b0030e2cf9a13b, upon
which it depends upon, should be backported.

Bug: T212428
Change-Id: I582eac2befec152cb48d898644bc024a5ade2260
2021-10-17 18:02:37 -04:00
Alexander Vorwerk
5aa1bf33f6 Make PageEditStash::checkCache() accept an UserIdentity
This allows using the already into PageEditStash injected UserFactory
instead of falling back to global state in DerivedPageDataUpdater.

Change-Id: I18f198d323c3ca001c6a0de91bc669180cd1d11c
2021-10-16 00:16:20 +02: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
Petr Pchelko
e33f6b4b8e MovePage - use PageUpdater to create redirect page
After parent patch MovePage changed code is covered
by tests, plus tested locally quite a bit. Seems to work.

Change-Id: I0f8db203eb4aa767e5e1f3067f3a9e35835f38ea
2021-09-17 15:49:50 +00:00
daniel
6ce0d2c825 Make EditPage use PageUpdater
This ensures that a DerivedPageDataUpdater is initialized earlier during
the edit process, so it can be used by hooks to access the state of the
ongoing edit.

This patch also cleans up PageUpdater a bit to make the internal information
flow more consistent with the idea that PageUpdater is acting as a
builder for a new revision.

Change-Id: I99abb7bdffb2b5ff5979ba5b1e56d39dba4cd3dc
2021-09-16 13:11:15 -07:00
Petr Pchelko
2c2ffb0bef Move revert detection code from WikiPage to EditResultBuilder
WikiPage is not the right spot to compute all the revert
related stuff - we already figure out manual reverts when
building the EditResult, lets figure out rollbacks and undos
in there as well.

Change-Id: I9fdc5f24c1db1eb0452b90bf4af1ef5ffbce6cb8
2021-09-16 12:24:34 -07:00
Petr Pchelko
35f38e995b Remove User from LinksUpdate
This does a breaking change, but all (2) known usages
of the LinksUpdate::getTriggeringUser are satisfied
by UserIdentity.

Change-Id: I682ee65f7b3d30fe6c0fe76d5106857ddfa6da5d
2021-09-13 09:40:24 -07:00
jenkins-bot
d74de7f9eb Merge "Make WikiPage a ProperPageIdentity" 2021-09-07 19:48:14 +00:00
jenkins-bot
79615a43c1 Merge "Drop wgAjaxEditStash, deprecated in 1.36" 2021-09-07 16:45:22 +00:00
James D. Forrester
df1e801cca Miscellaneous master -> primary switches for private functions and variables
Change-Id: I5c90822f1da6af7354ee7e2d67d579bd72bce8c3
2021-09-03 20:14:41 +00:00
Umherirrender
4d42b5e86e docs: Change wording master to primary in comments and log text
Bug: T254646
Change-Id: I5379dc79be60c99f0a30f74e5d624f81fe6f921b
2021-09-01 23:04:40 +02:00
jenkins-bot
56bfbb2d1c Merge "Make RevisionAccessException normalized" 2021-08-31 09:42:47 +00:00
Daimona Eaytoy
6a3b9daf29 Make WikiPage a ProperPageIdentity
Bug: T272424
Change-Id: I1dbcf1192390cbdfd6faaa60f9831f62ec1eff0d
2021-08-30 13:05:18 +00:00
jenkins-bot
c03a36a48a Merge "Introduce concept of generateHTMLOnEdit() for ContentHandler" 2021-08-25 10:17:31 +00:00
Amir Sarabadani
66a4b414e5 Introduce concept of generateHTMLOnEdit() for ContentHandler
This way you can avoid rendering HTML and storing ParserCache entries

Bug: T285987
Change-Id: I3c7023b776f2a1e35dafdbb6ac0eb3eb73ae5fd4
2021-08-24 22:40:46 +02:00
Umherirrender
1d178e177b Remove unneeded continue/return statements
Change-Id: I26f9845b09ecc15de8b6e0213ab369b386194c9d
2021-08-17 22:53:53 +02:00