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