Debian Codegraph @

includes/interwiki/Interwiki.php

raw symbols SCIP
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.
7 *
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.
12 *
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
17 *
18 * @file
19 */
20
21 /**
22 * An interwiki record value object.
23 *
24 * By default, these represent a row in the `interwiki` database table.
25 * See @ref \MediaWiki\Interwiki\ClassicInterwikiLookup for where this is used.
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 article path URL of the wiki, with "$1" as a placeholder for an article name. */
33 protected $mURL;
34
35 /** @var string The URL to the api.php entry point of the wiki. */
36 protected $mAPI;
37
38 /** @var string The name of the database (for a connection to be established
39 * with LBFactory::getMainLB( 'domainId' ))
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 * Get the URL for a particular title (or with $1 if no title given)
62 *
63 * @param string|null $title What text to put for the article name
64 * @return string The URL
65 * @note Prior to 1.19 The getURL with an argument was broken.
66 * If you use this arg in an extension that supports MW earlier
67 * than 1.19 please wfUrlencode and substitute $1 on your own.
68 */
69 public function getURL( $title = null ) {
70 $url = $this->mURL;
71 if ( $title !== null ) {
72 $url = str_replace( "$1", wfUrlencode( $title ), $url );
73 }
74
75 return $url;
76 }
77
78 /**
79 * Get the API URL for this wiki
80 *
81 * @return string The URL
82 */
83 public function getAPI() {
84 return $this->mAPI;
85 }
86
87 /**
88 * Get the DB name for this wiki
89 *
90 * @return string The DB name
91 */
92 public function getWikiID() {
93 return $this->mWikiID;
94 }
95
96 /**
97 * Is this a local link from a sister project, or is
98 * it something outside, like Google
99 *
100 * @return bool
101 */
102 public function isLocal() {
103 return $this->mLocal;
104 }
105
106 /**
107 * Can pages from this wiki be transcluded?
108 * Still requires $wgEnableScaryTransclusion
109 *
110 * @return bool
111 */
112 public function isTranscludable() {
113 return $this->mTrans;
114 }
115
116 /**
117 * Get the name for the interwiki site
118 *
119 * @return string
120 */
121 public function getName() {
122 $msg = wfMessage( 'interwiki-name-' . $this->mPrefix )->inContentLanguage();
123
124 return !$msg->exists() ? '' : $msg->text();
125 }
126
127 /**
128 * Get a description for this interwiki
129 *
130 * @return string
131 */
132 public function getDescription() {
133 $msg = wfMessage( 'interwiki-desc-' . $this->mPrefix )->inContentLanguage();
134
135 return !$msg->exists() ? '' : $msg->text();
136 }
137
138 }