1<?php
2
3namespace MediaWiki\Page;
4
5use IDBAccessObject;
6use InvalidArgumentException;
7use MediaWiki\Linker\LinkTarget;
8
9/**
10 * Service interface for looking up infermation about wiki pages
11 *
12 * @since 1.36
13 * @unstable
14 */
15interface PageLookup extends IDBAccessObject {
16
17	/**
18	 * Returns the PageIdentity for the given LinkTarget. The page does not have to exist.
19	 * Fragments are ignored.
20	 *
21	 * The LinkTarget must refer to a proper page - that is, it must not be a relative section link,
22	 * an interwiki link, or refer to a special page.
23	 *
24	 * @param LinkTarget $link
25	 * @param int $queryFlags
26	 *
27	 * @throws InvalidArgumentException if $link does not refer to a proper page.
28	 * @return ProperPageIdentity
29	 */
30	public function getPageForLink(
31		LinkTarget $link,
32		int $queryFlags = self::READ_NORMAL
33	): ProperPageIdentity;
34
35	/**
36	 * Returns the PageRecord of the given page.
37	 *
38	 * @param int $pageId
39	 * @param int $queryFlags
40	 *
41	 * @throws InvalidArgumentException if $pageId is 0 or negative.
42	 * @return ExistingPageRecord|null The page's PageRecord, or null if the page was not found.
43	 */
44	public function getPageById(
45		int $pageId,
46		int $queryFlags = self::READ_NORMAL
47	): ?ExistingPageRecord;
48
49	/**
50	 * Returns the PageRecord for the given name and namespace.
51	 *
52	 * @param int $namespace
53	 * @param string $dbKey
54	 * @param int $queryFlags
55	 *
56	 * @return ExistingPageRecord|null The page's PageRecord, or null if the page was not found.
57	 * @throws InvalidArgumentException if $namespace is negative or $dbKey is empty.
58	 */
59	public function getPageByName(
60		int $namespace,
61		string $dbKey,
62		int $queryFlags = self::READ_NORMAL
63	): ?ExistingPageRecord;
64
65	/**
66	 * Returns the PageRecord of the given page.
67	 * May return $page if that already is a PageRecord.
68	 *
69	 * @param PageIdentity $page
70	 * @param int $queryFlags
71	 *
72	 * @return ExistingPageRecord|null The page's PageRecord, or null if the page was not found.
73	 */
74	public function getPageByIdentity(
75		PageIdentity $page,
76		int $queryFlags = self::READ_NORMAL
77	): ?ExistingPageRecord;
78
79}
80