Commit graph

150 commits

Author SHA1 Message Date
TChin
e67f822bc9 Revert "Introduce AbstractLocalizedException"
This reverts commit 0d453d915a.

Reason for revert: Trying to find a better approach than an abstract class

Change-Id: I69c0ec25cb920f41cb0eb6b3ad921d7b02290581
2021-09-14 19:01:21 +00:00
TChin
0d453d915a Introduce AbstractLocalizedException
AbstractLocalizedException acts like a shim to ILocalizedException in preperation for refactoring

Bug: T287405
Change-Id: I01e40e82457d49487829d9a435b7a1198369ecf6
2021-09-10 10:32:57 -04:00
DannyS712
edd9ae23be Allow using MediaWikiTitleCodec with errors in unit tests
MediaWikiTitleCodec can throw MalformedTitleException,
which cannot be created in unit tests (see T281935). Until
that changes, add a helper callback
MediaWikiTitleCodec::$createMalformedTitleException
that will by default return a MalformedTitleException, but
tests can override this to return a mock.

We add this as an option to DummyServicesTrait to throw
generic `MalformedTitleException`s without regard to the
specifics of the message or parameters provided, this
can be used if no finer control is needed, or callers
can manually change the callback.

Demonstrate using it by moving the tests for UserNameUtils
to be unit tests - the only thing blocking this was the
creation of `MalformedTitleException`s.

Change-Id: I11ae4c6292465626ad1e432f7c6e9754c8ef36c2
2021-07-27 11:27:56 +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
Thiemo Kreuz
51777ee8c1 Add and fix various type hints in PHPDocs
Random fixes I collected the past weeks in my local dev
environment.

Change-Id: Ic8a6262fd28e05cb57335f2faf390a47ff97dbaa
2021-06-18 08:19:23 +00:00
DannyS712
f34005d208 TitleFormatter: fix typo ("of" -> "or")
Change-Id: I0d14886a6544a3141feb4172c25ff869f56ef5af
2021-06-08 05:27:18 +00:00
Thiemo Kreuz
6805f39a30 Remove unused default values from class properties
In all these cases the property is unconditionally set in
the constructor. The extra initialisation is effectively
dead code and an extra source of errors and confusion.

Change-Id: Icae13390d5ca5c14e2754f3be4eb956dd7f54ac4
2021-05-12 13:44:28 +02:00
daniel
c1eb74603a Remove Title from public interface of OutputPage
Bug: T278459
Change-Id: If455682540faf8d42fd8a14e0ef09bac24f72db4
2021-04-16 10:01:56 -07:00
daniel
5faa080374 Introduce PageReference
This explores the idea of a PageReference type which represents a
namespace/dbkey pair.

Every ProperPageIdentity is a PageReference. Some LinkTargets can be
mapped to a PageReference.

Bug: T279522
Change-Id: Id8b0c781fce329adcc4770f4840b2ba0108f6898
2021-04-13 23:32:20 +02:00
Vadim Kovalenko
6841c49dcf Make TitleFormatter accept PageIdentity interface
Refactor TitleFormatter
- ::getText(),
- ::getPrefixedTest,
- ::getPrefixedDBkey,
- ::getFullText

and their implementation

Refactor tests for MediaWikiTitleCodec class

Bug: T278125
Change-Id: I629291575720cc36110be63efcec7d5be57244c1
2021-03-24 17:27:19 -04:00
DannyS712
54cd9e478e Inject dependencies into some ImportTitleFactory classes
NaiveImportTitleFactory
NamespaceImportTitleFactory
SubpageImportTitleFactory

Change-Id: I0ab83d1c6361d5a6f06b0c765c0e997d16e3bdb5
2021-03-22 21:27:27 +00:00
Ammarpad
ba17c42a79 registry: Allow specifying immovable namespaces in extension.json
In most cases this will alleviate the need to use the
ImmovableNamespaces hook.

Bug: T277520
Change-Id: If1e1063a597ebdb39343a356cc381a6ceafaebcc
2021-03-17 06:10:35 +00:00
DannyS712
2ef7ef02f9 MediaWikiTitleCodec: remove deprecated support for missing params
Also note in the release notes that the class is not @newable

Change-Id: I6a83aafeafbba52484a08800bb8321a543898c5b
2021-03-16 01:30:55 +00:00
DannyS712
69babb9350 NaiveForeignTitleFactory: inject content language
Rather than retrieving from MediaWikiServices in
the factory class, retrieve it in WikiImporter and inject
it, so that the factory uses proper DI and the
tests can eventually become unit tests

