mediawiki-extensions-Descri.../includes/DescriptionProvider.php
alex4401 c146909532
Truncate descriptions to a certain length
With this change, generated descriptions are cut at 300 characters, without breaking words when possible, and with an ellipsis added in case the cut happened mid-sentence.

The `Description2::getFirstChars` function was borrowed from TextExtracts with minor alterations (added comment for their regex, and removed `>` from word healing given it's unclear why it's been included).

New configuration variable `$wgDescriptionMaxChars` (proposed default: 300, which seems like a sensible amount) controls this behaviour.

This has been in testing on ark.wiki.gg (with the platform's approval, which I'm glad for) since early September. Without this change, we had a few pages with little sections having a huge part of their body text thrown into the `description` meta tag...

Depends-On: I585f2c0046571310aad67f3ba148c4f22aaae49f
Change-Id: I04b00f99085f07f773212ee3eca8470eece34e9e
2024-02-24 08:44:53 +01:00

14 lines
361 B
PHP

<?php
namespace MediaWiki\Extension\Description2;
interface DescriptionProvider {
/**
* Extracts description from the HTML representation of a page.
*
* @param string $text HTML to extract the description from.
* @return ?string Plain text, or null if no description could have been generated
*/
public function derive( string $text ): ?string;
}