Merge "Added SpecialPageAfterExecute and SpecialPageBeforeExecute hooks"
[lhc/web/wiklou.git] / maintenance / mwdocgen.php
index 88b2b90..2edeaba 100644 (file)
@@ -33,7 +33,7 @@
  * @todo document
  * @ingroup Maintenance
  *
- * @author Ashar Voultoiz <hashar at free dot fr>
+ * @author Antoine Musso <hashar at free dot fr>
  * @author Brion Vibber
  * @author Alexandre Emsenhuber
  * @version first release
@@ -77,7 +77,9 @@ $mwExcludePaths = array(
 
 /** Variable to get user input */
 $input = '';
-$exclude_patterns = '';
+$excludePatterns = '';
+/** Whether to generates man pages: */
+$doxyGenerateMan = false;
 
 #
 # Functions
@@ -89,6 +91,7 @@ require_once( "$mwPath/includes/GlobalFunctions.php" );
 /**
  * Read a line from the shell
  * @param $prompt String
+ * @return string
  */
 function readaline( $prompt = '' ) {
        print $prompt;
@@ -113,31 +116,7 @@ function getSvnRevision( $dir ) {
 
        $content = file( $entries );
 
-       // check if file is xml (subversion release <= 1.3) or not (subversion release = 1.4)
-       if ( preg_match( '/^<\?xml/', $content[0] ) ) {
-               // subversion is release <= 1.3
-               if ( !function_exists( 'simplexml_load_file' ) ) {
-                       // We could fall back to expat... YUCK
-                       return false;
-               }
-
-               $xml = simplexml_load_file( $entries );
-
-               if ( $xml ) {
-                       foreach ( $xml->entry as $entry ) {
-                               if ( $xml->entry[0]['name'] == '' ) {
-                                       // The directory entry should always have a revision marker.
-                                       if ( $entry['revision'] ) {
-                                               return intval( $entry['revision'] );
-                                       }
-                               }
-                       }
-               }
-               return false;
-       } else {
-               // subversion is release 1.4
-               return intval( $content[3] );
-       }
+       return intval( $content[3] );
 }
 
 /**
@@ -149,10 +128,12 @@ function getSvnRevision( $dir ) {
  * @param $svnstat String: path to the svnstat file
  * @param $input String: Path to analyze.
  * @param $exclude String: Additionals path regex to exclude
- * @param $exclude_patterns String: Additionals path regex to exclude
+ * @param $excludePatterns String: Additionals path regex to exclude
  *                 (LocalSettings.php, AdminSettings.php, .svn and .git directories are always excluded)
+ * @param $doxyGenerateMan Boolean
+ * @return string
  */
-function generateConfigFile( $doxygenTemplate, $outputDirectory, $stripFromPath, $currentVersion, $svnstat, $input, $exclude_patterns ) {
+function generateConfigFile( $doxygenTemplate, $outputDirectory, $stripFromPath, $currentVersion, $svnstat, $input, $exclude, $excludePatterns, $doxyGenerateMan ) {
 
        $template = file_get_contents( $doxygenTemplate );
 
@@ -164,8 +145,9 @@ function generateConfigFile( $doxygenTemplate, $outputDirectory, $stripFromPath,
                '{{SVNSTAT}}'          => $svnstat,
                '{{INPUT}}'            => $input,
                '{{EXCLUDE}}'          => $exclude,
-               '{{EXCLUDE_PATTERNS}}' => $exclude_patterns,
+               '{{EXCLUDE_PATTERNS}}' => $excludePatterns,
                '{{HAVE_DOT}}'         => `which dot` ? 'YES' : 'NO',
+               '{{GENERATE_MAN}}'     => $doxyGenerateMan ? 'YES' : 'NO',
        );
        $tmpCfg = str_replace( array_keys( $replacements ), array_values( $replacements ), $template );
        $tmpFileName = tempnam( wfTempDir(), 'mwdocgen-' );
@@ -180,20 +162,56 @@ function generateConfigFile( $doxygenTemplate, $outputDirectory, $stripFromPath,
 
 unset( $file );
 
-if ( is_array( $argv ) && isset( $argv[1] ) ) {
-       switch( $argv[1] ) {
-       case '--all':         $input = 0; break;
-       case '--includes':    $input = 1; break;
-       case '--languages':   $input = 2; break;
-       case '--maintenance': $input = 3; break;
-       case '--skins':       $input = 4; break;
-       case '--file':
-               $input = 5;
-               if ( isset( $argv[2] ) ) {
-                       $file = $argv[2];
+if ( is_array( $argv ) ) {
+       for ($i = 0; $i < count($argv); $i++ ) {
+               switch( $argv[$i] ) {
+               case '--all':         $input = 0; break;
+               case '--includes':    $input = 1; break;
+               case '--languages':   $input = 2; break;
+               case '--maintenance': $input = 3; break;
+               case '--skins':       $input = 4; break;
+               case '--file':
+                       $input = 5;
+                       $i++;
+                       if ( isset( $argv[$i] ) ) {
+                               $file = $argv[$i];
+                       }
+                       break;
+               case '--no-extensions': $input = 6; break;
+               case '--output':
+                       $i++;
+                       if ( isset( $argv[$i] ) ) {
+                               $doxyOutput = realpath( $argv[$i] );
+                       }
+                       break;
+               case '--generate-man':
+                       $doxyGenerateMan = true;
+                       break;
+               case '--help':
+                       print <<<END
+Usage: php mwdocgen.php [<command>] [<options>]
+
+Commands:
+    --all           Process entire codebase
+    --includes      Process only files in includes/ dir
+    --languages     Process only files in languages/ dir
+    --maintenance   Process only files in maintenance/ dir
+    --skins         Process only files in skins/ dir
+    --file <file>   Process only the given file
+    --no-extensions Process everything but extensions directorys
+
+If no command is given, you will be prompted.
+
+Other options:
+    --output <dir>  Set output directory (default $doxyOutput)
+    --generate-man  Generates man page documentation
+    --help          Show this help and exit.
+
+
+END;
+                       exit(0);
+                       break;
                }
-               break;
-       case '--no-extensions': $input = 6; break;
        }
 }
 
@@ -230,15 +248,17 @@ case 5:
                $file = readaline( "Enter file name $mwPath" );
        }
        $input = $mwPath . $file;
+       break;
 case 6:
        $input = $mwPath;
-       $exclude_patterns = 'extensions';
+       $excludePatterns = 'extensions';
 }
 
 $versionNumber = getSvnRevision( $input );
 if ( $versionNumber === false ) { # Not using subversion ?
        $svnstat = ''; # Not really useful if subversion not available
-       $version = 'trunk'; # FIXME
+       # @todo FIXME
+       $version = 'trunk';
 } else {
        $version = "trunk (r$versionNumber)";
 }
@@ -247,7 +267,7 @@ if ( $versionNumber === false ) { # Not using subversion ?
 $excludedPaths = $mwPath . join( " $mwPath", $mwExcludePaths );
 print "EXCLUDE: $excludedPaths\n\n";
 
-$generatedConf = generateConfigFile( $doxygenTemplate, $doxyOutput, $mwPath, $version, $svnstat, $input, $excludedPaths, $exclude_patterns );
+$generatedConf = generateConfigFile( $doxygenTemplate, $doxyOutput, $mwPath, $version, $svnstat, $input, $excludedPaths, $excludePatterns, $doxyGenerateMan );
 $command = $doxygenBin . ' ' . $generatedConf;
 
 echo <<<TEXT