Commit graph

91 commits

Author SHA1 Message Date
Bartosz Dziewoński
c9f73efd5a Namespace MessageSpecifier under Wikimedia\Message\
In change I625a48a6ecd3fad5c2ed76b23343a0fef91e1b83 I am planning to
make Wikimedia\Message\MessageValue use it, and we try to pretend that
it is a library separate from MediaWiki, so it makes sense to move
MessageSpecifier to the same namespace under Wikimedia\.

Bug: T353458
Change-Id: I9ff4ff7beb098b60c92f564591937c7d789c6684
2024-07-28 14:21:32 +02:00
Bartosz Dziewoński
3d92cb2f82 Replace some uses of deprecated PermissionManager::getPermissionErrors()
getPermissionStatus() does the same thing but better.

A lot of things use the legacy error arrays though, we're nowhere near
removing it.

Change-Id: Iff60dbb0593329a584d003b2407bbf24d5b22aea
2024-06-27 18:14:28 +00:00
James D. Forrester
eeb5a740b3 Namespace Message, move to appropriate directory
Bug: T353458
Change-Id: I088cbc53fbcdb974e5b05b45a62e91709dacc024
2024-02-14 15:10:36 -05:00
James D. Forrester
4bae64d1c7 Namespace includes/context
Bug: T353458
Change-Id: I4dbef138fd0110c14c70214282519189d70c94fb
2024-02-08 11:07:01 -05:00
C. Scott Ananian
5c8be31628 Hard deprecate returning a string from Action::getPageTitle()
Bug: T343994
Bug: T343849
Depends-On: Ib59bf454ac265de74e268916bea2da15d4dbc4bd
Depends-On: I77b2c52d486265a3ed34c03d49b8add9d68b6181
Change-Id: I55109116e1e4f187cf9ce2de6916cdcbb24b3a5f
2023-09-22 12:04:33 -04:00
C. Scott Ananian
b8c229298f Deprecate returning a string from Action::getPageTitle()
In almost all cases we're already returning a Message object from
Action::getPageTitle().  Tighten this up by deprecating the string
return value and requiring the returned value be a Message; this also
encourages proper localization.

We pass the returned message to OutputPage::setPageTitleMsg(), which
uses FORMAT_ESCAPED.  This is a change from before this patch, where
messages are formatted using FORMAT_TEXT.  If you need to include
HTML in the page title, use Message::rawParams().

Bug: T343994
Bug: T343849
Depends-On: I2fe88d95737e673a381d039909e854e4410c8ce3
Change-Id: Ia7da1b7063a77bf94f4c71e9d77c9408c3f4aa46
2023-09-21 21:11:44 +02:00
daniel
7b8187f257 Introduce ActionFactory::getActionInfo
The new method encapsulates the fact that we currently have to
instantiate action objects to determine which permission the action
requires. This encapsulation reduces coupling in PermissionManager
and allows us to easily change to a better way to create ActionInfo
later.

Eventually, ActionInfo should be constructed based on the action's
object spec. This requires us to include the relevant information in all
specs, in core and extensions.

Change-Id: I707a165c41403ebd4a3edfc66c1595e1bd3a4087
2023-09-20 10:06:02 +10:00
James D. Forrester
1d0b7ae1e2 Namespace User under \MediaWiki\User
Bug: T166010
Change-Id: I7257302b485588af31384d4f7fc8e30551f161f1
2023-09-19 19:18:16 +00:00
Amir Sarabadani
5bd33d46ef Reorg: Move WebRequest to includes\Request
This has been approved as part of RFC T166010

Bug: T321882
Change-Id: I6bbdbbe6ea48cc1f50bc568bb8780fc7c5361a6f
2023-09-11 21:44:34 +01:00
Amir Sarabadani
d8e542abf9 Reorg: Move three output related classes to includes/Output/
And namesapce them:
 - StreamFile
 - OutputHandler
 - OutputPage

