MediaWiki  1.32.5
mwdocgen.php
Go to the documentation of this file.
1 <?php
36 require_once __DIR__ . '/Maintenance.php';
37 
42 class MWDocGen extends Maintenance {
43 
47  public function __construct() {
48  parent::__construct();
49  $this->addDescription( 'Build doxygen documentation' );
50 
51  $this->addOption( 'doxygen',
52  'Path to doxygen',
53  false, true );
54  $this->addOption( 'version',
55  'Pass a MediaWiki version',
56  false, true );
57  $this->addOption( 'generate-man',
58  'Whether to generate man files' );
59  $this->addOption( 'file',
60  "Only process given file or directory. Multiple values " .
61  "accepted with comma separation. Path relative to \$IP.",
62  false, true );
63  $this->addOption( 'output',
64  'Path to write doc to',
65  false, true );
66  $this->addOption( 'no-extensions',
67  'Ignore extensions' );
68  }
69 
70  public function getDbType() {
71  return Maintenance::DB_NONE;
72  }
73 
74  protected function init() {
75  global $wgPhpCli, $IP;
76 
77  $this->doxygen = $this->getOption( 'doxygen', 'doxygen' );
78  $this->mwVersion = $this->getOption( 'version', 'master' );
79 
80  $this->input = '';
81  $inputs = explode( ',', $this->getOption( 'file', '' ) );
82  foreach ( $inputs as $input ) {
83  # Doxygen inputs are space separted and double quoted
84  $this->input .= " \"$IP/$input\"";
85  }
86 
87  $this->output = $this->getOption( 'output', "$IP/docs" );
88 
89  // Do not use wfShellWikiCmd, because mwdoc-filter.php is not
90  // a Maintenance script.
91  $this->inputFilter = wfEscapeShellArg( [
92  $wgPhpCli,
93  $IP . '/maintenance/mwdoc-filter.php'
94  ] );
95 
96  $this->template = $IP . '/maintenance/Doxyfile';
97  $this->excludes = [
98  'vendor',
99  'node_modules',
100  'images',
101  'static',
102  ];
103  $this->excludePatterns = [];
104  if ( $this->hasOption( 'no-extensions' ) ) {
105  $this->excludePatterns[] = 'extensions';
106  }
107 
108  $this->doDot = shell_exec( 'which dot' );
109  $this->doMan = $this->hasOption( 'generate-man' );
110  }
111 
112  public function execute() {
113  global $IP;
114 
115  $this->init();
116 
117  # Build out directories we want to exclude
118  $exclude = '';
119  foreach ( $this->excludes as $item ) {
120  $exclude .= " $IP/$item";
121  }
122 
123  $excludePatterns = implode( ' ', $this->excludePatterns );
124 
125  $conf = strtr( file_get_contents( $this->template ),
126  [
127  '{{OUTPUT_DIRECTORY}}' => $this->output,
128  '{{STRIP_FROM_PATH}}' => $IP,
129  '{{CURRENT_VERSION}}' => $this->mwVersion,
130  '{{INPUT}}' => $this->input,
131  '{{EXCLUDE}}' => $exclude,
132  '{{EXCLUDE_PATTERNS}}' => $excludePatterns,
133  '{{HAVE_DOT}}' => $this->doDot ? 'YES' : 'NO',
134  '{{GENERATE_MAN}}' => $this->doMan ? 'YES' : 'NO',
135  '{{INPUT_FILTER}}' => $this->inputFilter,
136  ]
137  );
138 
139  $tmpFile = tempnam( wfTempDir(), 'MWDocGen-' );
140  if ( file_put_contents( $tmpFile, $conf ) === false ) {
141  $this->fatalError( "Could not write doxygen configuration to file $tmpFile\n" );
142  }
143 
144  $command = $this->doxygen . ' ' . $tmpFile;
145  $this->output( "Executing command:\n$command\n" );
146 
147  $exitcode = 1;
148  system( $command, $exitcode );
149 
150  $this->output( <<<TEXT
151 ---------------------------------------------------
152 Doxygen execution finished.
153 Check above for possible errors.
154 
155 You might want to delete the temporary file:
156  $tmpFile
157 ---------------------------------------------------
158 
159 TEXT
160  );
161 
162  if ( $exitcode !== 0 ) {
163  $this->fatalError( "Something went wrong (exit: $exitcode)\n", $exitcode );
164  }
165  }
166 }
167 
169 require_once RUN_MAINTENANCE_IF_MAIN;
$wgPhpCli
$wgPhpCli
Executable path of the PHP cli binary.
Definition: DefaultSettings.php:8349
file
Using a hook running we can avoid having all this option specific stuff in our mainline code Using the function We ve cleaned up the code here by removing clumps of infrequently used code and moving them off somewhere else It s much easier for someone working with this code to see what s _really_ going and make changes or fix bugs In we can take all the code that deals with the little used title reversing we can concentrate it all in an extension file
Definition: hooks.txt:91
MWDocGen\getDbType
getDbType()
Does the script need different DB access? By default, we give Maintenance scripts normal rights to th...
Definition: mwdocgen.php:70
errors
the value of this variable comes from LanguageConverter indexed by page_id indexed by prefixed DB keys on which the links will be shown can modify can modify can modify this should be populated with an alert message to that effect to be fed to an HTMLForm object and populate $result with the reason in the form of[messagename, param1, param2,...] or a MessageSpecifier error messages should be plain text with no special etc to show that they re errors
Definition: hooks.txt:1788
Maintenance\fatalError
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
Definition: Maintenance.php:465
Maintenance\addDescription
addDescription( $text)
Set the description text.
Definition: Maintenance.php:317
MWDocGen
Maintenance script that builds doxygen documentation.
Definition: mwdocgen.php:42
RUN_MAINTENANCE_IF_MAIN
require_once RUN_MAINTENANCE_IF_MAIN
Definition: maintenance.txt:50
Maintenance
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
Definition: maintenance.txt:39
MWDocGen\init
init()
Definition: mwdocgen.php:74
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
$input
if(is_array( $mode)) switch( $mode) $input
Definition: postprocess-phan.php:141
MWDocGen\execute
execute()
Do the actual work.
Definition: mwdocgen.php:112
Maintenance\addOption
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
Definition: Maintenance.php:236
$IP
$IP
Definition: update.php:3
MWDocGen\__construct
__construct()
Prepare Maintenance class.
Definition: mwdocgen.php:47
$command
$command
Definition: cdb.php:65
above
and give any other recipients of the Program a copy of this License along with the Program You may charge a fee for the physical act of transferring a and you may at your option offer warranty protection in exchange for a fee You may modify your copy or copies of the Program or any portion of thus forming a work based on the and copy and distribute such modifications or work under the terms of Section above
Definition: COPYING.txt:87
Maintenance\DB_NONE
const DB_NONE
Constants for DB access type.
Definition: Maintenance.php:65
wfTempDir
wfTempDir()
Tries to get the system directory for temporary files.
Definition: GlobalFunctions.php:2031
Maintenance\getOption
getOption( $name, $default=null)
Get an option, or return the default.
Definition: Maintenance.php:271
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
wfEscapeShellArg
wfEscapeShellArg(... $args)
Version of escapeshellarg() that works better on Windows.
Definition: GlobalFunctions.php:2183
system
this section has the sole purpose of protecting the integrity of the free software distribution system
Definition: COPYING.txt:218
Maintenance\output
output( $out, $channel=null)
Throw some output to the user.
Definition: Maintenance.php:414
class
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
Definition: maintenance.txt:52
Maintenance\hasOption
hasOption( $name)
Checks to see if a particular option exists.
Definition: Maintenance.php:257
$maintClass
$maintClass
Definition: mwdocgen.php:159