Merge "Fix 'Tags' padding to keep it farther from the edge and document the source...
[lhc/web/wiklou.git] / includes / interwiki / Interwiki.php
1 <?php
2 /**
3 * Interwiki table entry.
4 *
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.
9 *
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.
14 *
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
19 *
20 * @file
21 */
22 use MediaWiki\MediaWikiServices;
23
24 /**
25 * Value object for representing interwiki records.
26 */
27 class Interwiki {
28
29 /** @var string The interwiki prefix, (e.g. "Meatball", or the language prefix "de") */
30 protected $mPrefix;
31
32 /** @var string The URL of the wiki, with "$1" as a placeholder for an article name. */
33 protected $mURL;
34
35 /** @var string The URL of the file api.php */
36 protected $mAPI;
37
38 /** @var string The name of the database (for a connection to be established
39 * with LBFactory::getMainLB( 'wikiid' ))
40 */
41 protected $mWikiID;
42
43 /** @var bool Whether the wiki is in this project */
44 protected $mLocal;
45
46 /** @var bool Whether interwiki transclusions are allowed */
47 protected $mTrans;
48
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;
58 }
59
60 /**
61 * Check whether an interwiki prefix exists
62 *
63 * @deprecated since 1.28, use InterwikiLookup instead
64 *
65 * @param string $prefix Interwiki prefix to use
66 * @return bool Whether it exists
67 */
68 public static function isValidInterwiki( $prefix ) {
69 wfDeprecated( __METHOD__, '1.28' );
70 return MediaWikiServices::getInstance()->getInterwikiLookup()->isValidInterwiki( $prefix );
71 }
72
73 /**
74 * Fetch an Interwiki object
75 *
76 * @deprecated since 1.28, use InterwikiLookup instead
77 *
78 * @param string $prefix Interwiki prefix to use
79 * @return Interwiki|null|bool
80 */
81 public static function fetch( $prefix ) {
82 wfDeprecated( __METHOD__, '1.28' );
83 return MediaWikiServices::getInstance()->getInterwikiLookup()->fetch( $prefix );
84 }
85
86 /**
87 * Purge the cache (local and persistent) for an interwiki prefix.
88 *
89 * @param string $prefix
90 * @since 1.26
91 */
92 public static function invalidateCache( $prefix ) {
93 wfDeprecated( __METHOD__, '1.28' );
94 MediaWikiServices::getInstance()->getInterwikiLookup()->invalidateCache( $prefix );
95 }
96
97 /**
98 * Returns all interwiki prefix definitions.
99 *
100 * @deprecated since 1.28, unused. Use InterwikiLookup instead.
101 *
102 * @param string|null $local If set, limits output to local/non-local interwikis
103 * @return array[] List of interwiki rows
104 * @since 1.19
105 */
106 public static function getAllPrefixes( $local = null ) {
107 wfDeprecated( __METHOD__, '1.28' );
108 return MediaWikiServices::getInstance()->getInterwikiLookup()->getAllPrefixes( $local );
109 }
110
111 /**
112 * Get the URL for a particular title (or with $1 if no title given)
113 *
114 * @param string $title What text to put for the article name
115 * @return string The URL
116 * @note Prior to 1.19 The getURL with an argument was broken.
117 * If you if you use this arg in an extension that supports MW earlier
118 * than 1.19 please wfUrlencode and substitute $1 on your own.
119 */
120 public function getURL( $title = null ) {
121 $url = $this->mURL;
122 if ( $title !== null ) {
123 $url = str_replace( "$1", wfUrlencode( $title ), $url );
124 }
125
126 return $url;
127 }
128
129 /**
130 * Get the API URL for this wiki
131 *
132 * @return string The URL
133 */
134 public function getAPI() {
135 return $this->mAPI;
136 }
137
138 /**
139 * Get the DB name for this wiki
140 *
141 * @return string The DB name
142 */
143 public function getWikiID() {
144 return $this->mWikiID;
145 }
146
147 /**
148 * Is this a local link from a sister project, or is
149 * it something outside, like Google
150 *
151 * @return bool
152 */
153 public function isLocal() {
154 return $this->mLocal;
155 }
156
157 /**
158 * Can pages from this wiki be transcluded?
159 * Still requires $wgEnableScaryTransclusion
160 *
161 * @return bool
162 */
163 public function isTranscludable() {
164 return $this->mTrans;
165 }
166
167 /**
168 * Get the name for the interwiki site
169 *
170 * @return string
171 */
172 public function getName() {
173 $msg = wfMessage( 'interwiki-name-' . $this->mPrefix )->inContentLanguage();
174
175 return !$msg->exists() ? '' : $msg->text();
176 }
177
178 /**
179 * Get a description for this interwiki
180 *
181 * @return string
182 */
183 public function getDescription() {
184 $msg = wfMessage( 'interwiki-desc-' . $this->mPrefix )->inContentLanguage();
185
186 return !$msg->exists() ? '' : $msg->text();
187 }
188
189 }