Merge "docs: Fix typo"
[mediawiki.git] / includes / externalstore / ExternalStore.php
blob277ae36520309175bc6a275292279d8df1e9ae88
1 <?php
2 /**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
18 * @file
21 use MediaWiki\MediaWikiServices;
23 /**
24 * @ingroup ExternalStorage
25 * @deprecated since 1.34 Use the ExternalStoreAccess service instead.
27 class ExternalStore {
28 /**
29 * Get an external store object of the given type, with the given parameters
31 * @param string $proto Type of external storage, should be a value in $wgExternalStores
32 * @param array $params Associative array of ExternalStoreMedium parameters
33 * @return ExternalStoreMedium|bool The store class or false on error
34 * @deprecated since 1.34
36 public static function getStoreObject( $proto, array $params = [] ) {
37 try {
38 return MediaWikiServices::getInstance()
39 ->getExternalStoreFactory()
40 ->getStore( $proto, $params );
41 } catch ( ExternalStoreException $e ) {
42 return false;
46 /**
47 * Fetch data from given URL
49 * @param string $url The URL of the text to get
50 * @param array $params Associative array of ExternalStoreMedium parameters
51 * @return string|bool The text stored or false on error
52 * @deprecated since 1.34
54 public static function fetchFromURL( $url, array $params = [] ) {
55 try {
56 return MediaWikiServices::getInstance()
57 ->getExternalStoreAccess()
58 ->fetchFromURL( $url, $params );
59 } catch ( ExternalStoreException $e ) {
60 return false;
64 /**
65 * Store a data item to an external store, identified by a partial URL
66 * The protocol part is used to identify the class, the rest is passed to the
67 * class itself as a parameter.
69 * @param string $url A partial external store URL ("<store type>://<location>")
70 * @param string $data
71 * @param array $params Associative array of ExternalStoreMedium parameters
72 * @return string|bool The URL of the stored data item, or false on error
73 * @deprecated since 1.34
75 public static function insert( $url, $data, array $params = [] ) {
76 try {
77 $esFactory = MediaWikiServices::getInstance()->getExternalStoreFactory();
78 $location = $esFactory->getStoreLocationFromUrl( $url );
80 return $esFactory->getStoreForUrl( $url, $params )->store( $location, $data );
81 } catch ( ExternalStoreException $e ) {
82 return false;
86 /**
87 * Fetch data from multiple URLs with a minimum of round trips
89 * @param array $urls The URLs of the text to get
90 * @return array Map from url to its data. Data is either string when found
91 * or false on failure.
92 * @throws ExternalStoreException
93 * @deprecated since 1.34
95 public static function batchFetchFromURLs( array $urls ) {
96 return MediaWikiServices::getInstance()->getExternalStoreAccess()->fetchFromURLs( $urls );
99 /**
100 * Like insert() above, but does more of the work for us.
101 * This function does not need a url param, it builds it by
102 * itself. It also fails-over to the next possible clusters
103 * provided by $wgDefaultExternalStore.
105 * @param string $data
106 * @param array $params Map of ExternalStoreMedium::__construct context parameters
107 * @return string The URL of the stored data item
108 * @throws ExternalStoreException
109 * @deprecated since 1.34
111 public static function insertToDefault( $data, array $params = [] ) {
112 return MediaWikiServices::getInstance()->getExternalStoreAccess()->insert( $data, $params );
116 * Like insert() above, but does more of the work for us.
117 * This function does not need a url param, it builds it by
118 * itself. It also fails-over to the next possible clusters
119 * as provided in the first parameter.
121 * @param array $tryStores Refer to $wgDefaultExternalStore
122 * @param string $data
123 * @param array $params Map of ExternalStoreMedium::__construct context parameters
124 * @return string The URL of the stored data item
125 * @throws ExternalStoreException
126 * @deprecated since 1.34
128 public static function insertWithFallback( array $tryStores, $data, array $params = [] ) {
129 return MediaWikiServices::getInstance()
130 ->getExternalStoreAccess()
131 ->insert( $data, $params, $tryStores );
135 * @param string $data
136 * @param string $wiki
137 * @return string The URL of the stored data item
138 * @throws ExternalStoreException
139 * @deprecated since 1.34 Use insertToDefault() with 'wiki' set
141 public static function insertToForeignDefault( $data, $wiki ) {
142 return MediaWikiServices::getInstance()
143 ->getExternalStoreAccess()
144 ->insert( $data, [ 'domain' => $wiki ] );