Bug: T321882
Change-Id: Iedf8d88c595e580f2d8f0734c92aa5c45618ba33
2023-09-05 19:36:42 +01:00
James D. Forrester
a47f05e761 Drop Action::exists() and ActionFactory::actionExists(), deprecated since 1.38
Change-Id: Ie7bb32d6b28863e89f4ab7b1a37ce2756f7a03d9
2023-08-16 16:58:34 +08:00
C. Scott Ananian
9ed7133d6e Action::getPageTitle() can return a Message
In almost all cases we're already returning a Message object from
Action::getPageTitle(), despite the phpdoc on the parent class claiming
that the return value is a string.

Bug: T343994
Bug: T343849
Change-Id: I968e37f588bbdf0cddf4ad27087d55e95e8c1c17
2023-08-10 16:05:49 -04: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
thiemowmde
70aa9c8e35 Make use of ?:, ?? and ??= operators in mostly trivial cases
The motivation is to make the code less confusing. I hope this is the
case.

?? is an older PHP 7.0 feature.
??= was added in PHP 7.4, which we can finally use.

Change-Id: Id807affa52bd1151a74c064623b41d950a389560
2022-12-05 21:37:13 +01:00
Umherirrender
c29c8ae8bc actions: Inject HookContainer into abstract Action class
Use the instance of the abstract classe
instead of injection via ObjectFactory

Similiar to handling in abstract SpecialPage class

Change-Id: I638fc732db94413bf6b917b38daa221fb47931e3
2022-11-22 22:38:23 +01:00
jenkins-bot
22d51ac42a Merge "Action: Remove deprecated constructor parameters" 2022-11-22 21:29:10 +00:00
Bartosz Dziewoński
62d939ce6f Action: Remove deprecated constructor parameters
Change-Id: I8188172aeb7ec775eeb2060a1e163112e9e5ed66
2022-11-03 20:51:27 +01:00
Umherirrender
1b342a8893 Various doc fixes about false and null on method arguments/return types
Doc-only changes

Change-Id: Ice974b3ba41708859dfe646e94b31c5ebbf26410
2022-11-03 18:55:47 +01:00
Zabe
f6b9381d7f Revert "Reorg: Move some of request related classes to MediaWiki/Request"
This reverts commit 2bdc0b2b72.

Reason for revert: T166010#8349431

Bug: T166010
Change-Id: Idcd3025647aec99532f5d69b9c1718c531761283
2022-10-27 13:14:16 +00:00
Amir Sarabadani
2bdc0b2b72 Reorg: Move some of request related classes to MediaWiki/Request
Moving:
 - DerivativeRequest
 - FauxRequest
 - FauxRequestUpload
 - PathRouter
 - WebRequest
 - WebRequestUpload

Bug: T166010
Change-Id: I5ea70120d745f2876ae31d039f3f8a51e49e9ad8
2022-10-26 16:49:10 +02:00
Timo Tijhof
4ac588c634 Setup: Adopt RequestContext::getActionName for most early callers
Most accesses to this value (other than technically incorrect use
via WebRequest::getVal), such as in various extensions,
call Action::getActionName($ctx) rather than MediaWiki::getAction
or the new RequestContext::getActionName.

Related changes recently:
* Introduced in 3fdfef96e4 (I1e259b54dca4).
* Primary caller optimised in d7beb0e4ec (I72ffc9f36613bf9).
* Warning for misuse added in Ib9fc34ca64b7c0e89.

This fixes a bug in DerivativeContext, which got exposed by the
ActionTest test cases, which happen to use DerivativeContext and
inheriting from the global RequestContext. That's not ideal for
the test to do, but did luckily help find this bug.

The issue is that when changing the title or wikipage, the action
cache be cleared and re-computed the next time it is accessed.
The RequestContext class (which is also a mutable context) does
the same and that is already covered by tests.

Bug: T314008
Depends-On: I8434442a61449c16981b19935f2dbdf18e4b4e50
Change-Id: I7d40e7ca4878d43fd7d7614d9c8cf8d29a8c7c4b
2022-09-20 00:05:31 +00:00
Umherirrender
93decb4e9e actions: Add Action::getAuthority and use it
Shortcut function like SpecialPage::getAuthority

Change-Id: I6e83fa270a4c57bbbc8e7343325bfe438f4ff459
2022-07-08 21:29:53 +02:00
Timo Tijhof
c8ae6826f8 actions: Add missing ->text() in RevertAction::getPageTitle()
It currently becomes a string implicitly much later on based on the
default format. All other implementations return a string and for
messages that typically is formatted as text(). This should be done
explicitly as it is the responsibility of RevertAction to know this
message and how it is meant to be formatted to get the string that
the "getPageTitle" contract calls for.

