$section = str_replace( '[[', '', $section );
$section = str_replace( ']]', '', $section );
- $section = Sanitizer::normalizeSectionNameWhitespace( $section ); # T24784
+ $section = substr( Parser::guessSectionNameFromStrippedText( $section ), 1 );
if ( $local ) {
- $sectionTitle = Title::newFromText( '#' . $section );
+ $sectionTitle = Title::makeTitleSafe( NS_MAIN, '', $section );
} else {
$sectionTitle = Title::makeTitleSafe( $title->getNamespace(),
- $title->getDBkey(), Sanitizer::decodeCharReferences( $section ) );
+ $title->getDBkey(), $section );
}
if ( $sectionTitle ) {
$link = Linker::makeCommentLink( $sectionTitle, $wgLang->getArrow(), $wikiId, 'noclasses' );
# Decode HTML entities
$safeHeadline = Sanitizer::decodeCharReferences( $safeHeadline );
- $safeHeadline = $this->normalizeSectionName( $safeHeadline );
+ $safeHeadline = self::normalizeSectionName( $safeHeadline );
$fallbackHeadline = Sanitizer::escapeIdForAttribute( $safeHeadline, Sanitizer::ID_FALLBACK );
$linkAnchor = Sanitizer::escapeIdForLink( $safeHeadline );
return $this->mDefaultSort;
}
+ private static function getSectionNameFromStrippedText( $text ) {
+ $text = Sanitizer::normalizeSectionNameWhitespace( $text );
+ $text = Sanitizer::decodeCharReferences( $text );
+ $text = self::normalizeSectionName( $text );
+ return $text;
+ }
+
+ private static function makeAnchor( $sectionName ) {
+ return '#' . Sanitizer::escapeIdForLink( $sectionName );
+ }
+
+ private static function makeLegacyAnchor( $sectionName ) {
+ global $wgFragmentMode;
+ if ( isset( $wgFragmentMode[1] ) && $wgFragmentMode[1] === 'legacy' ) {
+ // ForAttribute() and ForLink() are the same for legacy encoding
+ $id = Sanitizer::escapeIdForAttribute( $text, Sanitizer::ID_FALLBACK );
+ } else {
+ $id = Sanitizer::escapeIdForLink( $text );
+ }
+
+ return "#$id";
+ }
+
/**
* Try to guess the section anchor name based on a wikitext fragment
* presumably extracted from a heading, for example "Header" from
* "== Header ==".
*
* @param string $text
- *
- * @return string
+ * @return string Anchor (starting with '#')
*/
public function guessSectionNameFromWikiText( $text ) {
# Strip out wikitext links(they break the anchor)
$text = $this->stripSectionName( $text );
- $text = Sanitizer::normalizeSectionNameWhitespace( $text );
- $text = Sanitizer::decodeCharReferences( $text );
- $text = $this->normalizeSectionName( $text );
-
- return '#' . Sanitizer::escapeIdForLink( $text );
+ $sectionName = self::getSectionNameFromStrippedText( $text );
+ return self::makeAnchor( $sectionName );
}
/**
* than UTF-8, resulting in breakage.
*
* @param string $text The section name
- * @return string An anchor
+ * @return string Anchor (starting with '#')
*/
public function guessLegacySectionNameFromWikiText( $text ) {
- global $wgFragmentMode;
-
# Strip out wikitext links(they break the anchor)
$text = $this->stripSectionName( $text );
- $text = Sanitizer::normalizeSectionNameWhitespace( $text );
- $text = Sanitizer::decodeCharReferences( $text );
- $text = $this->normalizeSectionName( $text );
-
- if ( isset( $wgFragmentMode[1] ) && $wgFragmentMode[1] === 'legacy' ) {
- // ForAttribute() and ForLink() are the same for legacy encoding
- $id = Sanitizer::escapeIdForAttribute( $text, Sanitizer::ID_FALLBACK );
- } else {
- $id = Sanitizer::escapeIdForLink( $text );
- }
+ $sectionName = self::getSectionNameFromStrippedText( $text );
+ return self::makeLegacyAnchor( $sectionName );
+ }
- return "#$id";
+ /**
+ * Like guessSectionNameFromWikiText(), but takes already-stripped text as input.
+ * @param string $text Section name (plain text)
+ * @return string Anchor (starting with '#')
+ */
+ public static function guessSectionNameFromStrippedText( $text ) {
+ $sectionName = self::getSectionNameFromStrippedText( $text );
+ return self::makeAnchor( $sectionName );
}
/**
* @param string $text
* @return string
*/
- private function normalizeSectionName( $text ) {
+ private static function normalizeSectionName( $text ) {
# T90902: ensure the same normalization is applied for IDs as to links
$titleParser = MediaWikiServices::getInstance()->getTitleParser();
try {
}
private function outputNamespaceProtectionInfo() {
- global $wgParser, $wgContLang;
+ global $wgContLang;
$out = $this->getOutput();
$namespaceProtection = $this->getConfig()->get( 'NamespaceProtection' );
return;
}
- $header = $this->msg( 'listgrouprights-namespaceprotection-header' )->parse();
+ $header = $this->msg( 'listgrouprights-namespaceprotection-header' )->text();
$out->addHTML(
Html::rawElement( 'h2', [], Html::element( 'span', [
'class' => 'mw-headline',
- 'id' => $wgParser->guessSectionNameFromWikiText( $header )
+ 'id' => substr( Parser::guessSectionNameFromStrippedText( $header ), 1 )
], $header ) ) .
Xml::openElement( 'table', [ 'class' => 'wikitable' ] ) .
Html::element(