Commit graph

56 commits

Author SHA1 Message Date
jenkins-bot 173012d395 Merge "ExtractFormatter: Rescue headings from being removed" 2024-07-16 15:05:46 +00:00
Bartosz Dziewoński 0fafa44a20 ExtractFormatter: Rescue headings from being removed
Bug: T363445
Change-Id: I662fe3dd06d6b010108c6f0ef891a8c6113b9a45
2024-07-16 15:02:03 +00:00
Umherirrender 290be2e8de Replace deprecated ApiPageSet::getGoodTitles
PageIdentity does not have inNamespace() (it is from LinkTarget)
PageIdentity does not have getContentModel(), use the WikiPage instead
Inject a TitleFormatter to get the prefixed title text

Bug: T339384
Change-Id: I0029e718f20ca01ee3cd13ada8be04a16480d51d
2024-07-05 22:05:55 +02:00
Umherirrender ee51b400b0 Use namespaced classes
Change-Id: Ic2db9150469e64bb0f478cf0c431d9f5824a23c9
2024-06-10 21:59:11 +02:00
Umherirrender 90040f278a Use namespaced classes
Changes to the use statements done automatically via script
Addition of missing use statement done manually

Change-Id: I45053ede3898b5c886a8182659466d321126ac1f
2024-01-04 22:22:49 +01:00
gerritbot 71e31619f2 Replace some moved Title class uses, now MediaWiki\Title\Title
Bug: T321681
Change-Id: I09a9c9f6294c9988feb3c2eba46ffde73996b3d3
2023-08-19 18:08:08 +00:00
Derick Alangi 627f65ebff
Use ExpirationAwareness instead of deprecated IExpiringStore
IExpiringStore has been deprecated since 1.35 and we can either
use the ExpirationAwareness or StorageAwareness constants where
necessary.

Change-Id: Ida557b3180eb5e7ebae46968142b4f154f26ffbc
2023-08-06 22:30:33 +01:00
Umherirrender b9f9e827be tests: Make PHPUnit data providers static
Initally used a new sniff with autofix (T333745)

Bug: T332865
Change-Id: Ifea9699646a5831471f4d536d0074d9976e1ac42
2023-05-20 14:13:35 +02:00
jenkins-bot 74baaa7ce1 Merge "Skip <h2> in TOC when extracting first section" 2023-03-20 09:23:31 +00:00
Thiemo Kreuz 60e1c5ad83 Skip <h2> in TOC when extracting first section
This piece of code is only relevant in case when:
- the intro section is requested (either in plaintext or html);
- the parse result for the full page is available in the parser cache;
- the full extract is not available in the TextExtracts WAN cache;
- the intro is also not available in the TextExtracts WAN cache.

In this case getFirstSection() is called with the parser output,
which is different from the the convertText() output it is called
with in other code paths, and still contains <h*> tags. A quick
regex is used to extract the first section. This stops at any <h2>.
A TOC also contains a <h2> (which will be removed later via
$wgExtractsRemoveClasses). This one needs to be ignored in case
the TOC is placed before the first section using e.g. the __TOC__
keyword.

The patch changes the regex so it ignores a h2 with
id="mw-toc-heading", but keeps working in plaintext mode when <h*>
tags are not present  (the code path when the intro section is
requested, and the full extract is available in the TextExtracts
WAN cache but the intro extract isn't).

Bug: T269967
Change-Id: I0a495d06cf1725744e556e81f17047fb53f53521
2023-03-20 07:40:07 +00:00
Reedy 0171e10a04 ApiQueryExtractsTest: Fix string interpolation
Bug: T314096
Change-Id: I8fb67f318c2f4b30dd2ad05a5e1d035017e0b022
2022-11-04 17:06:23 -06:00
Brian Wolff c77adce065 Tests: Use more complete mock to prevent php8.1 deprecated warnings
Fixes:

1) TextExtracts\Test\ApiQueryExtractsTest::testMemCacheHelpers
strtr(): Passing null to parameter #1 ($string) of type string is deprecated

