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