MediaWiki master
PageRestriction.php
Go to the documentation of this file.
1<?php
10
12
14
18 public const TYPE = 'page';
19
23 public const TYPE_ID = 1;
24
28 protected $title;
29
33 public function matches( Title $title ) {
34 if ( !$this->getTitle() ) {
35 return false;
36 }
37
38 return $title->equals( $this->getTitle() );
39 }
40
46 public function setTitle( Title $title ) {
47 $this->title = $title;
48
49 return $this;
50 }
51
56 public function getTitle() {
57 // If the title does not exist, set to false to prevent multiple database
58 // queries.
59 $this->title ??= Title::newFromID( $this->value ) ?? false;
60
61 return $this->title;
62 }
63
67 public static function newFromRow( \stdClass $row ) {
69 $restriction = parent::newFromRow( $row );
70 '@phan-var self $restriction';
71
72 // If the page_namespace and the page_title were provided, add the title to
73 // the restriction.
74 if ( isset( $row->page_namespace ) && isset( $row->page_title ) ) {
75 // Clone the row so it is not mutated.
76 $row = clone $row;
77 $row->page_id = $row->ir_value;
78 $title = Title::newFromRow( $row );
79 $restriction->setTitle( $title );
80 }
81
82 return $restriction;
83 }
84
91 public static function newFromTitle( $title ) {
92 if ( is_string( $title ) ) {
93 $title = Title::newFromText( $title );
94 }
95
96 $restriction = new self( 0, $title->getArticleID() );
97 // @phan-suppress-next-line PhanTypeMismatchArgumentNullable Title is always valid
98 $restriction->setTitle( $title );
99
100 return $restriction;
101 }
102}
matches(Title $title)
Determine if a restriction matches a given title.1.33 bool
static newFromRow(\stdClass $row)
Create a new Restriction from a database row.1.33 static
Represents a title within MediaWiki.
Definition Title.php:69
equals(object $other)
Compares with another Title.
Definition Title.php:3086
getArticleID( $flags=0)
Get the article ID for this Title from the link cache, adding it if necessary.
Definition Title.php:2558