Commit graph

390 commits

Author SHA1 Message Date
Ed Sanders e6e0b1ead9 PHP: Add missing typehints
Change-Id: I5639f8cbdae9aaa9cfa06136e19cc94f9fad10ea
2020-05-15 22:04:47 +02:00
Ed Sanders b78fb3f4c1 Move all PHP to the MediaWiki\Extension\DiscussionTools namespace
Change-Id: I654ebb3e646a6d8d62f7bd14d48805e39f836d7e
2020-05-15 21:57:13 +02:00
Ed Sanders 340572bc05 Create a Utils class in PHP
Also move htmlTrim to utils in JS.

Change-Id: Ia5356d713c1c5d521c396cc28bcd4ecc7ee5bbbb
2020-05-15 00:25:32 +01:00
Ed Sanders a3889fd400 Port modifier.js to PHP
Change-Id: I03b9e4377cb3ce6a5ca9d06e49dca9b2516f4979
2020-05-15 00:20:41 +01:00
Bartosz Dziewoński 6f32369b6a tests: Fix comparing PHP and JS ranges
In JS, strings are internally encoded as UTF-16, and properties like
.length return values in UTF-16 code units.

In PHP, strings are internally encoded as UTF-8, and we have the
option of using methods that return bytes like strlen() or UTF-8 code
units like mb_strlen().

However, the values produced by preg_match( …, PREG_OFFSET_CAPTURE )
are in bytes, and there's nothing we can do about that. So let's use
bytes throughout, mixing the two types results in meaningless numbers.

Then in the test code, we have to calculate UTF-16 code units offsets
based on the UTF-8 byte offsets.

We also have to copy the entire workaround for mw:Entity nodes… Maybe
the parser should be fixed to return the real nodes for ranges' ends
in this case.

Change-Id: I05804489d7de0d60be6e9f84e6a49a885e9fb870
2020-05-14 22:37:34 +00:00
Bartosz Dziewoński 76289cdf73 tests: Fix failures due to CDATA handling in PHP
It appears PHP's DOM library always uses CDATA nodes for the contents of
<style> tags, even if there is no such markup in the source HTML.

Change-Id: Id04b27086c5e7a0b016a3a440b2b4895d6b13c93
2020-05-14 22:37:23 +00:00
Bartosz Dziewoński 33d69e26c9 tests: Fix different whitespace trimming in PHP and JS
Notably, JS trims the no-break space, while PHP doesn't. There are
some other differences that don't come up in our tests. What we really
want is to trim the ASCII whitespace as defined in the HTML spec.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trim
https://www.php.net/manual/en/function.trim.php
https://infra.spec.whatwg.org/#ascii-whitespace

