ApiFormatPhp.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. /**
  3. * Copyright © 2006 Yuri Astrakhan "<Firstname><Lastname>@gmail.com"
  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. */
  22. /**
  23. * API Serialized PHP output formatter
  24. * @ingroup API
  25. */
  26. class ApiFormatPhp extends ApiFormatBase {
  27. public function getMimeType() {
  28. return 'application/vnd.php.serialized';
  29. }
  30. /**
  31. * @suppress SecurityCheck-XSS Output type is not text/html
  32. */
  33. public function execute() {
  34. $params = $this->extractRequestParams();
  35. switch ( $params['formatversion'] ) {
  36. case 1:
  37. $transforms = [
  38. 'BC' => [],
  39. 'Types' => [],
  40. 'Strip' => 'all',
  41. ];
  42. break;
  43. case 2:
  44. case 'latest':
  45. $transforms = [
  46. 'Types' => [],
  47. 'Strip' => 'all',
  48. ];
  49. break;
  50. default:
  51. // Should have been caught during parameter validation
  52. $this->dieDebug( __METHOD__, 'Unknown value for \'formatversion\'' );
  53. }
  54. $text = serialize( $this->getResult()->getResultData( null, $transforms ) );
  55. // T68776: OutputHandler::mangleFlashPolicy() avoids a nasty bug in
  56. // Flash, but what it does isn't friendly for the API. There's nothing
  57. // we can do here that isn't actively broken in some manner, so let's
  58. // just be broken in a useful manner.
  59. if ( $this->getConfig()->get( 'MangleFlashPolicy' ) &&
  60. in_array( 'MediaWiki\\OutputHandler::handle', ob_list_handlers(), true ) &&
  61. preg_match( '/\<\s*cross-domain-policy(?=\s|\>)/i', $text )
  62. ) {
  63. $this->dieWithError( 'apierror-formatphp', 'internalerror' );
  64. }
  65. $this->printText( $text );
  66. }
  67. public function getAllowedParams() {
  68. $ret = parent::getAllowedParams() + [
  69. 'formatversion' => [
  70. ApiBase::PARAM_TYPE => [ '1', '2', 'latest' ],
  71. ApiBase::PARAM_DFLT => '1',
  72. ApiBase::PARAM_HELP_MSG => 'apihelp-php-param-formatversion',
  73. ],
  74. ];
  75. return $ret;
  76. }
  77. }