2014-06-11 21:36:54 +00:00
|
|
|
/*
|
|
|
|
* This file is part of the MediaWiki extension MediaViewer.
|
|
|
|
*
|
|
|
|
* MediaViewer 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.
|
|
|
|
*
|
|
|
|
* MediaViewer 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 MediaViewer. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2018-11-12 16:33:24 +00:00
|
|
|
( function () {
|
2014-06-11 21:36:54 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* IwTitle represents a title in a foreign wiki. The long-term goal is to have an interface
|
|
|
|
* largely compatible with mw.Title, but for now we only implement what we actually need.
|
|
|
|
*/
|
2023-05-20 12:38:59 +00:00
|
|
|
class IwTitle {
|
|
|
|
/**
|
|
|
|
* @param {string} namespaceId namespace number
|
|
|
|
* @param {string} title full title, including namespace name; with underscores (as in mw.Title#getPrefixedDb())
|
|
|
|
* @param {string} domain domain name of the wiki
|
|
|
|
* @param {string} url full URL to the page
|
|
|
|
*/
|
|
|
|
constructor( namespaceId, title, domain, url ) {
|
|
|
|
/** @property {number} namespaceId - */
|
|
|
|
this.namespaceId = namespaceId;
|
2014-06-11 21:36:54 +00:00
|
|
|
|
2023-05-20 12:38:59 +00:00
|
|
|
/** @property {string} title - */
|
|
|
|
this.title = title;
|
2014-06-11 21:36:54 +00:00
|
|
|
|
2023-05-20 12:38:59 +00:00
|
|
|
/** @property {string} domain - */
|
|
|
|
this.domain = domain;
|
2014-06-11 21:36:54 +00:00
|
|
|
|
2023-05-20 12:38:59 +00:00
|
|
|
/** @property {string} url - */
|
|
|
|
this.url = url;
|
|
|
|
}
|
|
|
|
getUrl() {
|
|
|
|
return this.url;
|
|
|
|
}
|
|
|
|
getPrefixedDb() {
|
|
|
|
return this.title;
|
|
|
|
}
|
|
|
|
getPrefixedText() {
|
|
|
|
return text( this.getPrefixedDb() );
|
|
|
|
}
|
|
|
|
getDomain() {
|
|
|
|
return this.domain;
|
|
|
|
}
|
2014-06-11 21:36:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Turn underscores into spaces.
|
|
|
|
* Copy of the private function in mw.Title.
|
2016-07-18 13:49:27 +00:00
|
|
|
*
|
2014-06-11 21:36:54 +00:00
|
|
|
* @param {string} s
|
2016-12-14 13:09:10 +00:00
|
|
|
* @return {string}
|
2014-06-11 21:36:54 +00:00
|
|
|
*/
|
|
|
|
function text( s ) {
|
|
|
|
return s ? s.replace( /_/g, ' ' ) : '';
|
|
|
|
}
|
|
|
|
|
2023-05-19 20:26:45 +00:00
|
|
|
module.exports = IwTitle;
|
2018-11-12 16:33:24 +00:00
|
|
|
}() );
|