Adding updater for new pf_memory field
[lhc/web/wiklou.git] / maintenance / mwdocgen.php
1 <?php
2 /**
3 * Script to easily generate the mediawiki documentation using doxygen.
4 *
5 * By default it will generate the whole documentation but you will be able to
6 * generate just some parts.
7 *
8 * Usage:
9 * php mwdocgen.php
10 *
11 * Then make a selection from the menu
12 *
13 * KNOWN BUGS:
14 *
15 * - pass_thru seems to always use buffering (even with ob_implicit_flush()),
16 * that make output slow when doxygen parses language files.
17 * - the menu doesnt work, got disabled at revision 13740. Need to code it.
18 *
19 *
20 * @todo document
21 * @addtogroup Maintenance
22 *
23 * @author Ashar Voultoiz <thoane@altern.org>
24 * @version first release
25 */
26
27 #
28 # Variables / Configuration
29 #
30
31 if( php_sapi_name() != 'cli' ) {
32 echo 'Run me from the command line.';
33 die( -1 );
34 }
35
36 /** Figure out the base directory for MediaWiki location */
37 $mwPath = dirname( dirname( __FILE__ ) ) . DIRECTORY_SEPARATOR;
38
39 /** Global variable: temporary directory */
40 $tmpPath = '/tmp/';
41
42 /** doxygen binary script */
43 $doxygenBin = 'doxygen';
44
45 /** doxygen configuration template for mediawiki */
46 $doxygenTemplate = $mwPath . 'maintenance/Doxyfile';
47
48 /** where Phpdoc should output documentation */
49 #$doxyOutput = '/var/www/mwdoc/';
50 $doxyOutput = $mwPath . 'docs' . DIRECTORY_SEPARATOR ;
51
52 /** MediaWiki subpaths */
53 $mwPathI = $mwPath.'includes/';
54 $mwPathL = $mwPath.'languages/';
55 $mwPathM = $mwPath.'maintenance/';
56 $mwPathS = $mwPath.'skins/';
57
58 /** Variable to get user input */
59 $input = '';
60
61 /** shell command that will be run */
62 $command = $doxygenBin;
63
64 #
65 # Functions
66 #
67
68 function readaline( $prompt = '') {
69 print $prompt;
70 $fp = fopen( "php://stdin", "r" );
71 $resp = trim( fgets( $fp, 1024 ) );
72 fclose( $fp );
73 return $resp;
74 }
75
76 /**
77 * Generate a configuration file given user parameters and return the temporary filename.
78 * @param $doxygenTemplate String: full path for the template.
79 * @param $outputDirectory String: directory where the stuff will be output.
80 * @param $stripFromPath String: path that should be stripped out (usually mediawiki base path).
81 * @param $input String: Path to analyze.
82 */
83 function generateConfigFile($doxygenTemplate, $outputDirectory, $stripFromPath, $input) {
84 global $tmpPath ;
85
86 $template = file_get_contents($doxygenTemplate);
87
88 // Replace template placeholders by correct values.
89 $tmpCfg = str_replace(
90 array(
91 '{{OUTPUT_DIRECTORY}}',
92 '{{STRIP_FROM_PATH}}',
93 '{{INPUT}}',
94 ),
95 array(
96 $outputDirectory,
97 $stripFromPath,
98 $input,
99 ),
100 $template
101 );
102 $tmpFileName = $tmpPath . 'mwdocgen'. rand() .'.tmp';
103 file_put_contents( $tmpFileName , $tmpCfg ) or die("Could not write doxygen configuration to file $tmpFileName\n");
104
105 return $tmpFileName;
106 }
107
108 #
109 # Main !
110 #
111
112 unset( $file );
113
114 if( is_array( $argv ) && isset( $argv[1] ) ) {
115 switch( $argv[1] ) {
116 case '--all': $input = 0; break;
117 case '--includes': $input = 1; break;
118 case '--languages': $input = 2; break;
119 case '--maintenance': $input = 3; break;
120 case '--skins': $input = 4; break;
121 case '--file':
122 $input = 5;
123 if( isset( $argv[2] ) ) {
124 $file = $argv[2];
125 }
126 break;
127 }
128 }
129
130 if( $input === '' ) {
131 ?>Several documentation possibilities:
132 0 : whole documentation (1 + 2 + 3 + 4)
133 1 : only includes
134 2 : only languages
135 3 : only maintenance
136 4 : only skins
137 5 : only a given file<?php
138 while ( !is_numeric($input) )
139 {
140 $input = readaline( "\nEnter your choice [0]:" );
141 if($input == '') {
142 $input = 0;
143 }
144 }
145 }
146 /*
147 switch ($input) {
148 case 0:
149 $command .= " -f $mwBaseFiles -d $mwPathI,$mwPathL,$mwPathM,$mwPathS";
150 break;
151 case 1:
152 $command .= "-d $mwPathI";
153 break;
154 case 2:
155 $command .= "-d $mwPathL";
156 break;
157 case 3:
158 $command .= "-d $mwPathM";
159 break;
160 case 4:
161 $command .= "-d $mwPathS";
162 break;
163 case 5:
164 if( !isset( $file ) ) {
165 $file = readaline("Enter file name $mwPath");
166 }
167 $command .= ' -f '.$mwPath.$file;
168 }
169
170 $command .= " -t $pdOutput ".$pdOthers;
171
172 */
173
174 // TODO : generate a list of paths ))
175 $input = $mwPath;
176
177 $generatedConf = generateConfigFile($doxygenTemplate, $doxyOutput, $mwPath, $input );
178 $command = $doxygenBin . ' ' . $generatedConf ;
179
180 ?>
181 ---------------------------------------------------
182 Launching the command:
183
184 <?php echo $command ?>
185
186 ---------------------------------------------------
187 <?php
188
189 passthru($command);
190
191 ?>
192 ---------------------------------------------------
193 Doxygen execution finished.
194 Check above for possible errors.
195
196 You might want to deleted the temporary file <?php echo $generatedConf; ?>
197
198 <?php
199
200 # phpdoc -d ./mediawiki/includes/ ./mediawiki/maintenance/ -f ./mediawiki/*php -t ./mwdoc/ -dn 'MediaWiki' --title 'MediaWiki generated documentation' -o 'HTML:frames:DOM/earthli'
201
202 # phpdoc -f ./mediawiki/includes/GlobalFunctions.php -t ./mwdoc/ -dn 'MediaWiki' --title 'MediaWiki generated documentation' -o 'HTML:frames:DOM/earthli'
203
204 ?>