ApiFormatPhp.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. /**
  3. *
  4. *
  5. * Created on Oct 22, 2006
  6. *
  7. * Copyright © 2006 Yuri Astrakhan "<Firstname><Lastname>@gmail.com"
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License along
  20. * with this program; if not, write to the Free Software Foundation, Inc.,
  21. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  22. * http://www.gnu.org/copyleft/gpl.html
  23. *
  24. * @file
  25. */
  26. /**
  27. * API Serialized PHP output formatter
  28. * @ingroup API
  29. */
  30. class ApiFormatPhp extends ApiFormatBase {
  31. public function getMimeType() {
  32. return 'application/vnd.php.serialized';
  33. }
  34. public function execute() {
  35. $params = $this->extractRequestParams();
  36. switch ( $params['formatversion'] ) {
  37. case 1:
  38. $transforms = [
  39. 'BC' => [],
  40. 'Types' => [],
  41. 'Strip' => 'all',
  42. ];
  43. break;
  44. case 2:
  45. case 'latest':
  46. $transforms = [
  47. 'Types' => [],
  48. 'Strip' => 'all',
  49. ];
  50. break;
  51. default:
  52. // Should have been caught during parameter validation
  53. $this->dieDebug( __METHOD__, 'Unknown value for \'formatversion\'' );
  54. }
  55. $text = serialize( $this->getResult()->getResultData( null, $transforms ) );
  56. // T68776: wfMangleFlashPolicy() is needed to avoid a nasty bug in
  57. // Flash, but what it does isn't friendly for the API. There's nothing
  58. // we can do here that isn't actively broken in some manner, so let's
  59. // just be broken in a useful manner.
  60. if ( $this->getConfig()->get( 'MangleFlashPolicy' ) &&
  61. in_array( 'wfOutputHandler', ob_list_handlers(), true ) &&
  62. preg_match( '/\<\s*cross-domain-policy(?=\s|\>)/i', $text )
  63. ) {
  64. $this->dieWithError( 'apierror-formatphp', 'internalerror' );
  65. }
  66. $this->printText( $text );
  67. }
  68. public function getAllowedParams() {
  69. $ret = parent::getAllowedParams() + [
  70. 'formatversion' => [
  71. ApiBase::PARAM_TYPE => [ 1, 2, 'latest' ],
  72. ApiBase::PARAM_DFLT => 1,
  73. ApiBase::PARAM_HELP_MSG => 'apihelp-php-param-formatversion',
  74. ],
  75. ];
  76. return $ret;
  77. }
  78. }