parserOutputAccess = $parserOutputAccess; $this->commentParser = $commentParser; } /** * @inheritDoc */ public function getDescription() { return $this->msg( 'discussiontoolsdebug-title' ); } /** * @inheritDoc */ protected function getFormFields() { return [ 'pagetitle' => [ 'label-message' => 'discussiontoolsdebug-pagetitle', 'name' => 'pagetitle', 'type' => 'title', 'required' => true, 'exists' => true, ], ]; } /** * @inheritDoc */ protected function getSubpageField() { return 'pagetitle'; } /** * @inheritDoc */ protected function getDisplayFormat() { return 'ooui'; } /** * @inheritDoc */ public function requiresPost() { return false; } /** * @inheritDoc */ public function onSubmit( array $data ) { $title = Title::newFromText( $data['pagetitle'] ); $status = $this->parserOutputAccess->getParserOutput( $title->toPageRecord(), ParserOptions::newFromAnon() ); if ( !$status->isOK() ) { return $status; } $parserOutput = $status->getValue(); $html = $parserOutput->getText(); $doc = DOMUtils::parseHTML( $html ); $container = DOMCompat::getBody( $doc ); $threadItemSet = $this->commentParser->parse( $container, $title->getTitleValue() ); $out = $this->getOutput(); $out->addHTML( $this->msg( 'discussiontoolsdebug-intro', $title->getPrefixedText(), SpecialPage::getTitleFor( 'ApiSandbox', false, 'action=discussiontoolspageinfo&prop=threaditemshtml&excludesignatures=1&page=' . urlencode( $title->getPrefixedText() ) )->getFullText() )->parseAsBlock() ); $pageLang = $title->getPageViewLanguage(); $pageLangAttribs = [ 'lang' => $pageLang->getHtmlCode(), 'dir' => $pageLang->getDir(), 'class' => 'mw-content-' . $pageLang->getDir(), ]; foreach ( $threadItemSet->getThreadsStructured() as $thread ) { $out->addHTML( $this->formatComments( $thread, $pageLangAttribs ) ); } $out->addModuleStyles( 'ext.discussionTools.debug.styles' ); return true; } /** * Format a thread item with replies. * * @param ContentThreadItem $comment * @param array $pageLangAttribs * @return string HTML */ private function formatComments( ContentThreadItem $comment, array $pageLangAttribs ) { if ( $comment instanceof ContentHeadingItem ) { $contents = '' . $comment->getHTML() . ''; } else { Assert::precondition( $comment instanceof ContentCommentItem, 'Must be ContentCommentItem' ); $contents = '' . '' . Html::rawElement( 'div', $pageLangAttribs, ' ' . ' ' . '(' . Linker::userTalkLink( 0, $comment->getAuthor() ) . ') ' . ' ' . '