This bug has been here since 2012 with change I2c6fad30e2c4eaebf122,
where the code changed from wfMsg (string, unlike wfMessage) to
`$this->msg` without calling a format.

Bug: T252946
Change-Id: Ibfa335952eb752515a31be6feb6749534bb2a7c4
2022-04-13 23:33:20 +01:00
Tim Starling
1ae3b0ca86 Allow ContentHandler to "override" non-existent actions
Flow defines a lot of custom actions which are only implemented for its
own content type. This use case is not what we had in mind when
getActionOverrides() was introduced, but allowing it in ActionFactory
removes the need for Flow to write dummy ignored config to $wgActions.

Bug: T303237
Change-Id: I67c1ae95344b0004eb93023fae7e93de4e47888b
2022-03-08 14:17:22 +11:00
Umherirrender
b126dbe3f2 Fix various documentation related to null types
The functions returning null or the class property is set explict null

Found by phan strict checks

Change-Id: I4a271093fb6526564d8083a08249c64cb21f2453
2022-02-26 10:31:24 +01:00
Kunal Mehta
5d5a3c0720 SECURITY: Require 'read' right for most actions
As a security hardening measure to limit exposure on private wikis from
actions on $wgWhitelistRead pages, require an explicit 'read' right on
actions by default. Currently only ViewAction disables this check since
it does its own permissions checking.

This is somewhat duplicative of the permissions check in
MediaWiki::performRequest() but we'll call it defense in depth. It also
matches similar logic in the Action and REST APIs.

Bug: T34716
Bug: T297416
Change-Id: Ib2a6c08dc50c69c3ed6e5708ab72441a90fcd3e1
2021-12-15 16:12:27 +00:00
Derick Alangi
2c10f768f0 actions: Update deprecated code in Actions::checkCanExecute()
Inspired by T290004, attempting to solve that ticket will be done
in the next patch on this one.

Bug: T290004
Change-Id: I431e3eba1bcfb446a4ab60aa3d2189762ea9f65f
2021-10-28 11:23:32 +01:00
jenkins-bot
8d2bdc20c2 Merge "Specify DB to query when checking if a user is blocked from a page" 2021-08-26 17:43:34 +00:00
DannyS712
6c16d596e4 Action::addHelpLink() - don't call getActionName()
From within a specific action, the relevant context should
always point to that action, and so we can just use $this->getName()

Bug: T253078
Change-Id: I7d669fc199958cb86086985f954cd509a8957306
2021-08-06 21:44:31 +00:00
DannyS712
7a1dac1177 Mark Action::getHookContainer() as @internal
Once all actions are having dependencies injected,
those that need a hook container can just have it injected
instead of relying on the global state, which is what
Action::getHookContainer() and ::getHookRunner()
use.

