MediaWiki  master
PageStoreRecord.php
Go to the documentation of this file.
1 <?php
21 namespace MediaWiki\Page;
22 
23 use MWTimestamp;
24 use stdClass;
25 use Wikimedia\Assert\Assert;
26 
34 
41  public const REQUIRED_FIELDS = [
42  'page_id',
43  'page_namespace',
44  'page_title',
45  'page_is_redirect',
46  'page_is_new',
47  'page_latest',
48  'page_touched',
49  ];
50 
56  private $row;
57 
65  public function __construct( stdClass $row, $wikiId ) {
66  foreach ( self::REQUIRED_FIELDS as $field ) {
67  Assert::parameter( isset( $row->$field ), '$row->' . $field, 'is required' );
68  }
69 
70  Assert::parameter( $row->page_id > 0, '$pageId', 'must be greater than zero (page must exist)' );
71 
72  parent::__construct( $row->page_id, $row->page_namespace, $row->page_title, $wikiId );
73 
74  $this->row = $row;
75  }
76 
82  public function isNew(): bool {
83  return (bool)$this->row->page_is_new;
84  }
85 
91  public function isRedirect(): bool {
92  return (bool)$this->row->page_is_redirect;
93  }
94 
102  public function getLatest( $wikiId = self::LOCAL ): int {
103  $this->assertWiki( $wikiId );
104  return (int)$this->row->page_latest;
105  }
106 
112  public function getTouched(): string {
113  return MWTimestamp::convert( TS_MW, $this->row->page_touched );
114  }
115 
121  public function getLanguage(): ?string {
122  return $this->getField( 'page_lang' );
123  }
124 
138  public function getField( string $field ) {
139  // Field may be missing entirely.
140  return $this->row->$field ?? null;
141  }
142 
143 }
MWTimestamp
Library for creating and parsing MW-style timestamps.
Definition: MWTimestamp.php:38
Page\PageReferenceValue\$wikiId
bool string $wikiId
Definition: PageReferenceValue.php:55
Page\PageStoreRecord
Immutable data record representing an editable page on a wiki.
Definition: PageStoreRecord.php:33
Page\PageStoreRecord\__construct
__construct(stdClass $row, $wikiId)
The $row object must provide all fields listed in PageStoreRecord::REQUIRED_FIELDS.
Definition: PageStoreRecord.php:65
Page\PageStoreRecord\isNew
isNew()
False if the page has had more than one edit.
Definition: PageStoreRecord.php:82
Page\PageStoreRecord\getField
getField(string $field)
Return the raw value for the given field as returned by the database query.
Definition: PageStoreRecord.php:138
Page\PageStoreRecord\getLatest
getLatest( $wikiId=self::LOCAL)
The ID of the page'S latest revision.
Definition: PageStoreRecord.php:102
Page\ExistingPageRecord
Data record representing a page that currently exists as an editable page on a wiki.
Definition: ExistingPageRecord.php:15
MediaWiki\DAO\WikiAwareEntity\assertWiki
assertWiki( $wikiId)
Throws if $wikiId is different from the return value of getWikiId().
Page\PageStoreRecord\$row
stdClass $row
Fields from the page table.
Definition: PageStoreRecord.php:56
Page\PageStoreRecord\getLanguage
getLanguage()
Language in which the page is written.
Definition: PageStoreRecord.php:121
Page\PageIdentityValue
Immutable value object representing a page identity.
Definition: PageIdentityValue.php:41
MediaWiki\Page
Definition: ContentModelChangeFactory.php:23
Page\PageStoreRecord\getTouched
getTouched()
Timestamp at which the page was last rerendered.
Definition: PageStoreRecord.php:112
Page\PageStoreRecord\REQUIRED_FIELDS
const REQUIRED_FIELDS
Fields that must be present in the row object passed to the constructor.
Definition: PageStoreRecord.php:41
Page\PageStoreRecord\isRedirect
isRedirect()
True if the page is a redirect.
Definition: PageStoreRecord.php:91