MediaWiki  master
WikiAwareEntityTrait.php
Go to the documentation of this file.
1 <?php
21 namespace MediaWiki\DAO;
22 
25 use Wikimedia\Assert\Assert;
26 use Wikimedia\Assert\PreconditionException;
27 
33 
46  abstract public function getWikiId();
47 
55  public function assertWiki( $wikiId ) {
56  if ( $wikiId !== $this->getWikiId() ) {
57  $expected = $this->wikiIdToString( $wikiId );
58  $actual = $this->wikiIdToString( $this->getWikiId() );
59  throw new PreconditionException(
60  "Expected " . __CLASS__ . " to belong to $expected, but it belongs to $actual"
61  );
62  }
63  }
64 
71  protected function deprecateInvalidCrossWiki( $wikiId, string $since ) {
72  if ( $wikiId !== $this->getWikiId() ) {
73  $expected = $this->wikiIdToString( $wikiId );
74  $actual = $this->wikiIdToString( $this->getWikiId() );
76  'Deprecated cross-wiki access to ' . __CLASS__ . '. ' .
77  "Expected: {$expected}, Actual: {$actual}. " .
78  "Pass expected \$wikiId.",
79  $since
80  );
81  }
82  }
83 
89  protected function assertWikiIdParam( $wikiId ) {
90  Assert::parameterType( 'string|boolean', $wikiId, '$wikiId' );
91  Assert::parameter( $wikiId !== true, '$wikiId', 'must be false or a string' );
92  }
93 
100  private function wikiIdToString( $wikiId ): string {
101  return $wikiId === WikiAwareEntity::LOCAL ? 'the local wiki' : "'{$wikiId}'";
102  }
103 }
Page\PageIdentity
Interface for objects (potentially) representing an editable wiki page.
Definition: PageIdentity.php:64
MediaWiki\DAO\WikiAwareEntityTrait
trait WikiAwareEntityTrait
Definition: WikiAwareEntityTrait.php:32
MediaWiki\DAO\deprecateInvalidCrossWiki
deprecateInvalidCrossWiki( $wikiId, string $since)
Emits a deprecation warning $since version if $wikiId is not the same as this wiki.
Definition: WikiAwareEntityTrait.php:71
MediaWiki\User\UserIdentity
Interface for objects representing user identity.
Definition: UserIdentity.php:39
MediaWiki\DAO\wikiIdToString
wikiIdToString( $wikiId)
Convert $wikiId to a string for logging.
Definition: WikiAwareEntityTrait.php:100
wfDeprecatedMsg
wfDeprecatedMsg( $msg, $version=false, $component=false, $callerOffset=2)
Log a deprecation warning with arbitrary message text.
Definition: GlobalFunctions.php:1028
MediaWiki\DAO\assertWiki
assertWiki( $wikiId)
Throws if $wikiId is not the same as this entity wiki.
Definition: WikiAwareEntityTrait.php:55
MediaWiki\DAO
Definition: WikiAwareEntity.php:3
MediaWiki\DAO\assertWikiIdParam
assertWikiIdParam( $wikiId)
Asserts correct $wikiId parameter was passed.
Definition: WikiAwareEntityTrait.php:89