MediaWiki  1.34.0
PageRestriction.php
Go to the documentation of this file.
1 <?php
24 
26 
30  const TYPE = 'page';
31 
35  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 
60  public function setTitle( \Title $title ) {
61  $this->title = $title;
62 
63  return $this;
64  }
65 
72  public function getTitle() {
73  if ( $this->title === null ) {
74  $this->title = \Title::newFromID( $this->value );
75 
76  // If the title does not exist, set to false to prevent multiple database
77  // queries.
78  if ( $this->title === null ) {
79  $this->title = false;
80  }
81  }
82 
83  return $this->title ?? null;
84  }
85 
89  public static function newFromRow( \stdClass $row ) {
91  $restriction = parent::newFromRow( $row );
92  '@phan-var self $restriction';
93 
94  // If the page_namespace and the page_title were provided, add the title to
95  // the restriction.
96  if ( isset( $row->page_namespace ) && isset( $row->page_title ) ) {
97  // Clone the row so it is not mutated.
98  $row = clone $row;
99  $row->page_id = $row->ir_value;
100  $title = \Title::newFromRow( $row );
101  $restriction->setTitle( $title );
102  }
103 
104  return $restriction;
105  }
106 }
MediaWiki\Block\Restriction\PageRestriction\getTitle
getTitle()
Get Title.
Definition: PageRestriction.php:72
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:89
value
if( $inline) $status value
Definition: SyntaxHighlight.php:346
Title\equals
equals(LinkTarget $title)
Compare with another title.
Definition: Title.php:4113
MediaWiki\Block\Restriction
Definition: AbstractRestriction.php:23
Title\newFromRow
static newFromRow( $row)
Make a Title object from a DB row.
Definition: Title.php:518
MediaWiki\Block\Restriction\PageRestriction\setTitle
setTitle(\Title $title)
Set the title.
Definition: PageRestriction.php:60
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:42
MediaWiki\Block\Restriction\PageRestriction
Definition: PageRestriction.php:25
MediaWiki\Block\Restriction\PageRestriction\$title
Title bool $title
Definition: PageRestriction.php:40
Title\newFromID
static newFromID( $id, $flags=0)
Create a new Title from an article ID.
Definition: Title.php:467