formatInstallDoc.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. /**
  3. * Format RELEASE-NOTE file to wiki text or HTML markup.
  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 Maintenance
  22. */
  23. require_once __DIR__ . '/Maintenance.php';
  24. /**
  25. * Maintenance script that formats RELEASE-NOTE file to wiki text or HTML markup.
  26. *
  27. * @ingroup Maintenance
  28. */
  29. class MaintenanceFormatInstallDoc extends Maintenance {
  30. function __construct() {
  31. parent::__construct();
  32. $this->addArg( 'path', 'The file name to format', false );
  33. $this->addOption( 'outfile', 'The output file name', false, true );
  34. $this->addOption( 'html', 'Use HTML output format. By default, wikitext is used.' );
  35. }
  36. function execute() {
  37. if ( $this->hasArg( 0 ) ) {
  38. $fileName = $this->getArg( 0 );
  39. $inFile = fopen( $fileName, 'r' );
  40. if ( !$inFile ) {
  41. $this->error( "Unable to open input file \"$fileName\"" );
  42. exit( 1 );
  43. }
  44. } else {
  45. $inFile = STDIN;
  46. }
  47. if ( $this->hasOption( 'outfile' ) ) {
  48. $fileName = $this->getOption( 'outfile' );
  49. $outFile = fopen( $fileName, 'w' );
  50. if ( !$outFile ) {
  51. $this->error( "Unable to open output file \"$fileName\"" );
  52. exit( 1 );
  53. }
  54. } else {
  55. $outFile = STDOUT;
  56. }
  57. $inText = stream_get_contents( $inFile );
  58. $outText = InstallDocFormatter::format( $inText );
  59. if ( $this->hasOption( 'html' ) ) {
  60. global $wgParser;
  61. $opt = new ParserOptions;
  62. $title = Title::newFromText( 'Text file' );
  63. $out = $wgParser->parse( $outText, $title, $opt );
  64. $outText = "<html><body>\n" . $out->getText() . "\n</body></html>\n";
  65. }
  66. fwrite( $outFile, $outText );
  67. }
  68. }
  69. $maintClass = 'MaintenanceFormatInstallDoc';
  70. require_once RUN_MAINTENANCE_IF_MAIN;