MediaWiki  REL1_20
mwdocgen.php
Go to the documentation of this file.
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 
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 ) {
00120         global $doxygenInputFilter;
00121 
00122         $template = file_get_contents( $doxygenTemplate );
00123         // Replace template placeholders by correct values.
00124         $replacements = array(
00125                 '{{OUTPUT_DIRECTORY}}' => $outputDirectory,
00126                 '{{STRIP_FROM_PATH}}'  => $stripFromPath,
00127                 '{{CURRENT_VERSION}}'  => $currentVersion,
00128                 '{{INPUT}}'            => $input,
00129                 '{{EXCLUDE}}'          => $exclude,
00130                 '{{EXCLUDE_PATTERNS}}' => $excludePatterns,
00131                 '{{HAVE_DOT}}'         => `which dot` ? 'YES' : 'NO',
00132                 '{{GENERATE_MAN}}'     => $doxyGenerateMan ? 'YES' : 'NO',
00133                 '{{INPUT_FILTER}}'     => $doxygenInputFilter,
00134         );
00135         $tmpCfg = str_replace( array_keys( $replacements ), array_values( $replacements ), $template );
00136         $tmpFileName = tempnam( wfTempDir(), 'mwdocgen-' );
00137         file_put_contents( $tmpFileName , $tmpCfg ) or die( "Could not write doxygen configuration to file $tmpFileName\n" );
00138 
00139         return $tmpFileName;
00140 }
00141 
00142 #
00143 # Main !
00144 #
00145 
00146 unset( $file );
00147 
00148 if ( is_array( $argv ) ) {
00149         for ($i = 0; $i < count($argv); $i++ ) {
00150                 switch( $argv[$i] ) {
00151                 case '--all':         $input = 0; break;
00152                 case '--includes':    $input = 1; break;
00153                 case '--languages':   $input = 2; break;
00154                 case '--maintenance': $input = 3; break;
00155                 case '--skins':       $input = 4; break;
00156                 case '--file':
00157                         $input = 5;
00158                         $i++;
00159                         if ( isset( $argv[$i] ) ) {
00160                                 $file = $argv[$i];
00161                         }
00162                         break;
00163                 case '--no-extensions': $input = 6; break;
00164                 case '--output':
00165                         $i++;
00166                         if ( isset( $argv[$i] ) ) {
00167                                 $doxyOutput = realpath( $argv[$i] );
00168                         }
00169                         break;
00170                 case '--version':
00171                         $i++;
00172                         if ( isset( $argv[$i] ) ) {
00173                                 $doxyVersion = $argv[$i];
00174                         }
00175                         break;
00176                 case '--generate-man':
00177                         $doxyGenerateMan = true;
00178                         break;
00179                 case '--help':
00180                         print <<<END
00181 Usage: php mwdocgen.php [<command>] [<options>]
00182 
00183 Commands:
00184     --all           Process entire codebase
00185     --includes      Process only files in includes/ dir
00186     --languages     Process only files in languages/ dir
00187     --maintenance   Process only files in maintenance/ dir
00188     --skins         Process only files in skins/ dir
00189     --file <file>   Process only the given file
00190     --no-extensions Process everything but extensions directorys
00191 
00192 If no command is given, you will be prompted.
00193 
00194 Other options:
00195     --output <dir>  Set output directory (default: $doxyOutput)
00196     --generate-man  Generates man page documentation
00197     --version       Project version to display in the outut (default: $doxyVersion)
00198     --help          Show this help and exit.
00199 
00200 
00201 END;
00202                         exit(0);
00203                         break;
00204                 }
00205         }
00206 }
00207 
00208 // TODO : generate a list of paths ))
00209 
00210 if ( $input === '' ) {
00211         echo <<<OPTIONS
00212 Several documentation possibilities:
00213  0 : whole documentation (1 + 2 + 3 + 4)
00214  1 : only includes
00215  2 : only languages
00216  3 : only maintenance
00217  4 : only skins
00218  5 : only a given file
00219  6 : all but the extensions directory
00220 OPTIONS;
00221         while ( !is_numeric( $input ) )
00222         {
00223                 $input = readaline( "\nEnter your choice [0]:" );
00224                 if ( $input == '' ) {
00225                         $input = 0;
00226                 }
00227         }
00228 }
00229 
00230 switch ( $input ) {
00231 case 0: $input = $mwPath;  break;
00232 case 1: $input = $mwPathI; break;
00233 case 2: $input = $mwPathL; break;
00234 case 3: $input = $mwPathM; break;
00235 case 4: $input = $mwPathS; break;
00236 case 5:
00237         if ( !isset( $file ) ) {
00238                 $file = readaline( "Enter file name $mwPath" );
00239         }
00240         $input = $mwPath . $file;
00241         break;
00242 case 6:
00243         $input = $mwPath;
00244         $excludePatterns = 'extensions';
00245 }
00246 
00247 // Generate path exclusions
00248 $excludedPaths = $mwPath . join( " $mwPath", $mwExcludePaths );
00249 print "EXCLUDE: $excludedPaths\n\n";
00250 
00251 $generatedConf = generateConfigFile( $doxygenTemplate, $doxyOutput, $mwPath, $doxyVersion, $input, $excludedPaths, $excludePatterns, $doxyGenerateMan );
00252 $command = $doxygenBin . ' ' . $generatedConf;
00253 
00254 echo <<<TEXT
00255 ---------------------------------------------------
00256 Launching the command:
00257 
00258 $command
00259 
00260 ---------------------------------------------------
00261 
00262 TEXT;
00263 
00264 passthru( $command );
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;