Commit graph

160 commits

Author SHA1 Message Date
Reedy 2afb728a10 Fix PSR12.Properties.ConstantVisibility.NotFound
Bug: T253169
Change-Id: I506e43629a30ef34c9154b8212878255de7d90b9
2020-09-19 21:26:38 +00:00
C. Scott Ananian 37261f977e Remove calls to ParserOptions::setTidy()
ParserOptions::setTidy() was already a no-op in MW 1.35, and
Echo already requires MW >= 1.35 in extension.json.
ParserOptions::setTidy() was deprecated in MW 1.35 and will be removed
in a future release.

Bug: T198214
Change-Id: I6a5378a42a6cf035296ad549525c25438803970a
2020-08-12 23:41:49 -04:00
Ed Sanders 1b40b69481 Make default snippet length (150) a constant
Change-Id: Idb53b226618fa0d625c7e4713c780538bd6a76ea
2020-07-23 13:00:44 +01:00
Ed Sanders b5c919db25 DiscussionParser: Use strict (in)equality
Change-Id: I7c6a8453a5f7a6603c8f8c173e5bcfd3cafc25d6
2020-07-22 21:50:54 +01:00
Umherirrender 3c53d6acb9 phpcs: Break long lines
Use the codesniffer default of length = 120

Change-Id: Ifbfd56b20432e54805d3a9bce22cda888c1fc74d
2020-06-27 12:05:03 +02:00
DannyS712 9564e1ae50 Docs: Use replica instead of slave
Bug: T254646
Change-Id: I06387e33c5207ea59db34dba3b482893ff103288
2020-06-08 23:49:00 +00:00
Tim Starling 41d53fde50 Don't put a whole User object in extra[mentioned-users]
DiscussionParser::getUserMentions() returns mentions in an array of the
form [ID => ID]. UserLocator says "we shouldn't receive User instances,
but allow it for backward compatability". But
DiscussionParser::generateEventsForRevision() was putting User objects
into the extra when there is a mention in the edit summary.

I noticed this when I accidentally made User objects be unserializable
in a core patch.

So, I made generateEventsForRevision() generate mention arrays in the
same ID=>ID format as getUserMentions().

Change-Id: I7c6d25950c8887b50426863c7b0a2d5d007559dd
2020-05-05 14:41:49 +10:00
Ammar Abdulhamid ad8340ea59 Replace deprecated User::isAllowed with PermissionManager
Bug: T220191
Change-Id: I321a1d67a9272dfb305d76589c6371176f1afc16
2020-03-14 19:14:37 +00:00
Umherirrender a933412ea5 Use MediaWikiServices::getMessageCache
This required MediaWiki 1.34 (already set in extension.json)

Change-Id: Ib9f9fe6581c3019fa32dff53acf33edb4266e44d
2020-03-14 14:04:32 +01:00
DannyS712 72f30649d5 Pass a user when creating a new ParserOptions
Bug: T246861
Change-Id: Ie6b6504d3b78a33ecb89a5c431bc225622d715c2
2020-03-04 21:53:33 +00:00
libraryupgrader cbc50bd4fe build: Updating composer dependencies
* mediawiki/minus-x: 0.3.2 → 1.0.0
* mediawiki/mediawiki-phan-config: 0.9.0 → 0.9.2

Change-Id: I384e3624fadebd736a3ea465df79df6bf9dd5a74
2020-02-19 20:20:29 +00:00
jenkins-bot 30ed6adb92 Merge "build: Updating mediawiki/mediawiki-phan-config to 0.9.0" 2020-01-02 08:59:53 +00:00
Umherirrender 317246762c Removed comment out debug code from EchoDiscussionParser
Change-Id: I0f5823253e7dbad6aabcc85f3f1e0c2196874f66
2019-12-29 16:08:15 +01:00
libraryupgrader ef3d2b886d build: Updating mediawiki/mediawiki-phan-config to 0.9.0
Change-Id: I03333636654eff80d4fe7fa543ac9e6c321af891
2019-12-29 11:59:32 +00:00
Thiemo Kreuz (WMDE) 65700e6c0e Revert "Make method parseNonEditWikitext public"
This reverts commit b4fdb685cb.

