Commit graph

26 commits

Author SHA1 Message Date
David Causse
ce511406e0 ParserCache: add an option to explicitly trigger links update
Triggering an opportunistic LinksUpdate on every cache miss of the
current revision might not be appropriate in some cases.
Some functions like ContentHandler::getParserOutputForIndexing might
be called after all LinksUpdates but if these functions do explicitely
disallow populating the parser cache via OPT_NO_UPDATE_CACHE we might
enter a case where involved jobs would trigger themselves forever.

It is happening in the case of the CirrusSearch extension that listens
to LinksUpdate and is relying on
ContentHandler::getParserOutputForIndexing to fetch the parser output.

Introduce a new option ParserOutputAccess::OPT_LINKS_UPDATE to be
more intentional on whether such cascading LinksUpdate might occur
or not on cache misses.

Change the default to not trigger a LinksUpdate on every cache miss
and enable it only when rendering the article view (Article::view).
It does not seem ideal that this behavior is owned by the ParserCache
and further refactoring might be needed to separate these concerns.

Bug: T329842
Change-Id: Ib3c3ca935f316ea880ff6c6b393fa80166e42bd3
2023-05-16 11:32:55 +02:00
Tim Starling
5e30a927bc tests: Make some PHPUnit data providers static
Just methods where adding "static" to the declaration was enough, I
didn't do anything with providers that used $this.

Initially by search and replace. There were many mistakes which I
found mostly by running the PHPStorm inspection which searches for
$this usage in a static method. Later I used the PHPStorm "make static"
action which avoids the more obvious mistakes.

Bug: T332865
Change-Id: I47ed6692945607dfa5c139d42edbd934fa4f3a36
2023-03-24 02:53:57 +00:00
James D. Forrester
ad06527fb4 Reorg: Namespace the Title class
This is moderately messy.

Process was principally:

* xargs rg --files-with-matches '^use Title;' | grep 'php$' | \
  xargs -P 1 -n 1 sed -i -z 's/use Title;/use MediaWiki\\Title\\Title;/1'
* rg --files-without-match 'MediaWiki\\Title\\Title;' . | grep 'php$' | \
  xargs rg --files-with-matches 'Title\b' | \
  xargs -P 1 -n 1 sed -i -z 's/\nuse /\nuse MediaWiki\\Title\\Title;\nuse /1'
* composer fix

Then manual fix-ups for a few files that don't have any use statements.

Bug: T166010
Follows-Up: Ia5d8cb759dc3bc9e9bbe217d0fb109e2f8c4101a
Change-Id: If8fc9d0d95fc1a114021e282a706fc3e7da3524b
2023-03-02 08:46:53 -05:00
daniel
dc26cc92d3 Parsoid: trigger cache warming on page view
The cached parsoid output of a page may have been invalidated by
RefreshLinksJob. In that case, we want to trigger an async parsoid
rendering of the page when a user requests it for viewing.

Bug: T327164
Change-Id: I1e63b69cba5f56b001ca2fcad1d0805ca6dd2d39
2023-01-23 13:09:16 +01:00
xiplus
bde49b2153 Article: Fix missing patrol link for pages that have been moved
No need to check if the namespace is the same. There are many articles
moved from draft or user space.

Bug: T162871
Change-Id: Ide73adf356df2047ee821d2a3680c9c163e564a9
2022-10-21 22:13:14 +00:00
Derick Alangi
40c1f56dcc page: Change visibility of some WikiPage members to protected
After surveying consumers of these members, apart from the WikiPage
class itself that uses it internally and FlagabbleWikiPage in the
FlaggedRevs ext which subclasses WikiPage, I don't see any other
consumers of this member.

So it can be safely marked as protected as we're sure nothing is
consuming this publicly.
See: https://codesearch.wmcloud.org/search/?q=%5C-%5C%3EmDataLoaded&i=nope&files=&excludeFiles=&repos=,
https://codesearch.wmcloud.org/search/?q=%5C-%5C%3EmPreparedEdit&i=nope&files=&excludeFiles=&repos=,
https://codesearch.wmcloud.org/search/?q=%5C-%5C%3EmLatest&i=nope&files=&excludeFiles=&repos=

NOTE: The tests in ArticleTest.php was removed as the WikiPage::mLatest
      is now a protected member and can't be accessed publicly.

TODO: The last of it's kind is WikiPage::mTitle which will be removed in
      a later patch and that one will be quite bit and tricky.

Change-Id: I78c5b4c31090fe2e01b4cc922ec77131be3223dc
2022-06-16 13:21:34 +01:00
Reedy
6e29611642 Remove or replace usages of "sanity"
Still some more to go...

