2004-09-03 23:07:58 +00:00
|
|
|
<?php
|
|
|
|
|
/**
|
2010-12-27 16:56:50 +00:00
|
|
|
* Generate class and file reference documentation for MediaWiki using doxygen.
|
2004-09-03 23:07:58 +00:00
|
|
|
*
|
2010-12-27 16:56:50 +00:00
|
|
|
* If the dot DOT language processor is available, attempt call graph
|
|
|
|
|
* generation.
|
2004-09-03 23:07:58 +00:00
|
|
|
*
|
|
|
|
|
* Usage:
|
|
|
|
|
* php mwdocgen.php
|
|
|
|
|
*
|
2010-12-16 19:15:12 +00:00
|
|
|
* 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
|
2006-04-19 15:46:24 +00:00
|
|
|
*
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
* @file
|
2004-09-03 23:07:58 +00:00
|
|
|
* @todo document
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
* @ingroup Maintenance
|
2004-09-03 23:07:58 +00:00
|
|
|
*
|
2011-10-24 09:08:13 +00:00
|
|
|
* @author Antoine Musso <hashar at free dot fr>
|
2024-02-09 01:02:16 +00:00
|
|
|
* @author Brooke Vibber
|
2010-09-27 18:46:16 +00:00
|
|
|
* @author Alexandre Emsenhuber
|
2004-09-03 23:07:58 +00:00
|
|
|
* @version first release
|
|
|
|
|
*/
|
|
|
|
|
|
2019-04-07 11:36:22 +00:00
|
|
|
use MediaWiki\Shell\Shell;
|
|
|
|
|
|
2024-08-27 12:00:25 +00:00
|
|
|
// @codeCoverageIgnoreStart
|
2013-05-21 22:04:11 +00:00
|
|
|
require_once __DIR__ . '/Maintenance.php';
|
2024-08-27 12:00:25 +00:00
|
|
|
// @codeCoverageIgnoreEnd
|
2008-06-25 13:42:01 +00:00
|
|
|
|
2006-04-19 15:46:24 +00:00
|
|
|
/**
|
2013-05-21 22:04:11 +00:00
|
|
|
* Maintenance script that builds doxygen documentation.
|
|
|
|
|
* @ingroup Maintenance
|
2006-04-19 15:46:24 +00:00
|
|
|
*/
|
2013-05-21 22:04:11 +00:00
|
|
|
class MWDocGen extends Maintenance {
|
2019-09-09 09:11:50 +00:00
|
|
|
/** @var string */
|
|
|
|
|
private $doxygen;
|
|
|
|
|
/** @var string */
|
|
|
|
|
private $mwVersion;
|
|
|
|
|
/** @var string */
|
|
|
|
|
private $output;
|
|
|
|
|
/** @var string */
|
|
|
|
|
private $input;
|
|
|
|
|
/** @var string */
|
|
|
|
|
private $inputFilter;
|
|
|
|
|
/** @var string */
|
|
|
|
|
private $template;
|
|
|
|
|
/** @var string[] */
|
|
|
|
|
private $excludes;
|
|
|
|
|
/** @var bool */
|
|
|
|
|
private $doDot;
|
2013-05-21 22:04:11 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Prepare Maintenance class
|
|
|
|
|
*/
|
|
|
|
|
public function __construct() {
|
|
|
|
|
parent::__construct();
|
2016-01-30 02:48:47 +00:00
|
|
|
$this->addDescription( 'Build doxygen documentation' );
|
2013-05-21 22:04:11 +00:00
|
|
|
|
|
|
|
|
$this->addOption( 'doxygen',
|
|
|
|
|
'Path to doxygen',
|
|
|
|
|
false, true );
|
|
|
|
|
$this->addOption( 'version',
|
|
|
|
|
'Pass a MediaWiki version',
|
|
|
|
|
false, true );
|
|
|
|
|
$this->addOption( 'file',
|
2013-05-30 18:41:27 +00:00
|
|
|
"Only process given file or directory. Multiple values " .
|
2024-03-25 23:35:49 +00:00
|
|
|
"accepted with comma separation. Path relative to MW_INSTALL_PATH.",
|
2013-05-21 22:04:11 +00:00
|
|
|
false, true );
|
|
|
|
|
$this->addOption( 'output',
|
|
|
|
|
'Path to write doc to',
|
|
|
|
|
false, true );
|
2019-09-14 18:31:53 +00:00
|
|
|
$this->addOption( 'extensions',
|
|
|
|
|
'Process the extensions/ directory as well (ignored if --file is used)' );
|
|
|
|
|
$this->addOption( 'skins',
|
|
|
|
|
'Process the skins/ directory as well (ignored if --file is used)' );
|
2013-05-21 22:04:11 +00:00
|
|
|
}
|
2004-09-04 08:54:59 +00:00
|
|
|
|
2013-05-21 22:04:11 +00:00
|
|
|
public function getDbType() {
|
|
|
|
|
return Maintenance::DB_NONE;
|
|
|
|
|
}
|
2011-09-14 21:38:26 +00:00
|
|
|
|
2013-05-21 22:04:11 +00:00
|
|
|
protected function init() {
|
2024-03-25 23:35:49 +00:00
|
|
|
global $wgPhpCli;
|
2013-05-21 22:04:11 +00:00
|
|
|
|
|
|
|
|
$this->doxygen = $this->getOption( 'doxygen', 'doxygen' );
|
|
|
|
|
$this->mwVersion = $this->getOption( 'version', 'master' );
|
2013-05-30 18:41:27 +00:00
|
|
|
|
2024-03-25 23:35:49 +00:00
|
|
|
$this->output = $this->getOption( 'output', 'docs' );
|
2013-05-21 22:04:11 +00:00
|
|
|
|
2017-05-04 00:04:29 +00:00
|
|
|
// Do not use wfShellWikiCmd, because mwdoc-filter.php is not
|
|
|
|
|
// a Maintenance script.
|
2019-04-07 11:36:22 +00:00
|
|
|
$this->inputFilter = Shell::escape( [
|
2017-05-04 00:04:29 +00:00
|
|
|
$wgPhpCli,
|
2024-03-25 23:35:49 +00:00
|
|
|
MW_INSTALL_PATH . '/maintenance/mwdoc-filter.php'
|
2017-05-04 00:04:29 +00:00
|
|
|
] );
|
|
|
|
|
|
2024-03-25 23:35:49 +00:00
|
|
|
$this->template = MW_INSTALL_PATH . '/maintenance/Doxyfile';
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->excludes = [
|
2022-09-09 23:13:32 +00:00
|
|
|
'cache',
|
2013-05-21 22:04:11 +00:00
|
|
|
'images',
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2024-03-13 23:44:50 +00:00
|
|
|
|
|
|
|
|
$file = $this->getOption( 'file' );
|
|
|
|
|
if ( $file !== null ) {
|
|
|
|
|
$this->input = '';
|
|
|
|
|
foreach ( explode( ',', $file ) as $input ) {
|
|
|
|
|
// Doxygen inputs are space separated and double quoted
|
|
|
|
|
$this->input .= " \"$input\"";
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2024-03-09 02:44:23 +00:00
|
|
|
// If no explicit --file filter is set, we're indexing all of MediaWiki core
|
2024-03-25 23:35:49 +00:00
|
|
|
// in MW_INSTALL_PATH, but not extension and skin submodules (T317451).
|
2024-03-13 23:44:50 +00:00
|
|
|
$this->input = '';
|
2019-09-14 18:31:53 +00:00
|
|
|
if ( !$this->hasOption( 'extensions' ) ) {
|
2024-03-09 02:44:23 +00:00
|
|
|
$this->excludes[] = 'extensions';
|
2019-09-14 18:31:53 +00:00
|
|
|
}
|
|
|
|
|
if ( !$this->hasOption( 'skins' ) ) {
|
2024-03-09 02:44:23 +00:00
|
|
|
$this->excludes[] = 'skins';
|
2019-09-14 18:31:53 +00:00
|
|
|
}
|
2013-05-21 22:04:11 +00:00
|
|
|
}
|
2011-09-14 21:38:26 +00:00
|
|
|
|
2022-03-05 20:05:01 +00:00
|
|
|
$this->doDot = (bool)shell_exec( 'which dot' );
|
2013-05-21 22:04:11 +00:00
|
|
|
}
|
2011-09-14 21:38:26 +00:00
|
|
|
|
2013-05-21 22:04:11 +00:00
|
|
|
public function execute() {
|
|
|
|
|
$this->init();
|
2011-09-14 21:38:26 +00:00
|
|
|
|
2013-05-21 22:04:11 +00:00
|
|
|
# Build out directories we want to exclude
|
|
|
|
|
$exclude = '';
|
|
|
|
|
foreach ( $this->excludes as $item ) {
|
2024-03-25 23:35:49 +00:00
|
|
|
$exclude .= " $item";
|
2004-09-04 08:54:59 +00:00
|
|
|
}
|
2008-06-25 13:42:01 +00:00
|
|
|
|
2013-05-21 22:04:11 +00:00
|
|
|
$conf = strtr( file_get_contents( $this->template ),
|
2016-02-17 09:09:32 +00:00
|
|
|
[
|
2013-05-21 22:04:11 +00:00
|
|
|
'{{OUTPUT_DIRECTORY}}' => $this->output,
|
|
|
|
|
'{{CURRENT_VERSION}}' => $this->mwVersion,
|
|
|
|
|
'{{INPUT}}' => $this->input,
|
|
|
|
|
'{{EXCLUDE}}' => $exclude,
|
|
|
|
|
'{{HAVE_DOT}}' => $this->doDot ? 'YES' : 'NO',
|
|
|
|
|
'{{INPUT_FILTER}}' => $this->inputFilter,
|
2016-02-17 09:09:32 +00:00
|
|
|
]
|
2013-05-21 22:04:11 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$tmpFile = tempnam( wfTempDir(), 'MWDocGen-' );
|
|
|
|
|
if ( file_put_contents( $tmpFile, $conf ) === false ) {
|
2017-11-20 00:36:54 +00:00
|
|
|
$this->fatalError( "Could not write doxygen configuration to file $tmpFile\n" );
|
2004-09-04 01:58:17 +00:00
|
|
|
}
|
2004-09-03 23:07:58 +00:00
|
|
|
|
2013-05-21 22:04:11 +00:00
|
|
|
$command = $this->doxygen . ' ' . $tmpFile;
|
|
|
|
|
$this->output( "Executing command:\n$command\n" );
|
2011-02-08 22:33:57 +00:00
|
|
|
|
2013-05-21 22:04:11 +00:00
|
|
|
$exitcode = 1;
|
|
|
|
|
system( $command, $exitcode );
|
2006-04-19 15:46:24 +00:00
|
|
|
|
2013-05-21 22:04:11 +00:00
|
|
|
$this->output( <<<TEXT
|
2004-09-03 23:07:58 +00:00
|
|
|
---------------------------------------------------
|
2013-05-21 22:04:11 +00:00
|
|
|
Doxygen execution finished.
|
|
|
|
|
Check above for possible errors.
|
2005-04-07 19:46:06 +00:00
|
|
|
|
2013-05-21 22:04:11 +00:00
|
|
|
You might want to delete the temporary file:
|
|
|
|
|
$tmpFile
|
2004-09-03 23:07:58 +00:00
|
|
|
---------------------------------------------------
|
|
|
|
|
|
2013-05-21 22:04:11 +00:00
|
|
|
TEXT
|
2014-04-23 18:09:13 +00:00
|
|
|
);
|
2008-06-25 13:42:01 +00:00
|
|
|
|
2013-05-21 22:04:11 +00:00
|
|
|
if ( $exitcode !== 0 ) {
|
2017-11-20 00:36:54 +00:00
|
|
|
$this->fatalError( "Something went wrong (exit: $exitcode)\n", $exitcode );
|
2013-05-21 22:04:11 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-03-15 05:43:56 +00:00
|
|
|
|
2024-08-27 12:00:25 +00:00
|
|
|
// @codeCoverageIgnoreStart
|
2018-01-13 00:02:09 +00:00
|
|
|
$maintClass = MWDocGen::class;
|
2013-05-21 22:04:11 +00:00
|
|
|
require_once RUN_MAINTENANCE_IF_MAIN;
|
2024-08-27 12:00:25 +00:00
|
|
|
// @codeCoverageIgnoreEnd
|