X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FRevisionList.php;h=d909a652d7f0e03c66c0b0f5737aeaa4ad9003f1;hb=680de1a04acdbe56a7173aed6df684268f499ed3;hp=e4174730d1b487d2e2d5eca02bf525fffd08a2e7;hpb=61b0670e7ef034bf8af0f777b0b9a5e3a572c3a1;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/RevisionList.php b/includes/RevisionList.php index e4174730d1..d909a652d7 100644 --- a/includes/RevisionList.php +++ b/includes/RevisionList.php @@ -20,10 +20,13 @@ * @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; @@ -81,7 +84,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 +92,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 +114,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 @@ -121,7 +136,7 @@ abstract class RevisionListBase extends ContextSource { /** * 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 ); @@ -256,6 +271,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 { @@ -264,23 +287,23 @@ 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() ] ); } @@ -341,20 +364,21 @@ 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, - array(), - array( + [], + [ 'oldid' => $this->revision->getId(), 'unhide' => 1 - ) + ] ); } @@ -369,15 +393,16 @@ 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(), - array(), - array( + $this->list->msg( 'diff' )->text(), + [], + [ 'diff' => $this->revision->getId(), 'oldid' => 'prev', 'unhide' => 1 - ) + ] ); } }