linkPrefixRegex(); if ( !$noTrails && $linkPrefixRegex ) { $badPrefix = '/(' . PHPUtils::reStrip( $linkPrefixRegex, '/' ) . ')' . '|(' . PHPUtils::reStrip( $badPrefix, '/' ) . ')/uD'; } parent::__construct( [ 'text' => $text, 'node' => $node, 'badPrefix' => $badPrefix, 'badSuffix' => ( $noTrails ) ? null : $siteConfig->linkTrailRegex(), ] ); // We match link trails greedily when they exist. if ( !( $noTrails || substr( $text, -1 ) === ']' ) ) { $this->greedy = true; } } /** @inheritDoc */ public function escape( State $state ): Result { $r = parent::escape( $state ); // If previous token was also a WikiLink, its linktrail will // eat up any possible linkprefix characters, so we don't need // a in this case. (Eg: [[a]]-[[b]] in iswiki; the - // character is both a link prefix and a link trail, but it gets // preferentially associated with the [[a]] as a link trail.) $r->greedy = $this->greedy; return $r; } /** * @param string $text * @param DOMElement $node * @param stdClass $dataParsoid * @param Env $env * @param array $opts * @return ?WikiLinkText */ protected static function fromSelSerImpl( string $text, DOMElement $node, stdClass $dataParsoid, Env $env, array $opts ): ?WikiLinkText { $type = $node->getAttribute( 'rel' ) ?? ''; $stx = $dataParsoid->stx ?? ''; // TODO: Leaving this for backwards compatibility, remove when 1.5 is no longer bound if ( $type === 'mw:ExtLink' ) { $type = 'mw:WikiLink/Interwiki'; } if ( preg_match( '#^mw:WikiLink(/Interwiki)?$#D', $type ) && preg_match( '/^(simple|piped)$/D', $stx ) ) { return new WikiLinkText( $text, $node, $env->getSiteConfig(), $type ); } return null; } }