| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
use MediaWiki\Shell\Shell; |
| 37 |
|
| 38 |
|
| 39 |
require_once __DIR__ . '/Maintenance.php'; |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
class MWDocGen extends Maintenance { |
| 47 |
|
| 48 |
private $doxygen; |
| 49 |
|
| 50 |
private $mwVersion; |
| 51 |
|
| 52 |
private $output; |
| 53 |
|
| 54 |
private $input; |
| 55 |
|
| 56 |
private $inputFilter; |
| 57 |
|
| 58 |
private $template; |
| 59 |
|
| 60 |
private $excludes; |
| 61 |
|
| 62 |
private $doDot; |
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
public function __construct() { |
| 68 |
parent::__construct(); |
| 69 |
$this->addDescription( 'Build doxygen documentation' ); |
| 70 |
|
| 71 |
$this->addOption( 'doxygen', |
| 72 |
'Path to doxygen', |
| 73 |
false, true ); |
| 74 |
$this->addOption( 'version', |
| 75 |
'Pass a MediaWiki version', |
| 76 |
false, true ); |
| 77 |
$this->addOption( 'file', |
| 78 |
"Only process given file or directory. Multiple values " . |
| 79 |
"accepted with comma separation. Path relative to MW_INSTALL_PATH.", |
| 80 |
false, true ); |
| 81 |
$this->addOption( 'output', |
| 82 |
'Path to write doc to', |
| 83 |
false, true ); |
| 84 |
$this->addOption( 'extensions', |
| 85 |
'Process the extensions/ directory as well (ignored if --file is used)' ); |
| 86 |
$this->addOption( 'skins', |
| 87 |
'Process the skins/ directory as well (ignored if --file is used)' ); |
| 88 |
} |
| 89 |
|
| 90 |
public function getDbType() { |
| 91 |
return Maintenance::DB_NONE; |
| 92 |
} |
| 93 |
|
| 94 |
protected function init() { |
| 95 |
global $wgPhpCli; |
| 96 |
|
| 97 |
$this->doxygen = $this->getOption( 'doxygen', 'doxygen' ); |
| 98 |
$this->mwVersion = $this->getOption( 'version', 'master' ); |
| 99 |
|
| 100 |
$this->output = $this->getOption( 'output', 'docs' ); |
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
$this->inputFilter = Shell::escape( [ |
| 105 |
$wgPhpCli, |
| 106 |
MW_INSTALL_PATH . '/maintenance/mwdoc-filter.php' |
| 107 |
] ); |
| 108 |
|
| 109 |
$this->template = MW_INSTALL_PATH . '/maintenance/Doxyfile'; |
| 110 |
$this->excludes = [ |
| 111 |
'cache', |
| 112 |
'images', |
| 113 |
]; |
| 114 |
|
| 115 |
$file = $this->getOption( 'file' ); |
| 116 |
if ( $file !== null ) { |
| 117 |
$this->input = ''; |
| 118 |
foreach ( explode( ',', $file ) as $input ) { |
| 119 |
|
| 120 |
$this->input .= " \"$input\""; |
| 121 |
} |
| 122 |
} else { |
| 123 |
|
| 124 |
|
| 125 |
$this->input = ''; |
| 126 |
if ( !$this->hasOption( 'extensions' ) ) { |
| 127 |
$this->excludes[] = 'extensions'; |
| 128 |
} |
| 129 |
if ( !$this->hasOption( 'skins' ) ) { |
| 130 |
$this->excludes[] = 'skins'; |
| 131 |
} |
| 132 |
} |
| 133 |
|
| 134 |
$this->doDot = (bool)shell_exec( 'which dot' ); |
| 135 |
} |
| 136 |
|
| 137 |
public function execute() { |
| 138 |
$this->init(); |
| 139 |
|
| 140 |
|
| 141 |
$exclude = ''; |
| 142 |
foreach ( $this->excludes as $item ) { |
| 143 |
$exclude .= " $item"; |
| 144 |
} |
| 145 |
|
| 146 |
$conf = strtr( file_get_contents( $this->template ), |
| 147 |
[ |
| 148 |
'{{OUTPUT_DIRECTORY}}' => $this->output, |
| 149 |
'{{CURRENT_VERSION}}' => $this->mwVersion, |
| 150 |
'{{INPUT}}' => $this->input, |
| 151 |
'{{EXCLUDE}}' => $exclude, |
| 152 |
'{{HAVE_DOT}}' => $this->doDot ? 'YES' : 'NO', |
| 153 |
'{{INPUT_FILTER}}' => $this->inputFilter, |
| 154 |
] |
| 155 |
); |
| 156 |
|
| 157 |
$tmpFile = tempnam( wfTempDir(), 'MWDocGen-' ); |
| 158 |
if ( file_put_contents( $tmpFile, $conf ) === false ) { |
| 159 |
$this->fatalError( "Could not write doxygen configuration to file $tmpFile\n" ); |
| 160 |
} |
| 161 |
|
| 162 |
$command = $this->doxygen . ' ' . $tmpFile; |
| 163 |
$this->output( "Executing command:\n$command\n" ); |
| 164 |
|
| 165 |
$exitcode = 1; |
| 166 |
system( $command, $exitcode ); |
| 167 |
|
| 168 |
$this->output( <<<TEXT |
| 169 |
--------------------------------------------------- |
| 170 |
Doxygen execution finished. |
| 171 |
Check above for possible errors. |
| 172 |
|
| 173 |
You might want to delete the temporary file: |
| 174 |
$tmpFile |
| 175 |
--------------------------------------------------- |
| 176 |
|
| 177 |
TEXT |
| 178 |
); |
| 179 |
|
| 180 |
if ( $exitcode !== 0 ) { |
| 181 |
$this->fatalError( "Something went wrong (exit: $exitcode)\n", $exitcode ); |
| 182 |
} |
| 183 |
} |
| 184 |
} |
| 185 |
|
| 186 |
|
| 187 |
$maintClass = MWDocGen::class; |
| 188 |
require_once RUN_MAINTENANCE_IF_MAIN; |
| 189 |
|