MediaWiki
master
Toggle main menu visibility
mwdocgen.php
Go to the documentation of this file.
1
<?php
21
22
use
MediaWiki\Maintenance\Maintenance
;
23
use MediaWiki\Shell\Shell;
24
25
// @codeCoverageIgnoreStart
26
require_once __DIR__ .
'/Maintenance.php'
;
27
// @codeCoverageIgnoreEnd
28
33
class
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
( [
93
$wgPhpCli
,
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
---------------------------------------------------
158
Doxygen execution finished.
159
Check above
for
possible errors.
160
161
You might want to
delete
the temporary file:
162
$tmpFile
163
---------------------------------------------------
164
165
TEXT
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;
176
require_once RUN_MAINTENANCE_IF_MAIN;
177
// @codeCoverageIgnoreEnd
wfTempDir
wfTempDir()
Tries to get the system directory for temporary files.
Definition
GlobalFunctions.php:1072
$maintClass
$maintClass
Definition
addChangeTag.php:56
MWDocGen
Maintenance script that builds doxygen documentation.
Definition
mwdocgen.php:33
MWDocGen\__construct
__construct()
Prepare Maintenance class.
Definition
mwdocgen.php:54
MWDocGen\getDbType
getDbType()
Definition
mwdocgen.php:78
MWDocGen\init
init()
Definition
mwdocgen.php:82
MWDocGen\execute
execute()
Definition
mwdocgen.php:125
MediaWiki\Shell\Shell\escape
static escape(... $args)
Locale-independent version of escapeshellarg().
Definition
Shell.php:150
$wgPhpCli
$wgPhpCli
Config variable stub for the PhpCli setting, for use by phpdoc and IDEs.
Definition
config-vars.php:4436
MediaWiki\Maintenance
Definition
applyChangeTag.php:11
maintenance
mwdocgen.php
Generated on
for MediaWiki by
1.18.0