Commit graph

955 commits

Author SHA1 Message Date
jdlrobson
24949480eb Give skins more flexibility over table of contents render
* Do not store table of contents in parser output
* Instead inject table of contents via strpos where needed
  inside Article based on Skin "toc" option
* Use <mw:tocplace> as a TOC placeholder; for Parsoid compatibility
  this will be replaced with a <meta> tag in a followup patch.

Bug: T287767
Change-Id: I44045b3b9e78e7ab793da3f37e3c0dbc91cd7d39
2021-10-25 22:26:41 +00:00
Tim Starling
f7f84dddb3 Introduce CommentFormatter
CommentParser:

* Move comment formatting backend from Linker to a CommentParser service.
  Allow link existence and file existence to be batched.
* Rename $local to $samePage since I think that is clearer.
* Rename $title to $selfLinkTarget since it was unclear what the title
  was used for.
* Rename the "autocomment" concept to "section link" in public
  interfaces, although the old term remains in CSS classes.
* Keep unsafe HTML pass-through in separate "unsafe" methods, for easier
  static analysis and code review.

CommentFormatter:

* Add CommentFormatter and RowCommentFormatter services as a usable
  frontend for comment batches, and to replace the Linker static methods.
* Provide fluent and parametric interfaces.

Linker:

* Remove Linker::makeCommentLink() without deprecation -- nothing calls
  it and it is obviously an internal helper.
* Soft-deprecate Linker methods formatComment(), formatLinksInComment(),
  commentBlock() and revComment().

Caller migration:

* CommentFormatter single: Linker, RollbackAction, ApiComparePages,
  ApiParse
* CommentFormatter parametric batch: ImageHistoryPseudoPager
* CommentFormatter fluent batch: ApiQueryFilearchive
* RowCommentFormatter sequential: History feed, BlocklistPager,
  ProtectedPagesPager, ApiQueryProtectedTitles
* RowCommentFormatter with index: ChangesFeed, ChangesList,
  ApiQueryDeletedrevs, ApiQueryLogEvents, ApiQueryRecentChanges
* RevisionCommentBatch: HistoryPager, ContribsPager

Bug: T285917
Change-Id: Ia3fd50a4a13138ba5003d884962da24746d562d0
2021-09-28 11:13:03 -07:00
Petr Pchelko
5afc62f258 Remove stub threshold feature
Bug: T284917
Change-Id: I5c9ea04a9deca136bb7210f07200d18f97fd6686
2021-09-13 09:26:38 -07:00
Umherirrender
864068d000 Remove unneeded explicit true/false inside conditions
The non-strict conditions in if/while are true/false without the check.

In some situation the true/false is removed, because it is known to be a
bool (by is_bool check or type hint)

Change-Id: I5ca4c4771af25d2e785e82732df204a73653886e
2021-08-17 21:52:34 +02:00
mainframe98
3bab2cc853 EditPage: load mediawiki.interface.helpers.styles
This module provides styling for span.comment, produced by
Linker::commentBlock, which EditPage calls when generating the
HTML for the edit summary.

Add a notice for that to Linker::commentBlock, like was done
in ddbf011257, and update the
comment in the stylesheet.

Bug: T288907
Change-Id: I3d929eaae54754bd3e41a9add419f1098a7f8e3a
2021-08-15 16:01:07 +02:00
Kunal Mehta
a85f569dd1 Revert "Use CsrfTokenSet as CSRF token source"
This reverts commit 0d75fdb4f7.

Bug: T287542
Change-Id: Iedd3461869f973f8d621a39e6ad4674cbb577551
2021-08-05 15:48:26 -07: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
jdlrobson
d030d86357 Revise FIXME comments relating to use of '-' character as an access key
Introduced in 2008, and would involve a lot of unnecessary complexity
and potential software confusion, so revising comment to explain
the constraint that access key cannot be a "-" character.

