Commit graph

376 commits

Author SHA1 Message Date
DannyS712
e8b7c36181 ContentHandlerFactory: whitespace cleanup
Change-Id: Ie47dddc905ea7dc0b3e3d624dca91e354aa39110
2020-11-29 22:00:06 +00:00
Umherirrender
299f05c324 Use always RevisionStore in ContentHandler::getAutoDeleteReason
RevisionStore includes the RevisionLookup, use the same instance

Change-Id: I064605aa6b1037daf4507278cdb5a94ee8e8964b
2020-11-14 02:46:24 +01:00
Umherirrender
0933edbd85 Replace deprecated WikiPage::factory in AbstractContent
Change-Id: I618e899d150a3d608738ae42c050ac21fcf30d9d
2020-11-11 22:21:59 +01:00
Thiemo Kreuz
1fc8d79ac6 Remove documentation that literally repeats the code
For example, documenting the method getUser() with "get the User
object" does not add any information that's not already there.
But I have to read the text first to understand that it doesn't
document anything that's not already obvious from the code.

Some of this is from a time when we had a PHPCS sniff that was
complaining when a line like `@param User $user` doesn't end
with some descriptive text. Some users started adding text like
`@param User $user The User` back then. Let's please remove
this.

Change-Id: I0ea8d051bc732466c73940de9259f87ffb86ce7a
2020-10-27 19:20:26 +00:00
Aaron Schulz
ec86a370e1 Make WikitextContentTest set the context title to avoid failures
This avoids failures due to WikitextContent::isCountable() erroring
out when no title is set for the main RequestContext.

Bug: T257009
Change-Id: I70274e3876c5b7c273110f9afa713a85edcc6339
2020-10-20 16:13:42 -07:00
Lucas Werkmeister
d960d2f79d Make ContentHandler::latestRevision() available to subclasses
This method is useful when overriding getParserOutputForIndexing(), to
avoid the equivalent of T247859.

Note that the method is not stable to override, only to call.

Change-Id: Idd7e6ca6786f2c463737a47296b3da5f5e0e16f1
2020-10-12 12:13:40 +02:00
Lucas Werkmeister
775b068396 Clarify HTML generation for indexing in ContentHandler
Require that getDataForSearchIndex() is only called with the result of
getParserOutputForIndexing(), and update the documentation of both
methods. Extensions may now override getParserOutputForIndexing() to
skip generating HTML; MediaWiki guarantees that the HTML itself is not
required by the base implementation of getDataForSearchIndex().

Note that for Wikitext content, many meta-data fields of ParserOutput –
links, sections, etc. – can only be obtained by actually parsing the
content and generating HTML, whether the caller asked for it or not.
However, this is not the case for all content models. This change allows
those content models to save some work when indexing their content,
while still working with the MediaWiki getDataForSearchIndex() method.

The new requirement on getDataForSearchIndex() is strictly speaking a
breaking change, but not one that could be marked as a deprecation
first. Hopefully, the release notes entry is enough.

Bug: T239931
Bug: T264283
Change-Id: I50f3a530f25fbcf019d36d09c070b11a46066c61
2020-10-09 13:20:58 +02:00
daniel
2e57447c58 Document hook names in hook interfaces.
Bug: T258665
Change-Id: Ifddbf57f8aa2e3eb0d5845601376cbafa08ed407
2020-09-27 12:03:12 +02:00
Matěj Suchánek
51642e0aae Replace tabs with spaces
Change-Id: Id034c34a294585f58dba58c26db466e0e39cb557
2020-09-04 18:04:07 +02:00
C. Scott Ananian
770ace8723 content: Add hidden preference to disable PST on CSS/JS content
Test Plan:
* Logged-in, preview a change adding {{subst:CURRENTYEAR}}
  to User:You/common.css, User:You/common.js and Main_Page.
* Observe that it expands to 2020 in all cases.
* Run `(new mw.Api).saveOption('pst-cssjs', '0')`
* Try again. Observe that the first two are now left unchanged.

Bug: T236828
Change-Id: Ic13e2ff3b90f0c3587cdb1e97fffcd96be650e0e
2020-08-12 02:14:30 +00: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
5eff037194 Merge "Flip Yoda conditionals" 2020-07-28 19:22:38 +00:00
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
Ed Sanders
0cf40a4f7a Flip Yoda conditionals
Change-Id: Id3495b6f15c267123c89f3a0ace496e6ecbeb58e
2020-07-22 17:49:12 +01: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