Change-Id: Id39cb89bb5d49fbea543181da678b191f70311ac
2022-10-03 10:39:48 -07:00
Arlo Breault d67f9a73d5 Remove figures from text extracts
Bug: T318727
Change-Id: I304d4b794a0f27eb78ef013f911c444fc9a80cf1
2022-09-27 13:13:24 -04:00
Alexander Vorwerk abcb71cabb ApiQueryExtracts: inject WikiPageFactory
Bug: T297688
Change-Id: I8faa8a14efcd6cb6b247301aa4da0c1abac7c97b
2021-12-14 23:05:40 +01:00
libraryupgrader af581177ff build: Updating mediawiki/mediawiki-codesniffer to 38.0.0
Change-Id: I47fa2532c98e91e39443b93a6c789fad39ceb157
2021-10-24 14:22:47 +00:00
Alexander Vorwerk d70db0f0a7 MediaWikiTestCase -> MediaWikiIntegrationTestCase
MediaWikiTestCase has been renamed to MediaWikiIntegrationTestCase in 1.34.

Bug: T293043
Change-Id: I055adc107c175da9a0a8de276762bb2b323358e9
2021-10-13 12:28:17 +02:00
DannyS712 d7f93f5c17 ApiQueryExtracts: remove unneeded factory method
All services can be injected by bumping minimum
version of mediawiki (1.34 would be enough, but
since that is no longer supported require 1.35)

Change-Id: I8bb1573a02932ef5f2871606e94a41afe073fd00
2021-04-01 20:07:30 +00:00
jenkins-bot 40da2c16b9 Merge "Fix API adding ellipsis… when not needed" 2021-03-15 16:17:17 +00:00
jenkins-bot 0262d5409a Merge "Add test for ApiQueryExtracts::truncate()" 2021-03-11 17:57:42 +00:00
Daimona Eaytoy 8755419bfe Stop using deprecated Language methods
Change-Id: I8a4b7c470fdd7aca64667cf5ac93cd5619e7ca06
2021-02-27 15:23:35 +00:00
Thiemo Kreuz 29380b8d27 Fix API adding ellipsis… when not needed
When the text is short enough to be returned as it is, it's very
confusing to see it with an ellipsis added at the end. There is
no more text. It should not look like there is more text.

Change-Id: I7ef205fde6c358a1cbcbb41346a1c9e2a856d8fd
2021-01-08 14:40:06 +01:00
Thiemo Kreuz 471fdd0f89 Add test for ApiQueryExtracts::truncate()
Change-Id: Ia39188fe3ff1b87d82b4c573f8d27629e75c0aa4
2021-01-08 09:03:51 +01:00
C. Scott Ananian c1397847c0 Tidy is no longer configurable in MW 1.35
Remove use of deprecated MWTidy::isEnabled() and internal
MWTidy::singleton() methods.  See I3584181070da7ed4888beaaf04e083114aca1eab
for context.

Bug: T198214
Change-Id: I511068cc7b2398773a837f66e08def206cbb5626
2020-05-02 01:31:21 -04:00
Timo Tijhof 9d3ee77a95 tests: Remove PHP 7.4 workaround
Follows-up 955e0bb. Some of the other test cases already did this,
so let's do it here as well.

Change-Id: Ib39b03a38ff0d444568980db39a4d9b1e54618b7
2020-03-13 22:54:52 +00:00
Aaron Schulz e9d466f398 Convert $wgMemc use to WANObjectCache
Bug: T160813
Change-Id: If298927d6b90e1b94e83485e723f13aa2bad0932
2020-03-13 21:07:36 +00:00
libraryupgrader 7025be47c1 build: Updating dependencies
composer:
* mediawiki/mediawiki-codesniffer: 28.0.0 → 29.0.0
  The following sniffs are failing and were disabled:
  * MediaWiki.Commenting.FunctionComment.MissingDocumentationPrivate

npm:
* eslint-config-wikimedia: 0.12.0 → 0.15.0
* grunt-eslint: 21.0.0 → 22.0.0

