MediaWiki master
mwdocgen.php
Go to the documentation of this file.
1<?php
24
25// @codeCoverageIgnoreStart
26require_once __DIR__ . '/Maintenance.php';
27// @codeCoverageIgnoreEnd
28
33class MWDocGen extends Maintenance {
35 private $doxygen;
37 private $mwVersion;
39 private $output;
41 private $input;
43 private $inputFilter;
45 private $template;
47 private $excludes;
49 private $doDot;
50
54 public function __construct() {
55 parent::__construct();
56 $this->addDescription( 'Build doxygen documentation' );
57
58 $this->addOption( 'doxygen',
59 'Path to doxygen',
60 false, true );
61 $this->addOption( 'version',
62 'Pass a MediaWiki version',
63 false, true );
64 $this->addOption( 'file',
65 "Only process given file or directory. Multiple values " .
66 "accepted with comma separation. Path relative to MW_INSTALL_PATH.",
67 false, true );
68 $this->addOption( 'output',
69 'Path to write doc to',
70 false, true );
71 $this->addOption( 'extensions',
72 'Process the extensions/ directory as well (ignored if --file is used)' );
73 $this->addOption( 'skins',
74 'Process the skins/ directory as well (ignored if --file is used)' );
75 }
76
78 public function getDbType() {
79 return Maintenance::DB_NONE;
80 }
81
82 protected function init() {
83 global $wgPhpCli;
84
85 $this->doxygen = $this->getOption( 'doxygen', 'doxygen' );
86 $this->mwVersion = $this->getOption( 'version', 'master' );
87
88 $this->output = $this->getOption( 'output', 'docs' );
89
90 // Do not use wfShellWikiCmd, because mwdoc-filter.php is not
91 // a Maintenance script.
92 $this->inputFilter = Shell::escape( [
94 MW_INSTALL_PATH . '/maintenance/mwdoc-filter.php'
95 ] );
96
97 $this->template = MW_INSTALL_PATH . '/maintenance/Doxyfile';
98 $this->excludes = [
99 'cache',
100 'images',
101 ];
102
103 $file = $this->getOption( 'file' );
104 if ( $file !== null ) {
105 $this->input = '';
106 foreach ( explode( ',', $file ) as $input ) {
107 // Doxygen inputs are space separated and double quoted
108 $this->input .= " \"$input\"";
109 }
110 } else {
111 // If no explicit --file filter is set, we're indexing all of MediaWiki core
112 // in MW_INSTALL_PATH, but not extension and skin submodules (T317451).
113 $this->input = '';
114 if ( !$this->hasOption( 'extensions' ) ) {
115 $this->excludes[] = 'extensions';
116 }
117 if ( !$this->hasOption( 'skins' ) ) {
118 $this->excludes[] = 'skins';
119 }
120 }
121
122 $this->doDot = (bool)shell_exec( 'which dot' );
123 }
124
125 public function execute() {
126 $this->init();
127
128 # Build out directories we want to exclude
129 $exclude = '';
130 foreach ( $this->excludes as $item ) {
131 $exclude .= " $item";
132 }
133
134 $conf = strtr( file_get_contents( $this->template ),
135 [
136 '{{OUTPUT_DIRECTORY}}' => $this->output,
137 '{{CURRENT_VERSION}}' => $this->mwVersion,
138 '{{INPUT}}' => $this->input,
139 '{{EXCLUDE}}' => $exclude,
140 '{{HAVE_DOT}}' => $this->doDot ? 'YES' : 'NO',
141 '{{INPUT_FILTER}}' => $this->inputFilter,
142 ]
143 );
144
145 $tmpFile = tempnam( wfTempDir(), 'MWDocGen-' );
146 if ( file_put_contents( $tmpFile, $conf ) === false ) {
147 $this->fatalError( "Could not write doxygen configuration to file $tmpFile\n" );
148 }
149
150 $command = $this->doxygen . ' ' . $tmpFile;
151 $this->output( "Executing command:\n$command\n" );
152
153 $exitcode = 1;
154 system( $command, $exitcode );
155
156 $this->output( <<<TEXT
157---------------------------------------------------
158Doxygen execution finished.
159Check above for possible errors.
160
161You might want to delete the temporary file:
162 $tmpFile
163---------------------------------------------------
164
165TEXT
166 );
167
168 if ( $exitcode !== 0 ) {
169 $this->fatalError( "Something went wrong (exit: $exitcode)\n", $exitcode );
170 }
171 }
172}
173
174// @codeCoverageIgnoreStart
175$maintClass = MWDocGen::class;
176require_once RUN_MAINTENANCE_IF_MAIN;
177// @codeCoverageIgnoreEnd
wfTempDir()
Tries to get the system directory for temporary files.
Maintenance script that builds doxygen documentation.
Definition mwdocgen.php:33
__construct()
Prepare Maintenance class.
Definition mwdocgen.php:54
getDbType()
Does the script need different DB access? By default, we give Maintenance scripts normal rights to th...
Definition mwdocgen.php:78
execute()
Do the actual work.
Definition mwdocgen.php:125
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:32
$wgPhpCli
Config variable stub for the PhpCli setting, for use by phpdoc and IDEs.
$maintClass
Definition mwdocgen.php:175