Bug: T284139
Change-Id: I25f5b1943c58f76df9e3a7830d0d4c377494b280
2021-07-14 00:15:54 +00:00
Petr Pchelko
0d75fdb4f7 Use CsrfTokenSet as CSRF token source
Change-Id: I079d2c802d9b48d6abf7f37fa9ef7dafac631345
2021-07-12 14:19:15 -07:00
Arlo Breault
fdd8f864b8 Emit media structure as piloted in Parsoid
Gated behind the flag $wgParserEnableLegacyMediaDOM.  The scattershot
usage of it is a little unfortunate but isn't expected to live very long
so maybe that's acceptable.

Further details can be found at,
https://www.mediawiki.org/wiki/Parsing/Media_structure

Bug: T51097
Bug: T266148
Bug: T271129
Change-Id: I978187f9f6e9e0a105521ab3e26821e36a96b911
2021-06-24 23:32:40 +00:00
Thiemo Kreuz
2ba01c7ee7 Remove some more comments that literally repeat the code
… including PHPDoc tags like `@return <type> $variableName`.
A return value doesn't have a variable name. I can see that
some people do this intentionally, repeating the variable
name that was used in the final `return $var;` at the end
of a method. This can indeed be helpful. I leave a lot of
these untouched and removed them only when it's obviously
wrong, or does not provide any additional information in
addition to what the code already says.

Change-Id: Ia18cd9f25ef658b08ad25b97a744897e2a8deffc
2021-06-18 21:23:56 +00:00
DannyS712
a4673c7ee7 Linker: remove support for Revision parameters
- Linker::buildRollbackLink
- Linker::generateRollback
- Linker::getRevDeleteLink
- Linker::getRollbackEditCount
- Linker::revComment
- Linker::revUserLink
- Linker::revUserTools

Bug: T247143
Change-Id: I600b690788dedeb4c9f7bd92da4f24b7dae2c4d2
2021-05-04 19:20:12 +00:00
Ammarpad
168ac52a58 Prepare for renaming page_timestamp revision index
Bug: T270033
Change-Id: I28ab091cf741e080c88ac7209edf3652b0f12fc1
2021-04-29 22:58:02 +01:00
Amir Sarabadani
b6f148bec6 Add classes to when a linked change is suppressed
This also tries to centralize adding logic of adding history-deleted
class as well. To make future changes easier.

This doesn't affect history deletion on files, recentchanges, and logs yet

Bug: T23272
Change-Id: I08f14f712479e1b170c606e2b64857f8386acd76
2021-04-29 15:28:06 +00:00
mainframe98
ddbf011257 Move most remaining legacy styles to interface.helpers.styles
This module is used almost everywhere these elements are found.
Methods in Linker that produce these elements list that this module
is required for proper styling.

Where possible, the module is added to retain the styles.

Bug: T278576
Change-Id: I7dedebd3bce3b4aec127738edc81b180325f0836
2021-04-20 07:15:25 +00:00
ZabeMath
60606a2986 Avoid using User::getBoolOption()
User::getBoolOption() is deprecated and should be replaced with UserOptionsLookup::getBoolOption()

Bug: T277600
Change-Id: Ife3c721237258d50852bbf764def74657cc70428
2021-03-27 22:51:03 +01:00
Peter Ovchyn
45140daa29 Avoid using User ::getDefaultOption, ::getDefaultOptions
This patch hard-deprecates the methods above

Bug: T276035
Change-Id: Ic36b0702f7547acce0d162d6e0b54bbd4ecf4d81
2021-03-16 17:24:17 +02:00
Petr Pchelko
c4f28d017b Replace some usages of User with Authority/UserIdentity
Change-Id: I7dfbf9bbd1709f5e67de7f6680a5a5ad156994fa
2021-03-04 17:20:40 -07:00
Petr Pchelko
782a46f661 Use Authority for revision audience where possible
Depends-On: I963a79d94b9e39086940a43945def7c8eff1536d
Change-Id: If99d428b391c0eaf61396565af7f38740bef6c4a
2021-02-24 10:56:50 -07:00
Umherirrender
8de3b7d324 Use static closures where safe to use
This is micro-optimization of closure code to avoid binding the closure
to $this where it is not needed.

