More command-line options so I can just hit 'up, enter' instead of the tedious prompt. :)
[lhc/web/wiklou.git] / maintenance / mwdocgen.php
1 <?php
2 /**
3 * Script to easily generate the mediawiki documentation.
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 * @todo document
14 * @package MediaWiki
15 * @subpackage Maintenance
16 *
17 * @author Ashar Voultoiz <thoane@altern.org>
18 * @version first release
19 */
20
21 #
22 # Variables / Configuration
23 #
24
25 if( php_sapi_name() != 'cli' ) {
26 die( "Run me from the command line." );
27 }
28
29 /** Phpdoc script with full path */
30 #$pdExec = '/usr/bin/phpdoc';
31 $pdExec = 'phpdoc';
32
33 /** Figure out the base directory. This is harder than it should be. */
34 /** Since we're on the command line, don't trust the PWD! */
35 $here = null;
36 $self = $_SERVER['SCRIPT_FILENAME'];
37 $sep = DIRECTORY_SEPARATOR;
38 foreach( get_included_files() as $f ) {
39 if( preg_match( "!^(.*)maintenance$sep$self\$!", $f, $matches ) ) {
40 $here = $matches[1];
41 }
42 }
43 if( is_null( $here ) ) {
44 die( "Couldn't determine current directory.\n" );
45 }
46
47 /** where Phpdoc should output documentation */
48 #$pdOutput = '/var/www/mwdoc/';
49 $pdOutput = "{$here}{$sep}docs{$sep}html";
50
51 /** Some more Phpdoc settings */
52 $pdOthers = '';
53 //$pdOthers = ' -dn \'MediaWiki\' ';
54 $pdOthers .= ' --title \'MediaWiki generated documentation\' -o \'HTML:frames:DOM/earthli\' ';
55
56 /** MediaWiki location */
57 #$mwPath = '/var/www/mediawiki/';
58 $mwPath = "{$here}{$sep}";
59
60 /** MediaWiki subpaths */
61 $mwPathI = $mwPath.'includes/';
62 $mwPathM = $mwPath.'maintenance/';
63 $mwPathS = $mwPath.'skins/';
64 $mwBaseFiles = $mwPath.'*php ';
65
66
67 /** Variable to get user input */
68 $input = '';
69 /** shell command that will be run */
70 $command = '';
71
72 #
73 # Functions
74 #
75
76 function readaline( $prompt = '') {
77 print $prompt;
78 $fp = fopen( "php://stdin", "r" );
79 $resp = trim( fgets( $fp, 1024 ) );
80 fclose( $fp );
81 return $resp;
82 }
83
84 #
85 # Main !
86 #
87
88 unset( $file );
89
90 if( is_array( $argv ) && isset( $argv[1] ) ) {
91 switch( $argv[1] ) {
92 case '--all': $input = 0; break;
93 case '--includes': $input = 1; break;
94 case '--maintenance': $input = 2; break;
95 case '--skins': $input = 2; break;
96 case '--file':
97 $input = 4;
98 if( isset( $argv[2] ) ) {
99 $file = $argv[2];
100 }
101 break;
102 }
103 }
104
105 if( $input === '' ) {
106 print <<<END
107 Several documentation possibilities:
108 0 : whole documentation (1 + 2 + 3)
109 1 : only includes
110 2 : only maintenance
111 3 : only skins
112 4 : only a given file
113 END;
114
115 while ( !is_numeric($input) )
116 {
117 $input = readaline( "\nEnter your choice [0]:" );
118 if($input == '') {
119 $input = 0;
120 }
121 }
122 }
123
124 $command = 'phpdoc ';
125 switch ($input) {
126 case 0:
127 $command .= " -f $mwBaseFiles -d $mwPathI,$mwPathM,$mwPathS ";
128 break;
129 case 1:
130 $command .= "-d $mwPathI ";
131 break;
132 case 2:
133 $command .= "-d $mwPathM ";
134 break;
135 case 3:
136 $command .= "-d $mwPathS ";
137 break;
138 case 4:
139 if( !isset( $file ) ) {
140 $file = readaline("\Enter file name $mwPath");
141 }
142 $command .= ' -f '.$mwPath.$file;
143 }
144
145 $command .= " -t $pdOutput ".$pdOthers;
146
147 print <<<END
148 ---------------------------------------------------
149 Launching the command:
150 $command
151 ---------------------------------------------------
152 END;
153
154 passthru( $command);
155
156 print <<<END
157 ---------------------------------------------------
158 Phpdoc execution finished.
159 Check above for possible errors.
160
161 END;
162
163
164 # phpdoc -d ./mediawiki/includes/ ./mediawiki/maintenance/ -f ./mediawiki/*php -t ./mwdoc/ -dn 'MediaWiki' --title 'MediaWiki generated documentation' -o 'HTML:frames:DOM/earthli'
165
166 # phpdoc -f ./mediawiki/includes/GlobalFunctions.php -t ./mwdoc/ -dn 'MediaWiki' --title 'MediaWiki generated documentation' -o 'HTML:frames:DOM/earthli'
167
168 ?>