getRequest();
$this->setHeaders();
$this->getOutput()->addModuleStyles( 'ext.CommentStreamsAllComments' );
$offset = $request->getText( 'offset', 0 );
$limit = 20;
$pages = self::getCommentPages( $limit + 1, $offset );
if ( !$pages->valid() ) {
$offset = 0;
$pages = self::getCommentPages( $limit + 1, $offset );
if ( !$pages->valid() ) {
$this->displayMessage(
wfMessage( 'commentstreams-allcomments-nocommentsfound' )
);
return;
}
}
$wikitext = '{| class="wikitable csall-wikitable"' . PHP_EOL;
$wikitext .=
'!' . wfMessage( 'commentstreams-allcomments-label-page' ) . PHP_EOL;
$wikitext .=
'!' . wfMessage( 'commentstreams-allcomments-label-associatedpage' ) . PHP_EOL;
$wikitext .=
'!' . wfMessage( 'commentstreams-allcomments-label-commenttitle' ) . PHP_EOL;
$wikitext .=
'!' . wfMessage( 'commentstreams-allcomments-label-wikitext' ) . PHP_EOL;
$wikitext .=
'!' . wfMessage( 'commentstreams-allcomments-label-author' ) . PHP_EOL;
$wikitext .=
'!' . wfMessage( 'commentstreams-allcomments-label-lasteditor' ) . PHP_EOL;
$wikitext .=
'!' . wfMessage( 'commentstreams-allcomments-label-created' ) . PHP_EOL;
$wikitext .=
'!' . wfMessage( 'commentstreams-allcomments-label-lastedited' ) . PHP_EOL;
$index = 0;
$more = false;
foreach ( $pages as $page ) {
if ( $index < $limit ) {
$wikipage = WikiPage::newFromId( $page->page_id );
$comment = Comment::newFromWikiPage( $wikipage );
if ( $comment !== null ) {
$pagename = $comment->getWikiPage()->getTitle()->getPrefixedText();
$associatedpageid = $comment->getAssociatedId();
$associatedpage = WikiPage::newFromId( $associatedpageid );
if ( $associatedpage !== null ) {
$associatedpagename =
'[[' . $associatedpage->getTitle()->getPrefixedText() . ']]';
$author = $comment->getUser();
if ( $author->isAnon() ) {
$author = '' . wfMessage( 'commentstreams-author-anonymous' )
. '';
} else {
$author = $author->getName();
}
$modificationdate = $comment->getModificationDate();
if ( $modificationdate === null ) {
$lasteditor = '';
} else {
$lasteditor =
\User::newFromId( $wikipage->getRevision()->getUser() );
if ( $lasteditor->isAnon() ) {
$lasteditor = '' .
wfMessage( 'commentstreams-author-anonymous' ) . '';
} else {
$lasteditor = $lasteditor->getName();
}
}
$wikitext .= '|-' . PHP_EOL;
$wikitext .= '|[[' . $pagename . ']]' . PHP_EOL;
$wikitext .= '| ' . $associatedpagename . PHP_EOL;
$wikitext .= '| ' . $comment->getCommentTitle() . PHP_EOL;
$wikitext .= '| ' . $comment->getWikiText() . PHP_EOL;
$wikitext .= '| ' . $author . PHP_EOL;
$wikitext .= '| ' . $lasteditor . PHP_EOL;
$wikitext .= '| ' . $comment->getCreationDate() . PHP_EOL;
$wikitext .= '| ' . $modificationdate . PHP_EOL;
$index++;
}
}
} else {
$more = true;
}
}
$wikitext .= '|}' . PHP_EOL;
if ( method_exists( 'OutputPage', 'addWikiTextAsInterface' ) ) {
$this->getOutput()->addWikiTextAsInterface( $wikitext );
} else {
$this->getOutput()->addWikiText( $wikitext );
}
if ( $offset > 0 || $more ) {
$this->addTableNavigation( $offset, $more, $limit, 'offset' );
}
}
private function displayMessage( $message ) {
$html = Html::openElement( 'p', [
'class' => 'csall-message'
] )
. $message
. Html::closeElement( 'p' );
$this->getOutput()->addHtml( $html );
}
private function addTableNavigation( $offset, $more, $limit, $paramname ) {
$title = Title::newFromText( 'Special:' . __CLASS__ );
$url = $title->getFullURL();
$html = Html::openElement( 'table', [
'class' => 'csall-navigationtable'
] )
. Html::openElement( 'tr' )
. Html::openElement( 'td' );
if ( $offset > 0 ) {
$prevurl = $url . '?' . $paramname . '=' . ( $offset - $limit );
$html .= Html::openElement( 'a', [
'href' => $prevurl,
'class' => 'csall-button'
] )
. wfMessage( 'commentstreams-allcomments-button-previous' )
. Html::closeElement( 'a' );
}
$html .= Html::closeElement( 'td' )
. Html::openElement( 'td', [
'style' => 'text-align:right;'
] );
if ( $more ) {
$nexturl = $url . '?' . $paramname . '=' . ( $offset + $limit );
$html .= Html::openElement( 'a', [
'href' => $nexturl,
'class' => 'csall-button'
] )
. wfMessage( 'commentstreams-allcomments-button-next' )
. Html::closeElement( 'a' );
}
$html .= Html::closeElement( 'td' )
. Html::closeElement( 'tr' )
. Html::closeElement( 'table' );
$this->getOutput()->addHtml( $html );
}
private static function getCommentPages( $limit, $offset ) {
$dbr = wfGetDB( DB_REPLICA );
$pages = $dbr->select(
[
'cs_comment_data',
'page',
'revision'
],
[
'page_id'
],
[
'cst_page_id = page_id',
'page_latest = rev_id'
],
__METHOD__,
[
'ORDER BY' => 'rev_timestamp DESC' ,
'LIMIT' => $limit,
'OFFSET' => $offset
]
);
return $pages;
}
}