Remove hard-coded paths from documentation generation script, and don't allow running...
[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 if( is_array( $argv ) && isset( $argv[1] ) && $argv[1] == '--all' ) {
89 # Quick option
90 $input = 0;
91 } else {
92 print <<<END
93 Several documentation possibilities:
94 0 : whole documentation (1 + 2 + 3)
95 1 : only includes
96 2 : only maintenance
97 3 : only skins
98 4 : only a given file
99 END;
100
101 while ( !is_numeric($input) )
102 {
103 $input = readaline( "\nEnter your choice [0]:" );
104 if($input == '') {
105 $input = 0;
106 }
107 }
108 }
109
110 $command = 'phpdoc ';
111 switch ($input) {
112 case 0:
113 $command .= " -f $mwBaseFiles -d $mwPathI,$mwPathM,$mwPathS ";
114 break;
115 case 1:
116 $command .= "-d $mwPathI ";
117 break;
118 case 2:
119 $command .= "-d $mwPathM ";
120 break;
121 case 3:
122 $command .= "-d $mwPathS ";
123 break;
124 case 4:
125 $file = readaline("\Enter file name $mwPath");
126 $command .= ' -f '.$mwPath.$file;
127 }
128
129 $command .= " -t $pdOutput ".$pdOthers;
130
131 print <<<END
132 ---------------------------------------------------
133 Launching the command:
134 $command
135 ---------------------------------------------------
136 END;
137
138 passthru( $command);
139
140 print <<<END
141 ---------------------------------------------------
142 Phpdoc execution finished.
143 Check above for possible errors.
144
145 END;
146
147
148 # phpdoc -d ./mediawiki/includes/ ./mediawiki/maintenance/ -f ./mediawiki/*php -t ./mwdoc/ -dn 'MediaWiki' --title 'MediaWiki generated documentation' -o 'HTML:frames:DOM/earthli'
149
150 # phpdoc -f ./mediawiki/includes/GlobalFunctions.php -t ./mwdoc/ -dn 'MediaWiki' --title 'MediaWiki generated documentation' -o 'HTML:frames:DOM/earthli'
151
152 ?>