/** * {@inheritDoc} */ public function perform(ReferenceFactory $factory, DOMElement $element) { $href = $element->getAttribute('href'); if ($href === '') { return null; } return $factory->createWikiReference(Reference::TYPE_LINK, urldecode($href)); }
public function testAcceptsParsoidHrefs() { $workflow = $this->getMock('Flow\\Model\\Workflow'); $workflow->expects($this->any())->method('getId')->will($this->returnValue(UUID::create())); $workflow->expects($this->any())->method('getArticleTitle')->will($this->returnValue(Title::newMainPage())); $factory = new ReferenceFactory($workflow, 'foo', UUID::create()); $ref = $factory->createWikiReference('file', './File:Foo.jpg'); $this->assertInstanceOf('Flow\\Model\\WikiReference', $ref); $this->assertEquals('title:File:Foo.jpg', $ref->getTargetIdentifier()); }
/** * {@inheritDoc} */ public function perform(ReferenceFactory $factory, DOMElement $element) { foreach ($element->getElementsByTagName('img') as $item) { if (!$item instanceof DOMElement) { continue; } $resource = $item->getAttribute('resource'); if ($resource !== '') { return $factory->createWikiReference(WikiReference::TYPE_FILE, urldecode($resource)); } } return null; }
/** * {@inheritDoc} */ public function perform(ReferenceFactory $factory, DOMElement $element) { // our provided xpath guarantees there is a rel attribute // with our expected format so only perform a very minimal // validation. $rel = $element->getAttribute('rel'); if ($rel !== 'mw:PageProp/Category') { return null; } $href = $element->getAttribute('href'); if ($href) { return $factory->createWikiReference(WikiReference::TYPE_CATEGORY, urldecode($href)); } else { return null; } }
/** * {@inheritDoc} */ public function perform(ReferenceFactory $factory, DOMElement $element) { $data = FormatJson::decode($element->getAttribute('data-parsoid'), true); if (!isset($data['src'])) { return null; } /* * Parsoid only gives us the raw source to play with. Run it * through Parser to make sure we're dealing with an image * and get the image name. */ global $wgParser; $output = $wgParser->parse($data['src'], Title::newFromText('Main Page'), new ParserOptions()); $file = $output->getImages(); if (!$file) { return null; } // $file looks like array( 'Foo.jpg' => 1 ) $image = Title::newFromText(key($file), NS_FILE); return $factory->createWikiReference(WikiReference::TYPE_FILE, $image->getPrefixedDBkey()); }