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 Brion Vibber
32 * @author Alexandre Emsenhuber
33 * @version first release
36 use MediaWiki\Shell\Shell
;
38 require_once __DIR__
. '/Maintenance.php';
41 * Maintenance script that builds doxygen documentation.
42 * @ingroup Maintenance
44 class MWDocGen
extends Maintenance
{
47 * Prepare Maintenance class
49 public function __construct() {
50 parent
::__construct();
51 $this->addDescription( 'Build doxygen documentation' );
53 $this->addOption( 'doxygen',
56 $this->addOption( 'version',
57 'Pass a MediaWiki version',
59 $this->addOption( 'generate-man',
60 'Whether to generate man files' );
61 $this->addOption( 'file',
62 "Only process given file or directory. Multiple values " .
63 "accepted with comma separation. Path relative to \$IP.",
65 $this->addOption( 'output',
66 'Path to write doc to',
68 $this->addOption( 'no-extensions',
69 'Ignore extensions' );
72 public function getDbType() {
73 return Maintenance
::DB_NONE
;
76 protected function init() {
77 global $wgPhpCli, $IP;
79 $this->doxygen
= $this->getOption( 'doxygen', 'doxygen' );
80 $this->mwVersion
= $this->getOption( 'version', 'master' );
83 $inputs = explode( ',', $this->getOption( 'file', '' ) );
84 foreach ( $inputs as $input ) {
85 # Doxygen inputs are space separted and double quoted
86 $this->input
.= " \"$IP/$input\"";
89 $this->output
= $this->getOption( 'output', "$IP/docs" );
91 // Do not use wfShellWikiCmd, because mwdoc-filter.php is not
92 // a Maintenance script.
93 $this->inputFilter
= Shell
::escape( [
95 $IP . '/maintenance/mwdoc-filter.php'
98 $this->template
= $IP . '/maintenance/Doxyfile';
106 $this->excludePatterns
= [];
107 if ( $this->hasOption( 'no-extensions' ) ) {
108 $this->excludePatterns
[] = 'extensions';
111 $this->doDot
= shell_exec( 'which dot' );
112 $this->doMan
= $this->hasOption( 'generate-man' );
115 public function execute() {
120 # Build out directories we want to exclude
122 foreach ( $this->excludes
as $item ) {
123 $exclude .= " $IP/$item";
126 $excludePatterns = implode( ' ', $this->excludePatterns
);
128 $conf = strtr( file_get_contents( $this->template
),
130 '{{OUTPUT_DIRECTORY}}' => $this->output
,
131 '{{STRIP_FROM_PATH}}' => $IP,
132 '{{CURRENT_VERSION}}' => $this->mwVersion
,
133 '{{INPUT}}' => $this->input
,
134 '{{EXCLUDE}}' => $exclude,
135 '{{EXCLUDE_PATTERNS}}' => $excludePatterns,
136 '{{HAVE_DOT}}' => $this->doDot ?
'YES' : 'NO',
137 '{{GENERATE_MAN}}' => $this->doMan ?
'YES' : 'NO',
138 '{{INPUT_FILTER}}' => $this->inputFilter
,
142 $tmpFile = tempnam( wfTempDir(), 'MWDocGen-' );
143 if ( file_put_contents( $tmpFile, $conf ) === false ) {
144 $this->fatalError( "Could not write doxygen configuration to file $tmpFile\n" );
147 $command = $this->doxygen
. ' ' . $tmpFile;
148 $this->output( "Executing command:\n$command\n" );
151 system( $command, $exitcode );
153 $this->output( <<<TEXT
154 ---------------------------------------------------
155 Doxygen execution finished.
156 Check above for possible errors.
158 You might want to delete the temporary file:
160 ---------------------------------------------------
165 if ( $exitcode !== 0 ) {
166 $this->fatalError( "Something went wrong (exit: $exitcode)\n", $exitcode );
171 $maintClass = MWDocGen
::class;
172 require_once RUN_MAINTENANCE_IF_MAIN
;