Additional changes:
* Also sorted "composer fix" command to run phpcbf last.
* Removing manual reportUnusedDisableDirectives for eslint.

Change-Id: I351f0a333fd5f06e47f0748aa25cb3fff63cc67f
2020-01-15 09:17:22 +00:00
James D. Forrester d8eda5744f build: Upgrade mediawiki-codesniffer to v28.0.0
Change-Id: Ia1b33a8f268e6977ae32341a2b6b1e2f1603d776
2019-10-11 13:00:28 -07:00
Max Semenik c0b9bd8b77 Add more TextTruncator tests
This will take it to 100% coverage.

Change-Id: I835ac5795f15c65f07f47e9c00295d391dbf90ab
2019-07-17 20:29:00 -07:00
Thiemo Kreuz 8de415c4fd Fix truncate code potentially removing whitespace from extract
By turning the (?:…) into (?=…) they become lookaheads and are not
part of the returned string in $tail any more. This is exactly what we
want here. All we want is to *know* if the dot, question or exclamation
mark is followed by a space. But we don't need the space captured.

Change-Id: I4be715c4c084165e5ab25da77609f12ffce4d385
2019-05-03 08:46:29 +02:00
Thiemo Kreuz 81fd92685a Move Tidy functionality to TextTruncator
I argue that the code fixing unclosed HTML tags is – even if optional –
an integral part of the code that potentially breaks these HTML tags in
the first place. Notice how much code disappears in the ApiQueryExtracts
class.

Additionally, the new approach uses an interface instead of a static
function call that is impossible to mock and hard to test.

Change-Id: Ic1a65995f4dba11d060a8738d642905cbfc79271
2019-05-03 08:46:27 +02:00
jenkins-bot 8567e067f2 Merge "Extract unrelated static code from ExtractFormatter" 2019-05-02 21:03:58 +00:00
Thiemo Kreuz 8d3ff14a93 Consistently mention the @license in all files
Note how only two files mentioned the license before. For consistency
it should be either all or none. Both solutions would be possible. Even
*not* mentioning the license anywhere in these files would be fine from
a legal perspective, as long as the relevant file COPYING is still
there in the root folder of this extension.

The overly long "deed" text does not serve much of a purpose. It's not a
complete, legally relevant license text. It's hard to read as the fact
this is "GPL2+" is surprisingly hard to find. The @license tag solves
these problems, and is recognized by documentation generators.

Change-Id: I7844be0c5f4f3d7562156cd9f34fe466552a9c9d
2019-04-24 18:26:53 +02:00
Thiemo Kreuz a0d37fcb51 Extract unrelated static code from ExtractFormatter
This is a straightforward baseline patch that does nothing but moving
existing code around, without touching it. I'm not even trying to
remove the "static" keyword. The actual refactoring will be done in
the next patch. I hope with this the changes I do in the refactoring
become more visible and much easier to review.

Change-Id: Idba859ec0c24f3622ea8fb8d7a9b11843d1e3827
2019-03-21 12:38:13 +00:00
Thiemo Kreuz b6250d3791 Add missing test cases for ExtractFormatter
This is especially covering:
* The behavior on different kinds of HTML encoded characters.
* Trimming, or more precisely the fact that the formatter currently does
  not do all the trimming. There is a trim() call in the test that should
  not be there. This will be reworked in a following patch.

Additionally:
* Prefer strict assertSame() where possible.
* Remove two assertions that don't help making the test more safe.
* Utilize the new `// phpcs:…` syntax.

Change-Id: Ic361f2644300dcef3fc972a2dc2ae19ad34fa513
2019-03-19 17:58:32 +01:00
Max Semenik 0215eae3aa Make ExtractFormatter not depend on configuration
Change-Id: I4e9a0947bf50d062ea28004bde30d2e8b18788a4
2019-03-17 18:02:09 -07:00
Thiemo Kreuz ed1f73365f Add test cases for all (private) memory caching helper methods
This patch does two things:

