* @file
*/
+use MediaWiki\MediaWikiServices;
+use Wikimedia\Rdbms\ResultWrapper;
+
/**
* List for revision table items for a single page
*/
-abstract class RevisionListBase extends ContextSource {
+abstract class RevisionListBase extends ContextSource implements Iterator {
/** @var Title */
public $title;
/** @var array */
protected $ids;
+ /** @var ResultWrapper|bool */
protected $res;
/** @var bool|object */
*/
public function reset() {
if ( !$this->res ) {
- $this->res = $this->doQuery( wfGetDB( DB_SLAVE ) );
+ $this->res = $this->doQuery( wfGetDB( DB_REPLICA ) );
} else {
$this->res->rewind();
}
return $this->current;
}
+ public function rewind() {
+ $this->reset();
+ }
+
/**
* Get the current list item, or false if we are at the end
* @return Revision
return $this->current;
}
+ public function key() {
+ return $this->res ? $this->res->key(): 0;
+ }
+
+ public function valid() {
+ return $this->res ? $this->res->valid() : false;
+ }
+
/**
* Get the number of items in the list.
* @return int
/**
* Do the DB query to iterate through the objects.
- * @param DatabaseBase $db DatabaseBase object to use for the query
+ * @param IDatabase $db DB object to use for the query
*/
abstract public function doQuery( $db );
* This is used to show the list in HTML form, by the special page.
*/
abstract public function getHTML();
+
+ /**
+ * Returns an instance of LinkRenderer
+ * @return \MediaWiki\Linker\LinkRenderer
+ */
+ protected function getLinkRenderer() {
+ return MediaWikiServices::getInstance()->getLinkRenderer();
+ }
}
class RevisionList extends RevisionListBase {
}
/**
- * @param DatabaseBase $db
+ * @param IDatabase $db
* @return mixed
*/
public function doQuery( $db ) {
- $conds = array( 'rev_page' => $this->title->getArticleID() );
+ $conds = [ 'rev_page' => $this->title->getArticleID() ];
if ( $this->ids !== null ) {
$conds['rev_id'] = array_map( 'intval', $this->ids );
}
return $db->select(
- array( 'revision', 'page', 'user' ),
+ [ 'revision', 'page', 'user' ],
array_merge( Revision::selectFields(), Revision::selectUserFields() ),
$conds,
__METHOD__,
- array( 'ORDER BY' => 'rev_id DESC' ),
- array(
+ [ 'ORDER BY' => 'rev_id DESC' ],
+ [
'page' => Revision::pageJoinCond(),
- 'user' => Revision::userJoinCond() )
+ 'user' => Revision::userJoinCond() ]
);
}
}
public function getAuthorNameField() {
- return 'user_name'; // see Revision::selectUserFields()
+ return 'rev_user_text';
}
public function canView() {
/**
* Get the HTML link to the revision text.
- * Overridden by RevDelArchiveItem.
+ * @todo Essentially a copy of RevDelRevisionItem::getRevisionLink. That class
+ * should inherit from this one, and implement an appropriate interface instead
+ * of extending RevDelItem
* @return string
*/
protected function getRevisionLink() {
- $date = $this->list->getLanguage()->timeanddate( $this->revision->getTimestamp(), true );
+ $date = $this->list->getLanguage()->userTimeAndDate(
+ $this->revision->getTimestamp(), $this->list->getUser() );
+
if ( $this->isDeleted() && !$this->canViewContent() ) {
- return $date;
+ return htmlspecialchars( $date );
}
- return Linker::link(
+ $linkRenderer = $this->getLinkRenderer();
+ return $linkRenderer->makeKnownLink(
$this->list->title,
$date,
- array(),
- array(
+ [],
+ [
'oldid' => $this->revision->getId(),
'unhide' => 1
- )
+ ]
);
}
/**
* Get the HTML link to the diff.
- * Overridden by RevDelArchiveItem
+ * @todo Essentially a copy of RevDelRevisionItem::getDiffLink. That class
+ * should inherit from this one, and implement an appropriate interface instead
+ * of extending RevDelItem
* @return string
*/
protected function getDiffLink() {
if ( $this->isDeleted() && !$this->canViewContent() ) {
return $this->context->msg( 'diff' )->escaped();
} else {
- return Linker::link(
+ $linkRenderer = $this->getLinkRenderer();
+ return $linkRenderer->makeKnownLink(
$this->list->title,
- $this->context->msg( 'diff' )->escaped(),
- array(),
- array(
+ $this->list->msg( 'diff' )->text(),
+ [],
+ [
'diff' => $this->revision->getId(),
'oldid' => 'prev',
'unhide' => 1
- ),
- array(
- 'known',
- 'noclasses'
- )
+ ]
);
}
}
+ /**
+ * @todo Essentially a copy of RevDelRevisionItem::getHTML. That class
+ * should inherit from this one, and implement an appropriate interface instead
+ * of extending RevDelItem
+ * @return string
+ */
public function getHTML() {
$difflink = $this->context->msg( 'parentheses' )
->rawParams( $this->getDiffLink() )->escaped();