dépôts
/
lhc
/
web
/
wiklou.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
First version of AutoblockList special page
[lhc/web/wiklou.git]
/
includes
/
RevisionList.php
diff --git
a/includes/RevisionList.php
b/includes/RevisionList.php
index
1b865bb
..
d909a65
100644
(file)
--- a/
includes/RevisionList.php
+++ b/
includes/RevisionList.php
@@
-20,21
+20,29
@@
* @file
*/
* @file
*/
+use MediaWiki\MediaWikiServices;
+use Wikimedia\Rdbms\ResultWrapper;
+
/**
* List for revision table items for a single page
*/
/**
* List for revision table items for a single page
*/
-abstract class RevisionListBase extends ContextSource {
- /**
- * @var Title
- */
- var $title;
+abstract class RevisionListBase extends ContextSource implements Iterator {
+ /** @var Title */
+ public $title;
- var $ids, $res, $current;
+ /** @var array */
+ protected $ids;
+
+ /** @var ResultWrapper|bool */
+ protected $res;
+
+ /** @var bool|object */
+ protected $current;
/**
* Construct a revision list for a given title
/**
* Construct a revision list for a given title
- * @param
$context IContextSource
- * @param
$title T
itle
+ * @param
IContextSource $context
+ * @param
Title $t
itle
*/
function __construct( IContextSource $context, Title $title ) {
$this->setContext( $context );
*/
function __construct( IContextSource $context, Title $title ) {
$this->setContext( $context );
@@
-43,7
+51,7
@@
abstract class RevisionListBase extends ContextSource {
/**
* Select items only where the ID is any of the specified values
/**
* Select items only where the ID is any of the specified values
- * @param
$ids Array
+ * @param
array $ids
*/
function filterByIds( array $ids ) {
$this->ids = $ids;
*/
function filterByIds( array $ids ) {
$this->ids = $ids;
@@
-72,11
+80,11
@@
abstract class RevisionListBase extends ContextSource {
/**
* Start iteration. This must be called before current() or next().
/**
* Start iteration. This must be called before current() or next().
- * @return First list item
+ * @return
Revision
First list item
*/
public function reset() {
if ( !$this->res ) {
*/
public function reset() {
if ( !$this->res ) {
- $this->res = $this->doQuery( wfGetDB( DB_
SLAVE
) );
+ $this->res = $this->doQuery( wfGetDB( DB_
REPLICA
) );
} else {
$this->res->rewind();
}
} else {
$this->res->rewind();
}
@@
-84,8
+92,13
@@
abstract class RevisionListBase extends ContextSource {
return $this->current;
}
return $this->current;
}
+ public function rewind() {
+ $this->reset();
+ }
+
/**
* Get the current list item, or false if we are at the end
/**
* Get the current list item, or false if we are at the end
+ * @return Revision
*/
public function current() {
return $this->current;
*/
public function current() {
return $this->current;
@@
-93,6
+106,7
@@
abstract class RevisionListBase extends ContextSource {
/**
* Move the iteration pointer to the next list item, and return it.
/**
* Move the iteration pointer to the next list item, and return it.
+ * @return Revision
*/
public function next() {
$this->res->next();
*/
public function next() {
$this->res->next();
@@
-100,6
+114,14
@@
abstract class RevisionListBase extends ContextSource {
return $this->current;
}
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
/**
* Get the number of items in the list.
* @return int
@@
-114,13
+136,13
@@
abstract class RevisionListBase extends ContextSource {
/**
* Do the DB query to iterate through the objects.
/**
* Do the DB query to iterate through the objects.
- * @param
$db DatabaseBase
object to use for the query
+ * @param
IDatabase $db DB
object to use for the query
*/
abstract public function doQuery( $db );
/**
* Create an item object from a DB result row
*/
abstract public function doQuery( $db );
/**
* Create an item object from a DB result row
- * @param
$row stdclass
+ * @param
object $row
*/
abstract public function newItem( $row );
}
*/
abstract public function newItem( $row );
}
@@
-129,15
+151,15
@@
abstract class RevisionListBase extends ContextSource {
* Abstract base class for revision items
*/
abstract class RevisionItemBase {
* Abstract base class for revision items
*/
abstract class RevisionItemBase {
- /**
The parent RevisionListBase
*/
-
var
$list;
+ /**
@var RevisionListBase The parent
*/
+
protected
$list;
- /** The
DB
result row */
-
var
$row;
+ /** The
database
result row */
+
protected
$row;
/**
/**
- * @param
$list RevisionListBase
- * @param $row DB result row
+ * @param
RevisionListBase $list
+ * @param
object
$row DB result row
*/
public function __construct( $list, $row ) {
$this->list = $list;
*/
public function __construct( $list, $row ) {
$this->list = $list;
@@
-182,7
+204,7
@@
abstract class RevisionItemBase {
/**
* Get the ID, as it would appear in the ids URL parameter
/**
* Get the ID, as it would appear in the ids URL parameter
- * @return
+ * @return
int
*/
public function getId() {
$field = $this->getIdField();
*/
public function getId() {
$field = $this->getIdField();
@@
-191,7
+213,7
@@
abstract class RevisionItemBase {
/**
* Get the date, formatted in user's language
/**
* Get the date, formatted in user's language
- * @return
S
tring
+ * @return
s
tring
*/
public function formatDate() {
return $this->list->getLanguage()->userDate( $this->getTimestamp(),
*/
public function formatDate() {
return $this->list->getLanguage()->userDate( $this->getTimestamp(),
@@
-200,7
+222,7
@@
abstract class RevisionItemBase {
/**
* Get the time, formatted in user's language
/**
* Get the time, formatted in user's language
- * @return
S
tring
+ * @return
s
tring
*/
public function formatTime() {
return $this->list->getLanguage()->userTime( $this->getTimestamp(),
*/
public function formatTime() {
return $this->list->getLanguage()->userTime( $this->getTimestamp(),
@@
-209,7
+231,7
@@
abstract class RevisionItemBase {
/**
* Get the timestamp in MW 14-char form
/**
* Get the timestamp in MW 14-char form
- * @return
M
ixed
+ * @return
m
ixed
*/
public function getTimestamp() {
$field = $this->getTimestampField();
*/
public function getTimestamp() {
$field = $this->getTimestampField();
@@
-249,6
+271,14
@@
abstract class RevisionItemBase {
* This is used to show the list in HTML form, by the special page.
*/
abstract public function getHTML();
* 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 {
}
class RevisionList extends RevisionListBase {
@@
-257,23
+287,23
@@
class RevisionList extends RevisionListBase {
}
/**
}
/**
- * @param
$db DatabaseBase
+ * @param
IDatabase $db
* @return mixed
*/
public function doQuery( $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(
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_merge( Revision::selectFields(), Revision::selectUserFields() ),
$conds,
__METHOD__,
-
array( 'ORDER BY' => 'rev_id DESC' )
,
- array(
+
[ 'ORDER BY' => 'rev_id DESC' ]
,
+ [
'page' => Revision::pageJoinCond(),
'page' => Revision::pageJoinCond(),
- 'user' => Revision::userJoinCond()
)
+ 'user' => Revision::userJoinCond()
]
);
}
);
}
@@
-286,7
+316,11
@@
class RevisionList extends RevisionListBase {
* Item class for a live revision table row
*/
class RevisionItem extends RevisionItemBase {
* Item class for a live revision table row
*/
class RevisionItem extends RevisionItemBase {
- var $revision, $context;
+ /** @var Revision */
+ protected $revision;
+
+ /** @var RequestContext */
+ protected $context;
public function __construct( $list, $row ) {
parent::__construct( $list, $row );
public function __construct( $list, $row ) {
parent::__construct( $list, $row );
@@
-307,7
+341,7
@@
class RevisionItem extends RevisionItemBase {
}
public function getAuthorNameField() {
}
public function getAuthorNameField() {
- return '
user_name'; // see Revision::selectUserFields()
+ return '
rev_user_text';
}
public function canView() {
}
public function canView() {
@@
-324,51
+358,61
@@
class RevisionItem extends RevisionItemBase {
/**
* Get the HTML link to the revision text.
/**
* Get the HTML link to the revision text.
- * Overridden by RevDel_ArchiveItem.
+ * @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() {
* @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() ) {
if ( $this->isDeleted() && !$this->canViewContent() ) {
- return
$date
;
+ return
htmlspecialchars( $date )
;
}
}
- return Linker::link(
+ $linkRenderer = $this->getLinkRenderer();
+ return $linkRenderer->makeKnownLink(
$this->list->title,
$date,
$this->list->title,
$date,
-
array()
,
- array(
+
[]
,
+ [
'oldid' => $this->revision->getId(),
'unhide' => 1
'oldid' => $this->revision->getId(),
'unhide' => 1
- )
+ ]
);
}
/**
* Get the HTML link to the diff.
);
}
/**
* Get the HTML link to the diff.
- * Overridden by RevDel_ArchiveItem
+ * @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 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->list->title,
- $this->
context->msg( 'diff' )->escaped
(),
-
array()
,
- array(
+ $this->
list->msg( 'diff' )->text
(),
+
[]
,
+ [
'diff' => $this->revision->getId(),
'oldid' => 'prev',
'unhide' => 1
'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();
public function getHTML() {
$difflink = $this->context->msg( 'parentheses' )
->rawParams( $this->getDiffLink() )->escaped();