|
38 | 38 | */ |
39 | 39 | class CrawlerProtectionService { |
40 | 40 |
|
41 | | - /** @var string Prefix for special page names */ |
42 | | - private const SPECIAL_PAGE_PREFIX = 'Special:'; |
43 | | - |
44 | 41 | /** @var string[] List of constructor options this class accepts */ |
45 | 42 | public const CONSTRUCTOR_OPTIONS = [ |
46 | 43 | 'CrawlerProtectedSpecialPages', |
@@ -135,18 +132,27 @@ public function checkSpecialPage( |
135 | 132 | * Determine whether the given special page name is in the |
136 | 133 | * configured list of protected special pages. |
137 | 134 | * |
| 135 | + * Because this method is only called from the SpecialPageBeforeExecute |
| 136 | + * hook, any "Foo:" prefix on a configured value is necessarily the |
| 137 | + * "Special" namespace in English or its localized equivalent (e.g. |
| 138 | + * "Spezial:" in German). We therefore simply strip everything up to |
| 139 | + * and including the first colon rather than checking for a specific |
| 140 | + * namespace name, which keeps the logic language-agnostic. |
| 141 | + * |
138 | 142 | * @param string $specialPageName |
139 | 143 | * @return bool |
140 | 144 | */ |
141 | 145 | public function isProtectedSpecialPage( string $specialPageName ): bool { |
142 | 146 | $protectedSpecialPages = $this->options->get( 'CrawlerProtectedSpecialPages' ); |
143 | 147 |
|
144 | | - // Normalize protected special pages: lowercase and strip 'Special:' prefix |
| 148 | + // Normalize protected special pages: lowercase and strip any |
| 149 | + // namespace prefix (everything up to and including the first ':'). |
145 | 150 | $normalizedProtectedPages = array_map( |
146 | 151 | static function ( string $p ): string { |
147 | 152 | $lower = strtolower( $p ); |
148 | | - if ( strpos( $lower, strtolower( self::SPECIAL_PAGE_PREFIX ) ) === 0 ) { |
149 | | - return substr( $lower, strlen( self::SPECIAL_PAGE_PREFIX ) ); |
| 153 | + $colonPos = strpos( $lower, ':' ); |
| 154 | + if ( $colonPos !== false ) { |
| 155 | + return substr( $lower, $colonPos + 1 ); |
150 | 156 | } |
151 | 157 | return $lower; |
152 | 158 | }, |
|
0 commit comments