MediaWiki  1.33.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 ) {
90  $restriction = parent::newFromRow( $row );
91 
92  // If the page_namespace and the page_title were provided, add the title to
93  // the restriction.
94  if ( isset( $row->page_namespace ) && isset( $row->page_title ) ) {
95  // Clone the row so it is not mutated.
96  $row = clone $row;
97  $row->page_id = $row->ir_value;
98  $title = \Title::newFromRow( $row );
99  $restriction->setTitle( $title );
100  }
101 
102  return $restriction;
103  }
104 }
MediaWiki\Block\Restriction\PageRestriction\getTitle
getTitle()
Get Title.
Definition: PageRestriction.php:72
MediaWiki\Block\Restriction\PageRestriction\TYPE_ID
const TYPE_ID
@inheritDoc
Definition: PageRestriction.php:35
MediaWiki\Block\Restriction\PageRestriction\newFromRow
static newFromRow(\stdClass $row)
@inheritDoc
Definition: PageRestriction.php:89
value
if( $inline) $status value
Definition: SyntaxHighlight.php:345
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
MediaWiki\Block\Restriction
Definition: AbstractRestriction.php:23
Title\newFromRow
static newFromRow( $row)
Make a Title object from a DB row.
Definition: Title.php:506
MediaWiki\Block\Restriction\PageRestriction\setTitle
setTitle(\Title $title)
Set the title.
Definition: PageRestriction.php:60
MediaWiki\Block\Restriction\PageRestriction\TYPE
const TYPE
@inheritDoc
Definition: PageRestriction.php:30
Title\equals
equals(Title $title)
Compare with another title.
Definition: Title.php:4006
MediaWiki\Block\Restriction\PageRestriction\matches
matches(\Title $title)
@inheritDoc
Definition: PageRestriction.php:45
title
title
Definition: parserTests.txt:245
MediaWiki\Block\Restriction\AbstractRestriction
Definition: AbstractRestriction.php:25
Title
Represents a title within MediaWiki.
Definition: Title.php:40
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:457