2008-09-29 18:20:43 +00:00
|
|
|
<?php
|
|
|
|
|
/**
|
2012-05-04 06:29:11 +00:00
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
*
|
2008-09-29 18:20:43 +00:00
|
|
|
* @file
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
2022-08-16 13:01:51 +00:00
|
|
|
* An interwiki record value object.
|
|
|
|
|
*
|
2024-07-19 15:22:27 +00:00
|
|
|
* By default, these represent a row in the `interwiki` database table.
|
2022-08-16 13:01:51 +00:00
|
|
|
* See @ref \MediaWiki\Interwiki\ClassicInterwikiLookup for where this is used.
|
2008-09-29 18:20:43 +00:00
|
|
|
*/
|
|
|
|
|
class Interwiki {
|
|
|
|
|
|
2013-11-25 14:27:29 +00:00
|
|
|
/** @var string The interwiki prefix, (e.g. "Meatball", or the language prefix "de") */
|
|
|
|
|
protected $mPrefix;
|
|
|
|
|
|
2022-08-16 13:01:51 +00:00
|
|
|
/** @var string The article path URL of the wiki, with "$1" as a placeholder for an article name. */
|
2013-11-25 14:27:29 +00:00
|
|
|
protected $mURL;
|
|
|
|
|
|
2022-08-16 13:01:51 +00:00
|
|
|
/** @var string The URL to the api.php entry point of the wiki. */
|
2013-11-25 14:27:29 +00:00
|
|
|
protected $mAPI;
|
|
|
|
|
|
|
|
|
|
/** @var string The name of the database (for a connection to be established
|
2019-03-29 21:30:21 +00:00
|
|
|
* with LBFactory::getMainLB( 'domainId' ))
|
2013-11-25 14:27:29 +00:00
|
|
|
*/
|
|
|
|
|
protected $mWikiID;
|
|
|
|
|
|
2014-07-24 17:43:03 +00:00
|
|
|
/** @var bool Whether the wiki is in this project */
|
2013-11-25 14:27:29 +00:00
|
|
|
protected $mLocal;
|
|
|
|
|
|
|
|
|
|
/** @var bool Whether interwiki transclusions are allowed */
|
|
|
|
|
protected $mTrans;
|
2008-09-29 18:20:43 +00:00
|
|
|
|
2013-01-11 15:43:08 +00:00
|
|
|
public function __construct( $prefix = null, $url = '', $api = '', $wikiId = '', $local = 0,
|
|
|
|
|
$trans = 0
|
|
|
|
|
) {
|
2008-09-29 18:20:43 +00:00
|
|
|
$this->mPrefix = $prefix;
|
|
|
|
|
$this->mURL = $url;
|
2010-07-19 11:55:30 +00:00
|
|
|
$this->mAPI = $api;
|
2010-07-25 15:50:23 +00:00
|
|
|
$this->mWikiID = $wikiId;
|
2016-04-23 19:00:18 +00:00
|
|
|
$this->mLocal = (bool)$local;
|
|
|
|
|
$this->mTrans = (bool)$trans;
|
2008-09-29 18:20:43 +00:00
|
|
|
}
|
|
|
|
|
|
2009-03-29 16:18:58 +00:00
|
|
|
/**
|
2008-09-29 18:20:43 +00:00
|
|
|
* Get the URL for a particular title (or with $1 if no title given)
|
2010-07-25 15:50:23 +00:00
|
|
|
*
|
2018-06-26 21:14:43 +00:00
|
|
|
* @param string|null $title What text to put for the article name
|
2013-01-11 15:43:08 +00:00
|
|
|
* @return string The URL
|
2011-08-12 14:55:25 +00:00
|
|
|
* @note Prior to 1.19 The getURL with an argument was broken.
|
2024-07-19 15:22:27 +00:00
|
|
|
* If you use this arg in an extension that supports MW earlier
|
2011-08-12 14:55:25 +00:00
|
|
|
* than 1.19 please wfUrlencode and substitute $1 on your own.
|
2008-09-29 18:20:43 +00:00
|
|
|
*/
|
2009-07-25 14:28:53 +00:00
|
|
|
public function getURL( $title = null ) {
|
2008-09-29 18:20:43 +00:00
|
|
|
$url = $this->mURL;
|
2013-01-11 15:43:08 +00:00
|
|
|
if ( $title !== null ) {
|
2011-08-12 14:10:37 +00:00
|
|
|
$url = str_replace( "$1", wfUrlencode( $title ), $url );
|
2008-09-29 18:20:43 +00:00
|
|
|
}
|
2013-11-25 14:27:29 +00:00
|
|
|
|
2008-09-29 18:20:43 +00:00
|
|
|
return $url;
|
|
|
|
|
}
|
2009-03-29 16:18:58 +00:00
|
|
|
|
2010-07-19 11:55:30 +00:00
|
|
|
/**
|
|
|
|
|
* Get the API URL for this wiki
|
2010-07-25 15:50:23 +00:00
|
|
|
*
|
2013-01-11 15:43:08 +00:00
|
|
|
* @return string The URL
|
2010-07-19 11:55:30 +00:00
|
|
|
*/
|
2010-07-25 15:50:23 +00:00
|
|
|
public function getAPI() {
|
2010-07-19 11:55:30 +00:00
|
|
|
return $this->mAPI;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the DB name for this wiki
|
2010-07-25 15:50:23 +00:00
|
|
|
*
|
2013-01-11 15:43:08 +00:00
|
|
|
* @return string The DB name
|
2010-07-19 11:55:30 +00:00
|
|
|
*/
|
2010-07-25 15:50:23 +00:00
|
|
|
public function getWikiID() {
|
2010-07-19 11:55:30 +00:00
|
|
|
return $this->mWikiID;
|
|
|
|
|
}
|
|
|
|
|
|
2009-07-25 14:28:53 +00:00
|
|
|
/**
|
|
|
|
|
* Is this a local link from a sister project, or is
|
|
|
|
|
* it something outside, like Google
|
2010-02-16 22:06:04 +00:00
|
|
|
*
|
2013-01-11 15:43:08 +00:00
|
|
|
* @return bool
|
2009-07-25 14:28:53 +00:00
|
|
|
*/
|
|
|
|
|
public function isLocal() {
|
2008-09-29 18:20:43 +00:00
|
|
|
return $this->mLocal;
|
|
|
|
|
}
|
2009-03-29 16:18:58 +00:00
|
|
|
|
2009-07-25 14:28:53 +00:00
|
|
|
/**
|
|
|
|
|
* Can pages from this wiki be transcluded?
|
|
|
|
|
* Still requires $wgEnableScaryTransclusion
|
2010-02-16 22:06:04 +00:00
|
|
|
*
|
2013-01-11 15:43:08 +00:00
|
|
|
* @return bool
|
2009-07-25 14:28:53 +00:00
|
|
|
*/
|
|
|
|
|
public function isTranscludable() {
|
2008-09-29 18:20:43 +00:00
|
|
|
return $this->mTrans;
|
|
|
|
|
}
|
|
|
|
|
|
2009-07-25 14:28:53 +00:00
|
|
|
/**
|
|
|
|
|
* Get the name for the interwiki site
|
2010-02-16 22:06:04 +00:00
|
|
|
*
|
2013-01-11 15:43:08 +00:00
|
|
|
* @return string
|
2009-07-25 14:28:53 +00:00
|
|
|
*/
|
|
|
|
|
public function getName() {
|
2011-01-14 10:51:05 +00:00
|
|
|
$msg = wfMessage( 'interwiki-name-' . $this->mPrefix )->inContentLanguage();
|
2013-11-25 14:27:29 +00:00
|
|
|
|
2016-04-23 19:00:18 +00:00
|
|
|
return !$msg->exists() ? '' : $msg->text();
|
2009-07-25 14:28:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get a description for this interwiki
|
2010-02-16 22:06:04 +00:00
|
|
|
*
|
2013-01-11 15:43:08 +00:00
|
|
|
* @return string
|
2009-07-25 14:28:53 +00:00
|
|
|
*/
|
|
|
|
|
public function getDescription() {
|
2011-01-14 10:51:05 +00:00
|
|
|
$msg = wfMessage( 'interwiki-desc-' . $this->mPrefix )->inContentLanguage();
|
2013-11-25 14:27:29 +00:00
|
|
|
|
2016-04-23 19:00:18 +00:00
|
|
|
return !$msg->exists() ? '' : $msg->text();
|
2009-07-25 14:28:53 +00:00
|
|
|
}
|
2012-05-11 20:16:19 +00:00
|
|
|
|
2008-09-29 18:20:43 +00:00
|
|
|
}
|