Bug: T254646
Change-Id: Ia117f01e443c35b4765f3275cab4f2707e1be96f
2021-11-21 16:42:31 +00:00
libraryupgrader
5357695270 build: Updating dependencies
composer:
* mediawiki/mediawiki-codesniffer: 36.0.0 → 37.0.0
  The following sniffs now pass and were enabled:
  * Generic.ControlStructures.InlineControlStructure
  * MediaWiki.PHPUnit.AssertCount.NotUsed

npm:
* svgo: 2.3.0 → 2.3.1
  * https://npmjs.com/advisories/1754 (CVE-2021-33587)

Change-Id: I2a9bbee2fecbf7259876d335f565ece4b3622426
2021-07-22 03:36:05 +00:00
Roman Stolar
dbe594a3ce Replace RecentChange::getPerformer with RecentChange::getPerformerIdentity
Preparing replace in core (DifferenceEngine.php, Article.php, ChangesListSpecialPage.php)

Bug: T276412
Change-Id: I4fd9cbd9404879d082179b68a9993e7203e43a8d
2021-05-27 11:45:17 +03:00
daniel
a4ec04c6df WikiPage: deprecated construction on bad titles
WikiPage represents a page that can be created and edited.
WikiPage should not be constructed on Titles that represent things like
special pages or section links. Any such usage should be deprecated.

Bug: T272424
Change-Id: I03969883fc0b326dd2374d7f8e24c1d5a650d5fa
2021-01-20 14:31:11 +01:00
James D. Forrester
a547ef3b9e Revert "Make WikiPage a ProperPageIdentity"
This reverts commit 8f46ef5ff4.

This has seemingly broken FlaggedRevs and thus a bunch of repos.

Bug: T272170
Change-Id: I67de3dbbbc9163aae937f710ecb0e40db0d483a0
2021-01-15 12:30:30 -08:00
daniel
8f46ef5ff4 Make WikiPage a ProperPageIdentity
This makes it so methods that take a WikiPage can be narrowed to a
PageIdentity, and prepares WikiPage for the introduction of the PageRecord
interface.

Bug: T208776
Change-Id: Iab8bd75a1948873baab9c91c76f966d606b23c0f
2021-01-15 12:34:24 +01:00
DannyS712
6a93b0ca93 More misc test cleanup
* parent::setUp() should be first, and ::tearDown()
  should be last
* Move tests that directly extend PHPUnit\Framework\TestCase
  to /unit

Change-Id: I1172855c58f4f52a8f624e6d596ec43beb8c93ff
2020-12-24 00:52:06 +00:00
Petr Pchelko
890452301d Drop Article::getEmptyPageParserOutput
The only place where this was used is to show the system
message contents on a missing article page in NS_MEDIAWIKI
namespace, which is much easier done without MessageContent.

The override in ImagePage is a guaranteed no-op, cause we can't
have ImagePage for NS_MEDIAWIKI namespace.

These were the only two places where this method was used across
codesearch.

Change-Id: I9b9be61eaff6d153fbd2381c91c598b3421e5ea2
2020-11-15 08:57:24 -07:00
daniel
dc436c3cff Introduce and apply NonSerializableTrait
The NonSerializableTrait prevents object serialization via php's native
serialization mechanism. Most objects are not safe to serialize, and
NonSerializableTrait provides a covenient and uniform way to protect
against serialization attempts.

This patch applies the NonSerializableTrait to some key classes in
MediaWiki.

Bug: T187731
Bug: T259181
Change-Id: I0c3b558d97e3415413bbaa3d98f6ebd5312c4a67
2020-09-28 21:55:49 +02:00
addshore
959bc315f2 MediaWikiTestCase to MediaWikiIntegrationTestCase
The name change happened some time ago, and I think its
about time to start using the name name!
(Done with a find and replace)

My personal motivation for doing this is that I have started
trying out vscode as an IDE for mediawiki development, and
right now it doesn't appear to handle php aliases very well
or at all.

Change-Id: I412235d91ae26e4c1c6a62e0dbb7e7cf3c5ed4a6
2020-06-30 17:02:22 +01:00
Tim Starling
d459add63d Introduce wfDeprecatedMsg()
Deprecating something means to say something nasty about it, or to draw
its character into question. For example, "this function is lazy and good
for nothing". Deprecatory remarks by a developer are generally taken as a
warning that violence will soon be done against the function in question.
Other developers are thus warned to avoid associating with the deprecated
function.

However, since wfDeprecated() was introduced, it has become obvious that
the targets of deprecation are not limited to functions. Developers can
deprecate literally anything: a parameter, a return value, a file
format, Mondays, the concept of being, etc. wfDeprecated() requires
every deprecatory statement to begin with "use of", leading to some
awkward sentences. For example, one might say: "Use of your mouth to
cough without it being covered by your arm is deprecated since 2020."