Change-Id: I33abe899f34903cfcc24c7a4f45e70aaab3f0abb
2019-12-28 20:16:38 +00:00
Paladox b4fdb685cb Make method parseNonEditWikitext public
It's used by the Comments extension.

Change-Id: If69b1706067a0c80420e427a453da965f226aa75
2019-12-23 01:54:53 +00:00
Roan Kattouw d85252b97d DiscussionParser: Fix type hint fatal from getUserLinks()
Instead of returning false when no links in the user namespace are
found, return an empty array. They're both falsey, but this way we don't
break the type hint in generateMentionEvents(), which is the only thing
that getUserLinks() is used for anyway.

Bug: T239275
Change-Id: I93b320be07cfdae68c5e296b2caa62ea4fae5ff2
2019-11-26 17:57:16 -08:00
Umherirrender f62ab66363 build: Updating mediawiki/mediawiki-phan-config to 0.8.0
Bug: T235049
Change-Id: I93844dc6fae8a3dca3ced591d43caa2f994ba2f1
2019-11-18 20:03:13 +01:00
Thiemo Kreuz 0efef4faf3 Add strict "array" type hints to code expecting arrays
I found candidates for this by looking for parameters names that end
with a plural "s".

Change-Id: I61c706eb4dfbdadceb0129afd724e6ce1eb4f4a8
2019-10-24 15:18:58 +00:00
Dayllan Maza b3df45dc34 Add option to mute/unmute notifications on Special:Mute
The hook (SpecialMuteModifyFormFields) is used to append
the option to mute/unmute echo notifications from a specified user.

Special:Mute handles posting and saving the fields, the only
requirement is that the field name is the same as the property
that wants to be modified, in this case 'echo-notifications-blacklist'

Bug: T220163
Depends-On: I2b3eee0802cb086091f35ecce13ae77a8e7d518d
Change-Id: I77b3ccfdce9b501eb8ecd58c0d7bbecb78029a7e
2019-07-18 15:47:24 +00:00
Stephane Bisson 1ebb8e3daa Don't add CommentStoreComment as plaintext params
Follow-up Icfc8516 and I3d997f9 (migrating from deprecated Revision
to RevisionRecord)

When generating 'edit-user-talk' events, if we don't have the section-text,
we use the edit summary instead.

Revision->getComment() returns a string but RevisionRecord->getComment()
returns a CommentStoreComment. As a result of the migration, an instance
of CommentStoreComment was put into the event 'extra_data' and later
added as a plain text params during notification presentation.

This patch proposes to
1) Make sure to add the comment's TEXT to the event
2) Test that the 'section-text' is a string before using it
   as a message parameter. This will cause faulty notifications to
   render without a body instead of erroring out. We could write a
   maintenance script to fix those notifications but I don't
   think it's worth it.

Bug: T223741
Change-Id: Ie3a1c59a43b0981ec42fc77e7ebb0e8bd132dbe2
2019-05-21 11:44:54 -04:00
Derick Alangi 76544df40a Migrate DiscussionParser::getEditExcerpt() to accept only RevisionRecord
Follow up on Icfc85167a636bef95daab2.

Bug: T221163
Depends-On: I31d819f4453032da8deb117254b954fba058e0a3
Change-Id: I3d997f9e8d4bd1566ec6fd8fe2d33be5161458b3
2019-05-09 20:36:05 +00:00
Derick Alangi 8e5aa13a73 Remove usage of deprecated Revision class in Echo
Class Revision is deprecated and in this patch, replaces
usage with appropriate classes; RevisionRecord, RevisionStore,
etc.

Bug: T221163
Change-Id: Icfc85167a636bef95daab236ab80113c1a3cf41b
2019-05-08 19:50:58 +01:00
Thiemo Kreuz e649551e5e Simplify a few overly complex code snippets
* preg_match_all already returns the number of matches. We can just use
  this number instead of counting it.
* Checking for a strlen() of 0 is a little tooo expressive, because we
  don't really care about the actual length of the string.

