Commit graph

173 commits

Author SHA1 Message Date
jenkins-bot
7ece0e7afd Merge "Title: Make use of BacklinkCacheFactory service" 2021-09-10 14:31:23 +00:00
jenkins-bot
1efeefe017 Merge "PageStore: Use LinkCache" 2021-09-09 20:04:47 +00:00
jenkins-bot
150a589ecf Merge "Title: restore behavior of getCascadeStrictionSources" 2021-09-09 19:41:48 +00:00
Derick Alangi
db43511e6a Title: Make use of BacklinkCacheFactory service
Change-Id: I48161585de6f329ec4037156234e0b07b3b837e6
2021-09-09 14:04:02 +01:00
Derick Alangi
7d12da5595 tests: Extract pure unit tests from TitleTest integration test
-> Fixed TODOs such as adding test cases for namespaces that are
   not in `$wgNamespacesWithSubpages` in `testGetSubpageText()`.

-> Re-arranged provider methods to come before the test case as
   already in the files for consistency.

Change-Id: Ice2b3a07ea2ddd20417cbe87da93065e1812619e
2021-09-08 17:59:59 +01:00
Derick Alangi
043c2d5589 tests: Merge test cases of TitleMethodsTest into TitleTest
Change-Id: I31bfd91f393f7f69335687a4e7ca830f4831e2f3
2021-09-08 17:59:59 +01:00
daniel
abc2179820 Title: restore behavior of getCascadeStrictionSources
The behavior of getCascadeStrictionSources was changed by Ia73ea587586cb69eb5
to conform to the documented behavior: it would always return false as the
first element of the return value if there were no cascading restriction sources,
as specified in the documentation.

Hopwever, the previous behavior was to return an empty array in that
case, unless the $getPages parameter was false. That behavior seems more
senible, and there is existing code that relies on it.

This patch restores the previous behavior and updates the documentation
instead.

Bug: T218395
Needed-By: I31ca0a8987f9694bc3b312a48c2c111ceda6fa3e
Change-Id: I1f24703b80566220ac6fe8ee500e838ed7fd29af
2021-09-08 17:22:17 +02:00
Derick A
7ebf05256a tests: Cover more methods in the Title::class (increase code coverage)
The methods that have been covered in this patch are listed below:
~ Title::hasFragment()
~ Title::getFragment()
~ Title::setFragment()
~ Title::isMainPage()
~ Title::equals()
~ Title::getPrefixedURL()
~ Title::prefix()
~ Title::__toString()
~ Title::getFullText()

Bug: T241406
Change-Id: I51ffadb52e7eef822e9e619e5132513dc1501f9b
2021-09-07 13:58:38 +00:00
Derick A
18bfc1e0c3 tests: Cover more methods in the Title class
The methods covered are listed below:
~ Title::getNsText()
~ Title::getSubjectNsText()
~ Title::getTalkNsText()
~ Title::isSpecial()
~ Title::isTalkPage()
~ Title::getBacklinkCache()
~ Title::isSubpageOf()
~ Title::isSubpage()
~ Title::getEditURL()

Change-Id: Iae73d0837134964b82dddfc0f941c6abea8a1e1f
2021-09-02 19:24:18 +01:00
daniel
3b6345ca16 PageStore: Use LinkCache
This makes the data stored by LinkCache compatible with PageStoreRecord,
so we can use LinkCache inside PageStore.

This causes PageStore to make use of local caching as well as WANObjectCache.

Note that getPageById() does not yet benefit from cache, but does
populate the cache.

Bug: T278940
Change-Id: Icc27a0d9299a3e4ce45521daef87ad06ec06f064
2021-09-01 08:24:34 +00:00
Aryeh Gregor
cf818256fb New RestrictionStore service
This allows checking restrictions without a dependency on Title, based
only on a PageIdentity.

Additional fixes along the way:

* Correctly return false instead of 'infinity' for
  getRestrictionExpiry( 'create' ) on an existing page
* Correctly handle non-special pages that can't exist (like media pages)
  in listApplicableRestrictionTypes() (return empty array instead of
  'create')
* Improve readability of isProtected()

The expectation change in TitleTest::testIsProtected() is because the
test was formerly broken, since it set mRestrictions without setting
mRestrictionsLoaded. (Which illustrates how this approach to testing is
essentially broken.)

