MediaWiki  REL1_22
mwdocgen.php
Go to the documentation of this file.
00001 <?php
00036 require_once __DIR__ . '/Maintenance.php';
00037 
00042 class MWDocGen extends Maintenance {
00043 
00047     public function __construct() {
00048         parent::__construct();
00049         $this->mDescription = 'Build doxygen documentation';
00050 
00051         $this->addOption( 'doxygen',
00052             'Path to doxygen',
00053             false, true );
00054         $this->addOption( 'version',
00055             'Pass a MediaWiki version',
00056             false, true );
00057         $this->addOption( 'generate-man',
00058             'Whether to generate man files' );
00059         $this->addOption( 'file',
00060             "Only process given file or directory. Multiple values " .
00061             "accepted with comma separation. Path relative to \$IP.",
00062             false, true );
00063         $this->addOption( 'output',
00064             'Path to write doc to',
00065             false, true );
00066         $this->addOption( 'no-extensions',
00067             'Ignore extensions' );
00068     }
00069 
00070     public function getDbType() {
00071         return Maintenance::DB_NONE;
00072     }
00073 
00074     protected function init() {
00075         global $IP;
00076 
00077         $this->doxygen = $this->getOption( 'doxygen', 'doxygen' );
00078         $this->mwVersion = $this->getOption( 'version', 'master' );
00079 
00080         $this->input = '';
00081         $inputs = explode( ',', $this->getOption( 'file', '' ) );
00082         foreach ( $inputs as $input ) {
00083             # Doxygen inputs are space separted and double quoted
00084             $this->input .= " \"$IP/$input\"";
00085         }
00086 
00087         $this->output = $this->getOption( 'output', "$IP/docs" );
00088 
00089         $this->inputFilter = wfShellWikiCmd(
00090             $IP . '/maintenance/mwdoc-filter.php' );
00091         $this->template = $IP . '/maintenance/Doxyfile';
00092         $this->excludes = array(
00093             'vendor',
00094             'images',
00095             'static',
00096         );
00097         $this->excludePatterns = array();
00098         if ( $this->hasOption( 'no-extensions' ) ) {
00099             $this->excludePatterns[] = 'extensions';
00100         }
00101 
00102         $this->doDot = `which dot`;
00103         $this->doMan = $this->hasOption( 'generate-man' );
00104     }
00105 
00106     public function execute() {
00107         global $IP;
00108 
00109         $this->init();
00110 
00111         # Build out directories we want to exclude
00112         $exclude = '';
00113         foreach ( $this->excludes as $item ) {
00114             $exclude .= " $IP/$item";
00115         }
00116 
00117         $excludePatterns = implode( ' ', $this->excludePatterns );
00118 
00119         $conf = strtr( file_get_contents( $this->template ),
00120             array(
00121                 '{{OUTPUT_DIRECTORY}}' => $this->output,
00122                 '{{STRIP_FROM_PATH}}' => $IP,
00123                 '{{CURRENT_VERSION}}' => $this->mwVersion,
00124                 '{{INPUT}}' => $this->input,
00125                 '{{EXCLUDE}}' => $exclude,
00126                 '{{EXCLUDE_PATTERNS}}' => $excludePatterns,
00127                 '{{HAVE_DOT}}' => $this->doDot ? 'YES' : 'NO',
00128                 '{{GENERATE_MAN}}' => $this->doMan ? 'YES' : 'NO',
00129                 '{{INPUT_FILTER}}' => $this->inputFilter,
00130             )
00131         );
00132 
00133         $tmpFile = tempnam( wfTempDir(), 'MWDocGen-' );
00134         if ( file_put_contents( $tmpFile, $conf ) === false ) {
00135             $this->error( "Could not write doxygen configuration to file $tmpFile\n", 1 );
00137         }
00138 
00139         $command = $this->doxygen . ' ' . $tmpFile;
00140         $this->output( "Executing command:\n$command\n" );
00141 
00142         $exitcode = 1;
00143         system( $command, $exitcode );
00144 
00145         $this->output( <<<TEXT
00146 ---------------------------------------------------
00147 Doxygen execution finished.
00148 Check above for possible errors.
00149 
00150 You might want to delete the temporary file:
00151  $tmpFile
00152 ---------------------------------------------------
00153 
00154 TEXT
00155     );
00156 
00157         if ( $exitcode !== 0 ) {
00158             $this->error( "Something went wrong (exit: $exitcode)\n",
00159                 $exitcode );
00160         }
00161 
00162     }
00163 
00164 }
00165 
00166 $maintClass = 'MWDocGen';
00167 require_once RUN_MAINTENANCE_IF_MAIN;