Bug: T253078
Change-Id: I09c70703d4634f855620a56273a9ad924cf061a7
2021-08-02 01:57:27 +00:00
DannyS712
20293e4c99 Add an ActionFactory and start converting to DI
$wgActions used to map string action names to true,
false, a string, a callable, or an object. Now it can also
be an array (that isn't a callable) corresponding to an
ObjectFactory spec for DI.

This patch converts the revisiondelete and rollback actions to
use DI, with the rest to be converted later. The new structure
of $wgActions is fully backwards-compatible.

We don't yet deprecate Action::factory(), ::getActionName(),
and ::exists(), those will be deprecated in a follow-up.

Additionally, we no longer impose a rule that only some
actions can be overridden on a per-article basis via
Article::getActionOverrides().

Bug: T253078
Change-Id: I0fc3c53d671eced1758458f9a0148180b40c6c9b
2021-07-29 01:32:43 +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
Thalia
23b9b9c61b Specify DB to query when checking if a user is blocked from a page
When calling PermissionManager::isBlockedFrom, don't query the
primary database when only showing UI elements.

Bug: T283268
Change-Id: I9a79badf8a7cfb6afc7b4d12e4f1fbb5c24b6a86
2021-05-24 16:22:17 +01:00
DannyS712
39e62db589 Remove deprecated code in Action::factory
Action::factory() now requires a string and an article object,
dropping the deprecated support for null as the action name
and a non-article Page object.

Change-Id: I1e73a4638edb6f3aa14822b655d977da177d01bd
2021-03-22 20:42:09 +00:00
Umherirrender
aac47a6ba3 Replace deprecated WikiPage::factory in action related classes
Change-Id: Ibf5c546d8d817c0c1a636e3a90f5e40504f0c9d7
2020-11-11 22:23:33 +00:00
Ammar Abdulhamid
30f4e2847f Remove final modifier on private function
It's always been pointless and will generate warning in PHP 8.

Bug: T248925
Change-Id: Ibdc682c55cd35b1ee33f9a892fa9059b46dfe97a
2020-09-06 17:21:35 +01:00
Ammar Abdulhamid
c2a754b5c5 Replace usages and deprecate Skin::makeUrl
Bug: T258002
Change-Id: I5b0fc7b16754a446e33c7c5651823c8470fd7a31
2020-08-31 13:48:09 -07:00
jenkins-bot
39705eb311 Merge "Replace "@stable for subclassing" with "@stable to extend"" 2020-07-13 09:31:38 +00:00
jenkins-bot
0270990f0b Merge "Replace "@stable for calling" by "@stable to call"" 2020-07-13 09:27:04 +00:00
daniel
3c50afa46b Replace "@stable for subclassing" with "@stable to extend"
For compliance with the new version of the table interface policy
(T255803).

This patch was created by an automated search & replace operation
on the includes/ directory.

Bug: T257789
Change-Id: Ie32c1b11b3d16ddfc0c83a757327d449ff80b2e4
2020-07-13 11:00:30 +02:00
daniel
f7116bb3a2 Replace "@stable for overriding" with "@stable to override"
For compliance with the new version of the table interface policy
(T255803).

This patch was created by an automated search & replace operation
on the includes/ directory.

Bug: T257789
Change-Id: I5ffbb91882ecce2019ab644839eab5e8fb8a1c5f
2020-07-13 10:57:12 +02:00
daniel
272db6afde Replace "@stable for calling" by "@stable to call"
For compliance with the new version of the table interface policy
(T255803).

This patch was created by an automated search & replace operation
on the includes/ directory.

Bug: T257789
Change-Id: If560596f5e1e0a3da91afc36e656e7c27f040968
2020-07-13 08:55:28 +00:00
daniel
93f730d9d5 Mark action base classes as extensible
Bug: T247862
Change-Id: I8feae306c127b33c7f79ef81c5039f1442f35ab6
2020-07-08 17:36:15 +02:00
Tim Starling
47a1619027 Remove terminating line breaks from debug messages
A terminating line break has not been required in wfDebug() since 2014,
however no migration was done. Some of these line breaks found their way
into LoggerInterface::debug() calls, where they mess up the formatting
of the debug log.

So, remove terminating line breaks from wfDebug() and
LoggerInterface::debug() calls.

Also:
* Fix the stripping of leading line breaks from the log header emitted
  by Setup.php. This feature, accidentally broken in 2014, allows
  requests to be distinguished in the log file.
* Avoid using the global variable $self.
* Move the logging of the client IP back to Setup.php. It was moved to
  WebRequest in the hopes that it would not always be needed, however
  $wgRequest->getIP() is now called unconditionally a few lines up in
  Setup.php. This means that it is put in its proper place after the
  "start request" message.
* Wrap the log header code in a closure so that variables like $name do
  not leak into global scope.
* In Linker.php, remove a few instances of an unnecessary second
  parameter to wfDebug().

Change-Id: I96651d3044a95b9d210b51cb8368edc76bebbb9e
2020-06-03 12:01:16 +10:00
Tim Starling
68c433bd23 Hooks::run() call site migration
Migrate all callers of Hooks::run() to use the new
HookContainer/HookRunner system.

General principles:
* Use DI if it is already used. We're not changing the way state is
  managed in this patch.
* HookContainer is always injected, not HookRunner. HookContainer
  is a service, it's a more generic interface, it is the only
  thing that provides isRegistered() which is needed in some cases,
  and a HookRunner can be efficiently constructed from it
  (confirmed by benchmark). Because HookContainer is needed
  for object construction, it is also needed by all factories.
* "Ask your friendly local base class". Big hierarchies like
  SpecialPage and ApiBase have getHookContainer() and getHookRunner()
  methods in the base class, and classes that extend that base class
  are not expected to know or care where the base class gets its
  HookContainer from.
* ProtectedHookAccessorTrait provides protected getHookContainer() and
  getHookRunner() methods, getting them from the global service
  container. The point of this is to ease migration to DI by ensuring
  that call sites ask their local friendly base class rather than
  getting a HookRunner from the service container directly.
* Private $this->hookRunner. In some smaller classes where accessor
  methods did not seem warranted, there is a private HookRunner property
  which is accessed directly. Very rarely (two cases), there is a
  protected property, for consistency with code that conventionally
  assumes protected=private, but in cases where the class might actually
  be overridden, a protected accessor is preferred over a protected
  property.
* The last resort: Hooks::runner(). Mostly for static, file-scope and
  global code. In a few cases it was used for objects with broken
  construction schemes, out of horror or laziness.

Constructors with new required arguments:
* AuthManager
* BadFileLookup
* BlockManager
* ClassicInterwikiLookup
* ContentHandlerFactory
* ContentSecurityPolicy
* DefaultOptionsManager
* DerivedPageDataUpdater
* FullSearchResultWidget
* HtmlCacheUpdater
* LanguageFactory
* LanguageNameUtils
* LinkRenderer
* LinkRendererFactory
* LocalisationCache
* MagicWordFactory
* MessageCache
* NamespaceInfo
* PageEditStash
* PageHandlerFactory
* PageUpdater
* ParserFactory
* PermissionManager
* RevisionStore
* RevisionStoreFactory
* SearchEngineConfig
* SearchEngineFactory
* SearchFormWidget
* SearchNearMatcher
* SessionBackend
* SpecialPageFactory
* UserNameUtils
* UserOptionsManager
* WatchedItemQueryService
* WatchedItemStore

Constructors with new optional arguments:
* DefaultPreferencesFactory
* Language
* LinkHolderArray
* MovePage
* Parser
* ParserCache
* PasswordReset
* Router

setHookContainer() now required after construction:
* AuthenticationProvider
* ResourceLoaderModule
* SearchEngine

Change-Id: Id442b0dbe43aba84bd5cf801d86dedc768b082c7
2020-05-30 14:23:28 +00:00
ArtBaltai
8d2ebb5647 Hard deprecate Action construction with WikiPage
Tests, PermissionManager, EditAction: Construct Action with Article

Bug: T239975
Change-Id: Ia3f653f3c193312e03ccef56586e8b8222c80fa6
2020-04-14 23:13:59 +00:00
ArtBaltai
385d191025 Hard deprecate Action::factory with null argument $action
Bug: T248392
Change-Id: I68293a716ec90e5fd944c45d6ccd432ad3b82beb
2020-04-11 03:48:56 +00:00
Art-Baltai
6a0d3279f5 Revert "Revert "WikiPage/Article split. Rely on Article inside Action" "
This reverts commit 64650aaba9.

Reason for revert: incident T249162 is resolved

Change-Id: I3e16aed923b0f394d184b51cf7272318e1186837
2020-04-08 12:38:41 +03:00
Ppchelko
64650aaba9 Revert "WikiPage/Article split. Rely on Article inside Action"
This partialy reverts commit 07f57bd271.

Reason for revert: Article::newFromWikiPage causes an infinite loop
if 'ArticleFromTitle' hook handler ends up calling Action::getActionName.

The revert preserves new getArticle and getWikiPage methods since there
are a few extension changes merged dependent on these. Alternatively this partial revert, we could do a full revert with all the dependencies  https://gerrit.wikimedia.org/r/c/mediawiki/core/+/585343

Bug: T249162
Change-Id: Ifa642a631caa2d265ee097711dc8727f84435ef0
2020-04-01 22:30:51 +00:00
jenkins-bot
0de13c6125 Merge "Fix mismatching type hints in PHPDoc tags" 2020-03-26 13:35:31 +00:00