Commit graph

71 commits

Author SHA1 Message Date
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
ArtBaltai
07f57bd271 WikiPage/Article split. Rely on Article inside Action
This is a first step in the split. This keeps b/c for
constructing the Action with a WikiPage, but is deprecated.
Introduces article accessor to remove direct access to
Action::page property.
Action::page property is deprecated for direct access.
 Use Action::getArticle or Action::getWikiPage instead.

Bug: T239975
Change-Id: Ib8eb8a141b4b7cb72ff65afbcd17385fcc6b3b1c
2020-03-25 01:54:43 +03:00
Thiemo Kreuz
1006aa41e6 Fix mismatching type hints in PHPDoc tags
This is a collection of random bits from my local stashes. This patch
intentionally only touches comments, no code.

Notably:
* Use more specific string[] instead of array, if possible.
* Some comments mention "or null", but miss to list the type.

Change-Id: I712b28964f125c8e3dcb4e3fb993757a09f96644
2020-03-24 09:59:02 +01:00
DannyS712
909f0bef6e Replace calls to Title::getUserPermissionsErrors (part 5)
This does //not// fix all calls in core.

Bug: T244929
Change-Id: I02ffcca31fa0bdc6bffddf21e82f4ff5e9ab5374
2020-02-26 03:00:33 +00:00
Thiemo Kreuz
78ca9eff4a Remove duplicate variable name from class property PHPDocs
Repeating the variable name doesn't do anything. Documentation
generators don't need it. It's more stuff to read that doesn't add new
information. And it can become outdated.

Note there are two types of @var docs. When used inline (and not on a
class property) the variable name is needed.

Change-Id: If5a520405efacd8cefd90b878c999b842b91ac61
2019-12-02 12:58:29 +00:00
Thalia
538d333167 Allow user, language and IP to be passed to UserBlockedError
Accept these objects as params to the UserBlockedError constructor,
since they are used to make the block error message. Pass them from
SpecialPages, Actions and EditPage.

If a caller does not pass all of these params, get them from the
global context as before.

Bug: T234406
Change-Id: Ie8ef047d2710c523b67bfc54fa2ad70fc47c5236
2019-10-17 15:19:28 +01:00
Umherirrender
8752df6592 Use varargs for MessageLocalizer::msg and similar
Bug: T191666
Change-Id: I59f2ae1a96af392026fc106e57d23553003c16b8
2019-10-05 17:47:49 +00:00
Timo Tijhof
04ffdb9d0a actions: Rename Doxygen group from "Action done on pages" to "Actions"
Bug: T232104
Change-Id: Ia3b8c14bd62ac241824bce216361141adb77cc47
2019-09-14 00:32:16 +01:00
Derick Alangi
ae87a51b05 actions: Improve Action class code for clarity & consistency
~ Move local variable $obj to one liner as it's redundant in
  this case.
~ Use === check instead of == as in order case above for the
  purpose of consistency.
~ Make use of single quotes for strings literals instead of
  double quotes.

Change-Id: I69650cacb0658a7369147ea5e9933fb5585e3376
2019-02-25 13:28:37 +01:00
David Barratt
f205e6e9f0
Action::checkCanExecute should only block an Action if the user is sitewide blocked
The method over-enforces partial blocks by preventing users from performing
the action on unrelated pages.

Bug: T209284
Change-Id: I4ee0e7c0188d491cf8fc0bbbbf7e492cdf309f45
2018-11-14 14:45:30 -05:00
James D. Forrester
162af29e77 Drop UnknownAction, deprecated in 1.19(!)
Change-Id: Ia75552e69c07f6dc5da2f1e04ea813c912b04aef
2018-10-10 16:17:28 -07:00
Fomafix
1472f02b36 Phabricator: Use Tddddd instead of Bug ddddd in comments
Change-Id: Ic9fe03cab270bd6be738af346164ad5d31a0d780
2018-10-04 09:15:02 +02: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
Max Semenik
8085c58a4b Replace call_user_func_array(), part 1
Uses new PHP 5.6 syntax like ...parameter unpacking and
calling anything looking like a callback to make the code more readable.
There are much more occurrences but this commit is intentionally limited
to an easily reviewable size.

Change-Id: Idcec077ef3fdf029b632cceafd0150851ad723e3
2018-06-04 23:39:04 -07:00
Kunal Mehta
d1cf48a397 build: Update mediawiki/mediawiki-codesniffer to 0.10.1
And auto-fix all errors.

The `<exclude-pattern>` stanzas are now included in the default ruleset
and don't need to be repeated.

Change-Id: I928af549dc88ac2c6cb82058f64c7c7f3111598a
2017-07-22 18:24:09 -07:00
Thiemo Mättig
d14faa6bed Remove auto-generated "Constructor" documentation on constructors
Having such comments is worse than not having them. They add zero
information. But you must read the text to understand there is
nothing you don't already know from the class and the method name.

Change-Id: I994d11e05f202b880390723e148d79c72cca29f0
2017-07-10 10:15:51 +00:00
Amir Sarabadani
d062560f24 Require $key in msg() functions
Note: calling msg() with no parameter was never supported,
doing this on a RequestContext for example would result in:
PHP Warning:  Missing argument 1 for wfMessage() ...followed
by a bunch of fallout.

So this patch only formally declares what was already a
requirement in reality.

Change-Id: I1864afb8bcc641698689828914949a06506d8f3a
2017-06-14 13:26:27 +04:30
Thiemo Mättig
16c26f8eb8 Add missing …|null $context documentation to Action class
Change-Id: If365123ffafe8c3eb7566432276131f815a68280
2016-07-05 16:49:17 +02:00
jenkins-bot
f829125b49 Merge "Revert "Make an empty "?action=" parameter default to "view""" 2016-05-18 19:06:24 +00:00
Krinkle
caf87b4893 Revert "Make an empty "?action=" parameter default to "view""
This reverts commit b287ec2cc6.

Change-Id: I59e996dfe627e8a978ed849a8e82ad4e0b165d7f
2016-05-18 18:54:50 +00:00
jenkins-bot
92e3d2f1a3 Merge "Add actual documentation for ContentHandler::getActionOverrides" 2016-05-18 17:41:05 +00:00