Commit graph

363 commits

Author SHA1 Message Date
daniel
a67cad6d0f Create fallback for undefined content models.
This causes RevisionStore to use FallbackContent instances to represent
content for which no content handler is defined.

This may happen when loading revisions using a model that was defined
by an extension that has since been uninstalled.

Bug: T220594
Bug: T220793
Bug: T228921
Change-Id: I5cc9e61223ab22406091479617b077512aa6ae2d
2020-07-22 19:59:09 +02:00
Thiemo Kreuz
70027add5d Make use of the preg_match() return value, if possible
Instead of checking if the resulting $matches array is complete, we can
safely assume it is, as long as the preg_match() call returned a
non-false value.

Note that some of these used empty() before and are actually bogus
because of this! empty() considers the string "0" to be empty. In case
of a ==0== headline that's an actual bug.

I'm also removing the `= []` initialization before the preg_match.
I understand why it was added: to make it a little more obvious that the
variable is guaranteed to be initialized. But:
* This is guaranteed by the preg_match anyway.
* Neither initializing it with null or an empty array makes much sense
  because the code below assumes so much more, e.g. that specific
  elements exist, and are arrays. Again, these guarantees are all given
  by the preg_match.

I find the additional initialization more distracting than helpful.

Change-Id: I22b192b59038d9fa51a7e6f04d8d76634ae3de73
2020-07-14 19:26:35 +00:00
jenkins-bot
a5f4732261 Merge "Replace "@stable for implementation" with "@stable to implement"" 2020-07-13 09:31:44 +00: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
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
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
7b14d2f563 Mark Content and ContentHandler base classes as extensible
Bug: T247862
Change-Id: I37666c6372bd922768cf426b12951699d890272b
2020-07-09 12:03:56 +02:00
daniel
442fb30ce1 Stability annotations for interfaces.
Per the Stable Interface Policy, PHP interfaces should not be
directly implemented by extensions, unless they are marked to be safe
for that purpose.

Bug: T247862
Change-Id: Idd5783b70fc00c03d57f5b1a887f0e47c4d7b146
2020-07-07 22:01:29 +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
DannyS712
b6f020ff66 ContentHandlerFactory: Inject LoggerInstance instead of using wfDebugLog
Change-Id: Ifed1f2e28a5fec365103b1588a8cabff10ce6007
2020-06-01 22:37:12 +00:00
DannyS712
d6a38d0f10 Add ContentModelChangeFactory, implemented by PageCommandFactory
Bug: T253080
Change-Id: I62eda1163cd5b0472af912e8dbd5843df8303b8d
2020-05-30 22:36:16 +00:00
Daimona Eaytoy
2b37cfaf18 build: Bump mediawiki-codesniffer to 31.0.0
Done with `composer fix` and suppressing the rest (i.e. sniffs for
global variables, which for core should be suppressed anyway).

Additionally, add `-p` to `phpcbf`, as otherwise it just seems stuck.

Change-Id: Ide8d6cdd083655891b6d654e78440fbda81ab2bc
2020-05-30 14:56:28 +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
Timo Tijhof
0c7dc17757 content: Change log channel to 'ContentHandler'
Follows-up 30e54b3962, which accidentally passed the string
'MediaWiki\Content\ContentHandlerFactory::getContentHandler' as
the log channel. We generally use wide and generic channel names
named after a whole component. Or, if using wfDebug(), we
sometimes prefix the method name to the message. It looks like
these two idioms were accidentally mixed up which means this
message is missing when looking for 'ContentHandler', but it
also meant that when viewing the full debug log in Kibana, that
the channel column breaks due to this being too long.

Change-Id: If578893f568905ac0d560ecf544fcc28dd61ba91
2020-05-19 03:11:23 +01:00
Reedy
12a3883a7b Fix SingleSpaceBeforeSingleLineComment
Change-Id: I285af438ce484af40741489797f20455726ec110
2020-05-11 00:57:11 +00:00
Tim Starling
550f5930f2 Hook interface type fixes, to fix Phan errors
Phan flagged a lot of incorrect type hints when run against the call
site migration patch.

