# at least one character of a host name (embeds EXT_LINK_URL_CLASS)
const EXT_LINK_ADDR = '(?:[0-9.]+|\\[(?i:[0-9a-f:.]+)\\]|[^][<>"\\x00-\\x20\\x7F\p{Zs}\x{FFFD}])';
# RegExp to make image URLs (embeds IPv6 part of EXT_LINK_ADDR)
- // @codingStandardsIgnoreStart Generic.Files.LineLength
+ // phpcs:ignore Generic.Files.LineLength
const EXT_IMAGE_REGEX = '/^(http:\/\/|https:\/\/)((?:\\[(?i:[0-9a-f:.]+)\\])?[^][<>"\\x00-\\x20\\x7F\p{Zs}\x{FFFD}]+)
\\/([A-Za-z0-9_.,~%\\-+&;#*?!=()@\\x80-\\xFF]+)\\.((?i)gif|png|jpg|jpeg)$/Sxu';
- // @codingStandardsIgnoreEnd
# Regular expression for a non-newline space
const SPACE_NOT_NL = '(?:\t| |&\#0*160;|&\#[Xx]0*[Aa]0;|\p{Zs})';
$useSubpages = $this->areSubpagesAllowed();
- // @codingStandardsIgnoreStart Squiz.WhiteSpace.SemicolonSpacing.Incorrect
# Loop for each link
for ( ; $line !== false && $line !== null; $a->next(), $line = $a->current() ) {
- // @codingStandardsIgnoreEnd
-
# Check for excessive memory usage
if ( $holders->isBig() ) {
# Too big
throw $ex;
}
- # The interface for parser functions allows for extracting
- # flags into the local scope. Extract any forwarded flags
- # here.
- extract( $result );
+ // Extract any forwarded flags
+ if ( isset( $result['title'] ) ) {
+ $title = $result['title'];
+ }
+ if ( isset( $result['found'] ) ) {
+ $found = $result['found'];
+ }
+ if ( array_key_exists( 'text', $result ) ) {
+ // a string or null
+ $text = $result['text'];
+ }
+ if ( isset( $result['nowiki'] ) ) {
+ $nowiki = $result['nowiki'];
+ }
+ if ( isset( $result['isHTML'] ) ) {
+ $isHTML = $result['isHTML'];
+ }
+ if ( isset( $result['forceRawInterwiki'] ) ) {
+ $forceRawInterwiki = $result['forceRawInterwiki'];
+ }
+ if ( isset( $result['isChildObj'] ) ) {
+ $isChildObj = $result['isChildObj'];
+ }
+ if ( isset( $result['isLocalObj'] ) ) {
+ $isLocalObj = $result['isLocalObj'];
+ }
}
}
$deps = [];
# Loop to fetch the article, with up to 1 redirect
- // @codingStandardsIgnoreStart Generic.CodeAnalysis.ForLoopWithTestFunctionCall.NotAllowed
+ // phpcs:ignore Generic.CodeAnalysis.ForLoopWithTestFunctionCall
for ( $i = 0; $i < 2 && is_object( $title ); $i++ ) {
- // @codingStandardsIgnoreEnd
# Give extensions a chance to select the revision instead
$id = false; # Assume current
Hooks::run( 'BeforeParserFetchTemplateAndtitle',
}
if ( is_array( $output ) ) {
- # Extract flags to local scope (to override $markerType)
+ // Extract flags
$flags = $output;
$output = $flags[0];
- unset( $flags[0] );
- extract( $flags );
+ if ( isset( $flags['markerType'] ) ) {
+ $markerType = $flags['markerType'];
+ }
}
} else {
if ( is_null( $attrText ) ) {
$anchor = $safeHeadline;
$fallbackAnchor = $fallbackHeadline;
if ( isset( $refers[$arrayKey] ) ) {
- // @codingStandardsIgnoreStart
+ // phpcs:ignore Generic.CodeAnalysis.ForLoopWithTestFunctionCall,Generic.Formatting.DisallowMultipleStatements
for ( $i = 2; isset( $refers["${arrayKey}_$i"] ); ++$i );
- // @codingStandardsIgnoreEnd
$anchor .= "_$i";
$linkAnchor .= "_$i";
$refers["${arrayKey}_$i"] = true;
$refers[$arrayKey] = true;
}
if ( $fallbackHeadline !== false && isset( $refers[$fallbackArrayKey] ) ) {
- // @codingStandardsIgnoreStart
+ // phpcs:ignore Generic.CodeAnalysis.ForLoopWithTestFunctionCall,Generic.Formatting.DisallowMultipleStatements
for ( $i = 2; isset( $refers["${fallbackArrayKey}_$i"] ); ++$i );
- // @codingStandardsIgnoreEnd
$fallbackAnchor .= "_$i";
$refers["${fallbackArrayKey}_$i"] = true;
} else {
* Wrapper for preprocess()
*
* @param string $text The text to preprocess
- * @param ParserOptions $options Options
+ * @param ParserOptions $options
* @param Title|null $title Title object or null to use $wgTitle
* @return string
*/
$paramName = $paramMap[$magicName];
switch ( $paramName ) {
- case 'gallery-internal-alt':
- $alt = $this->stripAltText( $match, false );
- break;
- case 'gallery-internal-link':
- $linkValue = strip_tags( $this->replaceLinkHoldersText( $match ) );
- $chars = self::EXT_LINK_URL_CLASS;
- $addr = self::EXT_LINK_ADDR;
- $prots = $this->mUrlProtocols;
- // check to see if link matches an absolute url, if not then it must be a wiki link.
- if ( preg_match( '/^-{R|(.*)}-$/', $linkValue ) ) {
- // Result of LanguageConverter::markNoConversion
- // invoked on an external link.
- $linkValue = substr( $linkValue, 4, -2 );
- }
- if ( preg_match( "/^($prots)$addr$chars*$/u", $linkValue ) ) {
- $link = $linkValue;
- $this->mOutput->addExternalLink( $link );
- } else {
- $localLinkTitle = Title::newFromText( $linkValue );
- if ( $localLinkTitle !== null ) {
- $this->mOutput->addLink( $localLinkTitle );
- $link = $localLinkTitle->getLinkURL();
+ case 'gallery-internal-alt':
+ $alt = $this->stripAltText( $match, false );
+ break;
+ case 'gallery-internal-link':
+ $linkValue = strip_tags( $this->replaceLinkHoldersText( $match ) );
+ $chars = self::EXT_LINK_URL_CLASS;
+ $addr = self::EXT_LINK_ADDR;
+ $prots = $this->mUrlProtocols;
+ // check to see if link matches an absolute url, if not then it must be a wiki link.
+ if ( preg_match( '/^-{R|(.*)}-$/', $linkValue ) ) {
+ // Result of LanguageConverter::markNoConversion
+ // invoked on an external link.
+ $linkValue = substr( $linkValue, 4, -2 );
+ }
+ if ( preg_match( "/^($prots)$addr$chars*$/u", $linkValue ) ) {
+ $link = $linkValue;
+ $this->mOutput->addExternalLink( $link );
+ } else {
+ $localLinkTitle = Title::newFromText( $linkValue );
+ if ( $localLinkTitle !== null ) {
+ $this->mOutput->addLink( $localLinkTitle );
+ $link = $localLinkTitle->getLinkURL();
+ }
+ }
+ break;
+ default:
+ // Must be a handler specific parameter.
+ if ( $handler->validateParam( $paramName, $match ) ) {
+ $handlerOptions[$paramName] = $match;
+ } else {
+ // Guess not, consider it as caption.
+ wfDebug( "$parameterMatch failed parameter validation\n" );
+ $label = '|' . $parameterMatch;
}
- }
- break;
- default:
- // Must be a handler specific parameter.
- if ( $handler->validateParam( $paramName, $match ) ) {
- $handlerOptions[$paramName] = $match;
- } else {
- // Guess not, consider it as caption.
- wfDebug( "$parameterMatch failed parameter validation\n" );
- $label = '|' . $parameterMatch;
- }
}
} else {
} else {
# Validate internal parameters
switch ( $paramName ) {
- case 'manualthumb':
- case 'alt':
- case 'class':
- # @todo FIXME: Possibly check validity here for
- # manualthumb? downstream behavior seems odd with
- # missing manual thumbs.
- $validated = true;
- $value = $this->stripAltText( $value, $holders );
- break;
- case 'link':
- $chars = self::EXT_LINK_URL_CLASS;
- $addr = self::EXT_LINK_ADDR;
- $prots = $this->mUrlProtocols;
- if ( $value === '' ) {
- $paramName = 'no-link';
- $value = true;
+ case 'manualthumb':
+ case 'alt':
+ case 'class':
+ # @todo FIXME: Possibly check validity here for
+ # manualthumb? downstream behavior seems odd with
+ # missing manual thumbs.
$validated = true;
- } elseif ( preg_match( "/^((?i)$prots)/", $value ) ) {
- if ( preg_match( "/^((?i)$prots)$addr$chars*$/u", $value, $m ) ) {
- $paramName = 'link-url';
- $this->mOutput->addExternalLink( $value );
- if ( $this->mOptions->getExternalLinkTarget() ) {
- $params[$type]['link-target'] = $this->mOptions->getExternalLinkTarget();
- }
- $validated = true;
- }
- } else {
- $linkTitle = Title::newFromText( $value );
- if ( $linkTitle ) {
- $paramName = 'link-title';
- $value = $linkTitle;
- $this->mOutput->addLink( $linkTitle );
+ $value = $this->stripAltText( $value, $holders );
+ break;
+ case 'link':
+ $chars = self::EXT_LINK_URL_CLASS;
+ $addr = self::EXT_LINK_ADDR;
+ $prots = $this->mUrlProtocols;
+ if ( $value === '' ) {
+ $paramName = 'no-link';
+ $value = true;
$validated = true;
+ } elseif ( preg_match( "/^((?i)$prots)/", $value ) ) {
+ if ( preg_match( "/^((?i)$prots)$addr$chars*$/u", $value, $m ) ) {
+ $paramName = 'link-url';
+ $this->mOutput->addExternalLink( $value );
+ if ( $this->mOptions->getExternalLinkTarget() ) {
+ $params[$type]['link-target'] = $this->mOptions->getExternalLinkTarget();
+ }
+ $validated = true;
+ }
+ } else {
+ $linkTitle = Title::newFromText( $value );
+ if ( $linkTitle ) {
+ $paramName = 'link-title';
+ $value = $linkTitle;
+ $this->mOutput->addLink( $linkTitle );
+ $validated = true;
+ }
}
- }
- break;
- case 'frameless':
- case 'framed':
- case 'thumbnail':
- // use first appearing option, discard others.
- $validated = !$seenformat;
- $seenformat = true;
- break;
- default:
- # Most other things appear to be empty or numeric...
- $validated = ( $value === false || is_numeric( trim( $value ) ) );
+ break;
+ case 'frameless':
+ case 'framed':
+ case 'thumbnail':
+ // use first appearing option, discard others.
+ $validated = !$seenformat;
+ $seenformat = true;
+ break;
+ default:
+ # Most other things appear to be empty or numeric...
+ $validated = ( $value === false || is_numeric( trim( $value ) ) );
}
}
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 );
+ $id = Sanitizer::escapeIdForAttribute( $sectionName, Sanitizer::ID_FALLBACK );
} else {
- $id = Sanitizer::escapeIdForLink( $text );
+ $id = Sanitizer::escapeIdForLink( $sectionName );
}
return "#$id";
/**
* Remove any strip markers found in the given text.
*
- * @param string $text Input string
+ * @param string $text
* @return string
*/
public function killMarkers( $text ) {