/** * @dataProvider provideWrapAutoComment */ public function testWrapAutoComment($pre, $comment, $post, $expected) { $formatter = new AutoCommentFormatter($this->language, array()); $value = $formatter->wrapAutoComment($pre, $comment, $post); $this->assertEquals($expected, $value); }
/** * Handler for the FormatAutocomments hook, implementing localized formatting * for machine readable autocomments generated by SummaryFormatter. * * @param string[] $data Extra data supplied when registering the hook function, * matches list( $contentModel, $messagePrefix ). * @param string &$comment reference to the autocomment text * @param bool $pre true if there is content before the autocomment * @param string $auto the autocomment unformatted * @param bool $post true if there is content after the autocomment * @param Title|null $title use for further information * @param bool $local shall links be generated locally or globally * * @return bool */ public static function onFormat($data, &$comment, $pre, $auto, $post, $title, $local) { global $wgLang, $wgTitle; list($contentModel, $messagePrefix) = $data; // If it is possible to avoid loading the whole page then the code will be lighter on the server. if (!$title instanceof Title) { $title = $wgTitle; } if (!$title instanceof Title || $title->getContentModel() !== $contentModel) { return; } if ($wgLang instanceof StubUserLang) { wfDebugLog('wikibase-debug', 'Bug: T112070: ' . MWExceptionHandler::prettyPrintTrace(MWExceptionHandler::redactTrace(debug_backtrace()))); StubUserLang::unstub($wgLang); } $formatter = new AutoCommentFormatter($wgLang, array($messagePrefix, 'wikibase-entity')); $formattedComment = $formatter->formatAutoComment($auto); if (is_string($formattedComment)) { $comment = $formatter->wrapAutoComment($pre, $formattedComment, $post); } }
/** * Handler for the FormatAutocomments hook, implementing localized formatting * for machine readable autocomments generated by SummaryFormatter. * * @param string &$comment reference to the autocomment text * @param bool $pre true if there is content before the autocomment * @param string $auto the autocomment unformatted * @param bool $post true if there is content after the autocomment * @param Title|null $title use for further information * @param bool $local shall links be generated locally or globally * @param string|null $wikiId The ID of the wiki the comment applies to, if not the local wiki. * * @return bool */ public static function onFormat(&$comment, $pre, $auto, $post, $title, $local, $wikiId = null) { global $wgContLang; $wikibaseClient = WikibaseClient::getDefaultInstance(); $repoId = $wikibaseClient->getSettings()->getSetting('repoSiteId'); // Only do special formatting for comments from a wikibase repo. // XXX: what to do if the local wiki is the repo? For entity pages, RepoHooks has a handler. // But what to do for other pages? Note that if the local wiki is the repo, $repoId will be // false, and $wikiId will be null. if ($wikiId !== $repoId) { return; } StubObject::unstub($wgContLang); $formatter = new AutoCommentFormatter($wgContLang, array('wikibase-entity')); $formattedComment = $formatter->formatAutoComment($auto); if (is_string($formattedComment)) { $comment = $formatter->wrapAutoComment($pre, $formattedComment, $post); } }