MediaWiki  master
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 the title does not exist, set to false to prevent multiple database
70  // queries.
71  $this->title ??= \Title::newFromID( $this->value ) ?? false;
72 
73  return $this->title;
74  }
75 
79  public static function newFromRow( \stdClass $row ) {
81  $restriction = parent::newFromRow( $row );
82  '@phan-var self $restriction';
83 
84  // If the page_namespace and the page_title were provided, add the title to
85  // the restriction.
86  if ( isset( $row->page_namespace ) && isset( $row->page_title ) ) {
87  // Clone the row so it is not mutated.
88  $row = clone $row;
89  $row->page_id = $row->ir_value;
90  $title = \Title::newFromRow( $row );
91  $restriction->setTitle( $title );
92  }
93 
94  return $restriction;
95  }
96 
103  public static function newFromTitle( $title ) {
104  if ( is_string( $title ) ) {
106  }
107 
108  $restriction = new self( 0, $title->getArticleID() );
109  // @phan-suppress-next-line PhanTypeMismatchArgumentNullable Title is always valid
110  $restriction->setTitle( $title );
111 
112  return $restriction;
113  }
114 }
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:52
static newFromID( $id, $flags=0)
Create a new Title from an article ID.
Definition: Title.php:521
equals(object $other)
Compares with another Title.
Definition: Title.php:3418
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:373
getArticleID( $flags=0)
Get the article ID for this Title from the link cache, adding it if necessary.
Definition: Title.php:2838
static newFromRow( $row)
Make a Title object from a DB row.
Definition: Title.php:576