Created by I25a17fb22b6b669e817317a0f45051ae9c608208

Change-Id: I0ffc6200f6c6693d78a3151cb8cea7dce7c21653
2021-02-11 00:13:52 +00:00
diwanshu885
9f2dc47bc3 Add data attribute to the elements with class "history-size"
Bug: T147908
Change-Id: I9a27ff029e86c705271ef1c2289daa95eb927315
2020-12-23 19:44:54 +05:30
Arlo Breault
c2cef6cb58 Consistent label escaping in makeBrokenImageLinkObj
Html::element is more lenient about which characters it escapes.

But really this is just factored out of the next patch for ease of
review.

Change-Id: I9abb4d866a624df7bf4628ab9cc581967e715160
2020-12-18 11:41:09 -05:00
Ostrzyciel
b25d48ea03 Add hook to Linker::generateRollback()
Add a hook that would allow extensions to modify the default
rollback link in MW's interface.

Bug: T252518
Change-Id: Ia6920e601a4b9433f4083a386ff35f5478dc4e3c
2020-12-06 20:44:34 +01:00
hmonroy
0c2cc49bdc Update language in watchlist expiry
Update watchlist expiry language indicators (dropdowns, tooltips, watch
via star, watch via edit):
 * Change "Permanently" to "Permanent"
 * Change "XX days left" and "Expires in X days" to "XX days left in
   watchlist"
 * Update the "Click.." sentence by star to "Click to remove it."
 * Change watch period for a page that is less than "1 day left" to "A
   few hours left"

Bug: T253135
Bug: T255632
Change-Id: I114c6f77e86ad81b1810fedcd49f52c88700ca16
2020-08-14 11:47:03 -07:00
suecarmol
436d7fbf06 Display remaining watch period in watchstar
Add a new tooltip message that displays the remaining watch period of a
page, if it is being watched temporarily. The tooltip message remains
the same if it is being watched indefinitely.

Bug: T250215
Change-Id: Ic9d1301427d477de71fb6f63fe77554a33684cd1
2020-07-18 01:45:51 +00:00
Umherirrender
eb52709e7e Remove unused Title::newFromText in Linker::formatLinksInComment
Change-Id: I8001fe285e98c011268fe3e5a144089f141c2155
2020-06-15 01:13:00 +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
Timo Tijhof
45da13803d resources: Bundle ajax patrol and ajax rollback code
Create a small "curate"-related bundle of moderation and review
enhancements. The overlap between the two is not perfect, but the
scripts are small enough that it doesn't seem worth trying to
create separate bundles for.

Change-Id: Ibd00e0eddfafc57323b147e225ee668528dc1c1c
2020-05-28 07:22:07 +00:00
Derick A
707567bd73 linker: Move Linker::normaliseSpecialPage to LinkRenderer class
Would have love to just kill Linker::normaliseSpecialPage() but
the deprecation policy has to be followed and we'll drop the above
method in 1.36.

For now, we'll just soft and hard deprecate it, also, callers have
been updated.

Dependency inject SpecialPageFactory to LinkRenderer service and
note that ->normalizeTarget() is only for internal use by Linker
& DummyLinker via their `->normaliseSpecialPage()` methods.

Also, updated unit tests to capture injecting the special page
factory class.

