MediaWiki  1.33.0
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  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 
111  public function next() {
112  $this->res->next();
113  $this->initCurrent();
114  return $this->current;
115  }
116 
117  public function key() {
118  return $this->res ? $this->res->key() : 0;
119  }
120 
121  public function valid() {
122  return $this->res ? $this->res->valid() : false;
123  }
124 
129  public function length() {
130  if ( !$this->res ) {
131  return 0;
132  } else {
133  return $this->res->numRows();
134  }
135  }
136 
141  abstract public function doQuery( $db );
142 
147  abstract public function newItem( $row );
148 }
ContextSource\$context
IContextSource $context
Definition: ContextSource.php:33
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
RevisionListBase\valid
valid()
Definition: RevisionListBase.php:121
RevisionListBase\length
length()
Get the number of items in the list.
Definition: RevisionListBase.php:129
Wikimedia\Rdbms\ResultWrapper
Result wrapper for grabbing data queried from an IDatabase object.
Definition: ResultWrapper.php:24
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
Wikimedia\Rdbms\IDatabase
Basic database interface for live and lazy-loaded relation database handles.
Definition: IDatabase.php:38
Revision
Definition: Revision.php:40
RevisionListBase\next
next()
Move the iteration pointer to the next list item, and return it.
Definition: RevisionListBase.php:111
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:2636
ContextSource
The simplest way of implementing IContextSource is to hold a RequestContext as a member variable and ...
Definition: ContextSource.php:29
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
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
DB_REPLICA
const DB_REPLICA
Definition: defines.php:25
array
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))
ContextSource\setContext
setContext(IContextSource $context)
Definition: ContextSource.php:55
RevisionListBase\reset
reset()
Start iteration.
Definition: RevisionListBase.php:85
RevisionListBase\newItem
newItem( $row)
Create an item object from a DB result row.
title
title
Definition: parserTests.txt:245
RevisionListBase\$ids
array $ids
Definition: RevisionListBase.php:34
IContextSource
Interface for objects which can provide a MediaWiki context on request.
Definition: IContextSource.php:53
Title
Represents a title within MediaWiki.
Definition: Title.php:40
RevisionListBase\$res
ResultWrapper bool $res
Definition: RevisionListBase.php:37
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\$current
bool Revision $current
Definition: RevisionListBase.php:40
RevisionListBase\rewind
rewind()
Definition: RevisionListBase.php:95
RevisionListBase\key
key()
Definition: RevisionListBase.php:117