Co-authored-by: Vedmaka <god.vedmaka@gmail.com>
Bug: T218395
Change-Id: Ia73ea587586cb69eb53265b2f8f7a296a2573dd0
2021-08-28 16:01:06 +00:00
Umherirrender
134045b9aa tests: Swap assertion order in unit tests
Changes from patch set Icb93c79f4843b59dae80d3eda1a880457a1a68f2
Also some swaps from assertEquals to assertSame/True/False/Null

Change-Id: Ife497ae6cb1888b77eb25e85b76df72adc65641a
2021-08-04 20:21:01 +02:00
Aryeh Gregor
b19db60c70 Hard-deprecate Title::isNamespaceProtected
No callers, deprecated in 1.34.

Change-Id: If2e1c762f91e3c8255fbb58b7c9f01e8929a7fa2
2021-07-29 17:15:33 +03: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
DannyS712
7b556a5761 Move some Title tests to unit tests
Tests for the following methods don't need integration:
- legalChars()
- convertByteClassToUnicodeClass()
- newFromTitleValue()
- newFromLinkTarget()
- castFromLinkTarget()

Change-Id: I2ec6505088c74a90da9d0b8305ce94d81cc0562a
2021-07-09 23:18:57 +00:00
DannyS712
809798bd6d TitleTest::provideCastFromPageReference() remove unused $fake
Change-Id: I2d5b51a291cdfefcaaf8cf07de155a890e72a677
2021-07-05 07:14:29 +00:00
DannyS712
b45ddb2ab3 Use WikiPage::doUserEditContent() instead of ::doEditContent()
Results in passing a user where previously the fallback
to $wgUser was being used, mostly in tests.

Bug: T255507
Change-Id: Iabe24315b23c0ad1272353186425e71974528d23
2021-06-28 00:11:30 -07:00
Petr Pchelko
695e61ce14 Clean up hard deprecated Title methods
Depends-On: If27bb6b5142d09bc9293d080e97b6642462219f4
Change-Id: I37f012e53d1c881292a19aac87eb107636c6bfbe
2021-05-11 07:41:18 -07:00
DannyS712
31676abea5 Add DummyServicesTrait::getDummyInterwikiLookup
Replacing the mock InterwikiLookup used in
MediaWikiTitleCodecTest revealed that that test was,
because of the mock not behaving correctly, testing the
wrong thing - interwiki prefixes are *not* case sensitive,
and are always converted to lowercase in the actual
ClassicInterwikiLookup. Fixed those expectations.

Change-Id: I242431e88860b7700a9f93f77a0fe195fd748800
2021-05-05 10:57:59 -07:00
jenkins-bot
ca96e2c575 Merge "Hard deprecate Title::isWatchable()" 2021-04-30 18:51:14 +00:00
Cindy Cicalese
ca328d272f Hard deprecate Title::isWatchable()
Bug: T281497
Depends-On: I271960cbbbbb5db73aae36414a4c18c14940b6e1
Depends-On: I0f7a82191eae8edd4c0c1d16d89c81e601ae5c80
Change-Id: Ibb83ac71fc2214dcc71f73f009d137a2e5c80d0d
2021-04-29 14:43:00 -04:00
James D. Forrester
df5eb22f83 Replace uses of DB_MASTER with DB_PRIMARY
Just an auto-replace from codesniffer for now.

Change-Id: I5240dc9ac5929d291b0ef1c743ea2bfd3f428266
2021-04-29 09:24:31 -07:00
Thiemo Kreuz
b95a07380a Remove meaningless ->expects( $this->any() ) from all tests
It is not entirely meaningless. It might be an indicator that
the number of calls to a method is intentionally unlimited.
This is similar to e.g. an @inheritDoc PHPDoc comment that
marks a method as being "intentionally undocumented".

However, what's the meaning of being "intentionally
unconstrained"? Let's just not have any constraint then.

I feel all these ->expects( $this->any() ) bloat the test
code so much that it's never worth it.

Change-Id: I9925e7706bd03e1666f6eb0b284cb42b0dd3be23
2021-04-23 11:58:58 +02:00
jenkins-bot
37ab31298c Merge "Remove $actor field from UsererIdentityValue" 2021-04-14 14:40:12 +00:00
daniel
5faa080374 Introduce PageReference
This explores the idea of a PageReference type which represents a
namespace/dbkey pair.