Change-Id: I6fe63829f0e65b261b6ae12e17f354333cde70b9
2021-03-13 09:50:44 +00:00
Bartosz Dziewoński
55658ea936 Escape wikitext in the title in invalid title error messages
Bug: T275261
Change-Id: Ic916d0495f8a40cb6368b1c613fcbc5958e8f781
2021-02-22 15:33:32 +01:00
daniel
10ccdb2281 Define equality for PageIdentity and LinkTarget
Bug: T272420
Change-Id: I2e0eb21989e2d733088ab77d7461bf003c2905eb
2021-01-19 23:07:37 +00:00
daniel
61a5531e4a Strict return types for PageIdentity
Bug: T208776
Change-Id: I7e71ffc209465b7cca385603d844cd40178485a9
2021-01-18 17:33:14 +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
Thalia
9ffe5a880b Clarify uses of NamespaceInfo::hasSubpages in documentation
Clarify that this method does not refer to SpecialPage subpage
parameters.

Change-Id: Ief54be2e83d4b09b265754849db487923d872939
2020-12-04 20:37:28 +00:00
Ammar Abdulhamid
61b5970a30 Hard deprecate NamespaceInfo::getRestrictionLevels
It's overdue and appears unused

Change-Id: I5d7f4a52b3258b2e711792ac0f5487f0b44c92a6
2020-11-16 04:40:24 +01:00
Thiemo Kreuz
b0130ca649 Update a lot of unspecific "array" types in PHPDocs
This includes fixing some mistakes, as well as removing
redundant text that doesn't add new information, either because
it literally repeats what the code already says, or is actually
duplicated.

Change-Id: I3a8dd8ce57192deda8916cc444c87d7ab1a36515
2020-10-28 11:01:33 +01:00
jenkins-bot
72a90d3d06 Merge "Document hook names in hook interfaces." 2020-10-02 16:15:21 +00:00
Umherirrender
d790580fda Fix typos related to repeated words
Change-Id: Ibc187d95b003017255bc87adf56afae7a59bd3db
2020-09-27 10:25:36 +00:00
daniel
2e57447c58 Document hook names in hook interfaces.
Bug: T258665
Change-Id: Ifddbf57f8aa2e3eb0d5845601376cbafa08ed407
2020-09-27 12:03:12 +02:00
DannyS712
7d80fc0aa1 Remove $wgAllowImageMoving, deprecated
Bug: T245293
Change-Id: I4026eda0d072426112040c5c74cc6e14382b7681
2020-09-14 01:21:50 +00:00
Aryeh Gregor
a24e8a06b5 Mark CONSTRUCTOR_OPTIONS as internal
These were never meant to be part of the public interface and should not
ever have been marked with @since. They're only useful for constructing
the respective objects, which no outside users should be doing.

Change-Id: I86e01272d46fc72af32172d8a12b9180971d4613
2020-08-21 00:18:45 -04:00
Ed Sanders
7683f7d839 Use strict (in)equality with namespaces constants when LHS is definitely an integer
Change-Id: I8fede00dfe1270d93c5d78d3c36e788cddfc8a99
2020-07-31 18:03:28 +01:00
jenkins-bot
a5f4732261 Merge "Replace "@stable for implementation" with "@stable to implement"" 2020-07-13 09:31:44 +00:00
daniel
e6e0ad2472 Replace "@stable for implementation" with "@stable to implement"
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: I17e5e92e24c708ffc846945a136347670a3a20c7
2020-07-13 11:05:49 +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
102c9573b3 Mark exceptions as @newable
Exceptions classes are nearly always value objects, and should in most
cases by newable.

Bug: T247862
Change-Id: I4faa8ec6ea8bc44086cfc8075b32d10eea61e9df
2020-07-08 17:51:38 +00:00
daniel
bd5c3d06a2 Annotate newable classes
This annotates classes that can safely be instantiated by
extensions, per the Stable Interface Policy.

Bug: T247862
Change-Id: Ia280f559874fc0750265ddeb7f831e65fd7d7d6a
2020-07-07 15:38:57 +02:00
daniel
f59bf8a22f Use @internal instead of @private per policy
https://www.mediawiki.org/wiki/Stable_interface_policy mandates the use
of @internal. The semantics of @private was never properly defined.

Bug: T247862
Change-Id: I4c7c6e7b5a80e86456965521f88d1dfa7d698f84
2020-06-26 14:14:23 +02:00
Tim Starling
d459add63d Introduce wfDeprecatedMsg()
Deprecating something means to say something nasty about it, or to draw
its character into question. For example, "this function is lazy and good
for nothing". Deprecatory remarks by a developer are generally taken as a
warning that violence will soon be done against the function in question.
Other developers are thus warned to avoid associating with the deprecated
function.

However, since wfDeprecated() was introduced, it has become obvious that
the targets of deprecation are not limited to functions. Developers can
deprecate literally anything: a parameter, a return value, a file
format, Mondays, the concept of being, etc. wfDeprecated() requires
every deprecatory statement to begin with "use of", leading to some
awkward sentences. For example, one might say: "Use of your mouth to
cough without it being covered by your arm is deprecated since 2020."

So, introduce wfDeprecatedMsg(), which allows deprecation messages to be
specified in plain text, with the caller description being optionally
appended. Migrate incorrect or gramatically awkward uses of wfDeprecated()
to wfDeprecatedMsg().

