forked from sigbertklinke/R
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSpecialR.php
More file actions
executable file
·190 lines (167 loc) · 7.65 KB
/
Copy pathSpecialR.php
File metadata and controls
executable file
·190 lines (167 loc) · 7.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
<?php
/*
(C) 2006- Sigbert Klinke (sigbert@wiwi.hu-berlin.de),
Markus Cozowicz, Alex Browne, Michael Cassin
This file is part of R/Octave Extension for Mediawiki.
The R/Octave Extension 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 3 of the
License, or (at your option) any later version.
The R/Octave Extension 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 the R/Octave Extension.
If not, see http://www.gnu.org/licenses/.
*/
class SpecialR extends SpecialPage {
function __construct() {
parent::__construct( 'R' );
}
function extractFromExtLogfile () {
global $extr;
if (file_exists($extr->R_LOG)) {
$cmd = 'tail -n ' . $extr->options['maxloglines'] . ' ' . $extr->R_LOG;
$lines = array();
exec ($cmd, $lines);
$line = implode(array_reverse($lines), "\n");
return ('<pre>' . $line . '</pre>');
}
return ('File not found or not accessible: <tt>'. $extr->R_LOG . '</tt>');
}
function extractFromWebLogfile () {
global $extr;
if (file_exists($extr->options['errlog'])) {
$cmd = 'tail -n ' . $extr->options['maxloglines'] . ' ' . $extr->options['errlog'];
$lines = array();
exec ($cmd, $lines);
foreach ($lines as &$line) {
if ((strpos($line, '/extensions/R/')===false) &&
(strpos($line, '/Rcgi.php')===false)) {
$line = '';
}
}
$line = implode(array_reverse(array_filter($lines)), "\n");
return ('<pre>' . $line . '</pre>');
}
return ('File not found or not accessible: <tt>'. $extr->options['errlog'] . '</tt>');
}
function rglob ($dir, $pattern, $flags=0) {
$files = glob ($dir . $pattern, $flags);
foreach (glob($dir . '*', GLOB_ONLYDIR|GLOB_NOSORT) as $dir) {
$files = array_merge($files, $this->rglob($dir . '/', $pattern, $flags));
}
return ($files);
}
function lastRfiles () {
global $wgOut, $extr;
$exts = array ('.R' => 'rsplus',
'.m' => 'matlab');
$files = $this->rglob(R_DIR, '*.html');
$mtimes = array();
foreach ($files as $file) {
$mtimes[$file] = filemtime($file);
}
arsort($mtimes);
$wgOut->addHTML('<ul>');
$cnt = $extr->options['maxprograms'];
foreach ($mtimes as $file => $mtime) {
$fnp = pathinfo($file);
$wgOut->addHTML('<li><b><tt>' . $fnp['filename'] . '</tt></b>');
foreach ($exts as $ext => $lang) {
$cfn = $fnp['dirname'] . '/' . $fnp['filename'] . $ext;
if (file_exists($cfn)) {
if ($extr->options['usegeshi']) {
$wiki = '<syntaxhighlight lang="' . $lang . '" enclose line>';
$wiki .= file_get_contents($cfn);
$wiki .= '</syntaxhighlight>';
$wgOut->addWikiText($wiki);
} else {
$wgOut->addHTML('<pre>');
$wgOut->addHTML(htmlspecialchars(file_get_contents($cfn)));
$wgOut->addHTML('</pre>');
}
$wgOut->addHTML('<p>' . file_get_contents($file) . '</p></li>');
}
}
$cnt = $cnt-1;
if ($cnt<0) break;
}
$wgOut->addHTML('</ul>');
}
function execute( $par ) {
global $wgOut, $wgServer, $wgScriptPath, $wgUser, $wgArticlePath, $extr;
$this->setHeaders();
$wgOut->addHTML('<h2>Installed engines</h2>');
$wgOut->addHTML('<dl>');
foreach ($extr->engine as $key => $value) {
$wgOut->addHTML('<dt>' . $value->name . '</dt>');
$wgOut->addHTML('<dd><table class="wikitable zebra">');
$wgOut->addHTML('<tr><td>Description</td><td><tt>' . $value->desc . '</tt></td></tr>');
$wgOut->addHTML('<tr><td>Category</td><td><tt>' . $value->category . '</tt></td></tr>');
if ($wgUser->isAllowed('see-specialr')) {
$wgOut->addHTML('<tr><td>Call</td><td><tt>' . $value->cmd . '</tt></td></tr>');
$wgOut->addHTML('<tr><td>Security level</td><td><tt>' . $value->security . '</tt></td></tr>');
$wgOut->addHTML('<tr><td><tt>sudo</tt> call</td><td><tt>' . $value->sudo . '</tt></td></tr>');
$wgOut->addHTML('<tr><td>Graphic conversion call</td><td><tt>' . $value->convert->cmd . '</tt></td></tr>');
$wgOut->addHTML('<tr><td>Graphic conversion</td><td><tt>' . $value->convert->gin . '</tt> -> <tt>' . $value->convert->gout . '</tt></td></tr>');
$wgOut->addHTML('<tr><td>Forbidden commands</td><td>');
foreach ($value->banned as $fctxt => $fcregex) {
$wgOut->addHTML('<tt>' . $fctxt . '</tt>, ');
}
$wgOut->addHTML('</td><td>');
}
$wgOut->addHTML('</table></dd>');
}
$wgOut->addHTML('</dl>');
$wgOut->addHTML('<h2>Further informations</h2>');
if ($wgUser->isAllowed('see-specialr')) {
$wgOut->addHTML('<h3>General</h3>');
$wgOut->addHTML('<table class="wikitable zebra">');
$wgOut->addHTML('<tr><td><a href="http://www.mediawiki.org/wiki/Extension:R">R extension</a> (installed)</td><td><tt>' . $extr->R_VER . '</tt></a></td></tr>');
$wgOut->addHTML('<tr><td>R extension (<a href="http://mars.wiwi.hu-berlin.de/mediawiki/sk/index.php/R_Extension_for_MediaWiki">download</a>)</td><td><tt>' . file_get_contents('http://mars.wiwi.hu-berlin.de/mediawiki/sk/extensions/R/ExtR.ver') . '</tt></a></td></tr>');
$wgOut->addHTML('<tr><td><a href="http://jquery.com">jQuery</a> / <a href="http://jqueryui.com">jQuery UI</a></td><td>');
$wgOut->addModules('ext.R.jQueryVersion');
$wgOut->addHTML('<span id="jQueryVersion">--</span> / <span id="jQueryUIVersion">--</span>');
$wgOut->addHTML('</td></tr>');;
$wgOut->addHTML('<tr><td>Temporary directory</td><td><a href="' . $extr->R_URL . '"><tt>' . R_DIR . '</tt></a></td></tr>');
$wgOut->addHTML('<tr><td>Extension directory</td><td><a href="' . $wgServer . $wgScriptPath . DIRECTORY_SEPARATOR . 'extensions/R"><tt>' . $extr->R_EXT . '</tt></td></tr>');
$wgOut->addHTML('<tr><td>CGI script</td><td><tt>'. $extr->R_CGI . '</tt></td></tr>');
$wgOut->addHTML('<tr><td>Hash method</td><td><tt>' . $extr->R_HASHMTD . '</tt></td></tr>');
$wgOut->addHTML('<tr><td>Start of program</td><td><tt>' . htmlentities($extr->R_SOP) . '</tt></td></tr>');
$wgOut->addHTML('<tr><td>End of program</td><td><tt>' . htmlentities($extr->R_EOP) . '</tt></td></tr>');
$wgOut->addHTML('</table>');
$wgOut->addModules('ext.R.jQueryVersion');
$wgOut->addHTML('<h3>Options</h3>');
$wgOut->addHTML('<table class="wikitable zebra">');
foreach ($extr->options as $key => $val) {
$wgOut->addHTML('<tr><td>');
$wgOut->addHTML(htmlentities($key));
$wgOut->addHTML('</td><td>');
$wgOut->addHTML(htmlentities($val));
$wgOut->addHTML('</td></tr>');
}
$wgOut->addHTML('</table>');
$wgOut->addHTML('<h3>Extension log</h3>');
$wgOut->addHTML($this->extractFromExtLogfile());
$wgOut->addHTML('<h3>Webserver log</h3>');
$wgOut->addHTML($this->extractFromWebLogfile());
$wgOut->addHTML('<h3>Last programs</h3>');
$this->lastRfiles();
}
$wgOut->addHTML('<h3>Alphabetical list of named programs</h3>');
$files = glob(R_DIR . '*.param');
$wgOut->addHTML('<ul>');
foreach ($files as $fn) {
$fnb = basename($fn, '.param');
$fnl = explode('_', $fnb);
$wgOut->addHTML('<li><tt><a href="' . str_replace('$1', rawurldecode($fnl[0]), $wgArticlePath) . '">' . rawurldecode($fnb) . '</a></tt></li>');
}
$wgOut->addHTML('</ul>');
return true;
}
}
?>