/** * Usually aborts on failure * If errors are explicitly ignored, returns success * @param $sql String: SQL query * @param $db Mixed: database handler * @param $fname String: name of the php function calling */ function wfQuery($sql, $db, $fname = '') { if (!is_numeric($db)) { # Someone has tried to call this the old way throw new FatalError(wfMsgNoDB('wrong_wfQuery_params', $db, $sql)); } $c = wfGetDB($db); if ($c !== false) { return $c->query($sql, $fname); } else { return false; } }
} else { if (0 == $u->idForName()) { $u->addToDatabase(); $u->setPassword($conf->getSysopPass()); $u->saveSettings(); $u->addGroup("sysop"); $u->addGroup("bureaucrat"); print "<li>Created sysop account <tt>" . htmlspecialchars($conf->SysopName) . "</tt>.</li>\n"; } else { print "<li>Could not create user - already exists!</li>\n"; } } } else { print "<li>Skipped sysop account creation, no name given.</li>\n"; } $titleobj = Title::newFromText(wfMsgNoDB("mainpage")); $article = new Article($titleobj); $newid = $article->insertOn($wgDatabase); $revision = new Revision(array('page' => $newid, 'text' => wfMsg('mainpagetext') . "\n\n" . wfMsgNoTrans('mainpagedocfooter'), 'comment' => '', 'user' => 0, 'user_text' => 'MediaWiki default')); $revid = $revision->insertOn($wgDatabase); $article->updateRevisionOn($wgDatabase, $revision); } /* Write out the config file now that all is well */ print "<li style=\"list-style: none\">\n"; print "<p>Creating LocalSettings.php...</p>\n\n"; $localSettings = "<" . "?php{$endl}{$local}"; // Fix up a common line-ending problem (due to CVS on Windows) $localSettings = str_replace("\r\n", "\n", $localSettings); $f = fopen("LocalSettings.php", 'xt'); if ($f == false) { print "</li>\n";
function getHTML() { if ($this->useMessageCache()) { return wfMsgNoDB('dberrortext', htmlspecialchars($this->getSQL()), htmlspecialchars($this->fname), $this->errno, htmlspecialchars($this->error)); } else { return nl2br(htmlspecialchars($this->getMessage())); } }
/** * Get the index of the reader connection, which may be a slave * This takes into account load ratios and lag times. It should * always return a consistent index during a given invocation * * Side effect: opens connections to databases */ function getReaderIndex() { global $wgMaxLag, $wgReadOnly, $wgDBClusterTimeout; $fname = 'LoadBalancer::getReaderIndex'; wfProfileIn($fname); $i = false; if ($this->mForce >= 0) { $i = $this->mForce; } else { if ($this->mReadIndex >= 0) { $i = $this->mReadIndex; } else { # $loads is $this->mLoads except with elements knocked out if they # don't work $loads = $this->mLoads; $done = false; $totalElapsed = 0; do { if ($wgReadOnly) { $i = $this->pickRandom($loads); } else { $i = $this->getRandomNonLagged($loads); if ($i === false && count($loads) != 0) { # All slaves lagged. Switch to read-only mode $wgReadOnly = wfMsgNoDB('readonly_lag'); $i = $this->pickRandom($loads); } } if ($i !== false) { wfDebug("Using reader #{$i}: {$this->mServers[$i]['host']}...\n"); $this->openConnection($i); if (!$this->isOpen($i)) { wfDebug("Failed\n"); unset($loads[$i]); $sleepTime = 0; } else { $status = $this->mConnections[$i]->getStatus(); if (isset($this->mServers[$i]['max threads']) && $status['Threads_running'] > $this->mServers[$i]['max threads']) { # Slave is lagged, wait for a while $sleepTime = 5000 * $status['Threads_connected']; # If we reach the timeout and exit the loop, don't use it $i = false; } else { $done = true; $sleepTime = 0; } } } else { $sleepTime = 500000; } if ($sleepTime) { $totalElapsed += $sleepTime; usleep($sleepTime); } } while (count($loads) && !$done && $totalElapsed / 1000000.0 < $wgDBClusterTimeout); if ($i !== false && $this->isOpen($i)) { # Wait for the session master pos for a short time if ($this->mWaitForFile) { if (!$this->doWait($i)) { $this->mServers[$i]['slave pos'] = $this->mConnections[$i]->getSlavePos(); } } if ($i !== false) { $this->mReadIndex = $i; } } else { $i = false; } } } wfProfileOut($fname); return $i; }
function getHTML() { global $wgShowDBErrorBacktrace; if ($this->useMessageCache()) { $s = wfMsgNoDB('dberrortext', htmlspecialchars($this->getSQL()), htmlspecialchars($this->fname), $this->errno, htmlspecialchars($this->error)); } else { $s = nl2br(htmlspecialchars($this->getMessage())); } if ($wgShowDBErrorBacktrace) { $s .= '<p>Backtrace:</p><p>' . nl2br(htmlspecialchars($this->getTraceAsString())); } return $s; }
/** * Get the index of the reader connection, which may be a slave * This takes into account load ratios and lag times. It should * always return a consistent index during a given invocation * * Side effect: opens connections to databases */ function getReaderIndex() { global $wgReadOnly, $wgDBClusterTimeout; $fname = 'LoadBalancer::getReaderIndex'; wfProfileIn($fname); $i = false; if ($this->mForce >= 0) { $i = $this->mForce; } else { if ($this->mReadIndex >= 0) { $i = $this->mReadIndex; } else { # $loads is $this->mLoads except with elements knocked out if they # don't work $loads = $this->mLoads; $done = false; $totalElapsed = 0; do { if ($wgReadOnly or $this->mAllowLagged) { $i = $this->pickRandom($loads); } else { $i = $this->getRandomNonLagged($loads); if ($i === false && count($loads) != 0) { # All slaves lagged. Switch to read-only mode $wgReadOnly = wfMsgNoDB('readonly_lag'); $i = $this->pickRandom($loads); } } $serverIndex = $i; if ($i !== false) { wfDebugLog('connect', "{$fname}: Using reader #{$i}: {$this->mServers[$i]['host']}...\n"); $this->openConnection($i); if (!$this->isOpen($i)) { wfDebug("{$fname}: Failed\n"); unset($loads[$i]); $sleepTime = 0; } else { $status = $this->mConnections[$i]->getStatus("Thread%"); if (isset($this->mServers[$i]['max threads']) && $status['Threads_running'] > $this->mServers[$i]['max threads']) { # Too much load, back off and wait for a while. # The sleep time is scaled by the number of threads connected, # to produce a roughly constant global poll rate. $sleepTime = AVG_STATUS_POLL * $status['Threads_connected']; # If we reach the timeout and exit the loop, don't use it $i = false; } else { $done = true; $sleepTime = 0; } } } else { $sleepTime = 500000; } if ($sleepTime) { $totalElapsed += $sleepTime; $x = "{$this->mServers[$serverIndex]['host']} [{$serverIndex}]"; wfProfileIn("{$fname}-sleep {$x}"); usleep($sleepTime); wfProfileOut("{$fname}-sleep {$x}"); } } while (count($loads) && !$done && $totalElapsed / 1000000.0 < $wgDBClusterTimeout); if ($totalElapsed / 1000000.0 >= $wgDBClusterTimeout) { $this->mErrorConnection = false; $this->mLastError = 'All servers busy'; } if ($i !== false && $this->isOpen($i)) { # Wait for the session master pos for a short time if ($this->mWaitForFile) { if (!$this->doWait($i)) { $this->mServers[$i]['slave pos'] = $this->mConnections[$i]->getSlavePos(); } } if ($i !== false) { $this->mReadIndex = $i; } } else { $i = false; } } } wfProfileOut($fname); return $i; }
function databaseError($fname, $sql, $error, $errno) { global $wgUser, $wgCommandLineMode, $wgShowSQLErrors; $this->setPageTitle(wfMsgNoDB('databaseerror')); $this->setRobotpolicy('noindex,nofollow'); $this->setArticleRelated(false); $this->enableClientCache(false); $this->mRedirect = ''; if (!$wgShowSQLErrors) { $sql = wfMsg('sqlhidden'); } if ($wgCommandLineMode) { $msg = wfMsgNoDB('dberrortextcl', htmlspecialchars($sql), htmlspecialchars($fname), $errno, htmlspecialchars($error)); } else { $msg = wfMsgNoDB('dberrortext', htmlspecialchars($sql), htmlspecialchars($fname), $errno, htmlspecialchars($error)); } if ($wgCommandLineMode || !is_object($wgUser)) { print $msg . "\n"; wfErrorExit(); } $this->mBodytext = $msg; $this->output(); wfErrorExit(); }