MediaWiki REL1_40
mwdocgen.php
Go to the documentation of this file.
1<?php
37
38require_once __DIR__ . '/Maintenance.php';
39
44class MWDocGen extends Maintenance {
46 private $doxygen;
48 private $mwVersion;
50 private $output;
52 private $input;
54 private $inputFilter;
56 private $template;
58 private $excludes;
60 private $doDot;
61
65 public function __construct() {
66 parent::__construct();
67 $this->addDescription( 'Build doxygen documentation' );
68
69 $this->addOption( 'doxygen',
70 'Path to doxygen',
71 false, true );
72 $this->addOption( 'version',
73 'Pass a MediaWiki version',
74 false, true );
75 $this->addOption( 'file',
76 "Only process given file or directory. Multiple values " .
77 "accepted with comma separation. Path relative to MW_INSTALL_PATH.",
78 false, true );
79 $this->addOption( 'output',
80 'Path to write doc to',
81 false, true );
82 $this->addOption( 'extensions',
83 'Process the extensions/ directory as well (ignored if --file is used)' );
84 $this->addOption( 'skins',
85 'Process the skins/ directory as well (ignored if --file is used)' );
86 }
87
88 public function getDbType() {
90 }
91
92 protected function init() {
93 global $wgPhpCli;
94
95 $this->doxygen = $this->getOption( 'doxygen', 'doxygen' );
96 $this->mwVersion = $this->getOption( 'version', 'master' );
97
98 $this->output = $this->getOption( 'output', 'docs' );
99
100 // Do not use wfShellWikiCmd, because mwdoc-filter.php is not
101 // a Maintenance script.
102 $this->inputFilter = Shell::escape( [
103 $wgPhpCli,
104 MW_INSTALL_PATH . '/maintenance/mwdoc-filter.php'
105 ] );
106
107 $this->template = MW_INSTALL_PATH . '/maintenance/Doxyfile';
108 $this->excludes = [
109 'cache',
110 'images',
111 ];
112
113 $file = $this->getOption( 'file' );
114 if ( $file !== null ) {
115 $this->input = '';
116 foreach ( explode( ',', $file ) as $input ) {
117 // Doxygen inputs are space separated and double quoted
118 $this->input .= " \"$input\"";
119 }
120 } else {
121 // If no explicit --file filter is set, we're indexing all of MediaWiki core
122 // in MW_INSTALL_PATH, but not extension and skin submodules (T317451).
123 $this->input = '';
124 if ( !$this->hasOption( 'extensions' ) ) {
125 $this->excludes[] = 'extensions';
126 }
127 if ( !$this->hasOption( 'skins' ) ) {
128 $this->excludes[] = 'skins';
129 }
130 }
131
132 $this->doDot = (bool)shell_exec( 'which dot' );
133 }
134
135 public function execute() {
136 $this->init();
137
138 # Build out directories we want to exclude
139 $exclude = '';
140 foreach ( $this->excludes as $item ) {
141 $exclude .= " $item";
142 }
143
144 $conf = strtr( file_get_contents( $this->template ),
145 [
146 '{{OUTPUT_DIRECTORY}}' => $this->output,
147 '{{CURRENT_VERSION}}' => $this->mwVersion,
148 '{{INPUT}}' => $this->input,
149 '{{EXCLUDE}}' => $exclude,
150 '{{HAVE_DOT}}' => $this->doDot ? 'YES' : 'NO',
151 '{{INPUT_FILTER}}' => $this->inputFilter,
152 ]
153 );
154
155 $tmpFile = tempnam( wfTempDir(), 'MWDocGen-' );
156 if ( file_put_contents( $tmpFile, $conf ) === false ) {
157 $this->fatalError( "Could not write doxygen configuration to file $tmpFile\n" );
158 }
159
160 $command = $this->doxygen . ' ' . $tmpFile;
161 $this->output( "Executing command:\n$command\n" );
162
163 $exitcode = 1;
164 system( $command, $exitcode );
165
166 $this->output( <<<TEXT
167---------------------------------------------------
168Doxygen execution finished.
169Check above for possible errors.
170
171You might want to delete the temporary file:
172 $tmpFile
173---------------------------------------------------
174
175TEXT
176 );
177
178 if ( $exitcode !== 0 ) {
179 $this->fatalError( "Something went wrong (exit: $exitcode)\n", $exitcode );
180 }
181 }
182}
183
184$maintClass = MWDocGen::class;
185require_once RUN_MAINTENANCE_IF_MAIN;
wfTempDir()
Tries to get the system directory for temporary files.
Maintenance script that builds doxygen documentation.
Definition mwdocgen.php:44
__construct()
Prepare Maintenance class.
Definition mwdocgen.php:65
getDbType()
Does the script need different DB access? By default, we give Maintenance scripts normal rights to th...
Definition mwdocgen.php:88
execute()
Do the actual work.
Definition mwdocgen.php:135
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
const DB_NONE
Constants for DB access type.
output( $out, $channel=null)
Throw some output to the user.
hasOption( $name)
Checks to see if a particular option was set.
addDescription( $text)
Set the description text.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
getOption( $name, $default=null)
Get an option, or return the default.
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
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:184
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.
Definition router.php:42