TitleFormatter.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. /**
  3. * A title formatter service for MediaWiki.
  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. * @author Daniel Kinzler
  22. */
  23. use MediaWiki\Linker\LinkTarget;
  24. /**
  25. * A title formatter service for MediaWiki.
  26. *
  27. * This is designed to encapsulate knowledge about conventions for the title
  28. * forms to be used in the database, in urls, in wikitext, etc.
  29. *
  30. * @see https://www.mediawiki.org/wiki/Requests_for_comment/TitleValue
  31. * @since 1.23
  32. */
  33. interface TitleFormatter {
  34. /**
  35. * Returns the title formatted for display.
  36. * Per default, this includes the namespace but not the fragment.
  37. *
  38. * @note Normalization is applied if $title is not in TitleValue::TITLE_FORM.
  39. *
  40. * @param int|bool $namespace The namespace ID (or false, if the namespace should be ignored)
  41. * @param string $text The page title
  42. * @param string $fragment The fragment name (may be empty).
  43. * @param string $interwiki The interwiki prefix (may be empty).
  44. *
  45. * @return string
  46. */
  47. public function formatTitle( $namespace, $text, $fragment = '', $interwiki = '' );
  48. /**
  49. * Returns the title text formatted for display, without namespace of fragment.
  50. *
  51. * @note Consider using LinkTarget::getText() directly, it's identical.
  52. *
  53. * @param LinkTarget $title The title to format
  54. *
  55. * @return string
  56. */
  57. public function getText( LinkTarget $title );
  58. /**
  59. * Returns the title formatted for display, including the namespace name.
  60. *
  61. * @param LinkTarget $title The title to format
  62. *
  63. * @return string
  64. */
  65. public function getPrefixedText( LinkTarget $title );
  66. /**
  67. * Return the title in prefixed database key form, with interwiki
  68. * and namespace.
  69. *
  70. * @since 1.27
  71. *
  72. * @param LinkTarget $target
  73. *
  74. * @return string
  75. */
  76. public function getPrefixedDBkey( LinkTarget $target );
  77. /**
  78. * Returns the title formatted for display, with namespace and fragment.
  79. *
  80. * @param LinkTarget $title The title to format
  81. *
  82. * @return string
  83. */
  84. public function getFullText( LinkTarget $title );
  85. /**
  86. * Returns the name of the namespace for the given title.
  87. *
  88. * @note This must take into account gender sensitive namespace names.
  89. * @todo Move this to a separate interface
  90. *
  91. * @param int $namespace
  92. * @param string $text
  93. *
  94. * @throws InvalidArgumentException
  95. * @return string
  96. */
  97. public function getNamespaceName( $namespace, $text );
  98. }