Commit graph

144 commits

Author SHA1 Message Date
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
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
Timo Tijhof
2f35c3ae67 HtmlCacheUpdater: Add getUrls() method and support selective purging
* Move the Title::getCdnUrls() logic to the new HtmlCacheUpdater service.

* Introduce a runtime option to decide whether this is for a direct
  revision or a cascading LinksUpdate.

Bug: T250261
Change-Id: I514b9052761e0d949234996e97fdef255582df86
2020-04-30 18:16:07 +00:00
Timo Tijhof
f2be921509 title: Remove broken handling of language variant in getCdnUrls()
* This currently produced urls like "index.php?title=…&<langcode>"
  which don't actually do anything. The proper syntax is "variant=langcode".
  These danging variants were nothing but PURGE noise, as random
  as e.g. purging a url like "…&rand123" would have been.

* Regardless of all this, page views with a language variant don't
  actually emit a public cache header right now in MediaWiki, which
  means there is not actually anything to purge from the CDN in the first
  place. Revisiting whether we want to start caching them (and then
  where/when to purge them) is subject of T250511, which can happen
  after this logic is moved to the HtmlCacheUpdater service.

Bug: T250511
Bug: T250261
Change-Id: I497cb2be2e9f16156cf02afeb437bdca1b2cc1fd
2020-04-20 18:55:17 +00:00
Timo Tijhof
2ed2d49aad title: Add unit tests for Title::getCdnUrls()
Bug: T250261
Change-Id: I73c368ab81b62fa7363f4b06438f717822cc06b9
2020-04-17 18:39:53 +01:00
DannyS712
1948049498 Hard deprecate Title::userCan and ::quickUserCan
Bug: T244923
Bug: T244927
Change-Id: I1a064aeb3fc87573af50ae5b14793e750696371d
2020-02-22 01:53:03 +00:00
James D. Forrester
5e9fca47b9 Coding style: Auto-fix MediaWiki.Usage.PHPUnit*
Change-Id: I86fc55a4fc8ceafe368692173211bbcd6d8581d7
2020-01-10 10:17:12 +00:00
Vedmaka
0b20d225ec
Adds missing PHPUnit tests for the following Title methods:
- Title::loadRestrictions
- Title::loadRestrictionsFromRows
- Title::getRestrictions
- Title::getAllRestrictions
- Title::getRestrictionExpiry
- Title::getTitleProtection
- Title::isSemiProtected
- Title::deleteTitleProtection
- Title::isProtected
- Title::isNamespaceProtected
- Title::isCascadeProtected
- Title::getCascadeProtectionSources

Bug: T218395
Change-Id: I124e44af8f90c4a8345201c9973082d7aa97f27e
2019-11-07 23:42:25 +03:00
jenkins-bot
1bc7bc958c Merge "tests: Add explicit return type void to setUp() and tearDown()" 2019-11-01 02:08:24 +00:00
Max Semenik
48a323f702 tests: Add explicit return type void to setUp() and tearDown()
Bug: T192167
Depends-On: I581e54278ac5da3f4e399e33f2c7ad468bae6b43
Change-Id: I3a21fb55db76bac51afdd399cf40ed0760e4f343
2019-10-30 14:31:22 -07:00
Petr Pchelko
e4b7fc3570 Hard deprecate User::isEveryoneAllowed
The method was soft-deprecated in 1.34. It's not used in any WMF
installed extensions or the tarball, so it can be hard deprecated.

Bug: T220191
Change-Id: I2f48d62a8dd3592918a6197168d31a1e08bd2a3e
2019-10-30 11:17:19 -07:00
Max Semenik
665b7758c5 tests: getMock() is deprecated
Bug: T192167
Change-Id: I94a4674103b0946d208ff0c28f260506048cb211
2019-10-22 14:20:25 -07:00
jenkins-bot
05ce3b7740 Merge "Title: make newFromText, isValid, and canExist behave consistently." 2019-10-08 13:54:57 +00:00
daniel
9171cbe4ca Title: make newFromText, isValid, and canExist behave consistently.
This patch fixes the documentation of newFromText and makeTitleSafe to
no longer state incorrectly that any Title they return is guaranteed to
be valid. That has never been true.

