Example #1
0
    function getHTML()
    {
        global $wgTitle, $wgUseFileCache, $title, $wgInputEncoding, $wgOutputEncoding;
        global $wgSitename, $wgServer, $wgMessageCache, $wgLogo;
        # I give up, Brion is right. Getting the message cache to work when there is no DB is tricky.
        # Hard coding strings instead.
        $noconnect = "<p><strong>Sorry! This site is experiencing technical difficulties.</strong></p><p>Try waiting a few minutes and reloading.</p><p><small>(Can't contact the database server: \$1)</small></p>";
        $mainpage = 'Main Page';
        $searchdisabled = <<<EOT
<p style="margin: 1.5em 2em 1em">{$wgSitename} search is disabled for performance reasons. You can search via Google in the meantime.
<span style="font-size: 89%; display: block; margin-left: .2em">Note that their indexes of {$wgSitename} content may be out of date.</span></p>',
EOT;
        $googlesearch = "\n<!-- SiteSearch Google -->\n<FORM method=GET action=\"http://www.google.com/search\">\n<TABLE bgcolor=\"#FFFFFF\"><tr><td>\n<A HREF=\"http://www.google.com/\">\n<IMG SRC=\"http://www.google.com/logos/Logo_40wht.gif\"\nborder=\"0\" ALT=\"Google\"></A>\n</td>\n<td>\n<INPUT TYPE=text name=q size=31 maxlength=255 value=\"\$1\">\n<INPUT type=submit name=btnG VALUE=\"Google Search\">\n<font size=-1>\n<input type=hidden name=domains value=\"{$wgServer}\"><br /><input type=radio name=sitesearch value=\"\"> WWW <input type=radio name=sitesearch value=\"{$wgServer}\" checked> {$wgServer} <br />\n<input type='hidden' name='ie' value='\$2'>\n<input type='hidden' name='oe' value='\$2'>\n</font>\n</td></tr></TABLE>\n</FORM>\n<!-- SiteSearch Google -->";
        $cachederror = "The following is a cached copy of the requested page, and may not be up to date. ";
        # No database access
        if (is_object($wgMessageCache)) {
            $wgMessageCache->disable();
        }
        if (trim($this->error) == '') {
            $this->error = $this->db->getProperty('mServer');
        }
        $text = str_replace('$1', $this->error, $noconnect);
        $text .= wfGetSiteNotice();
        if ($wgUseFileCache) {
            if ($wgTitle) {
                $t =& $wgTitle;
            } else {
                if ($title) {
                    $t = Title::newFromURL($title);
                } elseif (@$_REQUEST['search']) {
                    $search = $_REQUEST['search'];
                    return $searchdisabled . str_replace(array('$1', '$2'), array(htmlspecialchars($search), $wgInputEncoding), $googlesearch);
                } else {
                    $t = Title::newFromText($mainpage);
                }
            }
            $cache = new CacheManager($t);
            if ($cache->isFileCached()) {
                $msg = '<p style="color: red"><b>' . $msg . "<br />\n" . $cachederror . "</b></p>\n";
                $tag = '<div id="article">';
                $text = str_replace($tag, $tag . $msg, $cache->fetchPageText());
            }
        }
        return $text;
    }
/**
 * Standard fail function, called by default when a connection cannot be
 * established.
 * Displays the file cache if possible
 */
function wfEmergencyAbort(&$conn, $error)
{
    global $wgTitle, $wgUseFileCache, $title, $wgInputEncoding, $wgOutputEncoding;
    global $wgSitename, $wgServer, $wgMessageCache, $wgLogo;
    # I give up, Brion is right. Getting the message cache to work when there is no DB is tricky.
    # Hard coding strings instead.
    $noconnect = "<h1><img src='{$wgLogo}' style='float:left;margin-right:1em' alt=''>{$wgSitename} has a problem</h1><p><strong>Sorry! This site is experiencing technical difficulties.</strong></p><p>Try waiting a few minutes and reloading.</p><p><small>(Can't contact the database server: \$1)</small></p>";
    $mainpage = 'Main Page';
    $searchdisabled = <<<EOT
<p style="margin: 1.5em 2em 1em">{$wgSitename} search is disabled for performance reasons. You can search via Google in the meantime.
<span style="font-size: 89%; display: block; margin-left: .2em">Note that their indexes of {$wgSitename} content may be out of date.</span></p>',
EOT;
    $googlesearch = "\n<!-- SiteSearch Google -->\n<FORM method=GET action=\"http://www.google.com/search\">\n<TABLE bgcolor=\"#FFFFFF\"><tr><td>\n<A HREF=\"http://www.google.com/\">\n<IMG SRC=\"http://www.google.com/logos/Logo_40wht.gif\"\nborder=\"0\" ALT=\"Google\"></A>\n</td>\n<td>\n<INPUT TYPE=text name=q size=31 maxlength=255 value=\"\$1\">\n<INPUT type=submit name=btnG VALUE=\"Google Search\">\n<font size=-1>\n<input type=hidden name=domains value=\"{$wgServer}\"><br /><input type=radio name=sitesearch value=\"\"> WWW <input type=radio name=sitesearch value=\"{$wgServer}\" checked> {$wgServer} <br />\n<input type='hidden' name='ie' value='\$2'>\n<input type='hidden' name='oe' value='\$2'>\n</font>\n</td></tr></TABLE>\n</FORM>\n<!-- SiteSearch Google -->";
    $cachederror = "The following is a cached copy of the requested page, and may not be up to date. ";
    if (!headers_sent()) {
        header('HTTP/1.0 500 Internal Server Error');
        header('Content-type: text/html; charset=' . $wgOutputEncoding);
        /* Don't cache error pages!  They cause no end of trouble... */
        header('Cache-control: none');
        header('Pragma: nocache');
    }
    # No database access
    if (is_object($wgMessageCache)) {
        $wgMessageCache->disable();
    }
    $msg = wfGetSiteNotice();
    if ($msg == '') {
        $msg = str_replace('$1', htmlspecialchars($error), $noconnect);
    }
    $text = $msg;
    if ($wgUseFileCache) {
        if ($wgTitle) {
            $t =& $wgTitle;
        } else {
            if ($title) {
                $t = Title::newFromURL($title);
            } elseif (@$_REQUEST['search']) {
                $search = $_REQUEST['search'];
                echo $searchdisabled;
                echo str_replace(array('$1', '$2'), array(htmlspecialchars($search), $wgInputEncoding), $googlesearch);
                wfErrorExit();
            } else {
                $t = Title::newFromText($mainpage);
            }
        }
        $cache = new CacheManager($t);
        if ($cache->isFileCached()) {
            $msg = '<p style="color: red"><b>' . $msg . "<br />\n" . $cachederror . "</b></p>\n";
            $tag = '<div id="article">';
            $text = str_replace($tag, $tag . $msg, $cache->fetchPageText());
        }
    }
    echo $text;
    wfErrorExit();
}