* Add a testMemCacheHelpers() test for the setCache(), getFromCache(),
as well as cacheKey() methods.

* Simplify the existing test setup utilizing the PHPUnit4And6Compat
layer. I'm also replacing the Config mock with an actual HashConfig,
because that's a really trivial object that does not need to be mocked.

Change-Id: I7e8a62651a53919d338a7d921f548e941b671670
2019-02-13 14:37:24 +01:00
Thiemo Kreuz ca83bbfd3b Improve coverage for mostly untested ApiQueryExtracts
Instead of trying to come up with a (probably hypercomplex) integration
test for the entire API module, I start to test a few more critical
details. Yes, this is now testing private implementation details. This
is meant as a migration path. See, it's hard to test code like this
without rewriting it, and hard to rewrite it without tests. This patch
aims to give us a little more confidence for future rewrites.

Change-Id: I0405e13eba31124fcb5af83159d7438fe0ad9879
2019-02-11 17:37:20 +01:00
Thiemo Kreuz 9f99628c1f Remove unused ParserOptions from ExtractFormatterTest
Change-Id: I685b468ad13da73b6273041f6ff068c2d8b730d0
2018-06-28 20:44:46 +02:00
libraryupgrader 2ecb9f8f06 build: Updating mediawiki/mediawiki-codesniffer to 16.0.0
Change-Id: Ib1a9584cab61f71c3525b0a81d906f457dab3eb6
2018-02-15 14:32:47 +00:00
Kunal Mehta b463a99a79 Fix and add @covers tags
Change-Id: Ifa11ee418e016c103fb0ac6b32a790a2977aec8d
2018-01-23 14:54:12 -08:00
jenkins-bot 03de2f62b4 Merge "Don't repeat the default in test setup" 2017-12-01 04:36:15 +00:00
Pppery d05f289032 Re-enable MediaWiki.WhiteSpace.SpaceBeforeSingleLineComment.NewLineComment sniff
Bug: T170580
Change-Id: Ib5bcab3414f44013cf57c0d006b212dea175473a
2017-11-29 23:07:30 -05:00
Brad Jorsch 6523ae42dd Don't repeat the default in test setup
For a new ParserOptions object, ->setEditSection( true ) is already the
default. Since it's being deprecated in MediaWiki core change
Ied5fe1a61, just remove the call.

Change-Id: Id517a8746d4cc4b0b26a98a74244e4d8c711358c
2017-11-22 17:44:44 -05:00
Umherirrender 01376c8e05 Improve some parameter docs
Change-Id: Ie4326ecb517e5c7381b946b45bc108f8889fd4b2
2017-10-07 11:24:02 +02:00
Max Semenik 753fc03c10 Don't call ParserOuptut::setTOCEnabled()
It's not really needed. Add tests verifying that.

Bug: T168040
Change-Id: I49cf58d92620ad53dd833bc8ce0d2443a00b48e4
2017-07-24 17:55:06 -07:00
Baha 182304dc6d API: Limit maximum number of characters when exchars is passed.
Set the limit to 1200 characters.

Bug: T156467
Change-Id: I4e53b26a3f57f5f5cf7acbd3702c8bc4541a5eb5
2017-05-24 18:04:20 -04:00
jenkins-bot a803755b3e Merge "Add phpcs and make pass" 2017-05-24 13:17:49 +00:00
Umherirrender 93be5e75f6 Add phpcs and make pass
Change-Id: I2f95b3dfa260d955a5a420d0bf3c914382c09746
2017-05-19 18:39:27 +02:00
Baha 6bfe60508a Increase default API limit from 1 to 20
Bug: T153707
Change-Id: I6ba3adb7c680e1a60461cd3903cbf8640721ea02
2017-05-19 09:39:13 -04:00
Max Semenik 21ef48483f getFirstSentences(): don't use crazy regexes
Bug: T145231
Change-Id: I820fb152e86b273ddeba1617658a13e3a3f0bae3
2017-01-20 10:13:46 -08:00