Merge "Whitelist the <wbr> element."
[mediawiki.git] / includes / profiler / ProfilerSimpleText.php
blob1d57ea8d9776661fecf5b7105a98ff605affe48d
1 <?php
2 /**
3 * Profiler showing output in page source.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
20 * @file
21 * @ingroup Profiler
24 /**
25 * The least sophisticated profiler output class possible, view your source! :)
27 * Put the following 2 lines in StartProfiler.php:
29 * $wgProfiler['class'] = 'ProfilerSimpleText';
30 * $wgProfiler['visible'] = true;
32 * @ingroup Profiler
34 class ProfilerSimpleText extends ProfilerSimple {
35 public $visible = false; /* Show as <PRE> or <!-- ? */
36 static private $out;
38 public function __construct( $profileConfig ) {
39 if ( isset( $profileConfig['visible'] ) && $profileConfig['visible'] ) {
40 $this->visible = true;
42 parent::__construct( $profileConfig );
45 public function logData() {
46 if ( $this->mTemplated ) {
47 $this->close();
48 $totalReal = isset( $this->mCollated['-total'] )
49 ? $this->mCollated['-total']['real']
50 : 0; // profiling mismatch error?
51 uasort( $this->mCollated, array( 'self', 'sort' ) );
52 array_walk( $this->mCollated, array( 'self', 'format' ), $totalReal );
53 if ( PHP_SAPI === 'cli' ) {
54 print "<!--\n" . self::$out . "\n-->\n";
55 } elseif ( $this->getContentType() === 'text/html' ) {
56 if ( $this->visible ) {
57 print '<pre>' . self::$out . '</pre>';
58 } else {
59 print "<!--\n" . self::$out . "\n-->\n";
61 } elseif ( $this->getContentType() === 'text/javascript' ) {
62 print "\n/*\n" . self::$out . "*/\n";
63 } elseif ( $this->getContentType() === 'text/css' ) {
64 print "\n/*\n" . self::$out . "*/\n";
69 static function sort( $a, $b ) {
70 return $a['real'] < $b['real']; /* sort descending by time elapsed */
73 static function format( $item, $key, $totalReal ) {
74 $perc = $totalReal ? $item['real'] / $totalReal * 100 : 0;
75 self::$out .= sprintf( "%6.2f%% %3.6f %6d - %s\n",
76 $perc, $item['real'], $item['count'], $key );