3 * Generate class and file reference documentation for MediaWiki using doxygen.
5 * If the dot DOT language processor is available, attempt call graph
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License along
22 * with this program; if not, write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24 * http://www.gnu.org/copyleft/gpl.html
28 * @ingroup Maintenance
30 * @author Antoine Musso <hashar at free dot fr>
31 * @author Brooke Vibber
32 * @author Alexandre Emsenhuber
33 * @version first release
36 use MediaWiki\Maintenance\Maintenance
;
37 use MediaWiki\Shell\Shell
;
39 // @codeCoverageIgnoreStart
40 require_once __DIR__
. '/Maintenance.php';
41 // @codeCoverageIgnoreEnd
44 * Maintenance script that builds doxygen documentation.
45 * @ingroup Maintenance
47 class MWDocGen
extends Maintenance
{
66 * Prepare Maintenance class
68 public function __construct() {
69 parent
::__construct();
70 $this->addDescription( 'Build doxygen documentation' );
72 $this->addOption( 'doxygen',
75 $this->addOption( 'version',
76 'Pass a MediaWiki version',
78 $this->addOption( 'file',
79 "Only process given file or directory. Multiple values " .
80 "accepted with comma separation. Path relative to MW_INSTALL_PATH.",
82 $this->addOption( 'output',
83 'Path to write doc to',
85 $this->addOption( 'extensions',
86 'Process the extensions/ directory as well (ignored if --file is used)' );
87 $this->addOption( 'skins',
88 'Process the skins/ directory as well (ignored if --file is used)' );
91 public function getDbType() {
92 return Maintenance
::DB_NONE
;
95 protected function init() {
98 $this->doxygen
= $this->getOption( 'doxygen', 'doxygen' );
99 $this->mwVersion
= $this->getOption( 'version', 'master' );
101 $this->output
= $this->getOption( 'output', 'docs' );
103 // Do not use wfShellWikiCmd, because mwdoc-filter.php is not
104 // a Maintenance script.
105 $this->inputFilter
= Shell
::escape( [
107 MW_INSTALL_PATH
. '/maintenance/mwdoc-filter.php'
110 $this->template
= MW_INSTALL_PATH
. '/maintenance/Doxyfile';
116 $file = $this->getOption( 'file' );
117 if ( $file !== null ) {
119 foreach ( explode( ',', $file ) as $input ) {
120 // Doxygen inputs are space separated and double quoted
121 $this->input
.= " \"$input\"";
124 // If no explicit --file filter is set, we're indexing all of MediaWiki core
125 // in MW_INSTALL_PATH, but not extension and skin submodules (T317451).
127 if ( !$this->hasOption( 'extensions' ) ) {
128 $this->excludes
[] = 'extensions';
130 if ( !$this->hasOption( 'skins' ) ) {
131 $this->excludes
[] = 'skins';
135 $this->doDot
= (bool)shell_exec( 'which dot' );
138 public function execute() {
141 # Build out directories we want to exclude
143 foreach ( $this->excludes
as $item ) {
144 $exclude .= " $item";
147 $conf = strtr( file_get_contents( $this->template
),
149 '{{OUTPUT_DIRECTORY}}' => $this->output
,
150 '{{CURRENT_VERSION}}' => $this->mwVersion
,
151 '{{INPUT}}' => $this->input
,
152 '{{EXCLUDE}}' => $exclude,
153 '{{HAVE_DOT}}' => $this->doDot ?
'YES' : 'NO',
154 '{{INPUT_FILTER}}' => $this->inputFilter
,
158 $tmpFile = tempnam( wfTempDir(), 'MWDocGen-' );
159 if ( file_put_contents( $tmpFile, $conf ) === false ) {
160 $this->fatalError( "Could not write doxygen configuration to file $tmpFile\n" );
163 $command = $this->doxygen
. ' ' . $tmpFile;
164 $this->output( "Executing command:\n$command\n" );
167 system( $command, $exitcode );
169 $this->output( <<<TEXT
170 ---------------------------------------------------
171 Doxygen execution finished.
172 Check above for possible errors.
174 You might want to delete the temporary file:
176 ---------------------------------------------------
181 if ( $exitcode !== 0 ) {
182 $this->fatalError( "Something went wrong (exit: $exitcode)\n", $exitcode );
187 // @codeCoverageIgnoreStart
188 $maintClass = MWDocGen
::class;
189 require_once RUN_MAINTENANCE_IF_MAIN
;
190 // @codeCoverageIgnoreEnd