Commit graph

132 commits

Author SHA1 Message Date
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
Kosta Harlan
7f90d1e3a3 Revert "Factors out permissions check from User into PermissionManager service"
This reverts commit 7faa7a7420.

Reason for revert: T224607

Change-Id: I549810a4cd2e424cc4a438887d2f24614a24cc00
2019-05-30 13:51:37 +00:00
Vedmaka
7faa7a7420 Factors out permissions check from User into PermissionManager service
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: I258f02e286b6ba0387e1bff540a744fafb03dc55
Depends-On: Ie4cedf457eaaa93ec3055c37539322855e02ce26
Depends-On: Id274f240d687efa61cb9f7a15033ae2a7a532083

Bug: T218558
Bug: T223294
Change-Id: Ia0d840b772ea5f20c9594ce151cc57adc270e48b
2019-05-29 17:41:07 +02:00
Aryeh Gregor
ed625e11cd Hard-deprecate Title::moveTo and friends
moveSubpages wasn't officially deprecated at all before this release,
but there were no callers in codesearch outside core, so it should be
safe to hard-deprecate.

Bug: T208775
Change-Id: Icea9f1dc45d8bd8c96cc159d631f18c394aab4b7
2019-05-28 11:52:36 -05:00
Aryeh Gregor
e30cb5ba90 Move Title::getSubject/Talk/OtherPage to NamespaceInfo
This allows converting some more code to LinkTarget. 100% test coverage.

Change-Id: I28903af6a41d02755f37f31561a524547445821e
2019-05-06 08:29:28 -07:00
Aryeh Gregor
571567cddc Update GenderCache to use NamespaceInfo
Change-Id: I0c2997bf8764249c26251d0f63f3ea0a0b272a7e
2019-05-06 12:08:45 +03:00
jenkins-bot
1139a444ee Merge "New Title::castFromLinkTarget/TitleValue" 2019-04-15 22:13:38 +00:00
jenkins-bot
f767f2a48d Merge "Update MediaWikiTitleCodec to use NamespaceInfo" 2019-04-15 21:40:16 +00:00
Aryeh Gregor
37fcedbb3f New Title::castFromLinkTarget/TitleValue
These behave the same as newFromLinkTarget/TitleValue, but accept null
as well (and then just return null). This makes things much easier when
converting code from using Title to LinkTarget, because you can wrap in
castFromLinkTarget without adding null checks.

Change-Id: Id61f91d40b81ad226532917c43e51f0b69af712c
2019-04-15 16:56:47 +03:00
Aryeh Gregor
69ef837f41 Update MediaWikiTitleCodec to use NamespaceInfo
Depends-On: I759cde50e42020699138d32431c27428737f700f
Change-Id: I57d77754288449ec54b039802adae05d56fa5563
2019-04-14 14:55:58 +03:00
Timo Tijhof
821505367e title: Allow passing MessageLocalizer to newMainPage()
The method could not be used in session-less endpoints. This was
worked around once in the Startup module.

I plan to use this method in an extension module as well,
and would prefer not to duplicate core's logic for determining
the main page, outside this repository.

As general dependency-injection pattern, it seems desirable
to allow injecting a MessageLocalizer here.

Change-Id: I76cd02b2f489882e9404b93270f76aad9f0a4d9d
2019-04-14 03:26:17 +01:00
Vedmaka
8e1342ed47 Introduce PermissionManager service
First iteration of adding a PermissionManager service as a replacement
for Title::userCan and User::isBlockedFrom methods.

- Created PermissionManager service
- Migrated Title::userCan to PermissionManager::userCan and deprecated the first
- Migrated Title::quickUserCan to PermissionManager::quickUserCan and deprecated the first
- Migrated User::isBlockedFrom to PermissionManager::isBlockedFrom and deprecated the first

Same for User::isBlockedFrom and PermissionManager::isBlockedFrom - the
$user parameter is now required so the declaration is changed from
isBlockedFrom( $title, ... ) to isBlockedFrom( $user, $title, .. ) which
means before User::isBlockedFrom removal all calls to it need to be updated.

Added PermissionManagerTest, it copies TitlePermissionTest but uses
PermissionManager instance instead of Title methods, this way keeping both tests
in place, we can ensure that nothing was broken and both are in working state
during the deprecation phase.

Bug: T208768
Change-Id: I94479b44afb3068695f8e327b46bda38e44e691f
2019-04-05 14:54:51 +00:00
daniel
2d721e69e8 Introduce 'clone' flag for newFromLinkTarget.
The "new" part of some of the newXXX pseudo-constructors
in the Title class is a lie: these methods do not always
return a new instance. This patch ensures that this fact is
documented, and we have a safe way to get a fresh Title
from a LinkTarget.

Needed by I94479b44afb30

Change-Id: I4d561ef7d7447d3d6e35079cf656bd564882d25e
2019-04-05 16:52:06 +02:00