2019-07-09 16:10:31 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*
|
|
|
|
* @file
|
|
|
|
*/
|
|
|
|
namespace MediaWiki\Minerva;
|
|
|
|
|
2024-03-02 19:34:53 +00:00
|
|
|
use MediaWiki\Languages\LanguageConverterFactory;
|
2024-01-06 15:31:38 +00:00
|
|
|
use MediaWiki\Output\OutputPage;
|
2023-08-19 04:23:00 +00:00
|
|
|
use MediaWiki\Title\Title;
|
2019-07-09 16:10:31 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper class to encapsulate logic responsible for checking languages and variants for given title
|
|
|
|
* @package MediaWiki\Minerva
|
|
|
|
*/
|
|
|
|
class LanguagesHelper {
|
|
|
|
|
2024-03-02 19:34:53 +00:00
|
|
|
private LanguageConverterFactory $languageConverterFactory;
|
|
|
|
|
2019-07-09 16:10:31 +00:00
|
|
|
/**
|
|
|
|
* @var bool
|
|
|
|
*/
|
|
|
|
private $hasLanguages;
|
|
|
|
|
|
|
|
/**
|
2024-03-02 19:34:53 +00:00
|
|
|
* @param LanguageConverterFactory $languageConverterFactory
|
2019-07-09 16:10:31 +00:00
|
|
|
* @param OutputPage $out Output page to fetch language links
|
|
|
|
*/
|
2024-03-02 19:34:53 +00:00
|
|
|
public function __construct(
|
|
|
|
LanguageConverterFactory $languageConverterFactory,
|
|
|
|
OutputPage $out
|
|
|
|
) {
|
|
|
|
$this->languageConverterFactory = $languageConverterFactory;
|
2024-02-09 21:20:25 +00:00
|
|
|
$this->hasLanguages = $out->getLanguageLinks() !== [];
|
2019-07-09 16:10:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether the Title is also available in other languages or variants
|
|
|
|
* @param Title $title
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function doesTitleHasLanguagesOrVariants( Title $title ) {
|
2021-02-27 14:36:08 +00:00
|
|
|
if ( $this->hasLanguages ) {
|
|
|
|
return true;
|
|
|
|
}
|
2024-03-02 19:34:53 +00:00
|
|
|
$langConv = $this->languageConverterFactory->getLanguageConverter( $title->getPageLanguage() );
|
2021-02-27 14:36:08 +00:00
|
|
|
return $langConv->hasVariants();
|
2019-07-09 16:10:31 +00:00
|
|
|
}
|
|
|
|
}
|