Change-Id: I0537a7740e5d369b79364f24aecf71c4e8fa7db1
2019-02-19 20:39:26 +00:00
libraryupgrader 5bd2eaf70e build: Updating mediawiki/mediawiki-codesniffer to 24.0.0
Change-Id: Ifd3dde125bae36b1076576ddc0c8b09eadd18a72
2019-02-06 13:01:32 +00:00
jenkins-bot 6b0eb59c5d Merge "Replace two regular expressions with cheap string manipulations" 2018-11-07 22:37:56 +00:00
jenkins-bot f75d5d120f Merge "Add method scope visibility" 2018-11-02 23:55:06 +00:00
Umherirrender 81183a6d86 Add method scope visibility
Change-Id: Id4fe59155d6e0fa2ef1ccf4dc46ee1f109265246
2018-11-02 18:47:39 +01:00
Roan Kattouw de536d09d9 Make notifyAgent a per-type property rather than per-event
Specify which notification types allow notifying the event agent in
$wgEchoNotifications, and stop specifying it in the event_extra data.

Putting 'notifyAgent' => true in event_extra will still work, but is
discouraged.

Change-Id: I4f558654ec23757dd4ecd6986eb3e9a5593f5386
2018-10-29 15:41:51 -07:00
Thiemo Kreuz 5cf0e6273f Add missing limits to explode() where possible
For the algorithms in question this does not make any difference. Excess
elements are thrown away anyway. This is for performance.

Change-Id: I645e389b3f993bc8015fd729b9302aa25471f833
2018-10-20 09:11:19 +00:00
Thiemo Kreuz 8c51f5bd45 Avoid count()ing where not necessary
If all the code needs to know is if an array is empty or not, using
count() creates more confusion than anything.

Change-Id: I253308505fe5af5b5c56d85169789271967298ba
2018-10-19 10:04:24 +02:00
jenkins-bot 319789827c Merge "Use \h instead of \s in regular expressions" 2018-10-11 22:11:58 +00:00
Thiemo Kreuz 44f861496f Replace two regular expressions with cheap string manipulations
Note that the array of matches returned by preg_match changes when
PREG_OFFSET_CAPTURE is set. That's why the additional [0] (for the
match) and [1] (for the offset) are needed.

Bug: T203930
Change-Id: I89f9ea3bef49fe9128fd42805695982f012ecba9
2018-10-11 10:59:04 +02:00
jenkins-bot a88c189301 Merge "Remove expensive regular expression that doesn't have any effect" 2018-10-04 13:23:28 +00:00
Thiemo Kreuz acba72e011 Remove expensive regular expression that doesn't have any effect
See, this last part of the compiled regular expression is wrapped in
an (…)*, which means it is entirely optional. It does not make any
difference if this part is found or not. The compiled regular
expression matches with or without any of these "line ending"
fragments being present.

I can not really figure out what the intention of this was. A line
ending anchor ($) is not missing – I'm pretty sure about this.
Otherwise it could not detect signatures that are wrapped in more
than a single HTML tag, for example.

Instead of fixing it I decided to remove it. The tests should show
this code was not needed.

The motivation for this patch is to improve performance. This part of
the regular expression is quite heavy and can cause a lot of
backtracking for literally zero benefit.

Bug: T203930
Bug: T204291
Change-Id: Ia5323b401b947edeb7094d7eec131ba6c80edf70
2018-09-25 18:15:49 +02:00
Thiemo Kreuz 17762b3b29 Use \h instead of \s in regular expressions
\h matches only horizontal whitespace, but no newlines. This is what
we want in all these cases, because nothing of this (headlines,
signatures, timestamps) is even allowed to span multiple lines in
wikitext. The tests should show this still succeeds.

The idea is to make these regular expressions more strict so they
don't run in so much expensive backtracking.

Bug: T203930
Bug: T204291
Change-Id: I805f8cb082edcd26713ef41d3ae5b61194c131e5
2018-09-25 18:09:51 +02:00
Thiemo Kreuz 0c7bd7dbc8 Wrap unknown \A escape sequence in single quotes
In double quoted strings PHP tries to understand all kinds of escape
sequences, but \A is not one of them. Such sequences are left untouched,
including the backslash.

