MediaWiki  master
RevisionListBase.php
Go to the documentation of this file.
1 <?php
25 
29 abstract class RevisionListBase extends ContextSource implements Iterator {
31  public $title;
32 
34  protected $ids;
35 
37  protected $res;
38 
40  protected $current;
41 
48  $this->setContext( $context );
49  $this->title = $title;
50  }
51 
56  public function filterByIds( array $ids ) {
57  $this->ids = $ids;
58  }
59 
65  public function getType() {
66  return null;
67  }
68 
72  protected function initCurrent() {
73  $row = $this->res->current();
74  if ( $row ) {
75  $this->current = $this->newItem( $row );
76  } else {
77  $this->current = false;
78  }
79  }
80 
85  public function reset() {
86  if ( !$this->res ) {
87  $this->res = $this->doQuery( wfGetDB( DB_REPLICA ) );
88  } else {
89  $this->res->rewind();
90  }
91  $this->initCurrent();
92  return $this->current;
93  }
94 
95  public function rewind() {
96  $this->reset();
97  }
98 
103  public function current() {
104  return $this->current;
105  }
106 
112  public function next() {
113  $this->res->next();
114  $this->initCurrent();
115  return $this->current;
116  }
117 
118  public function key() {
119  return $this->res ? $this->res->key() : 0;
120  }
121 
122  public function valid() {
123  return $this->res ? $this->res->valid() : false;
124  }
125 
130  public function length() {
131  if ( !$this->res ) {
132  return 0;
133  } else {
134  return $this->res->numRows();
135  }
136  }
137 
143  abstract public function doQuery( $db );
144 
150  abstract public function newItem( $row );
151 }
ContextSource\$context
IContextSource $context
Definition: ContextSource.php:37
RevisionListBase\filterByIds
filterByIds(array $ids)
Select items only where the ID is any of the specified values.
Definition: RevisionListBase.php:56
RevisionListBase
List for revision table items for a single page.
Definition: RevisionListBase.php:29
RevisionItemBase
Abstract base class for revision items.
Definition: RevisionItemBase.php:29
RevisionListBase\valid
valid()
Definition: RevisionListBase.php:122
RevisionListBase\$current
RevisionItemBase false $current
Definition: RevisionListBase.php:40
RevisionListBase\length
length()
Get the number of items in the list.
Definition: RevisionListBase.php:130
Wikimedia\Rdbms\IDatabase
Basic database interface for live and lazy-loaded relation database handles.
Definition: IDatabase.php:38
RevisionListBase\next
next()
Move the iteration pointer to the next list item, and return it.
Definition: RevisionListBase.php:112
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:2448
ContextSource
The simplest way of implementing IContextSource is to hold a RequestContext as a member variable and ...
Definition: ContextSource.php:31
RevisionListBase\current
current()
Get the current list item, or false if we are at the end.
Definition: RevisionListBase.php:103
RevisionListBase\$title
Title $title
Definition: RevisionListBase.php:31
DB_REPLICA
const DB_REPLICA
Definition: defines.php:25
RevisionListBase\$res
IResultWrapper false $res
Definition: RevisionListBase.php:37
ContextSource\setContext
setContext(IContextSource $context)
Definition: ContextSource.php:61
RevisionListBase\reset
reset()
Start iteration.
Definition: RevisionListBase.php:85
RevisionListBase\newItem
newItem( $row)
Create an item object from a DB result row.
RevisionListBase\$ids
int[] null $ids
Definition: RevisionListBase.php:34
IContextSource
Interface for objects which can provide a MediaWiki context on request.
Definition: IContextSource.php:55
Title
Represents a title within MediaWiki.
Definition: Title.php:41
RevisionListBase\getType
getType()
Get the internal type name of this list.
Definition: RevisionListBase.php:65
RevisionListBase\initCurrent
initCurrent()
Initialise the current iteration pointer.
Definition: RevisionListBase.php:72
RevisionListBase\__construct
__construct(IContextSource $context, Title $title)
Construct a revision list for a given title.
Definition: RevisionListBase.php:47
RevisionListBase\rewind
rewind()
Definition: RevisionListBase.php:95
RevisionListBase\key
key()
Definition: RevisionListBase.php:118