Merge "Enable RCFilters app on Watchlist"
[lhc/web/wiklou.git] / includes / RevisionList.php
index 731d1b3..b0bc60a 100644 (file)
  * @file
  */
 
+use MediaWiki\MediaWikiServices;
+use Wikimedia\Rdbms\ResultWrapper;
+use Wikimedia\Rdbms\IDatabase;
+
 /**
  * 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;
 
@@ -33,7 +37,7 @@ abstract class RevisionListBase extends ContextSource {
        /** @var ResultWrapper|bool */
        protected $res;
 
-       /** @var bool|object */
+       /** @var bool|Revision */
        protected $current;
 
        /**
@@ -81,7 +85,7 @@ abstract class RevisionListBase extends ContextSource {
         */
        public function reset() {
                if ( !$this->res ) {
-                       $this->res = $this->doQuery( wfGetDB( DB_SLAVE ) );
+                       $this->res = $this->doQuery( wfGetDB( DB_REPLICA ) );
                } else {
                        $this->res->rewind();
                }
@@ -89,6 +93,10 @@ abstract class RevisionListBase extends ContextSource {
                return $this->current;
        }
 
+       public function rewind() {
+               $this->reset();
+       }
+
        /**
         * Get the current list item, or false if we are at the end
         * @return Revision
@@ -107,6 +115,14 @@ abstract class RevisionListBase extends ContextSource {
                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
@@ -256,6 +272,14 @@ abstract class RevisionItemBase {
         * 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 {
@@ -341,13 +365,14 @@ class RevisionItem extends RevisionItemBase {
         * @return string
         */
        protected function getRevisionLink() {
-               $date = htmlspecialchars( $this->list->getLanguage()->userTimeAndDate(
-                       $this->revision->getTimestamp(), $this->list->getUser() ) );
+               $date = $this->list->getLanguage()->userTimeAndDate(
+                       $this->revision->getTimestamp(), $this->list->getUser() );
 
                if ( $this->isDeleted() && !$this->canViewContent() ) {
-                       return $date;
+                       return htmlspecialchars( $date );
                }
-               return Linker::linkKnown(
+               $linkRenderer = $this->getLinkRenderer();
+               return $linkRenderer->makeKnownLink(
                        $this->list->title,
                        $date,
                        [],
@@ -369,9 +394,10 @@ class RevisionItem extends RevisionItemBase {
                if ( $this->isDeleted() && !$this->canViewContent() ) {
                        return $this->context->msg( 'diff' )->escaped();
                } else {
-                       return Linker::linkKnown(
+                       $linkRenderer = $this->getLinkRenderer();
+                       return $linkRenderer->makeKnownLink(
                                        $this->list->title,
-                                       $this->list->msg( 'diff' )->escaped(),
+                                       $this->list->msg( 'diff' )->text(),
                                        [],
                                        [
                                                'diff' => $this->revision->getId(),