Commit graph

120 commits

Author SHA1 Message Date
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
James D. Forrester
76617a7771 Title: Test the ->equals() method more thoughroughly
Move from TitleMethodTest to TitleTest for simplicity with duplicating
into TitleValueTest. We're not using the language- and namespace-specific
test setup with these tests anyway.

Change-Id: Ieec78c35f04faea5e01da8d39ed88f7c4876ac84
2019-03-21 16:54:58 -07:00
Holger Knust
844f529119 Remove unused method Title::validateFileMoveOperation()
This method has never been used and isn't covered by the deprecation
policy since it was protected.

Bug: T214316
Change-Id: I96404792e895f12abec048c62c4b70d86a3d8310
2019-03-04 05:14:50 +00:00
James D. Forrester
9e82d41221 Remove Title->canTalk, deprecated in 1.30, unused
Change-Id: I0c397f8d33a2841343c7907b233530bf3c88e212
2019-02-07 18:34:44 -08:00
Kunal Mehta
9e5edca6c5 Title: Fix isRawHtmlMessage() for messages with underscores
Title::getRootText() uses the text form (spaces) of the title, while
$wgRawHtmlMessages was specifying them in dbkey form (underscores).

And add tests while we're at it. Which spotted that the existing
code didn't work. Whoops. Fixed.

Change-Id: I05eea553c588e0f99f862e07ad15386507ed0728
2018-08-31 09:45:01 -07:00
Aryeh Gregor
90d4f56fe4 Mass conversion of $wgContLang to service
Brought to you by vim macros.

Bug: T200246
Change-Id: I79e919f4553e3bd3eb714073fed7a43051b4fb2a
2018-08-11 22:44:29 -06:00
Kunal Mehta
c4e5a9dd97 Avoid deprecated LinkCache::singleton()
Change-Id: Ie0e5c4ef0fe6ec896378bb2433af0898655dd907
2018-06-10 23:55:11 -07:00
Umherirrender
45da581551 Use ::class to resolve class names in tests
This helps to find renamed or misspelled classes earlier.
Phan will check the class names

Change-Id: Ie541a7baae10ab6f5c13f95ac2ff6598b8f8950c
2018-01-26 22:49:13 +01:00
Kunal Mehta
0c77841534 Add @covers tags to miscellaneous tests
Change-Id: I7e65c1734aef01cd6395ee65204a0158d1635b0c
2017-12-24 23:29:00 -08:00
Max Semenik
4d8b064fae Title: Use a more proper way of detecting whether interwikis are local
Bug: T181575
Change-Id: Ifcfe609ce01b174120b81b8c0bf82c4ed6077641
2017-11-30 23:32:50 +00:00
addshore
e6e59bb425 Remove method level @group Database tags
MessageTest did not have the group at class level
either so that is added in this patch.

Change-Id: Idb6213282d6854044f374c9df51ea32d0a5523e1
2017-11-23 19:20:44 +00:00
daniel
fdf83070cd Add Title::isValid method
Make the notion of Title objects representing invalid titles explicit.

Bug: T165149
Change-Id: I89aaabdff9614fe63bd1244784a1d677dbc26f9e
2017-09-08 22:56:42 +00:00
daniel
f284dffc21 Introduce Title::getTalkPageIfDefined.
This is part of the effort to remove the assumption that every page
can have a talk page. Before we can merge Icee208dc4 which makes
Title::getTalkPage() throw an exception of no corresponding talk
namespace is defined, all extensions that call getTalkPage() must
be changed to either check canHaveTalkPage() first, or to use
the conveniance function getTalkPageIfDefined() instead.

Bug: T165149
Bug: T172146
Change-Id: I6d2613d8f7105048022f8093186dc57f1f8173ab
2017-08-01 19:09:13 +02:00