Change-Id: I951403c89ff497fd1f7441ad0304dd5bc9442ad7
2020-05-24 23:11:55 +00:00
WMDE-Fisch
40aba4175b Make formatLinksInComment understand and link [[Text[[Link]]
In Wikitext this will end up in [[Link]] being converted to a link.
In comments this is ignored prior to this patch.

Bug: T197958
Change-Id: I454d342a57c35c30af042349a04e3b86d778568f
2020-05-13 14:26:35 +02:00
Reedy
a8467a0fd7 Fix numerous PSR12.Properties.ConstantVisibility.NotFound
Change-Id: I157220c4e9ff516283a60f06af99efa2439332e3
2020-05-12 18:41:43 +00:00
Reedy
12a3883a7b Fix SingleSpaceBeforeSingleLineComment
Change-Id: I285af438ce484af40741489797f20455726ec110
2020-05-11 00:57:11 +00:00
DannyS712
5e9d155698 Remove extra space in Linker::revUserLink
Change-Id: Iff565360500abe1e64db10f6a781daf831a5f0a4
2020-05-01 13:36:11 +00:00
DannyS712
82657a347a Hard deprecate using Revision objects for Linker methods
Bug: T249561
Change-Id: I0a9ece35900e0b844e66ba119b04a848dc1ecc82
2020-04-18 02:01:42 +00:00
DannyS712
af7f397ccc Pass RevisionRecord to Linker methods
Hard deprecation of passing Revision objects will follow soon,
but until that is ready core calls can be updated

There is some code cleanup that could be done around the calls, but
to simplify review no other changes are made.

Bug: T249561
Change-Id: Ifcfb3811650decffeaa87dc033c41fd1710b47a6
2020-04-18 01:24:54 +00:00
DannyS712
ae690a533b Accept RevisionRecord in Linker methods
In addition to Revision, for now

Bug: T249561
Change-Id: Ia05db749ebceb419fb27a4120fdd10d7bda9f66b
2020-04-07 00:54:31 +00:00
jenkins-bot
b2be858d92 Merge "Remove direct access to Action::page and Article::page properties" 2020-03-27 04:36:51 +00:00
ArtBaltai
726a2650d3 Remove direct access to Action::page and Article::page properties
Bug: T239975
Change-Id: Id0d4d1e099edbdd67cabbed423dfff68cc48d323
2020-03-27 04:10:51 +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
0de13c6125 Merge "Fix mismatching type hints in PHPDoc tags" 2020-03-26 13:35:31 +00: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
a8d93e2169 Linker: Pass a user to revision methods using FOR_THIS_USER
Bug: T248291
Change-Id: I336f6a4ddd696f7471d09eaec252096a9c575abc
2020-03-23 05:40:42 +00:00
DannyS712
78bc3ae255 Hard deprecate Revision::userCan
Replace remaining uses outside of tests, hide deprecated in tests

Bug: T247259
Change-Id: I91dfb46ed6864ee89d968aea8ec93b5ea2f8389e
2020-03-11 02:10:52 +00:00
DannyS712
9e701c9698 Remove use of global $wgUser in Linker::userToolLinks
Bug: T244602
Change-Id: Id49043ca5ef9cf655f3aace520b344463991b39b
2020-02-19 23:39:28 +00:00
Matt Fitzpatrick
8a1f19d726 Add ARIA navigation role and label to table of contents div
Adds accessibility context to the automatically generated table
of contents div for a page. The div's role is navigation, and
its label is the heading "Contents".

JAWS, for example, can navigate to the table of contents by
region, and announces it as "Contents navigation region".

Bug: T139221
Change-Id: Ie9b291301f683d2be2cb2134f9d6ae3f7a6d831b
2020-02-05 16:24:46 -08:00
Kunal Mehta
99007e96c7 Use namespaced IPUtils class
Change-Id: I047e099a93203a59093946d336a143d899d0271f
2020-01-01 02:36:49 -08:00
Umherirrender
46f6a9e13f Document null for $html on Linker::link
The default value of null should be part of the @param

Change-Id: Ib612a29e355c7dda8f3f66270a2fbd33cb1938be
2019-12-12 19:57:11 +01:00
Umherirrender
925e3eb30b Set method visibility in some classes
Change-Id: I3c3d59d4b3edf2459efeac890721a43475e27198
2019-12-05 17:42:55 +00: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