本文整理汇总了PHP中Transaction::setAttribute方法的典型用法代码示例。如果您正苦于以下问题:PHP Transaction::setAttribute方法的具体用法?PHP Transaction::setAttribute怎么用?PHP Transaction::setAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Transaction
的用法示例。
在下文中一共展示了Transaction::setAttribute方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: performAction
/** Pass the request to our internal function.
* BEWARE! Data are passed as they have been supplied by the user,
* they should be carefully handled in the function processing the
* request.
*/
function performAction()
{
global $wgAjaxExportList, $wgOut, $wgUser;
if (empty($this->mode)) {
return;
}
/*
* Wikia Change - begin
*/
Transaction::setEntryPoint(Transaction::ENTRY_POINT_AJAX);
Transaction::setAttribute(Transaction::PARAM_FUNCTION, $this->func_name);
if (function_exists('newrelic_disable_autorum')) {
newrelic_disable_autorum();
}
/*
* Wikia Change - end
*/
wfProfileIn(__METHOD__);
if (!in_array($this->func_name, $wgAjaxExportList)) {
wfDebug(__METHOD__ . ' Bad Request for unknown function ' . $this->func_name . "\n");
wfHttpError(400, 'Bad Request', "unknown function " . (string) $this->func_name);
} elseif (!in_array('read', User::getGroupPermissions(array('*')), true) && !$wgUser->isAllowed('read')) {
wfHttpError(403, 'Forbidden', 'You must log in to view pages.');
} else {
wfDebug(__METHOD__ . ' dispatching ' . $this->func_name . "\n");
if (strpos($this->func_name, '::') !== false) {
$func = explode('::', $this->func_name, 2);
} else {
$func = $this->func_name;
}
try {
$result = call_user_func_array($func, $this->args);
if ($result === false || $result === null) {
wfDebug(__METHOD__ . ' ERROR while dispatching ' . $this->func_name . "(" . var_export($this->args, true) . "): " . "no data returned\n");
/* Wikia changes start */
//let's avoid falling back to Iowa (500, 503) in this case,
//probably someone is asking for a non-existing dynamic method name
wfHttpError(501, 'Not Implemented', "{$this->func_name} returned no data");
} else {
if (is_string($result)) {
$result = new AjaxResponse($result);
}
$result->sendHeaders();
$result->printText();
wfDebug(__METHOD__ . ' dispatch complete for ' . $this->func_name . "\n");
}
} catch (Exception $e) {
wfDebug(__METHOD__ . ' ERROR while dispatching ' . $this->func_name . "(" . var_export($this->args, true) . "): " . get_class($e) . ": " . $e->getMessage() . "\n");
if (!headers_sent()) {
wfHttpError(500, 'Internal Error', $e->getMessage());
} else {
print $e->getMessage();
}
}
}
$wgOut = null;
wfProfileOut(__METHOD__);
}
示例2: executePath
/**
* Execute a special page path.
* The path may contain parameters, e.g. Special:Name/Params
* Extracts the special page name and call the execute method, passing the parameters
*
* Returns a title object if the page is redirected, false if there was no such special
* page, and true if it was successful.
*
* @param $title Title object
* @param $context IContextSource
* @param $including Bool output is being captured for use in {{special:whatever}}
*
* @return bool
*/
public static function executePath(Title &$title, IContextSource &$context, $including = false)
{
wfProfileIn(__METHOD__);
// @todo FIXME: Redirects broken due to this call
$bits = explode('/', $title->getDBkey(), 2);
$name = $bits[0];
if (!isset($bits[1])) {
// bug 2087
$par = null;
} else {
$par = $bits[1];
}
$page = self::getPage($name);
// Nonexistent?
if (!$page) {
$context->getOutput()->setArticleRelated(false);
$context->getOutput()->setRobotPolicy('noindex,nofollow');
global $wgSend404Code;
if ($wgSend404Code) {
$context->getOutput()->setStatusCode(404);
}
$context->getOutput()->showErrorPage('nosuchspecialpage', 'nospecialpagetext');
wfProfileOut(__METHOD__);
return false;
}
// Page exists, set the context
$page->setContext($context);
if (!$including) {
// Redirect to canonical alias for GET commands
// Not for POST, we'd lose the post data, so it's best to just distribute
// the request. Such POST requests are possible for old extensions that
// generate self-links without being aware that their default name has
// changed.
if ($name != $page->getLocalName() && !$context->getRequest()->wasPosted()) {
$query = $context->getRequest()->getQueryValues();
unset($query['title']);
$query = wfArrayToCGI($query);
$title = $page->getTitle($par);
$url = $title->getFullUrl($query);
$context->getOutput()->redirect($url);
wfProfileOut(__METHOD__);
return $title;
} else {
$context->setTitle($page->getTitle($par));
}
} elseif (!$page->isIncludable()) {
wfProfileOut(__METHOD__);
return false;
}
$page->including($including);
// Wikia change - begin - @author: wladek
if (!$including) {
Transaction::setAttribute(Transaction::PARAM_SPECIAL_PAGE_NAME, $page->getName());
}
// Wikia change - end
// Execute special page
$profName = 'Special:' . $page->getName();
wfProfileIn($profName);
$page->execute($par);
wfProfileOut($profName);
wfProfileOut(__METHOD__);
return true;
}
示例3: view
//.........这里部分代码省略.........
wfIncrStats('pcache_miss_stub');
}
$this->showRedirectedFromHeader();
$this->showNamespaceHeader();
# Iterate through the possible ways of constructing the output text.
# Keep going until $outputDone is set, or we run out of things to do.
$pass = 0;
$outputDone = false;
$this->mParserOutput = false;
while (!$outputDone && ++$pass) {
switch ($pass) {
case 1:
wfRunHooks('ArticleViewHeader', array(&$this, &$outputDone, &$useParserCache));
break;
case 2:
# Early abort if the page doesn't exist
if (!$this->mPage->exists()) {
wfDebug(__METHOD__ . ": showing missing article\n");
$this->showMissingArticle();
wfProfileOut(__METHOD__);
/* Wikia change begin - @author: Marcin, #BugId: 30436 */
$text = '';
if (wfRunHooks('ArticleNonExistentPage', array(&$this, $wgOut, &$text))) {
$this->mParserOutput = $wgParser->parse($text, $this->getTitle(), $parserOptions);
$wgOut->addParserOutput($this->mParserOutput);
}
/* Wikia change end */
return;
}
# Try the parser cache
if ($useParserCache) {
$this->mParserOutput = $parserCache->get($this, $parserOptions);
//Wikia Change
Transaction::setAttribute(Transaction::PARAM_PARSER_CACHE_USED, $this->mParserOutput !== false);
//Wikia Change End
if ($this->mParserOutput !== false) {
if ($oldid) {
wfDebug(__METHOD__ . ": showing parser cache contents for current rev permalink\n");
$this->setOldSubtitle($oldid);
} else {
wfDebug(__METHOD__ . ": showing parser cache contents\n");
}
$wgOut->addParserOutput($this->mParserOutput);
// Wikia change - begin - @author: wladek
wfRunHooks('ArticleViewAddParserOutput', array($this, $this->mParserOutput));
// Wikia change - end
# Ensure that UI elements requiring revision ID have
# the correct version information.
$wgOut->setRevisionId($this->mPage->getLatest());
# Preload timestamp to avoid a DB hit
$cachedTimestamp = $this->mParserOutput->getTimestamp();
if ($cachedTimestamp !== null) {
$wgOut->setRevisionTimestamp($cachedTimestamp);
$this->mPage->setTimestamp($cachedTimestamp);
}
$outputDone = true;
}
// Wikia change - begin - @author: wladek
} else {
Transaction::setAttribute(Transaction::PARAM_PARSER_CACHE_USED, false);
// Wikia change - end
}
break;
case 3:
# This will set $this->mRevision if needed
$this->fetchContent();
示例4: disableCache
/**
* Set a flag in the output object indicating that the content is dynamic and
* shouldn't be cached.
*/
function disableCache()
{
wfDebug("Parser output marked as uncacheable.\n");
if (!$this->mOutput) {
throw new MWException(__METHOD__ . " can only be called when actually parsing something");
}
$this->mOutput->setCacheTime(-1);
// old style, for compatibility
$this->mOutput->updateCacheExpiry(0);
// new style, for consistency
// Wikia change - begin
Wikia\Logger\WikiaLogger::instance()->info(__METHOD__, ['exception' => new Exception()]);
Transaction::setAttribute(Transaction::PARAM_PARSER_CACHE_DISABLED, true);
// Wikia change - end
}
示例5: onArticleViewAddParserOutput
/**
* Hook handler. Sets a "size category" attribute based on the article that is displayed
*
* @param Article $article
* @param ParserOutput $parserOutput
* @return bool true (hook handler)
*/
public static function onArticleViewAddParserOutput(Article $article, ParserOutput $parserOutput)
{
$wikitextSize = $parserOutput->getPerformanceStats('wikitextSize');
$htmlSize = $parserOutput->getPerformanceStats('htmlSize');
$expFuncCount = $parserOutput->getPerformanceStats('expFuncCount');
$nodeCount = $parserOutput->getPerformanceStats('nodeCount');
if (!is_numeric($wikitextSize) || !is_numeric($htmlSize) || !is_numeric($expFuncCount) || !is_numeric($nodeCount)) {
return true;
}
if ($wikitextSize < 3000 && $htmlSize < 5000 && $expFuncCount == 0 && $nodeCount < 100) {
$sizeCategory = self::SIZE_CATEGORY_SIMPLE;
} elseif ($wikitextSize < 30000 && $htmlSize < 50000 && $expFuncCount <= 4 && $nodeCount < 3000) {
$sizeCategory = self::SIZE_CATEGORY_AVERAGE;
} else {
$sizeCategory = self::SIZE_CATEGORY_COMPLEX;
}
Transaction::setAttribute(Transaction::PARAM_SIZE_CATEGORY, $sizeCategory);
return true;
}
示例6: dynamicPageList
//.........这里部分代码省略.........
if ((!ExtDynamicPageList::$allowUnlimitedResults || $iCount >= 0) && $sGoal != 'categories') {
if ($iCount < 0) {
$iCount = intval(ExtDynamicPageList::$options['count']['default']);
}
$sSqlWhere .= " LIMIT {$iCount} OFFSET {$iOffset} ";
}
// when we go for a list of categories as result we transform the output of the normal query into a subquery
// of a selection on the categorylinks
if ($sGoal == 'categories') {
$sSqlSelectFrom = 'SELECT DISTINCT cl3.cl_to FROM ' . $sCategorylinksTable . ' AS cl3 WHERE cl3.cl_from IN ( ' . preg_replace('/SELECT +DISTINCT +.* FROM /', 'SELECT DISTINCT ' . $sPageTable . '.page_id FROM ', $sSqlSelectFrom);
if ($sOrder == 'descending') {
$sSqlWhere .= ' ) ORDER BY cl3.cl_to DESC';
} else {
$sSqlWhere .= ' ) ORDER BY cl3.cl_to ASC';
}
}
// ###### DUMP SQL QUERY ######
if ($logger->iDebugLevel >= 3) {
//DEBUG: output SQL query
$output .= "DPL debug -- Query=<br />\n<tt>" . $sSqlSelectFrom . $sSqlWhere . "</tt>\n\n";
}
// Do NOT proces the SQL command if debug==6; this is useful if the SQL statement contains bad code
if ($logger->iDebugLevel == 6) {
return $output;
}
// ###### PROCESS SQL QUERY ######
try {
$res = $dbr->query($sSqlSelectFrom . $sSqlWhere);
} catch (Exception $e) {
$result = "The DPL extension (version " . ExtDynamicPageList::$DPLVersion . ") produced a SQL statement which lead to a Database error.<br>\n" . "The reason may be an internal error of DPL or an error which you made,<br />\n" . "especially when using DPL options like titleregexp.<br />\n" . "Query text is:<br />\n<tt>" . $sSqlSelectFrom . $sSqlWhere . "</tt>\n\n" . "Error message is:<br />\n<tt>" . $dbr->lastError() . "</tt>\n\n";
return $result;
}
// Wikia change - mark transactions that trigger DPL queries (PLATFORM-1074)
Transaction::setAttribute(Transaction::PARAM_DPL, true);
if ($dbr->numRows($res) <= 0) {
$header = str_replace('%TOTALPAGES%', '0', str_replace('%PAGES%', '0', $sNoResultsHeader));
if ($sNoResultsHeader != '') {
$output .= str_replace('\\n', "\n", str_replace("¶", "\n", $header));
}
$footer = str_replace('%TOTALPAGES%', '0', str_replace('%PAGES%', '0', $sNoResultsFooter));
if ($sNoResultsFooter != '') {
$output .= str_replace('\\n', "\n", str_replace("¶", "\n", $footer));
}
if ($sNoResultsHeader == '' && $sNoResultsFooter == '') {
$output .= $logger->escapeMsg(ExtDynamicPageList::WARN_NORESULTS);
}
$dbr->freeResult($res);
return $output;
}
// generate title for Special:Contributions (used if adduser=true)
$sSpecContribs = '[[:Special:Contributions|Contributions]]';
$aHeadings = array();
// maps heading to count (# of pages under each heading)
$aArticles = array();
// pick some elements by random
$pick[0] = true;
if (isset($iRandomCount)) {
$nResults = $dbr->numRows($res);
if (isset($iRandomSeed)) {
mt_srand($iRandomSeed);
} else {
mt_srand((double) microtime() * 10000000);
}
if ($iRandomCount > $nResults) {
$iRandomCount = $nResults;
}
示例7: define
*/
// So extensions (and other code) can check whether they're running in API mode
define('MW_API', true);
// Bail if PHP is too low
if (!function_exists('version_compare') || version_compare(phpversion(), '5.2.3') < 0) {
require dirname(__FILE__) . '/includes/PHPVersionError.php';
wfPHPVersionError('api.php');
}
// Initialise common code.
if (isset($_SERVER['MW_COMPILED'])) {
require 'phase3/includes/WebStart.php';
} else {
require dirname(__FILE__) . '/includes/WebStart.php';
}
Transaction::setEntryPoint(Transaction::ENTRY_POINT_API);
Transaction::setAttribute(Transaction::PARAM_API_ACTION, $wgRequest->getVal('action', null));
wfProfileIn('api.php');
$starttime = microtime(true);
// URL safety checks
if (!$wgRequest->checkUrlExtension()) {
wfProfileOut('api.php');
return;
}
// Verify that the API has not been disabled
if (!$wgEnableAPI) {
header($_SERVER['SERVER_PROTOCOL'] . ' 500 MediaWiki configuration Error', true, 500);
echo 'MediaWiki API is not enabled for this site. Add the following line to your LocalSettings.php' . '<pre><b>$wgEnableAPI=true;</b></pre>';
die(1);
}
// Selectively allow cross-site AJAX
/**
示例8: header
if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
header("HTTP/1.1 200", true, 200);
return;
}
// prevent $_GET['title'] from being overwritten on API calls (BAC-906)
define('DONT_INTERPOLATE_TITLE', true);
// Initialise common MW code
require dirname(__FILE__) . '/includes/WebStart.php';
if ($wgProfiler instanceof Profiler) {
$wgProfiler->setTemplated(true);
}
// Construct a tag for newrelic -- wgRequest is global in this scope
Transaction::setEntryPoint(Transaction::ENTRY_POINT_NIRVANA);
if (is_object($wgRequest)) {
Transaction::setAttribute(Transaction::PARAM_CONTROLLER, $wgRequest->getVal('controller'));
Transaction::setAttribute(Transaction::PARAM_METHOD, $wgRequest->getVal('method'));
}
if (function_exists('newrelic_disable_autorum')) {
newrelic_disable_autorum();
}
if (!empty($wgEnableNirvanaAPI)) {
// temporarily force ApiDocs extension regardless of config
require_once $IP . "/extensions/wikia/ApiDocs/ApiDocs.setup.php";
// same for JsonFormat
require_once $IP . "/extensions/wikia/JsonFormat/JsonFormat.setup.php";
$app = F::app();
// Ensure that we have a title stub, otherwise parser does not work BugId: 12901
$app->wg->title = Wikia::createTitleFromRequest($app->wg->Request);
// support "mcache" URL parameter to ease debugging
Wikia::setUpMemcachePurge($app->wg->Request, $app->wg->User);
// initialize skin if requested
示例9: ob_start
require_once "{$IP}/includes/OutputHandler.php";
}
ob_start('wfOutputHandler');
}
// Wikia change - begin - @author: wladek
// Catch all output
echo $initialOutput;
// Wikia change - end
wfProfileOut('WebStart.php-ob_start');
if (!defined('MW_NO_SETUP')) {
require_once MWInit::compiledPath("includes/Setup.php");
}
if (is_object($wgRequest) && $wgRequest->wasPosted() && wfReadOnly()) {
if (strpos(strtolower($_SERVER['SCRIPT_URL']), 'datacenter') === false && strpos(strtolower($_SERVER['SCRIPT_URL']), 'api.php') === false) {
$js = <<<EOD
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("UA-288915-41");
pageTracker._trackEvent("error", "PostInReadOnly");
} catch(err) {}</script>
EOD;
echo "<html><head>{$js}</head><body>{$wgReadOnly}</body></html>";
die(-1);
}
}
Transaction::setAttribute(Transaction::PARAM_WIKI, $wgDBname);