Every ProperPageIdentity is a PageReference. Some LinkTargets can be
mapped to a PageReference.

Bug: T279522
Change-Id: Id8b0c781fce329adcc4770f4840b2ba0108f6898
2021-04-13 23:32:20 +02:00
daniel
fed7f0b179 Remove $actor field from UsererIdentityValue
Code that needs to store an actor ID in the database to
represent a UserIdentity, or needs to construct a UserIdentity based on
an actor ID loaded from the database, should use the ActorNormalization
service.

Note: The getActorId() method is removed from the UserIdentity interface,
but all concrete classes continue to support it for now.
UsererIdentityValue::getActorId() is hard deprecated and should
be removed in 1.37. It always returns 0.
User::getActorId() is not deprecated at this point.

Bug: T274179
Depends-On: Id2b3ddf6a2a7cdf90f8936a69148d2cce6fde237
Change-Id: I9925906d11e47efaec3c1f48d5cb3f9896a982c1
2021-04-13 18:18:06 +00:00
jenkins-bot
bee15a1689 Merge "title: Fix Title::findSubpageDivider() destroying certain strings" 2021-03-31 07:49:07 +00:00
Petr Pchelko
877720d7b4 Make Title::isWatchable more strict
We can't really watch invalid titles, since they
definitely can not exist in the database, so having
them in user watchlist doesn't make much sence either.

Bug: T278735
Change-Id: I411ca9227da8050d026a57db690824afd3423a89
2021-03-30 15:51:55 -06:00
jenkins-bot
0949c7ac20 Merge "WikiPage: don't record bad redirects." 2021-03-25 17:10:22 +00:00
daniel
935c10f86c WikiPage: don't record bad redirects.
Bad redirects in the database led to fatal errors when attempting to
resolve the redirect when visiting the page. This patch does three
things to address this:
* change Title::isValidRedirectTarget to actually check whether the
target is a valid title.
* change WikiPage::recorddRedirectEntry to reject invalid redirect
targets
* change WikiPage::getRedirectURL to ignore invalid redirect target
that may be present in the database.

Bug: T278367
Change-Id: Ib17ebfb99fa17b846302438c675a968a1ec0f488
2021-03-24 22:15:22 +00:00
daniel
d4b380ab27 Introduce PageSelectQueryBuilder
Change-Id: Ibcb37affa9ba1c891bc62964a3dd34b67214cfa1
2021-03-24 19:15:01 +01:00
DannyS712
a48bb43b55 Add more tests for creating Title objects
Bug: T241406
Change-Id: I4733fbb9765dc43f7b8d8fbe64a46877f6cde04f
2021-03-07 19:16:07 +00:00
Peter Ovchyn
7d8bf01855 Clean up Title deprecated methods of mediawiki core
This patch hard-deprecates the following methods,
that are overdue for hard deprecation:

- ::getPreviousRevisionID
- ::getNextRevisionID
- ::getFirstRevision
- ::getEarliestRevTime

Also, it removes the following methods:
- ::countRevisionsBetween
- ::getAuthorsBetween

Bug: T274151
Change-Id: If022b907652efdad84180476649a612059c6ef18
2021-02-28 21:08:11 +02:00
Umherirrender
a1de8b8700 Tests: Mark more more closures as static
Result of a new sniff I25a17fb22b6b669e817317a0f45051ae9c608208

Bug: T274036
Change-Id: I695873737167a75f0d94901fa40383a33984ca55
2021-02-09 02:55:57 +00:00
Umherirrender
62002cdcf1 build: Update mediawiki/mediawiki-codesniffer to 35.0.0
Change-Id: Idb413be4b8cba8611afdc022af59810ce1a4531e
2021-01-31 13:34:38 +00:00
daniel
10ccdb2281 Define equality for PageIdentity and LinkTarget
Bug: T272420
Change-Id: I2e0eb21989e2d733088ab77d7461bf003c2905eb
2021-01-19 23:07:37 +00:00
James D. Forrester
a8fe6c9841 Revert "Define equality for PageIdentity and LinkTarget"
This reverts commit 36f1adf670.

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

Bug: T272170
Change-Id: I26c6fd656c75a6b209fb17965dc9109edf68642b
2021-01-15 12:30:14 -08:00
daniel
36f1adf670 Define equality for PageIdentity and LinkTarget
This allows Title and WikiPage objects to be compared with PageIdentity
and LinkTarget instances consistently.

