Commit graph

43 commits

Author SHA1 Message Date
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
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
Petr Pchelko
a1aa3e0827 Hard-deprecate all public property access on CacheTime and ParserOutput.
- Added a test where ParserOutput objects with CacheTime
properties set are unserialized from previous versions.
- Generate new serialization tests for 1.38

Now all serialization in production is JSON, so changing
property visibility shouldn't affect ParserCache.

Bug: T263851
Depends-On: I283340ff559420ceee8f286ba3ef202c01206a23
Change-Id: I70d6feb1c995a0a0f763b21261141ae8ee6dc570
2021-10-13 13:27:16 -04:00
Timo Tijhof
481f1a49d6 WikiPage: Document triggerOpportunisticLinksUpdate and related code
== History of WikiPage::triggerOpportunisticLinksUpdate ==

* 2007 (r19095; T10575; b3a8d488a8)

  Introduces the "cascading protection" feature.

  This commit added code to Article.php, in a conditional branch
  where we encountered a ParserCache "miss" and thus have done a
  fresh parse. The code in question would query which templates
  we ended up using, and if that differed from what the database
  said (e.g. stored during the last actual edit or links update),
  then a new LinksUpdate is ad-hoc constructed and executed.

  I could not find it anywhere explicitly spelled out, but my best
  guess is that the reason for this is to make sure that if the page
  in question contains wikitext that trancludes a different page based
  on the current date and time (such as how most Wikipedia main pages
  transclude news information and "Did you know" information based on
  dated subpages that are prepared in advance), then we don't just
  want to re-render the page after a day has passed, we also want to
  re-do the links update to ensure the search index, category links,
  and "WhatLinksHere" is correct, and thus by extent, to make sure
  that cascading protection from the main page does in fact apply
  to the "current" set of subpages and templates actually in-use.

* 2007 (r19227; 0c0c0eff81)

  This adds an optimisation to the added logic that limits it to
  pages that satisfy `mTitle->areRestrictionsCascading()`.

  Thus for most articles, which aren't protected at all, we don't
  run LinksUpdate mid-request after a cache miss page view.

  Because of this commit, the pre-2007 status quo remained unaltered
  and has remains unaltered to this very day: We don't re-index
  categories and WhatLinksHere etc, unless an article edit or
  propagating template edit takes place.

* 2009 (r52888; 1353a8ba29)

  Introduces the PoolCounter feature.

  The logic in question moves to Article::doCascadeProtectionUpdates().

