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 ( $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 }
MediaWiki\Block\Restriction\PageRestriction\getTitle
getTitle()
Definition: PageRestriction.php:68
MediaWiki\Block\Restriction\PageRestriction\TYPE_ID
const TYPE_ID
Definition: PageRestriction.php:35
MediaWiki\Block\Restriction\PageRestriction\newFromRow
static newFromRow(\stdClass $row)
Creates a new Restriction from a database row.1.33 static
Definition: PageRestriction.php:85
Title\equals
equals(LinkTarget $title)
Compare with another title.
Definition: Title.php:3938
MediaWiki\Block\Restriction
Definition: AbstractRestriction.php:23
Title\newFromRow
static newFromRow( $row)
Make a Title object from a DB row.
Definition: Title.php:556
MediaWiki\Block\Restriction\PageRestriction\setTitle
setTitle(\Title $title)
Definition: PageRestriction.php:58
MediaWiki\Block\Restriction\PageRestriction\TYPE
const TYPE
Definition: PageRestriction.php:30
MediaWiki\Block\Restriction\PageRestriction\matches
matches(\Title $title)
Determine if a restriction matches a given title.1.33 bool
Definition: PageRestriction.php:45
MediaWiki\Block\Restriction\AbstractRestriction
Definition: AbstractRestriction.php:25
Title
Represents a title within MediaWiki.
Definition: Title.php:46
MediaWiki\Block\Restriction\PageRestriction
Definition: PageRestriction.php:25
Title\newFromID
static newFromID( $id, $flags=0)
Create a new Title from an article ID.
Definition: Title.php:505
MediaWiki\Block\Restriction\PageRestriction\$title
Title false null $title
Definition: PageRestriction.php:40