Change-Id: I1bbd15d17d046359393ecfc1acd2778273260a95
2021-01-15 17:53:28 +01:00
daniel
1a60008a9a Introduce PageIdentity interface
PageIdentity is intended as a lightweight alternative to Title,
similar to LinkTarget, but providing a page ID. It follows the precedent
of UserIdentity.

Bug: T208776
Change-Id: Iaed4871e0d32c67d4fb13e487625527f6a21e9c5
2021-01-14 13:18:05 -06: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
C. Scott Ananian
3d40c43b1f Deprecate InterwikiLoadPrefix hook
The InterwikiLoadPrefix hook isn't compatible with Parsoid, as it is
unidirectional and doesn't support enumerating all valid prefixes
(T270444).  Set/reset $wgInterwikiCache to mock the interwiki table
for parserTests and other unit tests instead.

This is a soft deprecation, as the used-in-production
Extension:Interwiki still uses InterwikiLoadPrefix, although not in a
way that would break Parsoid (since $wgInterwikiCache is set in
production).

Bug: T270444
Change-Id: If2507017c99c4ee42c104a0890bc45a84d7239d5
2020-12-21 19:28:48 +00:00
DannyS712
3503537452 TitleTest::testIsWatchable should call isWatchable
Instead of ::canHaveTalkPage
Likely a copy-paste error

Change-Id: I46c0ebd6267f8631907c011bca525572313154c1
2020-12-21 11:44:10 +00:00
Reedy
24a33520fe Correct position of $expected and $actual in TitleTest::testGetCascadeProtectionSources()
Change-Id: Ie72832ea6d672607c1e67ebf52601892af196ab2
2020-10-03 18:23:00 +01:00
DannyS712
eea7e16df4 Remove deprecated title permissions functions
Title::userCan, ::quickUserCan, and ::getUserPermissionsErrors, hard deprecated in 1.35

Bug: T246138
Change-Id: Iee990a16c15bd827cf631fb5ff683367082d2ebe
2020-08-26 21:21:11 +00:00
Thiemo Kreuz
ea7397e071 title: Fix Title::findSubpageDivider() destroying certain strings
This helper method was introduced in I3d8c6f6. I found this bug while
working on I0a5be39. The method was cutting off strings like "/subpage"
into "ubpage".

I made sure no existing test case changed, as you can see.

I also tried to document the basic idea:

The first character can never be a subpage divider, even if it is a
slash, because this would result in an empty base. The code tries to
skip initial slashes and use the first non-empty substring as the base.
However, if there is nothing but slashes, the worst-case fallback is
to use the first slash as if it is the base.

I think there are still 2 different ways to split the following
edge-cases:
* "//foo" could become:
  a) base "/" + divider + subpage "foo", or
  b) base "//foo" with NO subpage.
* "//" could become:
  a) base "/" + divider + empty subpage, or
  b) base "//" with NO subpage.

Personally, I would pick b). But there was a test case already that
forced me to stick to a).

Bug: T229443
Change-Id: I4914b57c81ce6c7fdf10746f0da902c65f0ac2c9
2020-07-28 12:49:55 +02:00
Daimona Eaytoy
719e185357 title: Make getSubpageText() return the title text if there's no subpage
This is for consistency with the previous behaviour.

Follow-up: I3d8c6f6ffc4234ac938a39f5cc55691d62e1d7ac

Bug: T256922
Change-Id: I0928f85c862d3b2baf49317a206ca140a1ab3c16
2020-07-02 00:08:51 +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
daniel
03397e46c5 Title: fix subpage split for degenerate cases
This ensures that getBaseText and getRootText always
return a valid title, even for degenerate cases like "/" or
"//foo//bar//baz//".

Bug: T229443
Change-Id: I3d8c6f6ffc4234ac938a39f5cc55691d62e1d7ac
2020-06-22 12:58:29 +02:00
Reedy
229b2c15e8 Fix a plethora of class and function call case mismatches
Bug: T231412
Change-Id: I597a25de3294a6673424f30475760280ef209a8a
2020-05-26 14:14:46 +01:00
Reedy
12a3883a7b Fix SingleSpaceBeforeSingleLineComment
Change-Id: I285af438ce484af40741489797f20455726ec110
2020-05-11 00:57:11 +00:00