Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 72 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
MWDocGen | |
0.00% |
0 / 72 |
|
0.00% |
0 / 4 |
156 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 19 |
|
0.00% |
0 / 1 |
2 | |||
getDbType | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
init | |
0.00% |
0 / 24 |
|
0.00% |
0 / 1 |
30 | |||
execute | |
0.00% |
0 / 28 |
|
0.00% |
0 / 1 |
30 |
1 | <?php |
2 | /** |
3 | * Generate class and file reference documentation for MediaWiki using doxygen. |
4 | * |
5 | * If the dot DOT language processor is available, attempt call graph |
6 | * generation. |
7 | * |
8 | * Usage: |
9 | * php mwdocgen.php |
10 | * |
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. |
15 | * |
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. |
20 | * |
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 |
25 | * |
26 | * @file |
27 | * @todo document |
28 | * @ingroup Maintenance |
29 | * |
30 | * @author Antoine Musso <hashar at free dot fr> |
31 | * @author Brooke Vibber |
32 | * @author Alexandre Emsenhuber |
33 | * @version first release |
34 | */ |
35 | |
36 | use MediaWiki\Shell\Shell; |
37 | |
38 | // @codeCoverageIgnoreStart |
39 | require_once __DIR__ . '/Maintenance.php'; |
40 | // @codeCoverageIgnoreEnd |
41 | |
42 | /** |
43 | * Maintenance script that builds doxygen documentation. |
44 | * @ingroup Maintenance |
45 | */ |
46 | class MWDocGen extends Maintenance { |
47 | /** @var string */ |
48 | private $doxygen; |
49 | /** @var string */ |
50 | private $mwVersion; |
51 | /** @var string */ |
52 | private $output; |
53 | /** @var string */ |
54 | private $input; |
55 | /** @var string */ |
56 | private $inputFilter; |
57 | /** @var string */ |
58 | private $template; |
59 | /** @var string[] */ |
60 | private $excludes; |
61 | /** @var bool */ |
62 | private $doDot; |
63 | |
64 | /** |
65 | * Prepare Maintenance class |
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 | // Do not use wfShellWikiCmd, because mwdoc-filter.php is not |
103 | // a Maintenance script. |
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 | // Doxygen inputs are space separated and double quoted |
120 | $this->input .= " \"$input\""; |
121 | } |
122 | } else { |
123 | // If no explicit --file filter is set, we're indexing all of MediaWiki core |
124 | // in MW_INSTALL_PATH, but not extension and skin submodules (T317451). |
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 | # Build out directories we want to exclude |
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 | // @codeCoverageIgnoreStart |
187 | $maintClass = MWDocGen::class; |
188 | require_once RUN_MAINTENANCE_IF_MAIN; |
189 | // @codeCoverageIgnoreEnd |