1 <?php
2 /**
3 * @package Joomla.Platform
4 * @subpackage MediaWiki
5 *
6 * @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved.
7 * @license GNU General Public License version 2 or later; see LICENSE
8 */
9
10 defined('JPATH_PLATFORM') or die;
11
12 /**
13 * MediaWiki API Search class for the Joomla Platform.
14 *
15 * @since 12.3
16 */
17 class JMediawikiSearch extends JMediawikiObject
18 {
19 /**
20 * Method to perform a full text search.
21 *
22 * @param string $srsearch Search for all page titles (or content) that has this value.
23 * @param array $srnamespace The namespace(s) to enumerate.
24 * @param string $srwhat Search inside the text or titles.
25 * @param array $srinfo What metadata to return.
26 * @param array $srprop What properties to return.
27 * @param boolean $srredirects Include redirect pages in the search.
28 * @param integer $sroffest Use this value to continue paging.
29 * @param integer $srlimit How many total pages to return.
30 *
31 * @return object
32 *
33 * @since 12.3
34 */
35 public function search($srsearch, array $srnamespace = null, $srwhat = null, array $srinfo = null, array $srprop = null,
36 $srredirects = null, $sroffest = null, $srlimit = null)
37 {
38 // Build the request.
39 $path = '?action=query&list=search';
40
41 if (isset($srsearch))
42 {
43 $path .= '&srsearch=' . $srsearch;
44 }
45
46 if (isset($srnamespace))
47 {
48 $path .= '&srnamespace=' . $this->buildParameter($srnamespace);
49 }
50
51 if (isset($srwhat))
52 {
53 $path .= '&srwhat=' . $srwhat;
54 }
55
56 if (isset($srinfo))
57 {
58 $path .= '&srinfo=' . $this->buildParameter($srinfo);
59 }
60
61 if (isset($srprop))
62 {
63 $path .= '&srprop=' . $this->buildParameter($srprop);
64 }
65
66 if ($srredirects)
67 {
68 $path .= '&srredirects=';
69 }
70
71 if (isset($sroffest))
72 {
73 $path .= '&sroffest=' . $sroffest;
74 }
75
76 if (isset($srlimit))
77 {
78 $path .= '&srlimit=' . $srlimit;
79 }
80
81 // Send the request.
82 $response = $this->client->get($this->fetchUrl($path));
83
84 return $this->validateResponse($response);
85 }
86
87 /**
88 * Method to search the wiki using opensearch protocol.
89 *
90 * @param string $search Search string.
91 * @param integer $limit Maximum amount of results to return.
92 * @param array $namespace Namespaces to search.
93 * @param string $suggest Do nothing if $wgEnableOpenSearchSuggest is false.
94 * @param string $format Output format.
95 *
96 * @return object
97 *
98 * @since 12.3
99 */
100 public function openSearch($search, $limit = null, array $namespace = null, $suggest = null, $format = null)
101 {
102 // Build the request.
103 $path = '?action=query&list=search';
104
105 if (isset($search))
106 {
107 $path .= '&search=' . $search;
108 }
109
110 if (isset($limit))
111 {
112 $path .= '&limit=' . $limit;
113 }
114
115 if (isset($namespace))
116 {
117 $path .= '&namespace=' . $this->buildParameter($namespace);
118 }
119
120 if (isset($suggest))
121 {
122 $path .= '&suggest=' . $suggest;
123 }
124
125 if (isset($format))
126 {
127 $path .= '&format=' . $format;
128 }
129
130 // Send the request.
131 $response = $this->client->get($this->fetchUrl($path));
132
133 return $this->validateResponse($response);
134 }
135 }
136