Bug: T240307
Change-Id: I698de5536446c241b200430198b21b72763b0c69
2020-05-05 11:22:04 +10:00
DannyS712
dd9ca82b44 ContentHandler::latestRevision - return RevisionRecord
Private method, no need to worry about breaking things

Bug: T249393
Change-Id: I997f84bd3c6acc0d4365bf31bece7c4f61c42d72
2020-04-27 22:04:18 +00:00
jenkins-bot
d3d759cee4 Merge "Hard deprecate using Revision objects in ContentHandler::getUndoContent" 2020-04-27 21:10:37 +00:00
jenkins-bot
89f14cf3e1 Merge "Hook interface doc comment followup" 2020-04-27 19:40:14 +00:00
DannyS712
625db9aca3 Hard deprecate using Revision objects in ContentHandler::getUndoContent
Bug: T250773
Change-Id: Id7a5f457637e1c8cf411a07c746004770507d6a7
2020-04-26 21:55:28 +00:00
jenkins-bot
f898b49c98 Merge "docs: Hook interface doc comment review" 2020-04-21 06:41:19 +00:00
jenkins-bot
cc89a81451 Merge "Automatically generated hook interfaces" 2020-04-21 00:07:41 +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
DannyS712
4721717527 Replace uses and hard deprecate Article:: and WikiPage::getRevision
Bug: T250532
Bug: T239975
Change-Id: Ic8f2baa0ac805d5196a7107bdc7a1abb36eba139
2020-04-20 23:06:48 +00: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
jenkins-bot
b8ce6dbc98 Merge "ContentModelChange: Remove use of Revision objects" 2020-04-13 18:16:27 +00:00
DannyS712
5451b5c0b3 ContentModelChange: Remove use of Revision objects
I wrote the code that needs to be fixed :(

Bug: T249183
Change-Id: Ibdf4836962e39b7a0fe316795bd23a630172e31f
2020-04-13 00:13:43 +00:00
DannyS712
f98520be7e ContentHandler::getAutoDeleteReason - remove use of Revision objects
Bug: T249183
Change-Id: I7babaa778c06762a41c9d3281326ae793437deca
2020-04-13 00:07:16 +00:00
DannyS712
ae2ea61bd0 Add @author tags I forgot to include
Added to files I originally authored; forgot to include at the time

Change-Id: Ibb619352ad346b4cb0ee4d4e60ee21e510ff3e04
2020-04-11 08:13:48 +00:00
jenkins-bot
a5f17ab4d5 Merge "Fix Doxygen comment of Content::replaceSection() - wrong return type" 2020-04-02 12:52:54 +00:00
DannyS712
1d4df4f221 Hard deprecate Revision::getQueryInfo and ::getArchiveQueryInfo
Bug: T246284
Change-Id: I708f265aac3016e34d02936cf5dff98a3036ef0f
2020-03-26 23:53:19 +00:00
jenkins-bot
ae34431312 Merge "contenthandler: Load revision from PAGE_LATEST when not found" 2020-03-18 10:38:58 +00:00
Erik Bernhardson
6c73dd2548 contenthandler: Load revision from PAGE_LATEST when not found
When retrieving indexable content for a WikiPage the page may be
brand new and not replicated yet. When no revision is found try
again reading from the master, then fail with a clear message instead
of the previous behaviour of dereferencing null.

Bug: T247859
Change-Id: Iab93984b26d40de00f3331ee1bbdde46b3370733
2020-03-17 15:48:09 -07:00
Thiemo Kreuz
7a4df9b019 Remove auto-generated and empty lines in comments
… and add the missing newline after the initial <?php.

Change-Id: I83bbbb1504e4b2bd97eec63c7626d34c655c3197
2020-03-17 09:55:24 +01:00
Umherirrender
3161311c5a Use MediaWikiServices::getMessageCache
Change-Id: I07fcc9529991adc634c10e5ed8498ac138a1c2b7
2020-03-14 14:25:03 +01:00
jenkins-bot
e005e08768 Merge "Add a ContentModelChange helper, and an api module that uses it" 2020-03-11 22:10:01 +00:00
DannyS712
a299ca0248 Follow up 568491 - remove extra space
Change-Id: I465dc90443f115df25622d4437b6eb50a5390e58
2020-03-07 04:30:07 +00:00
DannyS712
0789d1568d Add a ContentModelChange helper, and an api module that uses it
Bug: T107174
Change-Id: I6eb38c4aec23619d7ec42ef12092edf9ff25c6fa
2020-02-27 19:02:29 +00:00
Tim Starling
adc3c5f247 Don't use a dynamic hook name when calling a hook
It breaks my script.

Remove the IContentHandlerFactory consts without deprecation, they were
only introduced two weeks ago and are not used by anything.

Change-Id: I22eb637b64a9be8472affed1b4ae60c8fa3af93d
2020-02-25 13:42:30 +11:00
Petr Pchelko
204fa7e509 Remove usages of deprecated Language methods
Change-Id: Iad3375b141b1d87c890baec6ecd16ed92f93e699
2020-02-16 00:45:48 +00:00
ArtBaltai
0ef09103df TextConflictHelper: deprecate old constructor signature
A deprecation warning will be triggered if the constructor is called without providing a ContentHandlerFactory

Bug: T235165
Depends-On: I5996f0f01e28edf50d3caf2ca4557d64271d8545
Change-Id: Ie552b33a5644fa2aefd826df8fd18184434677b7
2020-02-12 14:02:38 +11:00
ArtBaltai
272e941b7f Use ObjectFactory to construct ContentHandlers
Changed
 - ContentHandlerFactory with legacy support
 - ContentHandlerFactoryTests
Added
 - MediaWikiIntegrationNoDbTestCase for test without preparing DB
New
 - tests

Bug: T243560
Change-Id: I693dda56af55bd03e48d62a2f1ade42f65a8fac9
2020-02-10 21:36:36 +03:00
Edward Chernenko
e1dc19b252 Fix Doxygen comment of Content::replaceSection() - wrong return type
This is a typo. (may cause Phan warnings)

This method doesn't return "string" in any of implementations of this
interface. It only returns Content (for WikitextContent) or null.

All code that calls replaceSection() assumes that it returns Content.

Change-Id: Iade4c24ff11cb839e6fc6828623f099c00cb3ef5
2020-02-09 05:08:36 +03:00
ArtBaltai
30e54b3962 Introduce ContentHandlerFactory
Added:
- ContentHandlerFactory
Tests:
- PHPUnit
Changed
- Calls of changed and deprecated
- DI for some service/api
Deprecated:
- ContentHandler::* then similar to ContentHandlerFactory
- ContentHandler::getForTitle
- ContentHandler::$handlers

Bug: T235165
Change-Id: I59246938c7ad7b3e70e46c9e698708ef9bc672c6
2020-02-07 00:53:51 +03:00
Peter Ovchyn
ed18dba8f4 language: remove Language hints for type check as it breaks using of StubUserLang
Bug: T244300
Change-Id: Iec1b5629617f1c171e8af507dc1dcebfef0666eb
2020-02-05 16:11:31 +02:00
Peter Ovchyn
61e0908fa2 languages: Introduce LanguageConverterFactory
Done:
* Replace LanguageConverter::newConverter by LanguageConverterFactory::getLanguageConverter
* Remove LanguageConverter::newConverter from all subclasses
* Add LanguageConverterFactory integration tests which covers all languages by their code.
* Caching of LanguageConverters in factory
* Make all tests running (hope that's would be enough)
* Uncomment  the deprecated functions.
* Rename FakeConverter to TrivialLanguageConverter
* Create ILanguageConverter to have shared ancestor
* Make the LanguageConverter class abstract.
* Create table with mapping between lang code and converter instead of using name convention
* ILanguageConverter @internal
* Clean up code

Change-Id: I0e4d77de0f44e18c19956a1ffd69d30e63cf51bf
Bug: T226833, T243332
2020-02-03 11:38:03 +02:00