* 2015 (Iea952d4d2e66; df5ef8b5d7).

  The logic in question is changed, motivated by wanting to avoid
  DB writes during page views.

  * Instead of executing LinksUpdate mid-request, we now queue a
    RefreshLinksJob on the JobQueue, and utilize a newly added
    `prioritize => true` parameter.

  This commit also introduces a new feature, which is to queue
  RefreshLinksJob also for pages that do not have cascading
  protection, but that do satisfy a new boolean method
  called `$parserOutput->hasDynamicContent()`, which is set when
  the Parser encounters TTL-reducing magic words and functions
  such as {{CURRENTDAY}} and {{#time}}. For this new case, however,
  the `prioritize` parameter is not set, and this feature is disabled
  in WMF production (and other farms that enable wgMiserMode).

  This commit also renamed doCascadeProtectionUpdates()
  to triggerOpportunisticLinksUpdate().

  This commit also removed various documentation comments, which
  I've partly restored in this patch, the patch you're looking at
  now.

== Actual changes ==

* Rename hasDynamicContent() to hasReducedExpiry() and keep the
  previous method as a non-deprecated wrapper.

  This change is motivated by T280605, in which I intent to make use
  of a Parser hook that reduces the cache expiry. There are numerous
  extensions in WMF production that already do this, and thus the
  assumption that these have "dynamic content" is already false in
  some cases. I'm not yet sure how or if to refactor this so to allow
  reducing of the TTL *without* causing this side-effect, but as a
  first step we can make the method more obvious in its impact
  and behaviour.

  I've also updated two of the callers that I think will benefit from
  this more explicit name and (current) implementation detail.

Bug: T280605
Change-Id: I85bdff7f86911f8ea5b866e3639f08ddd3f3bf6f
2021-05-05 02:03:30 +01:00
Umherirrender
76126158cb Fix CacheTime::getCacheExpiry for php8
CacheTime::mCacheTime can contain the empty string,
which makes it fail on php8

PHP 8 changes the handling for string and int comparison.
These non-numeric strings are no longer silently converted to int 0,
which previously allowed for the comparison to become false without
actually checking against non-integer values.
https://wiki.php.net/rfc/saner-numeric-strings

Bug: T248925
Change-Id: Idecd3a5cd41fc2d54968db4b02787fe2a81af9d2
2021-02-01 20:05:54 +00:00
Petr Pchelko
2010a912c2 CacheTime: remove mVersion field
Has to be merged at least one train after the parent patch.

Bug: T269393
Change-Id: Iee98950ad0452a50088e755252da8468f0bec1ae
2021-01-04 10:29:52 -06:00
Petr Pchelko
b56a3c0d23 CacheTime: Remove the version check.
Fot the sake for forward compatibility, first we need
to remove the check for version in case of a train rollback.

Bug: T269393
Change-Id: Ic7011e20a23e8ad99eb872b050e97baf1ef5c6a2
2020-12-14 19:29:24 -06:00
Daniel Kinzler
48172f794d Revert "Hard-deprecate all public property access on CacheTime and ParserOutput."
This reverts commit b1a30eb0c4.

Reason for revert: T269396

Bug: T269396
Change-Id: I374ca13ccc30418b8fe3bf98f5090f7643aac4d7
2020-12-04 11:47:55 +00:00
Petr Pchelko
b1a30eb0c4 Hard-deprecate all public property access on CacheTime and ParserOutput.
Bug: T263851
Change-Id: I3d3ff7b5b6899150df836e445b56896dfd5b887e
2020-11-19 10:12:41 -07:00
Petr Pchelko
b956c77d27 Merge CacheTime and ParserOutput accessedOptions properties
Change-Id: I5785596d68e8923f8bcbd182ace0b1991bd75c9a
2020-11-19 10:12:39 -07:00
Petr Pchelko
7c68ae9296 Safe ParserOutput extension data and JsonUnserializable helper.
One major difference with what we've had before is that now we
actually write class names into the serialization - given that
this new mechanism is extencible, we can't establish any kind
of mapping of allowed classes. I do not think it's a problem
though.

Bug: T264394
Change-Id: Ia152f3b76b967aabde2d8a182e3aec7d3002e5ea
2020-11-10 11:21:09 -07:00
Petr Pchelko
017cfcf016 Forward-compat for merging CacheTime and ParserOutput mOptions
CacheTime::mUsedOptions and ParserOutput::mAccessedOptions
do exactly the same thing and has to be merged into a single property.
This patch adds forward-compatibility and needs to be deployed
at least one train before the patch which actually merges the properties.

Change-Id: Ic9d71a443994e2545ebf2a826b9155c82961cb88
2020-11-10 07:09:41 -07:00
daniel
600f64029f Use JSON for parser cache
This adds JSON serialization and deserialization capabilities
to CacheTime and ParserOutput.

NOTE: JSON serialization is disabled for now. Merging this patch
should not change behavior in production.

Bug: T263579
Change-Id: I18187e8bce573d21f6f1bd29106e07c63a6d2f4d
2020-10-13 16:28:52 -07:00
Petr Pchelko
13574e8404 Deprecate ParserCache::getKey and replace it with getMetadata
Bug: T263689
Change-Id: I4a71e5a7eb1c25cd53b857c115883cd00160736b
2020-10-13 08:31:22 -07:00
Ppchelko
3254e41a4c Revert "Revert "Revert "Hard deprecate all public properties in CacheTime and ParserOutput"""
This reverts commit deacee9088.

Bug: T264257
Change-Id: Ie68d8081a42e7d8103e287b6d6857a30dc522f75
2020-10-01 12:03:41 -06:00
jenkins-bot
da3270feac Merge "Hard-deprecate passing -1 to CacheTime::setCacheTime" 2020-09-28 18:25:11 +00:00
Petr Pchelko
b21adfc7f8 Allow back getting/setting dynamic properties on ParserOutput.
Followup on Ic911c2724ad709931d3316e609781fb89b5b7b28

Bug: T263851
Change-Id: I6a3b8d43d9727e49f245bddf3b8380541ed4153a
2020-09-25 08:17:10 -07:00
Ppchelko
deacee9088 Revert "Revert "Hard deprecate all public properties in CacheTime and ParserOutput""
This reverts commit a4dc6d82af.

I've reverted the merged patch since I didn't do enough testing
on serialized/reserialized ParserOutput and CacheTime. Now I'm
confident serialization/deserialization works.

Changes since original reverted version:
 - Use __get/__set instead of DeprecationHelper in order to
   avoid $deprecateProperties array to be serialized.
 - Add test for old format serialization new format deserialization.

Change-Id: Ic911c2724ad709931d3316e609781fb89b5b7b28
2020-09-24 07:55:18 -07:00
Petr Pchelko
6a5eb040c7 Hard-deprecate passing -1 to CacheTime::setCacheTime
I've been trying to find how -1 can actually get to
the cacheTime and could find any usages in core or
extensions. The proper way of making ParserOutput
uncacheable is to use updateExpiry( 0 ), that is
documented and has some warning about performance costs.
Setting the cacheTime to -1 seems to be an undocumented
feature (it is mentioned in comments as undocumented)
that doesn't seem to be used anywhere anymore.

I intend to remove it entirely after the deprecation is
deployed and we so not see any warnings for a few weeks.

Change-Id: Ie90b7e4a21faae726940fa9082f2e6a6ea8df613
2020-09-23 19:48:51 -07:00
Ppchelko
a4dc6d82af Revert "Hard deprecate all public properties in CacheTime and ParserOutput"
This reverts commit 799c10b7eb.

Reason for revert: Didn't test how this would work with deserializing stored ParserOutput.

Change-Id: I4221bc26282f3b4bd044f0ab50d00e77eb57ede0
2020-09-23 22:46:33 +00:00
Petr Pchelko
799c10b7eb Hard deprecate all public properties in CacheTime and ParserOutput
* In preparation for ParserCache/Parsoid integration, it's nice to
  do some cleanups. Will untie our hands a bit more.
* Verified no usages in extensions deployed at wikimedia, other then
  Flow, fixed in the dependent patch.

Change-Id: Idd78413a36887e2ff5c902d410e55691cafb736b
2020-09-23 07:17:13 -07:00
daniel
414215ccac ParserOutput::getCacheTime should stay the same after the first call.
Previously, getCacheTime would default to the current time, potentially
causing the return value to change over subsequent calls. With this change,
the value is determined on the first call, and then remembered for subsequent
calls.

Bug: T205464
Change-Id: If240161c71d523ad5b0d33b9378950e0bebceb6e
2018-10-04 13:08:56 +02:00
Thiemo Kreuz
e6b6920cff Fix PHPDoc type hints in CacheTime, ParserOptions, and related
I'm intentionally not touching any code in this patch, only
documentation.

Change-Id: I6975194c218760031789d5335dfbb330017dc6fc
2018-04-18 15:10:31 +00:00
Aaron Schulz
7d42e96748 Deprecate Parser::disableCache
Few maintained extensions still rely on this and it is
bad practice to use this for handling cache correctness.

Change-Id: I2de481198bbff5c4f3dd81fc6d1b137e4c37b93f
2016-06-18 19:55:43 +00:00
Aaron Schulz
0fc6c8b592 Remove buggy b/c logic in Parser::disableCache()/updateCacheExpiry()
* Setting mCacheTime to -1 is for old callers that
  only check getCacheTime() instead of getCacheExpiry().
  Most of them are already broken (WikiLog/SemanticForms) as
  they check for -1 which is in fact never returned
  due to the TS_MW conversion in Parser::getCacheTime.
* By using -1, the value of page_links_updated can end up
  as 1969, which is confusing and broken.

Change-Id: I8809a4258eacff05992a2c27ade7f6a0c1731c51
2015-10-23 12:35:43 -07:00
Amir E. Aharoni
bd30ccd795 Make lines shorter to pass phpcs in some files under includes/parser
This doesn't fix all the files under includes/parser -
some of them deserve their own patches.

Bug: T102614
Change-Id: I2fcbc19ee337e1b7db4635b5e5f324c651b4d144
2015-09-26 18:19:11 +00:00
Aaron Schulz
6b0163391b Avoid parser cache miss that often occurs post-save
* This should not happen as doEditContent() saves the parser cache,
  so only the rare casing if incompatible options should have misses
* The bug could also cause post-save misses with edit stashing
* Avoid the second page parse post-redirect by making sure cache
  timestamps match up instead of calling time() at several points
* Likewise for null edits, which used a different code path
* Removed redundant purge in onArticleCreate() as the new row sets _touched
* Removed pointless purge in onArticleDelete() as there is no row to update
  (the method no-ops in that case to avoid contention already)

Change-Id: I178fe334a3f8691ffd9452bec30561a0c5d37c6c
2015-06-09 01:01:03 +00:00
Aaron Schulz
4111ff0dc3 Removed obsolete "containsOldMagic" code
Change-Id: Id225347e0599a6f79b30b0793cce7d97daed46f2
2015-02-15 14:41:49 -08:00
Yuri Astrakhan
573b1194b8 Minor spelling comment fix
Change-Id: Ic56f4e73e56e6dca4825c93b0a95f4d9de835fd4
2014-12-14 09:41:46 +00:00
addshore
61c989cfc0 Fix phpcs issues in parser
This fixes all issues except for:
 - class names
 - line length

Change-Id: Ie91b010d5b3eec49d3b80b6e93b125a901ef43c6
2014-08-12 01:00:15 +00:00
Ori.livneh
df983f6642 Revert "Declare visibility on class properties of includes/parser/"
See https://bugzilla.wikimedia.org/65375#c4

This reverts commit f359cdf614.

Bug: 65375
Change-Id: I12a60b5cc52a07a6deabcbf47c7c99cd2faac3c3
2014-05-16 00:52:24 +00:00
Siebrand Mazeland
2527cca6de Fix most CodeSniffer issues in includes/parser/
Remaining are the classes containing underscores and possibly a few other
issues that will be addressed soonish.

Change-Id: Icf56374c71afc134420ebbcfecf12dcb29dc9564
2014-05-11 08:44:52 +00:00
Siebrand Mazeland
f359cdf614 Declare visibility on class properties of includes/parser/
Change-Id: If03a9bd5eb83be4d15f54e73f49f42540fb7d5fc
2014-05-11 02:25:00 +02:00
umherirrender
7f9fd63901 Fixed some @params documentation (includes/parser)
Swapped some "$var type" to "type $var" or added missing types
before the $var. Changed some other types to match the more common
spelling. Makes beginning of some text in captial.
Also added some missing @param.

Change-Id: I49f8f48b521878de7abd9cc40efdeff6cf9a37e0
2014-04-22 01:38:39 +02:00
umherirrender
23fab68274 Fix spacing after @param and friends in comments
Searched for:
\@(param|return|throws|since|deprecated|access|todo|var)[ \t]{2,}

Change-Id: Icce22ba9fe0635455691ca58d9872d618151f346
2014-04-05 20:02:29 +00:00
Brad Jorsch
78aad9802d Include parsed revision ID in parser cache
One theory for what's behind bug 46014 is that the vandal submits the
edit, then someone (maybe the vandal) gets into the branch of
Article::view that uses PoolWorkArticleView, then ClueBot comes along
and reverts before the PoolWorkArticleView actually executes. Once that
PoolWorkArticleView actually does execute, it overwrites the parser
cache entry from ClueBot's revert with the one from the old edit.

To detect this sort of thing, let's include the revision id in the
parser cache entry and consider it expired if that doesn't match. Which
makes sense to do anyway.

And for good measure, let's have PoolWorkArticleView not save to the
parser cache if !$isCurrent.

Bug: 46014
Change-Id: Ifcc4d2f67f3b77f990eb2fa45417a25bd6c7b790
2014-04-01 12:15:34 -04:00
umherirrender
10b1ed4d22 Format functions in CacheTime
The function body should stay on it's own line

Change-Id: I1651ab2520ae278dd72a2f28718151280ddbba54
2013-12-30 22:00:22 +01:00
Aaron Schulz
48a77e1d83 Avoid parsing more in refreshLinksJobs
* This reuses the parser cache in some cases when possible
* Clarified the return value of CacheTime::getCacheTime()
* A few documentation tweaks

Change-Id: I80b7c6404b3f8c48b53c3bba96115dbf94d80873
2013-11-27 22:43:00 -08:00
Siebrand Mazeland
3f968db2cc Update some documentation in CacheTime and ParserCache
Change-Id: I31be0d4639f2a7189e15b622b34595564fad2a3d
2013-11-17 20:25:37 +00:00
umherirrender
6c38a5eb72 Fixed spacing in logging/parser/profiler/rl/revdel/search folder
Added spaces before if, foreach
Added some braces for one line statements

Change-Id: I11bbcfa351e945b7bde10c2105d61a3cf5622205
2013-04-20 17:38:24 +02: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
Alexandre Emsenhuber
d3e0168c67 Added missing GPLv2 headers in new files.
Also improved file documentation.

Change-Id: Ia5a383110769cf51603305dc639616d904ebbab2
2012-09-01 21:56:38 +02:00
jeroendedauw
df8245ba25 Split CacheTime into its own file
Change-Id: Iaa546fc5a30dad4bc0a0dbd0dc18dd2e05bf9d7f
2012-08-06 16:18:02 +02:00