Blame view

libraries/joomla/mediawiki/search.php 3.09 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
<?php
/**
 * @package     Joomla.Platform
 * @subpackage  MediaWiki
 *
 * @copyright   Copyright (C) 2005 - 2019 Open Source Matters, Inc. All rights reserved.
 * @license     GNU General Public License version 2 or later; see LICENSE
 */

defined('JPATH_PLATFORM') or die;

/**
 * MediaWiki API Search class for the Joomla Platform.
 *
 * @since  3.1.4
 */
class JMediawikiSearch extends JMediawikiObject
{
	/**
	 * Method to perform a full text search.
	 *
	 * @param   string   $srsearch     Search for all page titles (or content) that has this value.
	 * @param   array    $srnamespace  The namespace(s) to enumerate.
	 * @param   string   $srwhat       Search inside the text or titles.
	 * @param   array    $srinfo       What metadata to return.
	 * @param   array    $srprop       What properties to return.
	 * @param   boolean  $srredirects  Include redirect pages in the search.
	 * @param   integer  $sroffest     Use this value to continue paging.
	 * @param   integer  $srlimit      How many total pages to return.
	 *
	 * @return  object
	 *
	 * @since   3.1.4
	 */
	public function search($srsearch, array $srnamespace = null, $srwhat = null, array $srinfo = null, array $srprop = null,
		$srredirects = null, $sroffest = null, $srlimit = null)
	{
		// Build the request.
		$path = '?action=query&list=search';

		if (isset($srsearch))
		{
			$path .= '&srsearch=' . $srsearch;
		}

		if (isset($srnamespace))
		{
			$path .= '&srnamespace=' . $this->buildParameter($srnamespace);
		}

		if (isset($srwhat))
		{
			$path .= '&srwhat=' . $srwhat;
		}

		if (isset($srinfo))
		{
			$path .= '&srinfo=' . $this->buildParameter($srinfo);
		}

		if (isset($srprop))
		{
			$path .= '&srprop=' . $this->buildParameter($srprop);
		}

		if ($srredirects)
		{
			$path .= '&srredirects=';
		}

		if (isset($sroffest))
		{
			$path .= '&sroffest=' . $sroffest;
		}

		if (isset($srlimit))
		{
			$path .= '&srlimit=' . $srlimit;
		}

		// Send the request.
		$response = $this->client->get($this->fetchUrl($path));

		return $this->validateResponse($response);
	}

	/**
	 * Method to search the wiki using opensearch protocol.
	 *
	 * @param   string   $search     Search string.
	 * @param   integer  $limit	     Maximum amount of results to return.
	 * @param   array    $namespace  Namespaces to search.
	 * @param   string   $suggest    Do nothing if $wgEnableOpenSearchSuggest is false.
	 * @param   string   $format     Output format.
	 *
	 * @return  object
	 *
	 * @since   3.1.4
	 */
	public function openSearch($search, $limit = null, array $namespace = null, $suggest = null, $format = null)
	{
		// Build the request.
		$path = '?action=query&list=search';

		if (isset($search))
		{
			$path .= '&search=' . $search;
		}

		if (isset($limit))
		{
			$path .= '&limit=' . $limit;
		}

		if (isset($namespace))
		{
			$path .= '&namespace=' . $this->buildParameter($namespace);
		}

		if (isset($suggest))
		{
			$path .= '&suggest=' . $suggest;
		}

		if (isset($format))
		{
			$path .= '&format=' . $format;
		}

		// Send the request.
		$response = $this->client->get($this->fetchUrl($path));

		return $this->validateResponse($response);
	}
}