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; } protected static function fromSelSerImpl( string $text, Element $node, DataParsoid $dataParsoid, Env $env, array $opts ): ?WikiLinkText { $stx = $dataParsoid->stx ?? ''; if ( DOMUtils::matchRel( $node, '#^mw:WikiLink(/Interwiki)?$#D' ) && in_array( $stx, [ 'simple', 'piped' ], true ) ) { $rel = DOMCompat::getAttribute( $node, 'rel' ); return new WikiLinkText( $text, $node, $env->getSiteConfig(), $rel ); } return null; } }