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 | 5 | public function getPageListFromCategoryName( $name, array $extraParams = [] ) { |
|
32 | 5 | $params = array_merge( $extraParams, [ |
|
33 | 5 | 'list' => 'categorymembers', |
|
34 | 5 | 'cmtitle' => $name, |
|
35 | 5 | ] ); |
|
36 | 5 | return $this->runQuery( $params, 'cmcontinue', 'categorymembers' ); |
|
37 | } |
||
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 | 1 | public function getPageListFromPageTransclusions( $pageName, array $extraParams = [] ) { |
|
51 | 1 | $params = array_merge( $extraParams, [ |
|
52 | 1 | 'list' => 'embeddedin', |
|
53 | 1 | 'eititle' => $pageName, |
|
54 | 1 | ] ); |
|
55 | 1 | return $this->runQuery( $params, 'eicontinue', 'embeddedin' ); |
|
56 | } |
||
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 | 1 | public function getFromWhatLinksHere( $pageName, $extraParams = [] ) { |
|
71 | 1 | $params = array_merge( $extraParams, [ |
|
72 | 1 | 'prop' => 'info', |
|
73 | 1 | 'generator' => 'linkshere', |
|
74 | 1 | 'titles' => $pageName, |
|
75 | 1 | ] ); |
|
76 | 1 | return $this->runQuery( $params, 'glhcontinue', 'pages' ); |
|
77 | } |
||
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 = [] ) { |
||
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 | 1 | public function getFromPrefix( $prefix ) { |
|
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 | 1 | 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 | 9 | protected function runQuery( $params, $contName, $resName, $pageIdName = 'pageid', $cont = true ) { |
|
174 | } |
||
175 |