So, introduce wfDeprecatedMsg(), which allows deprecation messages to be
specified in plain text, with the caller description being optionally
appended. Migrate incorrect or gramatically awkward uses of wfDeprecated()
to wfDeprecatedMsg().

Change-Id: Ib3dd2fe37677d98425d0f3692db5c9e988943ae8
2020-06-22 14:34:39 +10:00
ArtBaltai
b32787cba2 Hard deprecate Article methods proxying to WikiPage
Hard deprecate and rewrite call of proxy methods
Deprecate Article::$mContext. It should become private

Bug: T239975
Change-Id: I92018a02b00fdc0b6cd90dfc77ad27782322f344
2020-04-24 01:02:16 +03:00
Matěj Suchánek
3ce567d8ac Replace Linker::link usage with LinkRenderer in includes
Needs one unit test to become integration again :(

Bug: T149346
Change-Id: I62fc566dfb542939431fd4a135c05e0924c70dbf
2020-01-11 11:20:17 +01:00
Amir Sarabadani
06f645c453 Load GlobalFunctions.php to tests/phpunit/bootstrap.php
That mostly enables testing global functions

Bug: T87781
Change-Id: Ib42c56a67926ebcdba53f4c6c54a5bff98cb77a3
2019-07-14 01:28:07 +02:00
Legoktm
4e35134f7a Revert "Separate MediaWiki unit and integration tests"
This reverts commit 0a2b996278.

Reason for revert: Broke postgres tests.

Change-Id: I27d8e0c807ad5f0748b9611a4f3df84cc213fbe1
2019-06-13 23:00:08 +00:00
Máté Szabó
0a2b996278 Separate MediaWiki unit and integration tests
This changeset implements T89432 and related tickets and is based on exploration
done at the Prague Hackathon. The goal is to identify tests in MediaWiki core
that can be run without having to install & configure MediaWiki and its dependencies,
and provide a way to execute these tests via the standard phpunit entry point,
allowing for faster development and integration with existing tooling like IDEs.

The initial set of tests that met these criteria were identified using the work Amir did in
I88822667693d9e00ac3d4639c87bc24e5083e5e8. These tests were then moved into a new subdirectory
under phpunit/ and organized into a separate test suite. The environment for this suite
is set up via a PHPUnit bootstrap file without a custom entry point.

You can execute these tests by running:
$ vendor/bin/phpunit -d memory_limit=512M -c tests/phpunit/unit-tests.xml

Bug: T89432
Bug: T87781
Bug: T84948
Change-Id: Iad01033a0548afd4d2a6f2c1ef6fcc9debf72c0d
2019-06-13 22:56:31 +02:00
Brad Jorsch
7d93d1d1cd Remove Article static methods deprecated in 1.24
The Article::selectFields(), Article::onArticleCreate(),
Article::onArticleDelete(), and Article::onArticleEdit() methods have
been deprecated in favor of the correponding WikiPage methods since
1.24. Remove them.

Change-Id: I30f3d88f8d28ccaebf5a858058e183112d29a1a7
2017-10-26 12:22:01 -04:00
Reedy
ec6d6762ea Article::getAutosummary() and WikiPage::getAutosummary() were removed
Bug: T145728
Change-Id: I233571658b902c93a148a992ea99eb159551e732
2016-12-03 12:16:41 +00:00
Timo Tijhof
4193700b19 Add missing namespace to @covers comments
PHP_CodeCoverage_Exception:
> Trying to @cover not existing method "SwiftFileBackend::sanitzeHdrs".
> Trying to @cover not existing method "LineFormatter::normalizeException".
> Trying to @cover not existing method "MonologSpi::mergeConfig".
> Trying to @cover not existing method "ProcessCacheLRU::het".
> Trying to @cover not existing method "BitmapHandler::swapICCProfile".
> Trying to @cover not existing class or interface "checkParseSafety".
> Trying to @cover not existing method "Article::__call". (was removed).
> Trying to @cover not existing method "ExtensionProcessor::extracttExtensionMessagesFiles".
> Trying to @cover not existing method "FileContentsHasher::getFileContentHash".

Makes code coverage run fail at the moment. These used to be warnings
in PHPUnit 3.x, but are now hard exceptions in PHPUnit 4.x when requesting
a coverage report.

Change-Id: If7f45ca57fd7d480d35b1414a889398837c0c472
2016-02-23 03:56:49 +00:00
umherirrender
1d8b52fbfd Move Test files under same folder structure where class is (/includes/)
Change-Id: I95f1aa6f0ed2cc3306aa6e588a11f359854315c1
2014-12-16 21:56:44 +01:00
Renamed from tests/phpunit/includes/ArticleTest.php (Browse further)