MediaWiki  master
PageRestriction.php
Go to the documentation of this file.
1 <?php
24 
26 
28 
32  public const TYPE = 'page';
33 
37  public const TYPE_ID = 1;
38 
42  protected $title;
43 
47  public function matches( Title $title ) {
48  if ( !$this->getTitle() ) {
49  return false;
50  }
51 
52  return $title->equals( $this->getTitle() );
53  }
54 
60  public function setTitle( Title $title ) {
61  $this->title = $title;
62 
63  return $this;
64  }
65 
70  public function getTitle() {
71  // If the title does not exist, set to false to prevent multiple database
72  // queries.
73  $this->title ??= Title::newFromID( $this->value ) ?? false;
74 
75  return $this->title;
76  }
77 
81  public static function newFromRow( \stdClass $row ) {
83  $restriction = parent::newFromRow( $row );
84  '@phan-var self $restriction';
85 
86  // If the page_namespace and the page_title were provided, add the title to
87  // the restriction.
88  if ( isset( $row->page_namespace ) && isset( $row->page_title ) ) {
89  // Clone the row so it is not mutated.
90  $row = clone $row;
91  $row->page_id = $row->ir_value;
92  $title = Title::newFromRow( $row );
93  $restriction->setTitle( $title );
94  }
95 
96  return $restriction;
97  }
98 
105  public static function newFromTitle( $title ) {
106  if ( is_string( $title ) ) {
108  }
109 
110  $restriction = new self( 0, $title->getArticleID() );
111  // @phan-suppress-next-line PhanTypeMismatchArgumentNullable Title is always valid
112  $restriction->setTitle( $title );
113 
114  return $restriction;
115  }
116 }
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:76
static newFromID( $id, $flags=0)
Create a new Title from an article ID.
Definition: Title.php:534
static newFromRow( $row)
Make a Title object from a DB row.
Definition: Title.php:559
equals(object $other)
Compares with another Title.
Definition: Title.php:3162
getArticleID( $flags=0)
Get the article ID for this Title from the link cache, adding it if necessary.
Definition: Title.php:2595
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:400