summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'CommentStreams/includes/CommentStreamsAllComments.php')
-rw-r--r--CommentStreams/includes/CommentStreamsAllComments.php88
1 files changed, 37 insertions, 51 deletions
diff --git a/CommentStreams/includes/CommentStreamsAllComments.php b/CommentStreams/includes/CommentStreamsAllComments.php
index c11810e7..17ca75a3 100644
--- a/CommentStreams/includes/CommentStreamsAllComments.php
+++ b/CommentStreams/includes/CommentStreamsAllComments.php
@@ -25,31 +25,34 @@
namespace MediaWiki\Extension\CommentStreams;
use Html;
+use MediaWiki\MediaWikiServices;
+use MWException;
use SpecialPage;
-use Title;
-use WikiPage;
class CommentStreamsAllComments extends SpecialPage {
-
public function __construct() {
parent::__construct( 'CommentStreamsAllComments' );
}
/**
* @inheritDoc
+ * @throws MWException
*/
- public function execute( $par ) {
+ public function execute( $subPage ) {
$request = $this->getRequest();
$this->setHeaders();
$this->getOutput()->addModuleStyles( 'ext.CommentStreamsAllComments' );
- $offset = $request->getText( 'offset', 0 );
+ $commentStreamsStore =
+ MediaWikiServices::getInstance()->getService( 'CommentStreamsStore' );
+
+ $offset = $request->getText( 'offset', '0' );
$limit = 20;
- $pages = self::getCommentPages( $limit + 1, $offset );
+ $pages = $commentStreamsStore->getCommentPages( $limit + 1, $offset );
if ( !$pages->valid() ) {
$offset = 0;
- $pages = self::getCommentPages( $limit + 1, $offset );
+ $pages = $commentStreamsStore->getCommentPages( $limit + 1, $offset );
if ( !$pages->valid() ) {
$this->displayMessage(
wfMessage( 'commentstreams-allcomments-nocommentsfound' )
@@ -75,21 +78,26 @@ class CommentStreamsAllComments extends SpecialPage {
'!' . wfMessage( 'commentstreams-allcomments-label-created' ) . PHP_EOL;
$wikitext .=
'!' . wfMessage( 'commentstreams-allcomments-label-lastedited' ) . PHP_EOL;
+ $wikitext .=
+ '!' . wfMessage( 'commentstreams-allcomments-label-blockid' ) . PHP_EOL;
+
+ $commentStreamsFactory =
+ MediaWikiServices::getInstance()->getService( 'CommentStreamsFactory' );
$index = 0;
$more = false;
foreach ( $pages as $page ) {
if ( $index < $limit ) {
- $wikipage = WikiPage::newFromId( $page->page_id );
- $comment = Comment::newFromWikiPage( $wikipage );
+ $wikipage = CommentStreamsUtils::newWikiPageFromId( $page->page_id );
+ $comment = $commentStreamsFactory->newFromWikiPage( $wikipage );
if ( $comment !== null ) {
- $pagename = $comment->getWikiPage()->getTitle()->getPrefixedText();
+ $pagename = $comment->getTitle()->getPrefixedText();
$associatedpageid = $comment->getAssociatedId();
- $associatedpage = WikiPage::newFromId( $associatedpageid );
+ $associatedpage = CommentStreamsUtils::newWikiPageFromId( $associatedpageid );
if ( $associatedpage !== null ) {
$associatedpagename =
'[[' . $associatedpage->getTitle()->getPrefixedText() . ']]';
- $author = $comment->getUser();
+ $author = $comment->getAuthor();
if ( $author->isAnon() ) {
$author = '<i>' . wfMessage( 'commentstreams-author-anonymous' )
. '</i>';
@@ -99,10 +107,10 @@ class CommentStreamsAllComments extends SpecialPage {
$modificationdate = $comment->getModificationDate();
if ( $modificationdate === null ) {
$lasteditor = '';
+ $modificationdate = '';
} else {
- $lasteditor =
- \User::newFromId( $wikipage->getRevision()->getUser() );
- if ( $lasteditor->isAnon() ) {
+ $lasteditor = $comment->getLastEditor();
+ if ( $lasteditor->getId() === 0 ) {
$lasteditor = '<i>' .
wfMessage( 'commentstreams-author-anonymous' ) . '</i>';
} else {
@@ -113,11 +121,12 @@ class CommentStreamsAllComments extends SpecialPage {
$wikitext .= '|[[' . $pagename . ']]' . PHP_EOL;
$wikitext .= '| ' . $associatedpagename . PHP_EOL;
$wikitext .= '| ' . $comment->getCommentTitle() . PHP_EOL;
- $wikitext .= '| ' . $comment->getWikiText() . PHP_EOL;
+ $wikitext .= '| ' . htmlentities( $comment->getWikiText() ) . PHP_EOL;
$wikitext .= '| ' . $author . PHP_EOL;
$wikitext .= '| ' . $lasteditor . PHP_EOL;
$wikitext .= '| ' . $comment->getCreationDate() . PHP_EOL;
$wikitext .= '| ' . $modificationdate . PHP_EOL;
+ $wikitext .= '| ' . $comment->getBlockId() . PHP_EOL;
$index++;
}
}
@@ -127,17 +136,16 @@ class CommentStreamsAllComments extends SpecialPage {
}
$wikitext .= '|}' . PHP_EOL;
- if ( method_exists( 'OutputPage', 'addWikiTextAsInterface' ) ) {
- $this->getOutput()->addWikiTextAsInterface( $wikitext );
- } else {
- $this->getOutput()->addWikiText( $wikitext );
- }
+ CommentStreamsUtils::addWikiTextToOutputPage( $wikitext, $this->getOutput() );
if ( $offset > 0 || $more ) {
$this->addTableNavigation( $offset, $more, $limit, 'offset' );
}
}
+ /**
+ * @param string $message
+ */
private function displayMessage( $message ) {
$html = Html::openElement( 'p', [
'class' => 'csall-message'
@@ -147,10 +155,13 @@ class CommentStreamsAllComments extends SpecialPage {
$this->getOutput()->addHtml( $html );
}
+ /**
+ * @param int $offset
+ * @param bool $more
+ * @param int $limit
+ * @param string $paramname
+ */
private function addTableNavigation( $offset, $more, $limit, $paramname ) {
- $title = Title::newFromText( 'Special:' . __CLASS__ );
- $url = $title->getFullURL();
-
$html = Html::openElement( 'table', [
'class' => 'csall-navigationtable'
] )
@@ -158,7 +169,7 @@ class CommentStreamsAllComments extends SpecialPage {
. Html::openElement( 'td' );
if ( $offset > 0 ) {
- $prevurl = $url . '?' . $paramname . '=' . ( $offset - $limit );
+ $prevurl = $this->getFullTitle()->getFullURL( [ $paramname => ( $offset - $limit ) ] );
$html .= Html::openElement( 'a', [
'href' => $prevurl,
'class' => 'csall-button'
@@ -173,7 +184,7 @@ class CommentStreamsAllComments extends SpecialPage {
] );
if ( $more ) {
- $nexturl = $url . '?' . $paramname . '=' . ( $offset + $limit );
+ $nexturl = $this->getFullTitle()->getFullURL( [ $paramname => ( $offset + $limit ) ] );
$html .= Html::openElement( 'a', [
'href' => $nexturl,
'class' => 'csall-button'
@@ -187,29 +198,4 @@ class CommentStreamsAllComments extends SpecialPage {
. 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;
- }
}