/** * Usually the revisions's content can just be displayed. In the event * of moderation, however, that info should not be exposed. * * If a specific i18n message is available for a certain moderation level, * that message will be returned (well, unless the user actually has the * required permissions to view the full content). Otherwise, in normal * cases, the full content will be returned. * * The content-type of the return value varies on the $format parameter. * Further processing in the final output stage must escape all formats * other than the default 'html'. * * @param AbstractRevision $revision Revision to display content for * @param string[optional] $format Format to output content in (fixed-html|html|wikitext|plaintext) * @return string HTML if requested, otherwise plain text * @throws InvalidInputException */ public function getContent(AbstractRevision $revision, $format = 'fixed-html') { if (!in_array($format, array('fixed-html', 'html', 'plaintext', 'wikitext'))) { throw new InvalidInputException('Invalid format: ' . $format); } $allowed = $this->permissions->isAllowed($revision, 'view'); // Posts require view access to the topic title as well if ($allowed && $revision instanceof PostRevision && !$revision->isTopicTitle()) { $allowed = $this->permissions->isAllowed($revision->getRootPost(), 'view'); } if (!$allowed) { // failsafe - never output content if permissions aren't satisfied! return ''; } try { if ($format === 'fixed-html') { // Parsoid doesn't render redlinks & doesn't strip bad images $content = $this->contentFixer->getContent($revision); } else { // plaintext = wikitext $format = $format === 'plaintext' ? 'wikitext' : $format; $content = $revision->getContent($format); } } catch (\Exception $e) { wfDebugLog('Flow', __METHOD__ . ': Failed to get content for rev_id = ' . $revision->getRevisionId()->getAlphadecimal()); \MWExceptionHandler::logException($e); $content = wfMessage('flow-stub-post-content')->parse(); if (!in_array($format, array('html', 'fixed-html'))) { $content = strip_tags($content); } } return $content; }
/** * @dataProvider imageRemovalProvider */ public function testImageRemoval($message, $expect, $content, $badImageFilter) { $fixer = new ContentFixer(new BadImageRemover($badImageFilter)); $result = $fixer->apply($content, Title::newMainPage()); $this->assertEquals($expect, $result, $message); }
/** * @dataProvider baseHrefProvider */ public function testBaseHrefFixer($message, $expectedAfter, $before) { $fixer = new ContentFixer(new BaseHrefFixer('/wiki/$1')); $result = $fixer->apply($before, Title::newMainPage()); $this->assertEquals($expectedAfter, $result, $message); }
/** * @dataProvider redLinkProvider */ public function testAppliesRedLinks($message, $anchor, $expect) { $fixer = new ContentFixer(new WikiLinkFixer($this->getMock('LinkBatch'))); $result = $fixer->apply($anchor, Title::newMainPage()); $this->assertContains($expect, $result, $message); }