00001 <?php
00028 #
00029 # Variables / Configuration
00030 #
00031
00032 if( php_sapi_name() != 'cli' ) {
00033 echo 'Run me from the command line.';
00034 die( -1 );
00035 }
00036
00038 $mwPath = dirname( dirname( __FILE__ ) ) . DIRECTORY_SEPARATOR;
00039
00041 $tmpPath = '/tmp/';
00042
00044 $doxygenBin = 'doxygen';
00045
00047 $doxygenTemplate = $mwPath . 'maintenance/Doxyfile';
00048
00050 $svnstat = $mwPath . 'bin/svnstat';
00051
00053 #$doxyOutput = '/var/www/mwdoc/';
00054 $doxyOutput = $mwPath . 'docs' . DIRECTORY_SEPARATOR ;
00055
00057 $mwPathI = $mwPath.'includes/';
00058 $mwPathL = $mwPath.'languages/';
00059 $mwPathM = $mwPath.'maintenance/';
00060 $mwPathS = $mwPath.'skins/';
00061
00063 $input = '';
00064 $exclude = '';
00065
00066 #
00067 # Functions
00068 #
00069
00074 function readaline( $prompt = '' ){
00075 print $prompt;
00076 $fp = fopen( "php://stdin", "r" );
00077 $resp = trim( fgets( $fp, 1024 ) );
00078 fclose( $fp );
00079 return $resp;
00080 }
00081
00087 function getSvnRevision( $dir ) {
00088
00089 $entries = $dir . '/.svn/entries';
00090
00091 if( !file_exists( $entries ) ) {
00092 return false;
00093 }
00094
00095 $content = file( $entries );
00096
00097
00098 if( preg_match( '/^<\?xml/', $content[0] ) ) {
00099
00100 if( !function_exists( 'simplexml_load_file' ) ) {
00101
00102 return false;
00103 }
00104
00105 $xml = simplexml_load_file( $entries );
00106
00107 if( $xml ) {
00108 foreach( $xml->entry as $entry ) {
00109 if( $xml->entry[0]['name'] == '' ) {
00110
00111 if( $entry['revision'] ) {
00112 return intval( $entry['revision'] );
00113 }
00114 }
00115 }
00116 }
00117 return false;
00118 } else {
00119
00120 return intval( $content[3] );
00121 }
00122 }
00123
00135 function generateConfigFile( $doxygenTemplate, $outputDirectory, $stripFromPath, $currentVersion, $svnstat, $input, $exclude ){
00136 global $tmpPath;
00137
00138 $template = file_get_contents( $doxygenTemplate );
00139
00140
00141 $replacements = array(
00142 '{{OUTPUT_DIRECTORY}}' => $outputDirectory,
00143 '{{STRIP_FROM_PATH}}' => $stripFromPath,
00144 '{{CURRENT_VERSION}}' => $currentVersion,
00145 '{{SVNSTAT}}' => $svnstat,
00146 '{{INPUT}}' => $input,
00147 '{{EXCLUDE}}' => $exclude,
00148 );
00149 $tmpCfg = str_replace( array_keys( $replacements ), array_values( $replacements ), $template );
00150 $tmpFileName = $tmpPath . 'mwdocgen'. rand() .'.tmp';
00151 file_put_contents( $tmpFileName , $tmpCfg ) or die("Could not write doxygen configuration to file $tmpFileName\n");
00152
00153 return $tmpFileName;
00154 }
00155
00156 #
00157 # Main !
00158 #
00159
00160 unset( $file );
00161
00162 if( is_array( $argv ) && isset( $argv[1] ) ) {
00163 switch( $argv[1] ) {
00164 case '--all': $input = 0; break;
00165 case '--includes': $input = 1; break;
00166 case '--languages': $input = 2; break;
00167 case '--maintenance': $input = 3; break;
00168 case '--skins': $input = 4; break;
00169 case '--file':
00170 $input = 5;
00171 if( isset( $argv[2] ) ) {
00172 $file = $argv[2];
00173 }
00174 break;
00175 case '--no-extensions': $input = 6; break;
00176 }
00177 }
00178
00179
00180
00181 if( $input === '' ) {
00182 echo <<<OPTIONS
00183 Several documentation possibilities:
00184 0 : whole documentation (1 + 2 + 3 + 4)
00185 1 : only includes
00186 2 : only languages
00187 3 : only maintenance
00188 4 : only skins
00189 5 : only a given file
00190 6 : all but the extensions directory
00191 OPTIONS;
00192 while ( !is_numeric($input) )
00193 {
00194 $input = readaline( "\nEnter your choice [0]:" );
00195 if($input == '') {
00196 $input = 0;
00197 }
00198 }
00199 }
00200
00201 switch ($input) {
00202 case 0: $input = $mwPath; break;
00203 case 1: $input = $mwPathI; break;
00204 case 2: $input = $mwPathL; break;
00205 case 3: $input = $mwPathM; break;
00206 case 4: $input = $mwPathS; break;
00207 case 5:
00208 if( !isset( $file ) ) {
00209 $file = readaline( "Enter file name $mwPath" );
00210 }
00211 $input = $mwPath.$file;
00212 case 6:
00213 $input = $mwPath;
00214 $exclude = 'extensions';
00215 }
00216
00217 $versionNumber = getSvnRevision( $input );
00218 if( $versionNumber === false ){ #Not using subversion ?
00219 $svnstat = ''; # Not really useful if subversion not available
00220 $version = 'trunk'; # FIXME
00221 } else {
00222 $version = "trunk (r$versionNumber)";
00223 }
00224
00225 $generatedConf = generateConfigFile( $doxygenTemplate, $doxyOutput, $mwPath, $version, $svnstat, $input, $exclude );
00226 $command = $doxygenBin . ' ' . $generatedConf;
00227
00228 echo <<<TEXT
00229 ---------------------------------------------------
00230 Launching the command:
00231
00232 $command
00233
00234 ---------------------------------------------------
00235
00236 TEXT;
00237
00238 passthru( $command );
00239
00240 echo <<<TEXT
00241 ---------------------------------------------------
00242 Doxygen execution finished.
00243 Check above for possible errors.
00244
00245 You might want to delete the temporary file $generatedConf
00246
00247 TEXT;