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 require_once __DIR__
. '/Maintenance.php';
39 * Maintenance script that builds doxygen documentation.
40 * @ingroup Maintenance
42 class MWDocGen
extends Maintenance
{
45 * Prepare Maintenance class
47 public function __construct() {
48 parent
::__construct();
49 $this->mDescription
= 'Build doxygen documentation';
51 $this->addOption( 'doxygen',
54 $this->addOption( 'version',
55 'Pass a MediaWiki version',
57 $this->addOption( 'generate-man',
58 'Whether to generate man files' );
59 $this->addOption( 'file',
60 "Only process given file or directory. Multiple values " .
61 "accepted with comma separation. Path relative to \$IP.",
63 $this->addOption( 'output',
64 'Path to write doc to',
66 $this->addOption( 'no-extensions',
67 'Ignore extensions' );
70 public function getDbType() {
71 return Maintenance
::DB_NONE
;
74 protected function init() {
77 $this->doxygen
= $this->getOption( 'doxygen', 'doxygen' );
78 $this->mwVersion
= $this->getOption( 'version', 'master' );
81 $inputs = explode( ',', $this->getOption( 'file', '' ) );
82 foreach ( $inputs as $input ) {
83 # Doxygen inputs are space separted and double quoted
84 $this->input
.= " \"$IP/$input\"";
87 $this->output
= $this->getOption( 'output', "$IP/docs" );
89 $this->inputFilter
= wfShellWikiCmd(
90 $IP . '/maintenance/mwdoc-filter.php' );
91 $this->template
= $IP . '/maintenance/Doxyfile';
92 $this->excludes
= array(
98 $this->excludePatterns
= array();
99 if ( $this->hasOption( 'no-extensions' ) ) {
100 $this->excludePatterns
[] = 'extensions';
103 $this->doDot
= `which dot`
;
104 $this->doMan
= $this->hasOption( 'generate-man' );
107 public function execute() {
112 # Build out directories we want to exclude
114 foreach ( $this->excludes
as $item ) {
115 $exclude .= " $IP/$item";
118 $excludePatterns = implode( ' ', $this->excludePatterns
);
120 $conf = strtr( file_get_contents( $this->template
),
122 '{{OUTPUT_DIRECTORY}}' => $this->output
,
123 '{{STRIP_FROM_PATH}}' => $IP,
124 '{{CURRENT_VERSION}}' => $this->mwVersion
,
125 '{{INPUT}}' => $this->input
,
126 '{{EXCLUDE}}' => $exclude,
127 '{{EXCLUDE_PATTERNS}}' => $excludePatterns,
128 '{{HAVE_DOT}}' => $this->doDot ?
'YES' : 'NO',
129 '{{GENERATE_MAN}}' => $this->doMan ?
'YES' : 'NO',
130 '{{INPUT_FILTER}}' => $this->inputFilter
,
134 $tmpFile = tempnam( wfTempDir(), 'MWDocGen-' );
135 if ( file_put_contents( $tmpFile, $conf ) === false ) {
136 $this->error( "Could not write doxygen configuration to file $tmpFile\n",
137 /** exit code: */ 1 );
140 $command = $this->doxygen
. ' ' . $tmpFile;
141 $this->output( "Executing command:\n$command\n" );
144 system( $command, $exitcode );
146 $this->output( <<<TEXT
147 ---------------------------------------------------
148 Doxygen execution finished.
149 Check above for possible errors.
151 You might want to delete the temporary file:
153 ---------------------------------------------------
158 if ( $exitcode !== 0 ) {
159 $this->error( "Something went wrong (exit: $exitcode)\n",
165 $maintClass = 'MWDocGen';
166 require_once RUN_MAINTENANCE_IF_MAIN
;