MediaWiki  master
RevisionListBase.php
Go to the documentation of this file.
1 <?php
26 
30 abstract class RevisionListBase extends ContextSource implements Iterator {
32 
34  protected $title;
35 
37  protected $ids;
38 
40  protected $res;
41 
43  protected $current;
44 
50  public function __construct( IContextSource $context, PageIdentity $page ) {
51  $this->setContext( $context );
52  $this->title = Title::castFromPageIdentity( $page );
53 
54  $this->deprecatePublicPropertyFallback( 'title', '1.37', function () {
55  return $this->title;
56  } );
57  }
58 
62  public function getPage(): PageIdentity {
63  return $this->title;
64  }
65 
70  public function getPageName(): string {
71  return $this->title->getPrefixedText();
72  }
73 
78  public function filterByIds( array $ids ) {
79  $this->ids = $ids;
80  }
81 
87  public function getType() {
88  return null;
89  }
90 
94  protected function initCurrent() {
95  $row = $this->res->current();
96  if ( $row ) {
97  $this->current = $this->newItem( $row );
98  } else {
99  $this->current = false;
100  }
101  }
102 
107  public function reset() {
108  if ( !$this->res ) {
109  $this->res = $this->doQuery( wfGetDB( DB_REPLICA ) );
110  } else {
111  $this->res->rewind();
112  }
113  $this->initCurrent();
114  return $this->current;
115  }
116 
117  public function rewind() {
118  $this->reset();
119  }
120 
125  public function current() {
126  return $this->current;
127  }
128 
134  public function next() {
135  $this->res->next();
136  $this->initCurrent();
137  return $this->current;
138  }
139 
140  public function key() {
141  return $this->res ? $this->res->key() : 0;
142  }
143 
144  public function valid() {
145  return $this->res ? $this->res->valid() : false;
146  }
147 
152  public function length() {
153  if ( !$this->res ) {
154  return 0;
155  } else {
156  return $this->res->numRows();
157  }
158  }
159 
165  abstract public function doQuery( $db );
166 
172  abstract public function newItem( $row );
173 }
Page\PageIdentity
Interface for objects (potentially) representing an editable wiki page.
Definition: PageIdentity.php:64
ContextSource\$context
IContextSource $context
Definition: ContextSource.php:39
RevisionListBase\filterByIds
filterByIds(array $ids)
Select items only where the ID is any of the specified values.
Definition: RevisionListBase.php:78
RevisionListBase
List for revision table items for a single page.
Definition: RevisionListBase.php:30
RevisionItemBase
Abstract base class for revision items.
Definition: RevisionItemBase.php:29
RevisionListBase\valid
valid()
Definition: RevisionListBase.php:144
RevisionListBase\$current
RevisionItemBase false $current
Definition: RevisionListBase.php:43
RevisionListBase\length
length()
Get the number of items in the list.
Definition: RevisionListBase.php:152
Wikimedia\Rdbms\IDatabase
Basic database interface for live and lazy-loaded relation database handles.
Definition: IDatabase.php:38
Title\castFromPageIdentity
static castFromPageIdentity(?PageIdentity $pageIdentity)
Return a Title for a given PageIdentity.
Definition: Title.php:364
deprecatePublicPropertyFallback
deprecatePublicPropertyFallback(string $property, string $version, callable $getter, ?callable $setter=null, $class=null, $component=null)
Mark a removed public property as deprecated and provide fallback getter and setter callables.
Definition: DeprecationHelper.php:132
RevisionListBase\next
next()
Move the iteration pointer to the next list item, and return it.
Definition: RevisionListBase.php:134
Wikimedia\Rdbms\IResultWrapper
Result wrapper for grabbing data queried from an IDatabase object.
Definition: IResultWrapper.php:24
RevisionListBase\doQuery
doQuery( $db)
Do the DB query to iterate through the objects.
wfGetDB
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:2226
ContextSource
The simplest way of implementing IContextSource is to hold a RequestContext as a member variable and ...
Definition: ContextSource.php:33
RevisionListBase\current
current()
Get the current list item, or false if we are at the end.
Definition: RevisionListBase.php:125
RevisionListBase\$title
Title $title
Definition: RevisionListBase.php:34
DB_REPLICA
const DB_REPLICA
Definition: defines.php:25
RevisionListBase\$res
IResultWrapper false $res
Definition: RevisionListBase.php:40
ContextSource\setContext
setContext(IContextSource $context)
Definition: ContextSource.php:63
RevisionListBase\reset
reset()
Start iteration.
Definition: RevisionListBase.php:107
RevisionListBase\newItem
newItem( $row)
Create an item object from a DB result row.
RevisionListBase\$ids
int[] null $ids
Definition: RevisionListBase.php:37
RevisionListBase\getPageName
getPageName()
Definition: RevisionListBase.php:70
RevisionListBase\getPage
getPage()
Definition: RevisionListBase.php:62
IContextSource
Interface for objects which can provide a MediaWiki context on request.
Definition: IContextSource.php:58
Title
Represents a title within MediaWiki.
Definition: Title.php:49
RevisionListBase\__construct
__construct(IContextSource $context, PageIdentity $page)
Construct a revision list for a given title.
Definition: RevisionListBase.php:50
RevisionListBase\getType
getType()
Get the internal type name of this list.
Definition: RevisionListBase.php:87
RevisionListBase\initCurrent
initCurrent()
Initialise the current iteration pointer.
Definition: RevisionListBase.php:94
DeprecationHelper
trait DeprecationHelper
Use this trait in classes which have properties for which public access is deprecated or implementati...
Definition: DeprecationHelper.php:60
RevisionListBase\rewind
rewind()
Definition: RevisionListBase.php:117
RevisionListBase\key
key()
Definition: RevisionListBase.php:140