MediaWiki REL1_39
PageRestriction.php
Go to the documentation of this file.
1<?php
24
26
30 public const TYPE = 'page';
31
35 public const TYPE_ID = 1;
36
40 protected $title;
41
45 public function matches( \Title $title ) {
46 if ( !$this->getTitle() ) {
47 return false;
48 }
49
50 return $title->equals( $this->getTitle() );
51 }
52
58 public function setTitle( \Title $title ) {
59 $this->title = $title;
60
61 return $this;
62 }
63
68 public function getTitle() {
69 if ( $this->title === null ) {
70 $this->title = \Title::newFromID( $this->value );
71
72 // If the title does not exist, set to false to prevent multiple database
73 // queries.
74 if ( $this->title === null ) {
75 $this->title = false;
76 }
77 }
78
79 return $this->title;
80 }
81
85 public static function newFromRow( \stdClass $row ) {
87 $restriction = parent::newFromRow( $row );
88 '@phan-var self $restriction';
89
90 // If the page_namespace and the page_title were provided, add the title to
91 // the restriction.
92 if ( isset( $row->page_namespace ) && isset( $row->page_title ) ) {
93 // Clone the row so it is not mutated.
94 $row = clone $row;
95 $row->page_id = $row->ir_value;
96 $title = \Title::newFromRow( $row );
97 $restriction->setTitle( $title );
98 }
99
100 return $restriction;
101 }
102
109 public static function newFromTitle( $title ) {
110 if ( is_string( $title ) ) {
111 $title = \Title::newFromText( $title );
112 }
113
114 $restriction = new self( 0, $title->getArticleID() );
115 // @phan-suppress-next-line PhanTypeMismatchArgumentNullable Title is always valid
116 $restriction->setTitle( $title );
117
118 return $restriction;
119 }
120}
matches(\Title $title)
Determine if a restriction matches a given title.1.33 bool
static newFromRow(\stdClass $row)
Creates a new Restriction from a database row.1.33 static
Represents a title within MediaWiki.
Definition Title.php:49
equals(object $other)
Compares with another Title.
Definition Title.php:3404
getArticleID( $flags=0)
Get the article ID for this Title from the link cache, adding it if necessary.
Definition Title.php:2824