handle naming checkpoint file with first/last pageID when the file is empty
[lhc/web/wiklou.git] / maintenance / mwdocgen.php
index c67c2ce..1e0221e 100644 (file)
@@ -1,21 +1,33 @@
 <?php
 /**
- * Script to easily generate the mediawiki documentation using doxygen.
+ * Generate class and file reference documentation for MediaWiki using doxygen.
  *
- * By default it will generate the whole documentation but you will be able to
- * generate just some parts.
+ * If the dot DOT language processor is available, attempt call graph
+ * generation.
  *
  * Usage:
  *   php mwdocgen.php
  *
- * Then make a selection from the menu
- *
  * KNOWN BUGS:
  *
  * - pass_thru seems to always use buffering (even with ob_implicit_flush()),
  * that make output slow when doxygen parses language files.
  * - the menu doesnt work, got disabled at revision 13740. Need to code it.
  *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
  *
  * @file
  * @todo document
@@ -32,7 +44,7 @@
 #
 
 if ( php_sapi_name() != 'cli' ) {
-       echo 'Run me from the command line.';
+       echo 'Run "' . __FILE__ . '" from the command line.';
        die( -1 );
 }
 
@@ -49,7 +61,6 @@ $doxygenTemplate = $mwPath . 'maintenance/Doxyfile';
 $svnstat = $mwPath . 'bin/svnstat';
 
 /** where Phpdoc should output documentation */
-# $doxyOutput = '/var/www/mwdoc/';
 $doxyOutput = $mwPath . 'docs' . DIRECTORY_SEPARATOR ;
 
 /** MediaWiki subpaths */
@@ -58,9 +69,15 @@ $mwPathL = $mwPath . 'languages/';
 $mwPathM = $mwPath . 'maintenance/';
 $mwPathS = $mwPath . 'skins/';
 
+/** Ignored paths relative to $mwPath */
+$mwExcludePaths = array(
+       'images',
+       'static',
+);
+
 /** Variable to get user input */
 $input = '';
-$exclude = '';
+$exclude_patterns = '';
 
 #
 # Functions
@@ -131,14 +148,15 @@ function getSvnRevision( $dir ) {
  * @param $currentVersion String: Version number of the software
  * @param $svnstat String: path to the svnstat file
  * @param $input String: Path to analyze.
- * @param $exclude String: Additionals path regex to exlcude 
- *                 (LocalSettings.php, AdminSettings.php and .svn directories are always excluded)
+ * @param $exclude String: Additionals path regex to exclude
+ * @param $exclude_patterns String: Additionals path regex to exclude
+ *                 (LocalSettings.php, AdminSettings.php, .svn and .git directories are always excluded)
  */
-function generateConfigFile( $doxygenTemplate, $outputDirectory, $stripFromPath, $currentVersion, $svnstat, $input, $exclude ) {
+function generateConfigFile( $doxygenTemplate, $outputDirectory, $stripFromPath, $currentVersion, $svnstat, $input, $exclude, $exclude_patterns ) {
 
        $template = file_get_contents( $doxygenTemplate );
 
-       // Replace template placeholders by correct values.     
+       // Replace template placeholders by correct values.
        $replacements = array(
                '{{OUTPUT_DIRECTORY}}' => $outputDirectory,
                '{{STRIP_FROM_PATH}}'  => $stripFromPath,
@@ -146,6 +164,8 @@ function generateConfigFile( $doxygenTemplate, $outputDirectory, $stripFromPath,
                '{{SVNSTAT}}'          => $svnstat,
                '{{INPUT}}'            => $input,
                '{{EXCLUDE}}'          => $exclude,
+               '{{EXCLUDE_PATTERNS}}' => $exclude_patterns,
+               '{{HAVE_DOT}}'         => `which dot` ? 'YES' : 'NO',
        );
        $tmpCfg = str_replace( array_keys( $replacements ), array_values( $replacements ), $template );
        $tmpFileName = tempnam( wfTempDir(), 'mwdocgen-' );
@@ -160,20 +180,51 @@ 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 '--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
+
+If no command is given, you will be prompted.
+
+Other options:
+    --output <dir>  Set output directory (default $doxyOutput)
+    --help          Show this help and exit.
+
+
+END;
+                       exit(0);
+                       break;
                }
-               break;
-       case '--no-extensions': $input = 6; break;
        }
 }
 
@@ -212,18 +263,23 @@ case 5:
        $input = $mwPath . $file;
 case 6:
        $input = $mwPath;
-       $exclude = 'extensions';
+       $exclude_patterns = '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)";
 }
 
-$generatedConf = generateConfigFile( $doxygenTemplate, $doxyOutput, $mwPath, $version, $svnstat, $input, $exclude );
+// Generate path exclusions
+$excludedPaths = $mwPath . join( " $mwPath", $mwExcludePaths );
+print "EXCLUDE: $excludedPaths\n\n";
+
+$generatedConf = generateConfigFile( $doxygenTemplate, $doxyOutput, $mwPath, $version, $svnstat, $input, $excludedPaths, $exclude_patterns );
 $command = $doxygenBin . ' ' . $generatedConf;
 
 echo <<<TEXT