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