Localisation updates from https://translatewiki.net.
[mediawiki.git] / includes / interwiki / Interwiki.php
blob558e32c11ecf8c77cb608826776d81738063751d
1 <?php
2 /**
3 * Interwiki table entry.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
20 * @file
22 use MediaWiki\MediaWikiServices;
24 /**
25 * Value object for representing interwiki records.
27 class Interwiki {
29 /** @var string The interwiki prefix, (e.g. "Meatball", or the language prefix "de") */
30 protected $mPrefix;
32 /** @var string The URL of the wiki, with "$1" as a placeholder for an article name. */
33 protected $mURL;
35 /** @var string The URL of the file api.php */
36 protected $mAPI;
38 /** @var string The name of the database (for a connection to be established
39 * with wfGetLB( 'wikiid' ))
41 protected $mWikiID;
43 /** @var bool Whether the wiki is in this project */
44 protected $mLocal;
46 /** @var bool Whether interwiki transclusions are allowed */
47 protected $mTrans;
49 public function __construct( $prefix = null, $url = '', $api = '', $wikiId = '', $local = 0,
50 $trans = 0
51 ) {
52 $this->mPrefix = $prefix;
53 $this->mURL = $url;
54 $this->mAPI = $api;
55 $this->mWikiID = $wikiId;
56 $this->mLocal = (bool)$local;
57 $this->mTrans = (bool)$trans;
60 /**
61 * Check whether an interwiki prefix exists
63 * @deprecated since 1.28, use InterwikiLookup instead
65 * @param string $prefix Interwiki prefix to use
66 * @return bool Whether it exists
68 public static function isValidInterwiki( $prefix ) {
69 return MediaWikiServices::getInstance()->getInterwikiLookup()->isValidInterwiki( $prefix );
72 /**
73 * Fetch an Interwiki object
75 * @deprecated since 1.28, use InterwikiLookup instead
77 * @param string $prefix Interwiki prefix to use
78 * @return Interwiki|null|bool
80 public static function fetch( $prefix ) {
81 return MediaWikiServices::getInstance()->getInterwikiLookup()->fetch( $prefix );
84 /**
85 * Purge the cache (local and persistent) for an interwiki prefix.
87 * @param string $prefix
88 * @since 1.26
90 public static function invalidateCache( $prefix ) {
91 return MediaWikiServices::getInstance()->getInterwikiLookup()->invalidateCache( $prefix );
94 /**
95 * Returns all interwiki prefixes
97 * @deprecated since 1.28, unused. Use InterwikiLookup instead.
99 * @param string|null $local If set, limits output to local/non-local interwikis
100 * @return array List of prefixes
101 * @since 1.19
103 public static function getAllPrefixes( $local = null ) {
104 return MediaWikiServices::getInstance()->getInterwikiLookup()->getAllPrefixes( $local );
108 * Get the URL for a particular title (or with $1 if no title given)
110 * @param string $title What text to put for the article name
111 * @return string The URL
112 * @note Prior to 1.19 The getURL with an argument was broken.
113 * If you if you use this arg in an extension that supports MW earlier
114 * than 1.19 please wfUrlencode and substitute $1 on your own.
116 public function getURL( $title = null ) {
117 $url = $this->mURL;
118 if ( $title !== null ) {
119 $url = str_replace( "$1", wfUrlencode( $title ), $url );
122 return $url;
126 * Get the API URL for this wiki
128 * @return string The URL
130 public function getAPI() {
131 return $this->mAPI;
135 * Get the DB name for this wiki
137 * @return string The DB name
139 public function getWikiID() {
140 return $this->mWikiID;
144 * Is this a local link from a sister project, or is
145 * it something outside, like Google
147 * @return bool
149 public function isLocal() {
150 return $this->mLocal;
154 * Can pages from this wiki be transcluded?
155 * Still requires $wgEnableScaryTransclusion
157 * @return bool
159 public function isTranscludable() {
160 return $this->mTrans;
164 * Get the name for the interwiki site
166 * @return string
168 public function getName() {
169 $msg = wfMessage( 'interwiki-name-' . $this->mPrefix )->inContentLanguage();
171 return !$msg->exists() ? '' : $msg->text();
175 * Get a description for this interwiki
177 * @return string
179 public function getDescription() {
180 $msg = wfMessage( 'interwiki-desc-' . $this->mPrefix )->inContentLanguage();
182 return !$msg->exists() ? '' : $msg->text();