Last active
March 8, 2026 12:01
-
-
Save ciencia/e44bfa8caff74da85137adb17f12dbd5 to your computer and use it in GitHub Desktop.
ext-DisplayTitle-parentheses_REL1_43
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| diff --git a/extension.json b/extension.json | |
| index cc7602a..282af99 100644 | |
| --- a/extension.json | |
| +++ b/extension.json | |
| @@ -56,6 +56,9 @@ | |
| }, | |
| "DisplayTitleFollowRedirects": { | |
| "value": true | |
| + }, | |
| + "DisplayTitleAutoRemoveParentheses": { | |
| + "value": false | |
| } | |
| }, | |
| "manifest_version": 2 | |
| diff --git a/includes/DisplayTitleService.php b/includes/DisplayTitleService.php | |
| index 2b1fd10..4bac60e 100644 | |
| --- a/includes/DisplayTitleService.php | |
| +++ b/includes/DisplayTitleService.php | |
| @@ -34,8 +34,9 @@ class DisplayTitleService { | |
| public const CONSTRUCTOR_OPTIONS = [ | |
| 'DisplayTitleHideSubtitle', | |
| 'DisplayTitleExcludes', | |
| 'DisplayTitleExcludeLinksToNamespaces', | |
| - 'DisplayTitleFollowRedirects' | |
| + 'DisplayTitleFollowRedirects', | |
| + 'DisplayTitleAutoRemoveParentheses', | |
| ]; | |
| /** | |
| @@ -57,6 +58,11 @@ class DisplayTitleService { | |
| */ | |
| private $namespaceInfo; | |
| + /** | |
| + * @var bool | |
| + */ | |
| + private readonly bool $autoRemoveParentheses; | |
| + | |
| /** | |
| * @var RedirectLookup | |
| */ | |
| @@ -90,6 +96,7 @@ class DisplayTitleService { | |
| $this->hideSubtitle = $options->get( 'DisplayTitleHideSubtitle' ); | |
| $this->excludes = $options->get( 'DisplayTitleExcludes' ); | |
| $this->followRedirects = $options->get( 'DisplayTitleFollowRedirects' ); | |
| + $this->autoRemoveParentheses = $options->get( 'DisplayTitleAutoRemoveParentheses' ); | |
| $this->namespaceInfo = $namespaceInfo; | |
| $this->redirectLookup = $redirectLookup; | |
| $this->pageProps = $pageProps; | |
| @@ -207,6 +214,9 @@ class DisplayTitleService { | |
| if ( trim( str_replace( ' ', '', strip_tags( $value ) ) ) !== '' && | |
| $value !== $originalPageName ) { | |
| $displaytitle = $value; | |
| + if ( $this->autoRemoveParentheses ) { | |
| + $displaytitle = self::stripDisambiguation( $displaytitle ); | |
| + } | |
| if ( $wrap ) { | |
| // @phan-suppress-next-line SecurityCheck-XSS | |
| $displaytitle = new HtmlArmor( $displaytitle ); | |
| @@ -215,6 +225,9 @@ class DisplayTitleService { | |
| } | |
| } elseif ( $redirect ) { | |
| $displaytitle = $title->getPrefixedText(); | |
| + if ( $this->autoRemoveParentheses ) { | |
| + $displaytitle = self::stripDisambiguation( $displaytitle ); | |
| + } | |
| if ( $wrap ) { | |
| $displaytitle = new HtmlArmor( $displaytitle ); | |
| } | |
| @@ -249,4 +262,14 @@ class DisplayTitleService { | |
| $out->addSubtitle( "<span class=\"mw-displaytitle-subtitle\">" . $title->getPrefixedText() . "</span>" ); | |
| } | |
| } | |
| + | |
| + /** | |
| + * Removes parentheses from the title like [[Page (disambig)|]] results in [[Page (disambig)|Page]] | |
| + * | |
| + * @param string $title Title to be modified | |
| + * @return string | |
| + */ | |
| + private static function stripDisambiguation( $title ): string { | |
| + return preg_replace( '# ?\([^()]*\)#', '', $title ); | |
| + } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment