parserOutputAccess = $parserOutputAccess; $this->commentParser = $commentParser; } /** * @inheritDoc */ public function getDescription() { return $this->msg( 'discussiontoolsdebug-title' )->text(); } /** * @inheritDoc */ protected function getFormFields() { return [ 'pagetitle' => [ 'label-message' => 'discussiontoolsdebug-pagetitle', 'name' => 'pagetitle', 'type' => 'title', 'required' => 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() )->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 = '' . '' . Linker::userLink( 0, $comment->getAuthor() ) . '' . ' ' . '(' . Linker::userTalkLink( 0, $comment->getAuthor() ) . ') ' . '' . htmlspecialchars( $this->getLanguage()->getHumanTimestamp( new MWTimestamp( $comment->getTimestamp()->getTimestamp() ) ) ) . '' . '' . Html::rawElement( 'div', $pageLangAttribs, '
' . $comment->getBodyHtml( true ) . '
' ); } $level = $comment->getLevel(); $replies = ''; foreach ( $comment->getReplies() as $reply ) { $replies .= $this->formatComments( $reply, $pageLangAttribs ); } return Html::rawElement( $replies ? 'details' : 'div', [ 'open' => (bool)$replies, 'class' => 'mw-dt-comment', 'data-level' => $level, ], ( $replies ? Html::rawElement( 'summary', [], $contents ) : $contents ) . $replies ); } }