Commit graph

177 commits

Author SHA1 Message Date
Matěj Suchánek d8168ca071 Do minor code cleanup
Change-Id: I0beba40920e5ddc0abbf49f9765a1ef9e3d3d1e5
2022-06-24 13:25:43 +02:00
Jack Phoenix 9ed8612642 Make some DiscussionParser methods public instead of private for reusability
Comments has been duplicating these methods for quite some time for no real reason other than that they're private here.
Duplicating these methods appears to be necessary if and when working with extensions where users can be @mentioned but which are
not implemented as ContentHandler subclasses or otherwise related to regular wikitext pages.

Change-Id: I9c097bab9c5eed8f2399c86897b1f8968126c765
2022-02-17 14:21:09 +02:00
Umherirrender f21d2a5088 build: Remove unneeded phan suppression
Bug: T290624
Change-Id: Ie0209c72863aae8ac020a09e625f0c4613decca5
2022-02-11 20:57:34 +01:00
Bartosz Dziewoński 3493317d79 Parse section titles in notifs as if they weren't at the start of line
The section titles are wikitext extracted from inside heading markup
like `== … ==`, so start-of-line markup like `*` should not be parsed.

Bug: T299572
Change-Id: Ie3995b943e5fe20ad86041d6be755f14f32eb01e
2022-01-21 00:07:53 +01:00
Kunal Mehta 2cfe757af4 Suppress SecurityCheck-DoubleEscaped in DiscussionParser
For now, to get phan/CI to pass again.

Change-Id: Ie69da3fd2b2b5463e9d22f0d77d10ddf6dfb3c72
2021-11-23 11:24:29 -08:00
Reedy 4814d14b85 Update comment about AbuseFilterVariableHolder
Change-Id: I81f71179ce7af081bedf1ed36bdb1aed80f9a08f
2021-10-14 21:38:55 +01:00
libraryupgrader 43efb95e8b build: Updating composer dependencies
* mediawiki/mediawiki-phan-config: 0.10.6 → 0.11.0
* php-parallel-lint/php-parallel-lint: 1.3.0 → 1.3.1

Change-Id: If2e235fb97c0d39c3c14ba7c423ef45f5c0013d0
2021-09-08 23:40:19 +00:00
DannyS712 4cc8233ee5 DiscussionParser: fetch UserNameUtils service outside of loop
Change-Id: I6c523dcc2ca1e06136f2f5ad18c0ac371c7f9494
2021-07-26 09:40:49 +00:00
Alexander Vorwerk bba113d92e Avoid using ContentHandler::getContentText()
ContentHandler::getContentText() is deprecated and should be
replaced with Content::getText() for TextContent instances.

Change-Id: Ia92c5a41954b1d21deb39dcafabbdff60a414f55
2021-05-17 23:44:00 +02:00
Umherirrender 37c602c532 Replace uses of DB_MASTER with DB_PRIMARY
Change-Id: I20abc845a3c74173ec4a111874c20cdeb1abd1d9
2021-05-13 02:04:54 +02:00
Ed Sanders 756b02b566 Introduce 'EchoGetEventsForRevision' hook
Collect event data and allow modification by a hook.

This allows extensions to look at the events generated so far,
add more events, or remove events.

Bug: T276990
Change-Id: I60818d57552946857077dee93b0adb036621b791
2021-03-17 21:59:13 +00:00
vladshapik e0d64d00d0 Avoid using User ::getCanonicalName
Remove using of User::getCanonicalName since this method will be hard-deprecated. Now it is soft-deprecated

Bug: T275030
Change-Id: Id708800bc709de175bc7c6acc422368a734b00f1
2021-03-01 19:50:14 +00:00
vladshapik 107c0dfccd Avoid using User::IsIP
Remove using of User::isIP since this method will be hard-deprecated. Now it is soft-deprecated

Bug: T275602
Change-Id: Ic1749cbad92bfe0eeae40736403fd5ceb6d504e8
2021-02-24 15:31:50 +02:00
Umherirrender ddf5b4bd24 Remove wrong return null from function documentation
Change-Id: I1a702bbdd4378a35216641ec73fbe318f02bde69
2021-02-03 21:59:07 +01:00
Thiemo Kreuz 0f954929a7 Remove comments that literally repeat the code
This also fixes a remaining `var` that should be `private`.

Change-Id: Ifa37a097a9d60bd22a16bc626d4b4271b8df2da7
2021-01-29 13:55:41 +01:00
Umherirrender d7556b1d96 Add missing @var and improve documentation
Change-Id: I729d5ff5afd4d45022fa0a4e42d060d35543b567
2020-12-17 20:55:49 +01:00
Thiemo Kreuz 8880df4123 Fix DiscussionParser failing in certain languages
It appears like the initial \h in this non-Unicode regular
expression matches parts of an UTF-8 character, destroying it.
This makes the final preg_match() in this method fail, when
$output is going to be used as a pattern.

Bug: T264922
Change-Id: Iaf240bc2e0808c2f57c1f8bab2589d3207915afe
2020-10-27 20:03:18 +01:00
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