From 5ffae93ef89a16ecf38722f53f68213893d076fe Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Tue, 10 Jul 2007 13:46:22 +0000 Subject: [PATCH] Added $wgShowHostnames to shows/hide host names in API results and HTML comments --- RELEASE-NOTES | 1 + includes/DefaultSettings.php | 6 +++++- includes/GlobalFunctions.php | 10 ++++++---- includes/Wiki.php | 9 +++++++-- includes/api/ApiQuerySiteinfo.php | 7 +++++-- 5 files changed, 24 insertions(+), 9 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index b4d3af0cc6..d962d81736 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -25,6 +25,7 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN * $wgAddGroups, $wgRemoveGroups - Finer control over who can assign which usergroups * $wgEnotifImpersonal, $wgEnotifUseJobQ - Bulk mail options for large sites +* $wgShowHostnames - Shows host names in API results and HTML comments == New features since 1.10 == diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 2a702504fa..74ffbe4605 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -921,7 +921,11 @@ $wgColorErrors = true; $wgShowExceptionDetails = false; /** - * disable experimental dmoz-like category browsing. Output things like: + * If set to true, exposes host names through API and HTML comments. + */ +$wgShowHostnames = false; + +/** * disable experimental dmoz-like category browsing. Output things like: * Encyclopedia > Music > Style of Music > Jazz */ $wgUseCategoryBrowser = false; diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index aaf150c1c9..a1db8f83da 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -701,14 +701,16 @@ function wfHostname() { * @return string */ function wfReportTime() { - global $wgRequestTime; + global $wgRequestTime, $wgShowHostnames; $now = wfTime(); $elapsed = $now - $wgRequestTime; - $com = sprintf( "", - wfHostname(), $elapsed ); - return $com; + if ($wgShowHostnames) { + return sprintf( "", wfHostname(), $elapsed ); + } else { + return sprintf( "", $elapsed ); + } } /** diff --git a/includes/Wiki.php b/includes/Wiki.php index 924a977905..9593033615 100644 --- a/includes/Wiki.php +++ b/includes/Wiki.php @@ -57,14 +57,19 @@ class MediaWiki { } function checkMaxLag( $maxLag ) { - global $wgLoadBalancer; + global $wgLoadBalancer, $wgShowHostnames; + list( $host, $lag ) = $wgLoadBalancer->getMaxLag(); if ( $lag > $maxLag ) { header( 'HTTP/1.1 503 Service Unavailable' ); header( 'Retry-After: ' . max( intval( $maxLag ), 5 ) ); header( 'X-Database-Lag: ' . intval( $lag ) ); header( 'Content-Type: text/plain' ); - echo "Waiting for $host: $lag seconds lagged\n"; + if ($wgShowHostnames) { + echo "Waiting for $host: $lag seconds lagged\n"; + } else { + echo "Waiting for a database server: $lag seconds lagged\n"; + } return false; } else { return true; diff --git a/includes/api/ApiQuerySiteinfo.php b/includes/api/ApiQuerySiteinfo.php index 9f10a617bf..c3bfbc0959 100644 --- a/includes/api/ApiQuerySiteinfo.php +++ b/includes/api/ApiQuerySiteinfo.php @@ -132,11 +132,14 @@ class ApiQuerySiteinfo extends ApiQueryBase { } protected function appendDbReplLagInfo($property, $includeAll) { - global $wgLoadBalancer; + global $wgLoadBalancer, $wgShowHostnames; $data = array(); if ($includeAll) { + if (!$wgShowHostnames) + $this->dieUsage('Cannot view all servers info unless $wgShowHostnames is true', 'includeAllDenied'); + global $wgDBservers; $lags = $wgLoadBalancer->getLagTimes(); foreach( $lags as $i => $lag ) { @@ -147,7 +150,7 @@ class ApiQuerySiteinfo extends ApiQueryBase { } else { list( $host, $lag ) = $wgLoadBalancer->getMaxLag(); $data[] = array ( - 'host' => $host, + 'host' => $wgShowHostnames ? $host : '', 'lag' => $lag); } -- 2.20.1