It also makes canExist() checks a lot stricter, to match the assumptions
of current callers, namely that the title can exist as a wiki page.

Finally, it replaces several existing calls to isValid() with calls to
canExist().

Bug: T229705
Change-Id: I2a483136ec6acca49afb5eb32cb94616672b8fb2
2019-10-08 11:16:11 +02:00
Amir Sarabadani
440297fa3a Clean up most of b/c for phpunit4
We don't support phpunit4 anymore:
https://w.wiki/9UT

Change-Id: Ia7c932998f1a49af1e322ab9e1dc249b7bd2e8b2
2019-10-06 00:14:35 +02:00
Thiemo Kreuz
e4272518f7 tests: Replace PHPUnit's loose assertEquals(false) with assertFalse()
assertEquals( false, … ) still succeeds when the actual value is 0, null,
an empty string, even an empty array. All these should be reported as a
failure, I would argue.

Note this patch previously also touched assertSame( false ). I reverted
these. The only benefit would have been consistency within this codebase,
but there is no strict reason to prefer one over the other. assertFalse()
and assertSame( false ) are functionally identical.

Change-Id: Ic5f1c7d504e7249002d3184520012e03313137b4
2019-10-04 00:30:36 +00:00
jenkins-bot
f97d13a10c Merge "Title::getTalkPage(): Restore behavior of interwiki-prefixed & fragment-only titles" 2019-09-16 23:16:16 +00:00
Aaron Schulz
a5c7fd0db2 Move callers away from Title::GAID_FOR_UPDATE
These callers just need to load some data from DB_MASTER.
Subsequent code needing that latest title data should also use the
required flags, rather than relying on flakey global cache state.

Change-Id: I53248ea4b5bf1cd953f956c41b8244831ec5ef04
2019-09-09 13:19:08 -07:00
daniel
53ef1fa67b Title::getTalkPage(): Restore behavior of interwiki-prefixed & fragment-only titles
NamespaceInfo::getTalkPage will throw an exception for these.
With this patch, Title::getTalkPage() will be reverted to the old
behavior of returning an incorrect meaningless value. Logging has been
added to identify code paths that trigger this behavior.

This patch should be undone once all such code paths have been found and
fixed.

Bug: T227817
Change-Id: I4727c7bb54d6f712ddcab05ef278a08d728f5726
2019-09-04 22:37:52 +02:00
Aryeh Gregor
7fb4a95563 Remove unneeded overrideMwServices/resetServices
Change-Id: If6cbdec05b8f310ef3a0b4649aaa16d9fb80a047
2019-08-29 14:26:18 +03:00
Aryeh Gregor
8a8f23ddc6 Add a bunch of MovePage tests
The expected values in many cases are silly, because our code is
currently silly and could use some refactoring. These are marked with
@todo. In one case the return value is even wrong (moving to an invalid
non-empty name is considered valid).

Change-Id: I9649a4de12bbcd6263c85de37d7b9365d9c0aeb4
2019-08-19 20:26:02 +03:00
Aryeh Gregor
752e7dd707 Convert MessageCache to service
Depends-On: Ia70e6c75f6e8a533f20cd44ebb05e013678e9951
Depends-On: I546eda0377f3a50843144b1450d3fbe8e4e02a8a
Change-Id: I305539a8598535a73e5cd280b2becdafa740ef97
2019-08-18 12:11:36 +03:00
Aryeh Gregor
a3e8e22f9d Don't use new MCR schema without using DB
If $wgContentHandlerUseDB is false and
$wgMultiContentRevisionSchemaMigrationStage is not SCHEMA_COMPAT_OLD,
RevisionStoreFactory::getRevisionStore() throws. This is coming up in
some seemingly unrelated code changes, perhaps due to access of stale
service objects, but I'm not sure because I can't reproduce locally. So
this is a shot in the dark to fix it.

