Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
n/a
0 / 0
n/a
0 / 0
CRAP
n/a
0 / 0
1<?php
2
3namespace MediaWiki\DAO;
4
5use MediaWiki\Page\PageIdentity;
6use MediaWiki\Revision\RevisionRecord;
7use MediaWiki\User\UserIdentity;
8use Wikimedia\Assert\PreconditionException;
9
10/**
11 * Marker interface for entities aware of the wiki they belong to.
12 *
13 * Instances of classes implementing this interface belong to a specific
14 * wiki and may be used in a cross-wiki context. Services using these
15 * classes have to ensure the entities they operate on belong to the
16 * correct wiki by calling assertWiki().
17 *
18 * Additionally, some getters of implementing classes can take an optional
19 * $wikiId parameter to assert on for extra protection against incorrect
20 * cross-wiki access. The parameter should be added if using the property in
21 * the context of a wrong wiki will cause DB corruption. Usually the rule of
22 * thumb is fields which are commonly used as foreign keys, like page_id, rev_id,
23 * user_id, actor_id etc. However, the exact line is left to the best judgement
24 * of the implementers.
25 *
26 * Examples: {@link RevisionRecord::getId()} or {@link PageIdentity::getId()}
27 *
28 * @see Block
29 * @see PageIdentity
30 * @see RevisionRecord
31 * @see UserIdentity
32 *
33 * @since 1.36
34 */
35interface WikiAwareEntity {
36
37    /**
38     * @var bool Wiki ID value to use with instances that are
39     *      defined relative to the local wiki.
40     */
41    public const LOCAL = false;
42
43    /**
44     * Throws if $wikiId is different from the return value of getWikiId().
45     *
46     * @param string|false $wikiId The wiki ID expected by the caller.
47     *        Use self::LOCAL for the local wiki.
48     *
49     * @throws PreconditionException If $wikiId is not the ID of the wiki this entity
50     *         belongs to.
51     */
52    public function assertWiki( $wikiId );
53
54    /**
55     * Get the ID of the wiki this page belongs to.
56     *
57     * @return string|false The wiki's logical name,
58     *         or self::LOCAL to indicate the local wiki.
59     */
60    public function getWikiId();
61}