MediaWiki
REL1_21
|
00001 <?php 00042 # 00043 # Variables / Configuration 00044 # 00045 00046 if ( PHP_SAPI != 'cli' ) { 00047 echo 'Run "' . __FILE__ . '" from the command line.'; 00048 die( -1 ); 00049 } 00050 00052 $mwPath = dirname( __DIR__ ) . DIRECTORY_SEPARATOR; 00053 00055 $doxygenBin = 'doxygen'; 00056 00058 $doxygenTemplate = $mwPath . 'maintenance/Doxyfile'; 00059 00061 $doxygenInputFilter = "php {$mwPath}maintenance/mwdoc-filter.php"; 00062 00064 $doxyOutput = $mwPath . 'docs' . DIRECTORY_SEPARATOR ; 00065 00066 $doxyVersion = 'master'; 00067 00069 $mwPathI = $mwPath . 'includes/'; 00070 $mwPathL = $mwPath . 'languages/'; 00071 $mwPathM = $mwPath . 'maintenance/'; 00072 $mwPathS = $mwPath . 'skins/'; 00073 00075 $mwExcludePaths = array( 00076 'images', 00077 'static', 00078 ); 00079 00081 $input = ''; 00082 $excludePatterns = ''; 00084 $doxyGenerateMan = false; 00085 00086 # 00087 # Functions 00088 # 00089 00090 define( 'MEDIAWIKI', true ); 00091 require_once( "$mwPath/includes/GlobalFunctions.php" ); 00092 00098 function readaline( $prompt = '' ) { 00099 print $prompt; 00100 $fp = fopen( "php://stdin", "r" ); 00101 $resp = trim( fgets( $fp, 1024 ) ); 00102 fclose( $fp ); 00103 return $resp; 00104 } 00105 00119 function generateConfigFile( $doxygenTemplate, $outputDirectory, $stripFromPath, $currentVersion, $input, $exclude, $excludePatterns, $doxyGenerateMan, $doxygenInputFilter ) { 00120 00121 $template = file_get_contents( $doxygenTemplate ); 00122 // Replace template placeholders by correct values. 00123 $replacements = array( 00124 '{{OUTPUT_DIRECTORY}}' => $outputDirectory, 00125 '{{STRIP_FROM_PATH}}' => $stripFromPath, 00126 '{{CURRENT_VERSION}}' => $currentVersion, 00127 '{{INPUT}}' => $input, 00128 '{{EXCLUDE}}' => $exclude, 00129 '{{EXCLUDE_PATTERNS}}' => $excludePatterns, 00130 '{{HAVE_DOT}}' => `which dot` ? 'YES' : 'NO', 00131 '{{GENERATE_MAN}}' => $doxyGenerateMan ? 'YES' : 'NO', 00132 '{{INPUT_FILTER}}' => $doxygenInputFilter, 00133 ); 00134 $tmpCfg = str_replace( array_keys( $replacements ), array_values( $replacements ), $template ); 00135 $tmpFileName = tempnam( wfTempDir(), 'mwdocgen-' ); 00136 file_put_contents( $tmpFileName, $tmpCfg ) or die( "Could not write doxygen configuration to file $tmpFileName\n" ); 00137 00138 return $tmpFileName; 00139 } 00140 00141 # 00142 # Main ! 00143 # 00144 00145 unset( $file ); 00146 00147 if ( is_array( $argv ) ) { 00148 for ($i = 0; $i < count($argv); $i++ ) { 00149 switch( $argv[$i] ) { 00150 case '--all': $input = 0; break; 00151 case '--includes': $input = 1; break; 00152 case '--languages': $input = 2; break; 00153 case '--maintenance': $input = 3; break; 00154 case '--skins': $input = 4; break; 00155 case '--file': 00156 $input = 5; 00157 $i++; 00158 if ( isset( $argv[$i] ) ) { 00159 $file = $argv[$i]; 00160 } 00161 break; 00162 case '--no-extensions': $input = 6; break; 00163 case '--output': 00164 $i++; 00165 if ( isset( $argv[$i] ) ) { 00166 $doxyOutput = realpath( $argv[$i] ); 00167 } 00168 break; 00169 case '--version': 00170 $i++; 00171 if ( isset( $argv[$i] ) ) { 00172 $doxyVersion = $argv[$i]; 00173 } 00174 break; 00175 case '--generate-man': 00176 $doxyGenerateMan = true; 00177 break; 00178 case '--help': 00179 print <<<END 00180 Usage: php mwdocgen.php [<command>] [<options>] 00181 00182 Commands: 00183 --all Process entire codebase 00184 --includes Process only files in includes/ dir 00185 --languages Process only files in languages/ dir 00186 --maintenance Process only files in maintenance/ dir 00187 --skins Process only files in skins/ dir 00188 --file <file> Process only the given file 00189 --no-extensions Process everything but extensions directorys 00190 00191 If no command is given, you will be prompted. 00192 00193 Other options: 00194 --output <dir> Set output directory (default: $doxyOutput) 00195 --generate-man Generates man page documentation 00196 --version Project version to display in the outut (default: $doxyVersion) 00197 --help Show this help and exit. 00198 00199 00200 END; 00201 exit(0); 00202 break; 00203 } 00204 } 00205 } 00206 00207 // TODO : generate a list of paths )) 00208 00209 if ( $input === '' ) { 00210 echo <<<OPTIONS 00211 Several documentation possibilities: 00212 0 : whole documentation (1 + 2 + 3 + 4) 00213 1 : only includes 00214 2 : only languages 00215 3 : only maintenance 00216 4 : only skins 00217 5 : only a given file 00218 6 : all but the extensions directory 00219 OPTIONS; 00220 while ( !is_numeric( $input ) ) 00221 { 00222 $input = readaline( "\nEnter your choice [0]:" ); 00223 if ( $input == '' ) { 00224 $input = 0; 00225 } 00226 } 00227 } 00228 00229 switch ( $input ) { 00230 case 0: $input = $mwPath; break; 00231 case 1: $input = $mwPathI; break; 00232 case 2: $input = $mwPathL; break; 00233 case 3: $input = $mwPathM; break; 00234 case 4: $input = $mwPathS; break; 00235 case 5: 00236 if ( !isset( $file ) ) { 00237 $file = readaline( "Enter file name $mwPath" ); 00238 } 00239 $input = $mwPath . $file; 00240 break; 00241 case 6: 00242 $input = $mwPath; 00243 $excludePatterns = 'extensions'; 00244 } 00245 00246 // Generate path exclusions 00247 $excludedPaths = $mwPath . join( " $mwPath", $mwExcludePaths ); 00248 print "EXCLUDE: $excludedPaths\n\n"; 00249 00250 $generatedConf = generateConfigFile( $doxygenTemplate, $doxyOutput, $mwPath, $doxyVersion, $input, $excludedPaths, $excludePatterns, $doxyGenerateMan, $doxygenInputFilter ); 00251 $command = $doxygenBin . ' ' . $generatedConf; 00252 00253 echo <<<TEXT 00254 --------------------------------------------------- 00255 Launching the command: 00256 00257 $command 00258 00259 --------------------------------------------------- 00260 00261 TEXT; 00262 00263 $exitcode = 1; 00264 passthru( $command, $exitcode ); 00265 00266 echo <<<TEXT 00267 --------------------------------------------------- 00268 Doxygen execution finished. 00269 Check above for possible errors. 00270 00271 You might want to delete the temporary file $generatedConf 00272 00273 TEXT; 00274 00275 exit( $exitcode );