Tim Starling has submitted this change and it was merged.

Change subject: Replace easter egg by a more explaining message
......................................................................


Replace easter egg by a more explaining message

also if highlight.php is navigated directly, redirect to overview,
but if tried to give a filename, give a bit explaining error message.

also don't display helper links to versions control etc. in case of an
error

Bug: 60741
Change-Id: I24ff4d72a447dae03fa7c92fa6b2189a62105b1d
---
M docroot/noc/conf/highlight.php
M tests/noc-conf/highlightTest.php
2 files changed, 21 insertions(+), 12 deletions(-)

Approvals:
  Tim Starling: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/docroot/noc/conf/highlight.php b/docroot/noc/conf/highlight.php
index 3963508..d6cf8ed 100644
--- a/docroot/noc/conf/highlight.php
+++ b/docroot/noc/conf/highlight.php
@@ -20,6 +20,8 @@
 // Relative path to the symlink in conf/*
 $selectedFileViewRawUrl = false;
 
+$hlHtml = "";
+
 foreach ( $selectableFilepaths as $filePath ) {
        $fileName = basename( $filePath );
        // Map .txt links to the original filename
@@ -31,28 +33,35 @@
                break;
        }
 }
-if ( PHP_SAPI !== 'cli' ) {
+if ( PHP_SAPI !== 'cli' ) { // Don't run if executing unit tests
        ob_start( 'ob_gzhandler' );
        header( 'Content-Type: text/html; charset=utf-8' );
 }
 
 if ( !$selectedFilePath ) {
-       if ( PHP_SAPI !== 'cli' ) {
-               header( "HTTP/1.1 404 Not Found" );
-       }
-       if ( isset( $_SERVER['HTTP_REFERER'] ) && strpos( strtolower( 
$_SERVER['HTTP_REFERER'] ), 'google' ) !== false ) {
-               echo "File not found\n";
+       if( $selectedFileName === null ){
+               // No parameter file given, e.g. if you go to this file 
directly, redirect to overview
+               if( isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' ){
+                       $protocol = "https";
+               } {
+                       $protocol = "http";
+               }
+               header( "HTTP/1.1 302 Found" );
+               header( "Location: ". $protocol . "://" . $_SERVER[ 
'SERVER_NAME'] ."/conf/index.php" );
+               echo $protocol . "://" . $_SERVER[ 'SERVER_NAME'] 
."/conf/index.php";
                exit;
+       } else {
+               // Parameter file IS given, but for whatever reason no filename 
given or filename not existing in this directory
+               $hlHtml = "<pre>No valid, whitelisted filename in parameter 
\"file\" given.</pre>";
        }
-       // Easter egg
-       $hlHtml = highlight_string( '<'."?php\n\$secretSitePassword = 
'jgmeidj28gms';\n", true );
-
 } else {
        // Follow symlink
        if ( !file_exists( $selectedFilePath ) ) {
-               $hlHtml = 'Whitelist contains inexistant entry. :(';
+               $hlHtml = 'Whitelist contains nonexistent entry. :(';
+               $selectedFilePath = false;
        } elseif ( !is_link( $selectedFilePath ) ) {
                $hlHtml = 'Whitelist must only contain symlinks.';
+               $selectedFilePath = false;
        } else {
                $selectedFileViewRawUrl = './' . urlencode( basename( 
$selectedFilePath ) );
                // Resolve symlink
diff --git a/tests/noc-conf/highlightTest.php b/tests/noc-conf/highlightTest.php
index 7d7d58f..874420d 100644
--- a/tests/noc-conf/highlightTest.php
+++ b/tests/noc-conf/highlightTest.php
@@ -78,11 +78,11 @@
        /**
         * @dataProvider provideInvalidCases
         */
-       public function testInvalidCases( $q, $expect = 'secretSitePassword' ) {
+       public function testInvalidCases( $q, $expect = 'No valid, whitelisted 
filename' ) {
                $this->assertContains(
                        $expect,
                        $this->runHighlight( $q ),
-                       "file=$q should be 404"
+                       "file=$q should not work"
                );
        }
 

-- 
To view, visit https://gerrit.wikimedia.org/r/110926
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I24ff4d72a447dae03fa7c92fa6b2189a62105b1d
Gerrit-PatchSet: 5
Gerrit-Project: operations/mediawiki-config
Gerrit-Branch: master
Gerrit-Owner: Hashar <[email protected]>
Gerrit-Reviewer: Hashar <[email protected]>
Gerrit-Reviewer: Hoo man <[email protected]>
Gerrit-Reviewer: MZMcBride <[email protected]>
Gerrit-Reviewer: Matanya <[email protected]>
Gerrit-Reviewer: MaxSem <[email protected]>
Gerrit-Reviewer: Odder <[email protected]>
Gerrit-Reviewer: Ori.livneh <[email protected]>
Gerrit-Reviewer: Se4598 <[email protected]>
Gerrit-Reviewer: TTO <[email protected]>
Gerrit-Reviewer: Tim Landscheidt <[email protected]>
Gerrit-Reviewer: Tim Starling <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to