IContextSource.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <?php
  2. /**
  3. * This program is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation; either version 2 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License along
  14. * with this program; if not, write to the Free Software Foundation, Inc.,
  15. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  16. * http://www.gnu.org/copyleft/gpl.html
  17. *
  18. * @since 1.18
  19. *
  20. * @author Happy-melon
  21. * @file
  22. */
  23. /**
  24. * Interface for objects which can provide a MediaWiki context on request
  25. *
  26. * Context objects contain request-dependent objects that manage the core
  27. * web request/response logic for essentially all requests to MediaWiki.
  28. * The contained objects include:
  29. * a) Key objects that depend (for construction/loading) on the HTTP request
  30. * b) Key objects used for response building and PHP session state control
  31. * c) Performance metric deltas accumulated from request execution
  32. * d) The site configuration object
  33. * All of the objects are useful for the vast majority of MediaWiki requests.
  34. * The site configuration object is included on grounds of extreme
  35. * utility, even though it should not actually depend on the web request.
  36. *
  37. * More specifically, the scope of the context includes:
  38. * a) Objects that represent the HTTP request/response and PHP session state
  39. * b) Object representing the MediaWiki user (as determined by the HTTP request)
  40. * c) Primary MediaWiki output builder objects (OutputPage, user skin object)
  41. * d) The language object for the user/request
  42. * e) The title and wiki page objects requested via URL (if any)
  43. * f) Performance metric deltas accumulated from request execution
  44. * g) The site configuration object
  45. *
  46. * This class is not intended as a service-locator nor a service singleton.
  47. * Objects that only depend on site configuration do not belong here (aside
  48. * from Config itself). Objects that represent persistent data stores do not
  49. * belong here either. Session state changes should only be propagated on
  50. * shutdown by separate persistence handler objects, for example.
  51. */
  52. interface IContextSource extends MessageLocalizer {
  53. /**
  54. * @return WebRequest
  55. */
  56. public function getRequest();
  57. /**
  58. * @return Title|null
  59. */
  60. public function getTitle();
  61. /**
  62. * Check whether a WikiPage object can be get with getWikiPage().
  63. * Callers should expect that an exception is thrown from getWikiPage()
  64. * if this method returns false.
  65. *
  66. * @since 1.19
  67. * @return bool
  68. */
  69. public function canUseWikiPage();
  70. /**
  71. * Get the WikiPage object.
  72. * May throw an exception if there's no Title object set or the Title object
  73. * belongs to a special namespace that doesn't have WikiPage, so use first
  74. * canUseWikiPage() to check whether this method can be called safely.
  75. *
  76. * @since 1.19
  77. * @return WikiPage
  78. */
  79. public function getWikiPage();
  80. /**
  81. * @return OutputPage
  82. */
  83. public function getOutput();
  84. /**
  85. * @return User
  86. */
  87. public function getUser();
  88. /**
  89. * @return Language
  90. * @since 1.19
  91. */
  92. public function getLanguage();
  93. /**
  94. * @return Skin
  95. */
  96. public function getSkin();
  97. /**
  98. * Get the site configuration
  99. *
  100. * @since 1.23
  101. * @return Config
  102. */
  103. public function getConfig();
  104. /**
  105. * @deprecated since 1.27 use a StatsdDataFactory from MediaWikiServices (preferably injected)
  106. *
  107. * @since 1.25
  108. * @return IBufferingStatsdDataFactory
  109. */
  110. public function getStats();
  111. /**
  112. * @since 1.27
  113. * @return Timing
  114. */
  115. public function getTiming();
  116. /**
  117. * Export the resolved user IP, HTTP headers, user ID, and session ID.
  118. * The result will be reasonably sized to allow for serialization.
  119. *
  120. * @return array
  121. * @since 1.21
  122. */
  123. public function exportSession();
  124. }