. * * @file * @ingroup Skins */ declare( strict_types=1 ); namespace MediaWiki\Skins\Citizen\Partials; use MediaWiki\MediaWikiServices; /** * Title partial of Skin Citizen */ final class PageTitle extends Partial { /** * Wrap text within parenthesis with a span tag * * @param string $data HTML of the title of the page * @return string */ public function decorateTitle( $data ) { if ( $this->shouldAddParenthesis() ) { // Look for the to ensure that it is the last parenthesis of the title $pattern = '/\s(\(.+\))<\/span>/'; $replacement = ' $1'; return preg_replace( $pattern, $replacement, $data ); } return $data; } /** * Check if the current page is in the content namespace * * @return bool */ private function shouldAddParenthesis(): bool { $ns = $this->title->getNamespace(); $contentNs = MediaWikiServices::getInstance()->getNamespaceInfo()->getContentNamespaces(); return in_array( $ns, $contentNs ); } }