- private function processHeadingText( $headline ) {
- global $wgEnforceHtmlIds;
-
- # The safe header is a version of the header text safe to use for links
- # Avoid insertion of weird stuff like <math> by expanding the relevant sections
- $safeHeadline = $this->mStripState->unstripBoth( $headline );
-
- # Remove link placeholders by the link text.
- # <!--LINK number-->
- # turns into
- # link text with suffix
- $safeHeadline = $this->replaceLinkHoldersText( $safeHeadline );
-
- # Strip out HTML (other than plain <sup> and <sub>: bug 8393)
- $tocline = preg_replace(
- array( '#<(?!/?(sup|sub)).*?'.'>#', '#<(/?(sup|sub)).*?'.'>#' ),
- array( '', '<$1>'),
- $safeHeadline
- );
- $tocline = trim( $tocline );
-
- # For the anchor, strip out HTML-y stuff period
- $safeHeadline = preg_replace( '/<.*?'.'>/', '', $safeHeadline );
- $safeHeadline = trim( $safeHeadline );
-
- # Save headline for section edit hint before it's escaped
- $headlineHint = $safeHeadline;
-
- if ( $wgEnforceHtmlIds ) {
- $legacyHeadline = false;
- $safeHeadline = Sanitizer::escapeId( $safeHeadline,
- 'noninitial' );
- } else {
- # For reverse compatibility, provide an id that's
- # HTML4-compatible, like we used to.
- #
- # It may be worth noting, academically, that it's possible for
- # the legacy anchor to conflict with a non-legacy headline
- # anchor on the page. In this case likely the "correct" thing
- # would be to either drop the legacy anchors or make sure
- # they're numbered first. However, this would require people
- # to type in section names like "abc_.D7.93.D7.90.D7.A4"
- # manually, so let's not bother worrying about it.
- $legacyHeadline = Sanitizer::escapeId( $safeHeadline,
- 'noninitial' );
- $safeHeadline = Sanitizer::escapeId( $safeHeadline, 'xml' );
-
- if ( $legacyHeadline == $safeHeadline ) {
- # No reason to have both (in fact, we can't)
- $legacyHeadline = false;
- } elseif ( $legacyHeadline != Sanitizer::escapeId(
- $legacyHeadline, 'xml' ) ) {
- # The legacy id is invalid XML. We used to allow this, but
- # there's no reason to do so anymore. Backward
- # compatibility will fail slightly in this case, but it's
- # no big deal.
- $legacyHeadline = false;
- }
- }
-
- return array( $safeHeadline, $legacyHeadline, $tocline,
- $headlineHint );
- }
-