MediaWiki REL1_33
mwdocgen.php
Go to the documentation of this file.
1<?php
37
38require_once __DIR__ . '/Maintenance.php';
39
44class MWDocGen extends Maintenance {
45
49 public function __construct() {
50 parent::__construct();
51 $this->addDescription( 'Build doxygen documentation' );
52
53 $this->addOption( 'doxygen',
54 'Path to doxygen',
55 false, true );
56 $this->addOption( 'version',
57 'Pass a MediaWiki version',
58 false, true );
59 $this->addOption( 'generate-man',
60 'Whether to generate man files' );
61 $this->addOption( 'file',
62 "Only process given file or directory. Multiple values " .
63 "accepted with comma separation. Path relative to \$IP.",
64 false, true );
65 $this->addOption( 'output',
66 'Path to write doc to',
67 false, true );
68 $this->addOption( 'no-extensions',
69 'Ignore extensions' );
70 }
71
72 public function getDbType() {
74 }
75
76 protected function init() {
77 global $wgPhpCli, $IP;
78
79 $this->doxygen = $this->getOption( 'doxygen', 'doxygen' );
80 $this->mwVersion = $this->getOption( 'version', 'master' );
81
82 $this->input = '';
83 $inputs = explode( ',', $this->getOption( 'file', '' ) );
84 foreach ( $inputs as $input ) {
85 # Doxygen inputs are space separted and double quoted
86 $this->input .= " \"$IP/$input\"";
87 }
88
89 $this->output = $this->getOption( 'output', "$IP/docs" );
90
91 // Do not use wfShellWikiCmd, because mwdoc-filter.php is not
92 // a Maintenance script.
93 $this->inputFilter = Shell::escape( [
95 $IP . '/maintenance/mwdoc-filter.php'
96 ] );
97
98 $this->template = $IP . '/maintenance/Doxyfile';
99 $this->excludes = [
100 'vendor',
101 'node_modules',
102 'images',
103 'static',
104 ];
105 $this->excludePatterns = [];
106 if ( $this->hasOption( 'no-extensions' ) ) {
107 $this->excludePatterns[] = 'extensions';
108 }
109
110 $this->doDot = shell_exec( 'which dot' );
111 $this->doMan = $this->hasOption( 'generate-man' );
112 }
113
114 public function execute() {
115 global $IP;
116
117 $this->init();
118
119 # Build out directories we want to exclude
120 $exclude = '';
121 foreach ( $this->excludes as $item ) {
122 $exclude .= " $IP/$item";
123 }
124
125 $excludePatterns = implode( ' ', $this->excludePatterns );
126
127 $conf = strtr( file_get_contents( $this->template ),
128 [
129 '{{OUTPUT_DIRECTORY}}' => $this->output,
130 '{{STRIP_FROM_PATH}}' => $IP,
131 '{{CURRENT_VERSION}}' => $this->mwVersion,
132 '{{INPUT}}' => $this->input,
133 '{{EXCLUDE}}' => $exclude,
134 '{{EXCLUDE_PATTERNS}}' => $excludePatterns,
135 '{{HAVE_DOT}}' => $this->doDot ? 'YES' : 'NO',
136 '{{GENERATE_MAN}}' => $this->doMan ? 'YES' : 'NO',
137 '{{INPUT_FILTER}}' => $this->inputFilter,
138 ]
139 );
140
141 $tmpFile = tempnam( wfTempDir(), 'MWDocGen-' );
142 if ( file_put_contents( $tmpFile, $conf ) === false ) {
143 $this->fatalError( "Could not write doxygen configuration to file $tmpFile\n" );
144 }
145
146 $command = $this->doxygen . ' ' . $tmpFile;
147 $this->output( "Executing command:\n$command\n" );
148
149 $exitcode = 1;
150 system( $command, $exitcode );
151
152 $this->output( <<<TEXT
153---------------------------------------------------
154Doxygen execution finished.
155Check above for possible errors.
156
157You might want to delete the temporary file:
158 $tmpFile
159---------------------------------------------------
160
161TEXT
162 );
163
164 if ( $exitcode !== 0 ) {
165 $this->fatalError( "Something went wrong (exit: $exitcode)\n", $exitcode );
166 }
167 }
168}
169
170$maintClass = MWDocGen::class;
171require_once RUN_MAINTENANCE_IF_MAIN;
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two and(2) offer you this license which gives you legal permission to copy
this section has the sole purpose of protecting the integrity of the free software distribution system
Definition COPYING.txt:218
and give any other recipients of the Program a copy of this License along with the Program You may charge a fee for the physical act of transferring a and you may at your option offer warranty protection in exchange for a fee You may modify your copy or copies of the Program or any portion of thus forming a work based on the and copy and distribute such modifications or work under the terms of Section above
Definition COPYING.txt:93
$wgPhpCli
Executable path of the PHP cli binary.
wfTempDir()
Tries to get the system directory for temporary files.
$command
Definition cdb.php:65
Maintenance script that builds doxygen documentation.
Definition mwdocgen.php:44
__construct()
Prepare Maintenance class.
Definition mwdocgen.php:49
getDbType()
Does the script need different DB access? By default, we give Maintenance scripts normal rights to th...
Definition mwdocgen.php:72
execute()
Do the actual work.
Definition mwdocgen.php:114
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 exists.
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:44
$IP
Definition update.php:3
require_once RUN_MAINTENANCE_IF_MAIN
$maintClass
Definition mwdocgen.php:170
if(is_array($mode)) switch( $mode) $input