Change-Id: I95b8fb38878716a2fa7ec84c9f2e8065ebe77c0d
2020-05-14 21:37:26 +00:00
Ed Sanders 076c6d828a Parser: Use Element instead of Node when appropriate
Change-Id: I67015989954e61810302bf8931d05419f007ffeb
2020-05-13 14:46:36 +01:00
Bartosz Dziewoński b8d7a75c34 Fix performance of DiscussionToolsCommentParser::childIndexOf()
Profiling reveals that >87% of the run time of our test suite is spent
in this tiny method. Apparently, DOMNodeList::item() is extremely slow
(possibly it's linear time instead of constant time?).

Profiled using XDebug and KCacheGrind:
https://phabricator.wikimedia.org/F31815264

We can calculate the child's index in its parent by counting its
precending siblings instead, which turns out to be much faster.

Before:
 1. 275444ms to run DiscussionToolsCommentParserTest:testGetComments with data set #2
 2. 12668ms to run DiscussionToolsCommentParserTest:testGetComments with data set #3
 ...
After:
 1. 9545ms to run DiscussionToolsCommentParserTest:testGetComments with data set #2
 2. 5549ms to run DiscussionToolsCommentParserTest:testGetComments with data set #3
 ...

That's still kind of slow but now it's bearable to run the test suite.

Change-Id: I49155f7aa2e231a9a20bf282cf6aaa28fc902e0b
2020-05-13 02:56:39 +02:00
Roan Kattouw 7b7a2cd69c The Great Parser JS to PHP port of 2020!*
* Not to be confused with the Parsing Team's
"Great Parser JS to PHP port of 2019"

Gasp as OR hacks are changed to null coalescing operators.
Applaud as variable declarations are dropped.
Cheer as parameters and return values are type-hinted.
Shudder as DomNodeLists have no indexOf method.

Moving discussion parsing to the server should allow
us to implement much cleaner APIs for commenting.

Bug: T252252
Co-authored-by: Ed Sanders <esanders@wikimedia.org>
Change-Id: Ic1438d516e223db462cb227f6668e856672f538c
2020-05-12 12:33:04 +01:00
Ed Sanders 78aba45909 Hooks: Remove unused variable
Change-Id: I80f5dd63a2224f1c523ab1aa53da435851c2789d
2020-05-11 16:55:08 +01:00
jenkins-bot 922443f68f Merge "ConfirmEdit CAPTCHA support" 2020-04-29 12:04:44 +00:00
jenkins-bot 483aac1fca Merge "Enable on all ExtraSignaturesNamespaces" 2020-04-28 18:32:36 +00:00
Bartosz Dziewoński 7ef3bffb1e Show error on pages with fostered content to avoid page corruption in Parsoid
When the user clicks a "Reply" link on a page that is affected by the
'fostered' lint error (indicating fostered content in the HTML
representation), display an error and refuse to edit it, as Parsoid's
transformations will damage the page content.

The error message includes a link to documentation about lint errors,
and a link to the editor that will highlight the error location.

Depends-On: I723ec766d1244d117f8d624440026fe5af0d3403
Bug: T246481
Change-Id: Ic60cb58f98d10dc9b113469e5d3bbfb2d2b0564f
2020-04-21 17:40:39 +00:00
Bartosz Dziewoński 40c18508ec ConfirmEdit CAPTCHA support
Depends-On: I6605017fd31a4f96c529dd0beb69e9f4433cebc1
Bug: T247513
Change-Id: If9b3162969aa6ee67baff80aa84fa719bd3c3720
2020-04-21 18:55:38 +02:00
Ed Sanders 5565c7e4f0 Enable on all ExtraSignaturesNamespaces
For most Wikimedia wikis, this is Project (Wikipedia) and Help.

Bug: T249036
Change-Id: I535240dc5232b78f11d5003d1141ad8114f01be2
2020-04-19 14:53:40 +01:00
jenkins-bot c5e9185ae7 Merge "DiscussionToolsHooks: Only enable when viewing pages" 2020-04-14 15:29:04 +00:00
David Lynch e38aad96e4 Add override config for instrumentation rates
Bug: T250086
Change-Id: I32fbf3d6562fb0a93698a24bbd8177149a19fed3
2020-04-13 12:38:40 -05:00
Bartosz Dziewoński 3bd513374e DiscussionToolsHooks: Only enable when viewing pages
Previously we'd also run on action=history, action=info etc. (which did nothing).

Change-Id: I4bd10311a91433f357a6f5506c65364d399f3915
2020-04-01 22:48:51 +02:00
Ed Sanders bcd3fbfe9a Treat pages with __NEWSECTIONLINK__ as talk pages
Bug: T245890
Change-Id: Ibb9f6c675ce26c5a0e6e7934bd4659f5aaae6a25
2020-04-01 14:34:05 +01:00
Bartosz Dziewoński 92c3f079b8 controller: Make edit summary use the wiki's content language
Bug: T246043
Change-Id: I591e1a3ed3e7c8b68f5e203a0c77d057793fc767
2020-03-14 14:17:29 +01:00
Thiemo Kreuz d217b2b85f Replace deprecated Language class properties with constants
These are going to be removed via Id370937.

Change-Id: I87b3d13f66f0f449fead49865af9f9242717c568
2020-02-28 09:19:21 +01:00
jenkins-bot fcb935a2ba Merge "Add beta feature preference" 2020-02-21 22:00:44 +00:00
jenkins-bot cf8913d6a0 Merge "Don't use globals to access config" 2020-02-21 21:16:04 +00:00
Ed Sanders 2577d5aa28 Add beta feature preference
Bug: T245539
Change-Id: I8bb2c10255a13c291bc97c591612cadaf0e4339f
2020-02-21 15:20:48 +00:00
Ed Sanders f75137ecc1 Don't use globals to access config
Change-Id: I6180dff629af554b5430e20c2db2f6f94ef96478
2020-02-21 15:20:47 +00:00
DannyS712 6bef74693f Stop using old deprecated SpecialPageFactory static functions
Bug: T245686
Change-Id: I7501a66b0649bb3d2a928999f63a08371e1856ff
2020-02-19 23:15:32 +00:00
David Lynch 16215bbea2 Change tags method so anon edits will get tagged
Bug: T242184
Change-Id: I38baddc0febe02f6d2321be616adc018c87b5a54
2020-02-07 01:19:11 -06:00
David Lynch 2fcc23ae61 Add editor-mode changetags
Bug: T242184
Change-Id: Ib307e44ec883b01e0705c889f97e16326519f4c2
2020-02-06 20:22:27 +01:00
Bartosz Dziewoński 44eb801844 Add config option and query parameter to control loading
By default, DiscussionTools loads on all talk pages when the extension
is installed. This can now be disabled by setting the configuration
option `$wgDiscussionToolsEnable=false`.

To test DiscussionTools, one can now use the query parameter
`?dtenable=1`, which allows it to be loaded on any wikitext page
(overriding the config option).

Bug: T243621
Change-Id: I3d5a9cc9a4183fb6951f05c557b1d42735a9df7c
2020-02-04 22:06:13 +01:00
David Lynch 664b2890d7 Tag DiscussionTools edits
This sets up the tags:
* discussiontools
* discussiontools-reply
* discussiontools-edit (not yet implemented)
* discussiontools-newsection (not yet implemented)

The tags are flagged as user-addable, because otherwise they can't be
passed through to the VE API (at least, not without editing it so that
it explicitly knows about them, which seems like a strange
interdependency). It's assumed that letting users who know about the
tags add them to random changes via action=editchangetags would be
(a) the pettiest and most inconsequential vandalism possible, and
(b) unlikely to happen.

This relies upon I2c1d0f8d69bc03e5c1877c790247e165f160e966 in
VisualEditor to not also tag the edits with `visualeditor`.

Bug: T242184
Change-Id: I4e5e26afdd52279df242e1912f073b415b812c3b
2020-02-04 11:15:18 -06:00
Umherirrender 1c05fa9049 build: Add missing .phpcs.xml and make pass
Add .phpcs.xml to run codesniffer against the extension.
The entry in composer.json is already there

Change-Id: If9de7e9b1b9439dc4d5fa2ba521883d13deaa739
2020-01-13 20:48:11 +01:00
Ed Sanders e2c31a8450 Don't load DT on edit pages
Bug: T239873
Change-Id: I2aaa2f008d08dd5be9e0dfa980a68a9bfda91b44
2019-12-09 14:43:39 +00:00
Ed Sanders 7745d4a610 Require $wgLocaltimezone to be set
Change-Id: I0e09d87152bf7694c8ada935d5c37c244d70cb69
2019-10-28 22:41:10 +00:00
Ed Sanders ccb631eedc Separate DiscussionToolsData from DiscussionToolsHooks
Change-Id: Icb15cc7d118ac20bcf131f6862095b4481d1c882
2019-10-28 12:29:56 +00:00
Bartosz Dziewoński 9efe8b1dd4 Add unit tests for parser#getTimestampRegexp
Depends-On: I6c3d186de1877f73d4a4e3fec7d6d632a5d5fa83
Change-Id: Icdb44f793a8f5e56666ec635bb8b0125041b5aab
2019-10-24 23:21:29 +02:00
Bartosz Dziewoński db80e48933 Handle timestamps in daylight saving time
Add the Moment Timezone library. Add a script for managing libraries,
like in MediaWiki core.

Depends-On: I9a59a6ad01850b30327e4215f2be61b8d1c41277
Change-Id: I64bc79e7d0ccdf42b006e5a225c8aa70ea5f4e15
2019-10-22 16:33:21 +02:00
Bartosz Dziewoński b105bf7ded Detect and parse timestamps, signatures, comments and threads
Bug: T232780
Bug: T234404
Change-Id: Ie9c80121089742cfc7cd7c04d694c2e0fe8d6a98
2019-10-18 13:59:07 +02:00
Ed Sanders 53fae97723 Add an empty hook to load discussion tools on talk pages
Change-Id: Iafa24ed41c06d4bd8b9a7a684b986fdb37aa87c7
2019-10-12 17:14:28 +00:00
Ed Sanders fe0a05ad49 Add required files for an extension
Change-Id: I626e607e6ae7efc2521f9dd1da83c6fd90b0767d
2019-10-10 19:42:56 +01:00