Change-Id: Id29a62e1f537fa1b2016aac396773b728e238cda
2019-08-13 17:05:24 +03:00
Thalia
5f89f7040f Fix grammatical error in several comments
Change-Id: Ibd8ad594950d53f5feb337c30f184ecaf218bc81
2019-08-08 14:02:13 +01:00
jenkins-bot
dd49c0c312 Merge "When title contains only slashes, Title::getRootText() shouldn't return false" 2019-07-14 12:40:30 +00:00
Martin Urbanec
ed1ab4034e When title contains only slashes, Title::getRootText() shouldn't return false
Otherwise, Title::makeTitleSafe() will return null, which
breaks the assumption that Title::makeTitleSafe() always
returns something meaningful for strings
returned by Title::getRootText().

Bug: T227816
Change-Id: If79a12bb8d23f1eafc10017d56c62566f39347ad
2019-07-14 13:27:20 +02:00
daniel
54626e5ce1 Title: Title::getSubpage should not lose the interwiki prefix
This issue was discovered while investigating T227700, and added some
confusion. This patch is necessary for Special:MyLanguage to behave
correctly in all cases, but it's not necessary for fixing the primary
critical problem.

Bug: T227700
Change-Id: Ib4cbeec47a877c473cbd501cc964cc66d169b99e
2019-07-13 17:49:11 +00:00
daniel
dbce648a15 Ensure canHaveTalkPage returns false when getTalkPage would fail.
This causes Title::getTalkPage and NamespaceInfo::getTitle() to throw
an MWException when called on a LinkTarget that is an interwiki link
or a relative section link. These methods were already throwing
MWException when called on a link to a Special page.

Bug: T224814
Change-Id: I525c186a5b8b8fc22bca195da48afead3bfbd402
2019-07-03 10:40:10 +02:00
daniel
3b3115e7f3 Title: ensure getBaseTitle and getRootTitle return valid Titles
Since getBaseText() and getRootText() may return text with trailing
whitespace, getBaseTitle and getRootTitle must use makeTitleSafe instead
of makeTitle.

Bug: T225585
Change-Id: Id92df552f05e6a9ed7c9259a8779fa94c3587a3e
2019-07-01 22:22:10 +02:00
Vedmaka
dd6b94024c Re-apply: Factors out permissions check from User into PermissionManager service
Was reverted by I549810a4cd2e424cc4a438887d2f24614a24cc00 due to
T224607.

Original change by  Vedmaka Wakalaka was
Ia0d840b772ea5f20c9594ce151cc57adc270e48b.

Original commit message:

The following methods should are factored out of the User class into PermissionManager,
leaving only deprecated stubs:

- User::isAllowed -> PermissionManager::userHasRight
- User::getRights -> PermissionManager::getUserPermissions
- User::groupHasPermission -> PermissionManager::groupHasPermission
- User::getGroupPermissions -> PermissionManager::getGroupPermissions
 -User::getGroupsWithPermission -> PermissionManager::getGroupsWithPermission
- User::groupHasPermission -> PermissionManager::groupHasPermission
- User::isEveryoneAllowed -> PermissionManager::isEveryoneAllowed
- User::getAllRights -> PermissionManager::getAllPermissions

Depends-On: I7909e9bd6bbfbd708c0a00b861a9b22a38c6665d

Bug: T218558
Bug: T223294
Change-Id: I8899240378f636ea70f447616710516c0a3c5c31
2019-06-28 13:19:38 -07:00
Fomafix
110a5877e9 Use [...] instead of array(...) in PHP comments and documentation
Change-Id: I0c83783051bf35fe785bc01644eeb2946902b6b2
2019-06-17 21:15:09 +02:00