Change-Id: Ib3dd2fe37677d98425d0f3692db5c9e988943ae8
2020-06-22 14:34:39 +10:00
James D. Forrester
d443d5e114 NamespaceInfo::makeValidNamespace: Don't throw for -1 or -2
Bug: T253098
Change-Id: Ifa5a3d587fe8298d356f513bcbf2a432cc70712b
2020-06-10 21:37:52 +01:00
jenkins-bot
eafe225ed8 Merge "Deprecate setting $wgAllowImageMoving to false" 2020-06-09 00:35:04 +00:00
DannyS712
9d91c4c640 Deprecate setting $wgAllowImageMoving to false
Trigger deprecation warnings in NamespaceInfo::isMovable, where it is
used

Bug: T245293
Change-Id: Iec8b60ae97e390e7aa88ae2e8fbeb234e728d9d9
2020-06-06 15:02:02 +00:00
James D. Forrester
0349fc8b4a NamespaceInfo: Throw specifically if called on a non-int/non-int-like namespace
Mostly just for debugging purposes; later we can enforce this with a type hint,
but first I want to track down the uses.

Bug: T253098
Depends-On: Ieecbc91a8f26076775149a96fbe1b19a7f39dcef
Change-Id: I66ea07f1acf6db2d13de488b775361f45b69020c
2020-06-03 19:55:44 +00: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
Tim Starling
0b7295a5cd Hook interface doc comment followup
Mostly just narrower array types. A handful of other errors fixed.

Change-Id: Ied79d9e389867911bf83696dbb47f43305f8be7b
2020-04-21 09:12:23 +10:00
apaskulin
c44488f725 docs: Hook interface doc comment review
Edited doc comments for hook interfaces to improve
consistency and add type hints.

Bug: T246855
Change-Id: I38fa802463cd6f39bf5946dbbeb1b3ebaea604b2
2020-04-21 09:10:08 +10:00
Tim Starling
f5aaf75ad1 Automatically generated hook interfaces
Add hook interfaces which were generated by a script which parses
hooks.txt and identifies caller namespaces and directories.

Hook interfaces are mostly placed in a Hook/ subdirectory
relative to the caller location. When there are callers in multiple
directories, a "primary" caller was manually selected. The exceptions to
this are:

* The source root, maintenance and tests, which use includes/Hook. Test
  hooks need to be autoloadable in a non-test request so that
  implementing test interfaces in a generic handler will not fail.
* resources uses includes/resourceloader/Hook
* The following third-level subdirectories had their hooks placed in
  the parent ../Hook:
    * includes/filerepo/file
    * includes/search/searchwidgets
    * includes/specials/forms
    * includes/specials/helpers
    * includes/specials/pagers

Parameters marked as legacy references in hooks.txt are passed
by value in the interfaces.

Bug: T240307
Change-Id: I6efe2e7dd1f0c6a3d0f4d100a4c34e41f8428720
2020-04-20 13:31:05 +10:00
James D. Forrester
0958a0bce4 Coding style: Auto-fix MediaWiki.Usage.IsNull.IsNull
Change-Id: I90cfe8366c0245c9c67e598d17800684897a4e27
2020-01-10 14:17:13 -08:00
James D. Forrester
4f2d1efdda Coding style: Auto-fix MediaWiki.Classes.UnsortedUseStatements.UnsortedUse
Change-Id: I94a0ae83c65e8ee419bbd1ae1e86ab21ed4d8210
2020-01-10 09:32:25 -08:00
Kunal Mehta
99007e96c7 Use namespaced IPUtils class
Change-Id: I047e099a93203a59093946d336a143d899d0271f
2020-01-01 02:36:49 -08:00
daniel
e98094956a Don't fail hard on bad titles in the database.
This updates some code that has been constructing TitleValue directly
to use TitleValue::tryNew or TitleParser::makeTitleValueSafe.

Bug: T200055
Change-Id: If781fe62213413c8fb847fd9e90f079e2f9ffc9d
2019-11-25 22:15:38 +01:00
Aryeh Gregor
b4a7620b9e Hard-deprecate Title::getUserCaseDBKey
The only use-case for this was if the local wiki's File namespace didn't
allow initial-lowercase names but a remote repo did. This case is
unlikely to be useful and was broken anyway, so it's now prohibited, and
getUserCaseDBKey is no longer needed. It's now an alias for getDBkey
until we remove it.

This includes a breaking change to
MediaWikiTitleCodec::splitTitleString, but that was always intended as
an internal method and I have now marked it officially as such. There is
one caller in code search outside core (JsonConfig), but it looks like
it will be unaffected.

Bug: T202094
Depends-On: I4b8ceb8a7f4624d6a3763aca6df41bf1a0d7293f
Depends-On: I724be15e93421f874fb202f0ec2ca6940e56a20a
Change-Id: I4fd64d4b0036b6dabdcfeee18766df18bf538542
2019-10-24 19:26:37 +03: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
Max Semenik
2f749f7cb3 NamespaceInfo: use array constants now that we can
Change-Id: I676a68fdc42ff2f37c7e4a2700b7c0c448155d47
2019-10-05 00:26:56 -07:00