MediaWiki master
mwdocgen.php
Go to the documentation of this file.
1<?php
38
39// @codeCoverageIgnoreStart
40require_once __DIR__ . '/Maintenance.php';
41// @codeCoverageIgnoreEnd
42
47class MWDocGen extends Maintenance {
49 private $doxygen;
51 private $mwVersion;
53 private $output;
55 private $input;
57 private $inputFilter;
59 private $template;
61 private $excludes;
63 private $doDot;
64
68 public function __construct() {
69 parent::__construct();
70 $this->addDescription( 'Build doxygen documentation' );
71
72 $this->addOption( 'doxygen',
73 'Path to doxygen',
74 false, true );
75 $this->addOption( 'version',
76 'Pass a MediaWiki version',
77 false, true );
78 $this->addOption( 'file',
79 "Only process given file or directory. Multiple values " .
80 "accepted with comma separation. Path relative to MW_INSTALL_PATH.",
81 false, true );
82 $this->addOption( 'output',
83 'Path to write doc to',
84 false, true );
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)' );
89 }
90
91 public function getDbType() {
92 return Maintenance::DB_NONE;
93 }
94
95 protected function init() {
96 global $wgPhpCli;
97
98 $this->doxygen = $this->getOption( 'doxygen', 'doxygen' );
99 $this->mwVersion = $this->getOption( 'version', 'master' );
100
101 $this->output = $this->getOption( 'output', 'docs' );
102
103 // Do not use wfShellWikiCmd, because mwdoc-filter.php is not
104 // a Maintenance script.
105 $this->inputFilter = Shell::escape( [
106 $wgPhpCli,
107 MW_INSTALL_PATH . '/maintenance/mwdoc-filter.php'
108 ] );
109
110 $this->template = MW_INSTALL_PATH . '/maintenance/Doxyfile';
111 $this->excludes = [
112 'cache',
113 'images',
114 ];
115
116 $file = $this->getOption( 'file' );
117 if ( $file !== null ) {
118 $this->input = '';
119 foreach ( explode( ',', $file ) as $input ) {
120 // Doxygen inputs are space separated and double quoted
121 $this->input .= " \"$input\"";
122 }
123 } else {
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).
126 $this->input = '';
127 if ( !$this->hasOption( 'extensions' ) ) {
128 $this->excludes[] = 'extensions';
129 }
130 if ( !$this->hasOption( 'skins' ) ) {
131 $this->excludes[] = 'skins';
132 }
133 }
134
135 $this->doDot = (bool)shell_exec( 'which dot' );
136 }
137
138 public function execute() {
139 $this->init();
140
141 # Build out directories we want to exclude
142 $exclude = '';
143 foreach ( $this->excludes as $item ) {
144 $exclude .= " $item";
145 }
146
147 $conf = strtr( file_get_contents( $this->template ),
148 [
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,
155 ]
156 );
157
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" );
161 }
162
163 $command = $this->doxygen . ' ' . $tmpFile;
164 $this->output( "Executing command:\n$command\n" );
165
166 $exitcode = 1;
167 system( $command, $exitcode );
168
169 $this->output( <<<TEXT
170---------------------------------------------------
171Doxygen execution finished.
172Check above for possible errors.
173
174You might want to delete the temporary file:
175 $tmpFile
176---------------------------------------------------
177
178TEXT
179 );
180
181 if ( $exitcode !== 0 ) {
182 $this->fatalError( "Something went wrong (exit: $exitcode)\n", $exitcode );
183 }
184 }
185}
186
187// @codeCoverageIgnoreStart
188$maintClass = MWDocGen::class;
189require_once RUN_MAINTENANCE_IF_MAIN;
190// @codeCoverageIgnoreEnd
wfTempDir()
Tries to get the system directory for temporary files.
Maintenance script that builds doxygen documentation.
Definition mwdocgen.php:47
__construct()
Prepare Maintenance class.
Definition mwdocgen.php:68
getDbType()
Does the script need different DB access? By default, we give Maintenance scripts normal rights to th...
Definition mwdocgen.php:91
execute()
Do the actual work.
Definition mwdocgen.php:138
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
output( $out, $channel=null)
Throw some output to the user.
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
hasOption( $name)
Checks to see if a particular option was set.
getOption( $name, $default=null)
Get an option, or return the default.
addDescription( $text)
Set the description text.
Executes shell commands.
Definition Shell.php:46
$wgPhpCli
Config variable stub for the PhpCli setting, for use by phpdoc and IDEs.
$maintClass
Definition mwdocgen.php:188