MediaWiki
REL1_19
|
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( dirname( __FILE__ ) ) . DIRECTORY_SEPARATOR; 00053 00055 $doxygenBin = 'doxygen'; 00056 00058 $doxygenTemplate = $mwPath . 'maintenance/Doxyfile'; 00059 00061 $doxyOutput = $mwPath . 'docs' . DIRECTORY_SEPARATOR ; 00062 00063 $doxyVersion = 'master'; 00064 00066 $mwPathI = $mwPath . 'includes/'; 00067 $mwPathL = $mwPath . 'languages/'; 00068 $mwPathM = $mwPath . 'maintenance/'; 00069 $mwPathS = $mwPath . 'skins/'; 00070 00072 $mwExcludePaths = array( 00073 'images', 00074 'static', 00075 ); 00076 00078 $input = ''; 00079 $exclude_patterns = ''; 00080 00081 # 00082 # Functions 00083 # 00084 00085 define( 'MEDIAWIKI', true ); 00086 require_once( "$mwPath/includes/GlobalFunctions.php" ); 00087 00093 function readaline( $prompt = '' ) { 00094 print $prompt; 00095 $fp = fopen( "php://stdin", "r" ); 00096 $resp = trim( fgets( $fp, 1024 ) ); 00097 fclose( $fp ); 00098 return $resp; 00099 } 00100 00113 function generateConfigFile( $doxygenTemplate, $outputDirectory, $stripFromPath, $currentVersion, $input, $exclude, $exclude_patterns ) { 00114 global $wgDoxyGenerateMan; 00115 00116 $template = file_get_contents( $doxygenTemplate ); 00117 00118 // Replace template placeholders by correct values. 00119 $replacements = array( 00120 '{{OUTPUT_DIRECTORY}}' => $outputDirectory, 00121 '{{STRIP_FROM_PATH}}' => $stripFromPath, 00122 '{{CURRENT_VERSION}}' => $currentVersion, 00123 '{{INPUT}}' => $input, 00124 '{{EXCLUDE}}' => $exclude, 00125 '{{EXCLUDE_PATTERNS}}' => $exclude_patterns, 00126 '{{HAVE_DOT}}' => `which dot` ? 'YES' : 'NO', 00127 '{{GENERATE_MAN}}' => $wgDoxyGenerateMan ? 'YES' : 'NO', 00128 ); 00129 $tmpCfg = str_replace( array_keys( $replacements ), array_values( $replacements ), $template ); 00130 $tmpFileName = tempnam( wfTempDir(), 'mwdocgen-' ); 00131 file_put_contents( $tmpFileName , $tmpCfg ) or die( "Could not write doxygen configuration to file $tmpFileName\n" ); 00132 00133 return $tmpFileName; 00134 } 00135 00136 # 00137 # Main ! 00138 # 00139 00140 unset( $file ); 00141 00142 if ( is_array( $argv ) ) { 00143 for ($i = 0; $i < count($argv); $i++ ) { 00144 switch( $argv[$i] ) { 00145 case '--all': $input = 0; break; 00146 case '--includes': $input = 1; break; 00147 case '--languages': $input = 2; break; 00148 case '--maintenance': $input = 3; break; 00149 case '--skins': $input = 4; break; 00150 case '--file': 00151 $input = 5; 00152 $i++; 00153 if ( isset( $argv[$i] ) ) { 00154 $file = $argv[$i]; 00155 } 00156 break; 00157 case '--no-extensions': $input = 6; break; 00158 case '--output': 00159 $i++; 00160 if ( isset( $argv[$i] ) ) { 00161 $doxyOutput = realpath( $argv[$i] ); 00162 } 00163 break; 00164 case '--version': 00165 $i++; 00166 if ( isset( $argv[$i] ) ) { 00167 $doxyVersion = $argv[$i]; 00168 } 00169 break; 00170 case '--generate-man': 00171 $wgDoxyGenerateMan = true; 00172 break; 00173 case '--help': 00174 print <<<END 00175 Usage: php mwdocgen.php [<command>] [<options>] 00176 00177 Commands: 00178 --all Process entire codebase 00179 --includes Process only files in includes/ dir 00180 --languages Process only files in languages/ dir 00181 --maintenance Process only files in maintenance/ dir 00182 --skins Process only files in skins/ dir 00183 --file <file> Process only the given file 00184 --no-extensions Process everything but extensions directorys 00185 00186 If no command is given, you will be prompted. 00187 00188 Other options: 00189 --output <dir> Set output directory (default: $doxyOutput) 00190 --generate-man Generates man page documentation 00191 --version Project version to display in the outut (default: $doxyVersion) 00192 --help Show this help and exit. 00193 00194 00195 END; 00196 exit(0); 00197 break; 00198 } 00199 } 00200 } 00201 00202 // TODO : generate a list of paths )) 00203 00204 if ( $input === '' ) { 00205 echo <<<OPTIONS 00206 Several documentation possibilities: 00207 0 : whole documentation (1 + 2 + 3 + 4) 00208 1 : only includes 00209 2 : only languages 00210 3 : only maintenance 00211 4 : only skins 00212 5 : only a given file 00213 6 : all but the extensions directory 00214 OPTIONS; 00215 while ( !is_numeric( $input ) ) 00216 { 00217 $input = readaline( "\nEnter your choice [0]:" ); 00218 if ( $input == '' ) { 00219 $input = 0; 00220 } 00221 } 00222 } 00223 00224 switch ( $input ) { 00225 case 0: $input = $mwPath; break; 00226 case 1: $input = $mwPathI; break; 00227 case 2: $input = $mwPathL; break; 00228 case 3: $input = $mwPathM; break; 00229 case 4: $input = $mwPathS; break; 00230 case 5: 00231 if ( !isset( $file ) ) { 00232 $file = readaline( "Enter file name $mwPath" ); 00233 } 00234 $input = $mwPath . $file; 00235 case 6: 00236 $input = $mwPath; 00237 $exclude_patterns = 'extensions'; 00238 } 00239 00240 // Generate path exclusions 00241 $excludedPaths = $mwPath . join( " $mwPath", $mwExcludePaths ); 00242 print "EXCLUDE: $excludedPaths\n\n"; 00243 00244 $generatedConf = generateConfigFile( $doxygenTemplate, $doxyOutput, $mwPath, $doxyVersion, $input, $excludedPaths, $exclude_patterns ); 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;