Matthias Mullie has uploaded a new change for review. https://gerrit.wikimedia.org/r/116085
Change subject: Non-hacky way to feed title to Redlinker ...................................................................... Non-hacky way to feed title to Redlinker This gets rid of $wgFlowParsoidTitle completely. Bug: 58664 Change-Id: I7368f3bd476d254bd3a28f6b54ae164509bce8d2 --- M container.php M includes/Redlinker.php M includes/Templating.php M includes/api/ApiFlow.php M includes/api/ApiParsoidUtilsFlow.php M includes/api/ApiQueryFlow.php M tests/RedlinkerTest.php 7 files changed, 18 insertions(+), 33 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Flow refs/changes/85/116085/1 diff --git a/container.php b/container.php index 126b7b5..76ce151 100644 --- a/container.php +++ b/container.php @@ -73,8 +73,7 @@ } ); $c['redlinker'] = $c->share( function( $c ) { - global $wgTitle, $wgFlowParsoidTitle; - return new Flow\Redlinker( $wgFlowParsoidTitle ?: $wgTitle, $c['link_batch'] ); + return new Flow\Redlinker( $c['link_batch'] ); } ); $c['templating.namespaces'] = array( diff --git a/includes/Redlinker.php b/includes/Redlinker.php index da46607..38c8cca 100644 --- a/includes/Redlinker.php +++ b/includes/Redlinker.php @@ -46,12 +46,6 @@ * $content = $redlinker->apply( $foo->getContent() ); */ class Redlinker { - - /** - * @var Title To resolve relative links against - */ - protected $title; - /** * @var LinkBatch */ @@ -79,11 +73,9 @@ protected $callback; /** - * @param Title $title To resolve relative links against * @param LinkBatch $batch */ - public function __construct( Title $title, LinkBatch $batch ) { - $this->title = $title; + public function __construct( LinkBatch $batch ) { $this->batch = $batch; $this->processed = new ArrayObject; } @@ -178,9 +170,10 @@ * It will then substitute original link HTML for the one Linker generated. * * @param string $content + * @param Title $title Title to resolve relative links against * @return string */ - public function apply( $content ) { + public function apply( $content, Title $title ) { if ( !$content ) { return ''; } @@ -197,8 +190,8 @@ */ $dom = ParsoidUtils::createDOM( '<?xml encoding="utf-8"?>' . $content ); $self = $this; - self::forEachLink( $dom, function( DOMNode $linkNode, array $parsoid ) use ( $self, $dom ) { - $title = $self->createRelativeTitle( $parsoid['sa']['href'] ); + self::forEachLink( $dom, function( DOMNode $linkNode, array $parsoid ) use ( $self, $dom, $title ) { + $title = $self->createRelativeTitle( $parsoid['sa']['href'], $title ); // Don't process invalid links if ( $title === null ) { return; @@ -247,16 +240,17 @@ } /** - * Subpage links from parsoid don't contain any direct context, its applied via + * Subpage links from Parsoid don't contain any direct context, its applied via * a <base href="..."> tag, so here we apply a similar rule resolving against - * $wgFlowParsoidTitle falling back to $wgTitle. + * $title. * * @param string $text + * @param Title $title Title to resolve relative links against * @return Title|null */ - public function createRelativeTitle( $text ) { + public function createRelativeTitle( $text, Title $title ) { if ( $text && $text[0] === '/' ) { - return Title::newFromText( $this->title->getDBkey() . $text, $this->title->getNamespace() ); + return Title::newFromText( $title->getDBkey() . $text, $title->getNamespace() ); } else { return Title::newFromText( $text ); } diff --git a/includes/Templating.php b/includes/Templating.php index f29d950..8e88fb8 100644 --- a/includes/Templating.php +++ b/includes/Templating.php @@ -438,7 +438,7 @@ if ( $format === 'html' ) { // Parsoid doesn't render redlinks try { - $content = $this->redlinks->apply( $content ); + $content = $this->redlinks->apply( $content, $revision->getCollection()->getTitle() ); } catch ( \Exception $e ) { wfDebugLog( __CLASS__, __METHOD__ . ': Failed applying redlinks for rev_id = ' . $revision->getRevisionId()->getAlphadecimal() ); \MWExceptionHandler::logException( $e ); diff --git a/includes/api/ApiFlow.php b/includes/api/ApiFlow.php index 90fa371..dd3e8b5 100644 --- a/includes/api/ApiFlow.php +++ b/includes/api/ApiFlow.php @@ -28,10 +28,6 @@ $workflow = $this->loader->getWorkflow(); $article = new Article( $workflow->getArticleTitle(), 0 ); - // @todo: this is a hack; see ParsoidUtils::convert - global $wgFlowParsoidTitle; - $wgFlowParsoidTitle = $workflow->getArticleTitle(); - $isNew = $workflow->isNew(); // Is this making unnecesary db round trips? if ( !$isNew ) { diff --git a/includes/api/ApiParsoidUtilsFlow.php b/includes/api/ApiParsoidUtilsFlow.php index 9efdb8c..f67637b 100644 --- a/includes/api/ApiParsoidUtilsFlow.php +++ b/includes/api/ApiParsoidUtilsFlow.php @@ -25,8 +25,8 @@ if ( $params['to'] === 'html' ) { // convert redlinks - $redlinker = new Redlinker( $page->getTitle(), new LinkBatch ); - $content = $redlinker->apply( $content ); + $redlinker = new Redlinker( new LinkBatch ); + $content = $redlinker->apply( $content, $page->getTitle() ); } $result = array( diff --git a/includes/api/ApiQueryFlow.php b/includes/api/ApiQueryFlow.php index e09f143..cade49e 100644 --- a/includes/api/ApiQueryFlow.php +++ b/includes/api/ApiQueryFlow.php @@ -18,10 +18,6 @@ $pageTitle = Title::newFromText( $params['page'] ); $id = $params['workflow'] ? UUID::create( $params['workflow'] ) : null; - // @todo: this is a hack; see ParsoidUtils::convert - global $wgFlowParsoidTitle; - $wgFlowParsoidTitle = $pageTitle; - $this->loader = $this->container['factory.loader.workflow'] ->createWorkflowLoader( $pageTitle, $id ); diff --git a/tests/RedlinkerTest.php b/tests/RedlinkerTest.php index b8fbb04..94e552a 100644 --- a/tests/RedlinkerTest.php +++ b/tests/RedlinkerTest.php @@ -60,8 +60,8 @@ * @dataProvider redLinkProvider */ public function testApplysRedLinks( $message, $anchor, $expect ) { - $redlink = new Redlinker( Title::newMainPage(), $this->getMock( 'LinkBatch' ) ); - $result = $redlink->apply( $anchor ); + $redlink = new Redlinker( $this->getMock( 'LinkBatch' ) ); + $result = $redlink->apply( $anchor, Title::newMainPage() ); $this->assertContains( $expect, $result, $message ); } @@ -91,7 +91,7 @@ $this->matches( $saHref ) ) ); - $redlinker = new Redlinker( Title::newMainPage(), $batch ); + $redlinker = new Redlinker( $batch ); $redlinker->registerPost( $post ); $redlinker->resolveLinkStatus(); } @@ -111,7 +111,7 @@ $this->matches( $saHref ) ) ); - $redlinker = new Redlinker( Title::newMainPage(), $batch ); + $redlinker = new Redlinker( $batch ); $redlinker->collectLinks( $anchor ); } } -- To view, visit https://gerrit.wikimedia.org/r/116085 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I7368f3bd476d254bd3a28f6b54ae164509bce8d2 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Flow Gerrit-Branch: master Gerrit-Owner: Matthias Mullie <mmul...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits