1 | <?php |
||
16 | class PageListGetter extends Service { |
||
17 | |||
18 | /** |
||
19 | * Get the set of pages in a given category. Extra parameters can include: |
||
20 | * cmtype: default 'page|subcat|file' |
||
21 | * cmlimit: default 10, maximum 500 (5000 for bots) |
||
22 | * |
||
23 | * @link https://www.mediawiki.org/wiki/API:Categorymembers |
||
24 | * @since 0.3 |
||
25 | * |
||
26 | * @param string $name |
||
27 | * @param array $extraParams |
||
28 | * |
||
29 | * @return Pages |
||
30 | */ |
||
31 | public function getPageListFromCategoryName( $name, array $extraParams = [] ) { |
||
38 | |||
39 | /** |
||
40 | * List pages that transclude a certain page. |
||
41 | * |
||
42 | * @link https://www.mediawiki.org/wiki/API:Embeddedin |
||
43 | * @since 0.5 |
||
44 | * |
||
45 | * @param string $pageName |
||
46 | * @param array $extraParams |
||
47 | * |
||
48 | * @return Pages |
||
49 | */ |
||
50 | public function getPageListFromPageTransclusions( $pageName, array $extraParams = [] ) { |
||
57 | |||
58 | /** |
||
59 | * Get all pages that link to the given page. |
||
60 | * |
||
61 | * @link https://www.mediawiki.org/wiki/API:Linkshere |
||
62 | * @since 0.5 |
||
63 | * @uses PageListGetter::runQuery() |
||
64 | * |
||
65 | * @param string $pageName The page name |
||
66 | * @param string[] Any extra parameters to use: glhprop, glhnamespace, glhshow, glhlimit |
||
67 | * |
||
68 | * @return Pages |
||
69 | */ |
||
70 | public function getFromWhatLinksHere( $pageName, $extraParams = [] ) { |
||
78 | |||
79 | /** |
||
80 | * Get all pages that are linked to from the given page. |
||
81 | * |
||
82 | * @link https://www.mediawiki.org/wiki/API:Links |
||
83 | * @uses PageListGetter::runQuery() |
||
84 | * |
||
85 | * @param string $pageName The page name |
||
86 | * @param string[] Any extra parameters to use: gpltitles, gplnamespace, gpldir, gpllimit |
||
87 | * |
||
88 | * @return Pages |
||
89 | */ |
||
90 | public function getLinksFromHere( $pageName, $extraParams = [] ) { |
||
91 | $params = array_merge( $extraParams, [ |
||
92 | 'prop' => 'info', |
||
93 | 'generator' => 'links', |
||
94 | 'titles' => $pageName, |
||
95 | ] ); |
||
96 | return $this->runQuery( $params, 'gplcontinue', 'pages' ); |
||
97 | } |
||
98 | |||
99 | /** |
||
100 | * Get all pages that have the given prefix. |
||
101 | * |
||
102 | * @link https://www.mediawiki.org/wiki/API:Allpages |
||
103 | * |
||
104 | * @param string $prefix The page title prefix. |
||
105 | * |
||
106 | * @return Pages |
||
107 | */ |
||
108 | public function getFromPrefix( $prefix ) { |
||
109 | $params = [ |
||
110 | 'list' => 'allpages', |
||
111 | 'apprefix' => $prefix, |
||
112 | ]; |
||
113 | return $this->runQuery( $params, 'apcontinue', 'allpages' ); |
||
114 | } |
||
115 | |||
116 | /** |
||
117 | * Get up to 10 random pages. |
||
118 | * |
||
119 | * @link https://www.mediawiki.org/wiki/API:Random |
||
120 | * @uses PageListGetter::runQuery() |
||
121 | * |
||
122 | * @param array $extraParams |
||
123 | * |
||
124 | * @return Pages |
||
125 | */ |
||
126 | public function getRandom( array $extraParams = [] ) { |
||
130 | |||
131 | /** |
||
132 | * Run a query to completion. |
||
133 | * |
||
134 | * @param string[] $params Query parameters |
||
135 | * @param string $contName Result subelement name for continue details |
||
136 | * @param string $resName Result element name for main results array |
||
137 | * @param string $pageIdName Result element name for page ID |
||
138 | * @param bool $cont Whether to continue the query, using multiple requests |
||
139 | * @return Pages |
||
140 | */ |
||
141 | protected function runQuery( $params, $contName, $resName, $pageIdName = 'pageid', $cont = true ) { |
||
174 | } |
||
175 |