FakeConverter.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <?php
  2. /**
  3. * Internationalisation code.
  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. * @ingroup Language
  22. */
  23. /**
  24. * A fake language variant converter. Languages which do not implement variant
  25. * conversion, for example, English, should return a FakeConverter rather than a
  26. * LanguageConverter when asked for their converter. The fake converter just
  27. * returns text unchanged, i.e. it doesn't do any conversion.
  28. *
  29. * See https://www.mediawiki.org/wiki/Writing_systems#LanguageConverter.
  30. *
  31. * @ingroup Language
  32. */
  33. class FakeConverter {
  34. /**
  35. * @var Language
  36. */
  37. public $mLang;
  38. function __construct( $langobj ) {
  39. $this->mLang = $langobj;
  40. }
  41. function autoConvert( $text, $variant = false ) {
  42. return $text;
  43. }
  44. function autoConvertToAllVariants( $text ) {
  45. return [ $this->mLang->getCode() => $text ];
  46. }
  47. function convert( $t ) {
  48. return $t;
  49. }
  50. function convertTo( $text, $variant ) {
  51. return $text;
  52. }
  53. /**
  54. * @param Title $t
  55. * @return mixed
  56. */
  57. function convertTitle( $t ) {
  58. return $t->getPrefixedText();
  59. }
  60. function convertNamespace( $ns ) {
  61. return $this->mLang->getFormattedNsText( $ns );
  62. }
  63. /**
  64. * @return string[]
  65. */
  66. function getVariants() {
  67. return [ $this->mLang->getCode() ];
  68. }
  69. function getVariantFallbacks( $variant ) {
  70. return $this->mLang->getCode();
  71. }
  72. function getPreferredVariant() {
  73. return $this->mLang->getCode();
  74. }
  75. function getDefaultVariant() {
  76. return $this->mLang->getCode();
  77. }
  78. function getURLVariant() {
  79. return '';
  80. }
  81. function getConvRuleTitle() {
  82. return false;
  83. }
  84. function findVariantLink( &$l, &$n, $ignoreOtherCond = false ) {
  85. }
  86. function getExtraHashOptions() {
  87. return '';
  88. }
  89. function getParsedTitle() {
  90. return '';
  91. }
  92. function markNoConversion( $text, $noParse = false ) {
  93. return $text;
  94. }
  95. function convertCategoryKey( $key ) {
  96. return $key;
  97. }
  98. function validateVariant( $variant = null ) {
  99. return $variant === $this->mLang->getCode() ? $variant : null;
  100. }
  101. function translate( $text, $variant ) {
  102. return $text;
  103. }
  104. public function updateConversionTable( Title $title ) {
  105. }
  106. /**
  107. * Used by test suites which need to reset the converter state.
  108. *
  109. * @private
  110. */
  111. private function reloadTables() {
  112. }
  113. }