In single quoted strings, there are no escape sequences. All are left
untouched, which is what we want in case of a regular expression.

TL;DR: The resulting string is the same in both cases. I'm touching this
because my IDE shows a warning about the unknown \A escape sequence.
It must be either turned into "\\A" or '\A'.

Change-Id: Ie1e84c67c344faf77bc86a0b28dc82d31c3a7dbe
2018-09-25 18:05:40 +02:00
jenkins-bot d53af8b8d3 Merge "Use "false" as type hint in PHPDoc tags" 2018-08-16 01:00:05 +00:00
jenkins-bot ef233becf5 Merge "Make "@… array" type hints more specific" 2018-08-16 00:57:12 +00:00
jenkins-bot b0e11b45f0 Merge "Make use of inline {@see …} tags" 2018-08-15 22:18:56 +00:00
Thiemo Kreuz e5546e50b6 Add missing strict "array" type hints to DiscussionParser
This patch adds a few strict type hints on the language level, not
only on the PHPDoc level as my other patches do.

Change-Id: Ie66f9ebf80317dcaf13e2e96a93332a1a93cebbe
2018-08-15 09:03:33 +00:00
Fomafix a1f72bbfa0 Use ContentLanguage service instead of global $wgContLang
This change requires MediaWiki 1.32 which is already required in
extension.json.

Change-Id: I61856796d864c9493c1a7a875cb2415f11f081a9
Depends-On: I193f5b9a95430b0a05573c361715e053e5411e32
2018-08-13 23:30:34 +02:00
Thiemo Kreuz 8a7c3a78a9 Use "false" as type hint in PHPDoc tags
Most modern IDEs as well as documentation generators understand the
keywords "false" and "true", when a bool can only be one of the two.

Change-Id: I83dd1f0cc0802fa74ee35e7ca7425615230a767f
2018-08-13 15:31:13 +00:00
Thiemo Kreuz c1c3c7b672 Make "@… array" type hints more specific
There are about 200 of such generic "array" type hints in this code base,
the majority in @param tags. I started with what I found most relevant:
@var and @return tags. I might continue working on this later, but
wanted to stop for now to keep this patch moderately small.

Change-Id: Iff0d9590a794ae0f885466ef6bb336b0b42a6cd3
2018-08-13 09:27:37 +02:00
Thiemo Kreuz cf4ba1e6b8 Make use of inline {@see …} tags
Tested with the quick preview (Ctrl+Q) feature in PHPStorm.

I'm also updating a few type hints I could not split off into a separate
patch, because the lines are to close to each other.

Change-Id: I312ec601a5f443c2b12515e34c574b8889c4c128
2018-08-13 09:17:15 +02:00
Thiemo Kreuz 75a55b80ee Remove some non-helpful lines of documentation
Explaining that a variable named "$username" contains a "username" is
not helpful. One have to read this comment first to understand that it
does not add anything to what's already obvious from the variable name
and the type.

Change-Id: I9a43866498d0c94422caf16233f502320a8e36c9
2018-07-06 15:14:44 +00:00
jenkins-bot 855497c3ba Merge "Avoid counting where not necessary" 2018-06-26 13:54:59 +00:00
Thiemo Kreuz cb282251a8 Avoid counting where not necessary
Change-Id: I0abbdced4474dabbdecd3bbfae194e79b7c29db1
2018-06-26 07:10:38 +00:00
C. Scott Ananian 190377dbbc Replace uses of deprecated Language::truncate()
See I2291c69d9df17c1a9e4ab1b7d4cbc73bc51d3ebb for the anticipated
hard-deprecation of this method in core.

Bug: T197492
Change-Id: I4687db09c27480147cfa7a648a886b1670812deb
2018-06-16 09:30:06 -04:00
Umherirrender b166664efc Fix parameter docs
Change @param to @var
Add |null to nullable arguments
Removed comment out code

Change-Id: I535ad4d544284c1e0fb6f39c254761f0810b4cc7
2018-04-06 08:17:17 +00:00