本文整理汇总了PHP中IContextSource::getRequest方法的典型用法代码示例。如果您正苦于以下问题:PHP IContextSource::getRequest方法的具体用法?PHP IContextSource::getRequest怎么用?PHP IContextSource::getRequest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IContextSource
的用法示例。
在下文中一共展示了IContextSource::getRequest方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1:
function __construct(IContextSource $context, $par = null)
{
$this->like = $context->getRequest()->getText('like');
$this->showbots = $context->getRequest()->getBool('showbots', 0);
if (is_numeric($par)) {
$this->setLimit($par);
}
parent::__construct($context);
}
示例2: __construct
/**
* Generates a brief review form for a page
* @param \IContextSource|\RequestContext $context
* @param FlaggableWikiPage $article
* @param Revision $rev
*/
public function __construct(IContextSource $context, FlaggableWikiPage $article, Revision $rev)
{
$this->user = $context->getUser();
$this->request = $context->getRequest();
$this->article = $article;
$this->rev = $rev;
}
示例3: useFileCache
/**
* Check if pages can be cached for this request/user
* @param $context IContextSource
* @return bool
*/
public static function useFileCache(IContextSource $context)
{
global $wgUseFileCache, $wgShowIPinHeader, $wgDebugToolbar, $wgContLang;
if (!$wgUseFileCache) {
return false;
}
if ($wgShowIPinHeader || $wgDebugToolbar) {
wfDebug("HTML file cache skipped. Either \$wgShowIPinHeader and/or \$wgDebugToolbar on\n");
return false;
}
// Get all query values
$queryVals = $context->getRequest()->getValues();
foreach ($queryVals as $query => $val) {
if ($query === 'title' || $query === 'curid') {
continue;
// note: curid sets title
// Normal page view in query form can have action=view.
} elseif ($query === 'action' && in_array($val, self::cacheablePageActions())) {
continue;
// Below are header setting params
} elseif ($query === 'maxage' || $query === 'smaxage') {
continue;
}
return false;
}
$user = $context->getUser();
// Check for non-standard user language; this covers uselang,
// and extensions for auto-detecting user language.
$ulang = $context->getLanguage()->getCode();
$clang = $wgContLang->getCode();
// Check that there are no other sources of variation
return !$user->getId() && !$user->getNewtalk() && $ulang == $clang;
}
示例4: checkMaxLag
/**
* Checks if the request should abort due to a lagged server,
* for given maxlag parameter.
*
* @param boolean $abort True if this class should abort the
* script execution. False to return the result as a boolean.
* @return boolean True if we passed the check, false if we surpass the maxlag
*/
private function checkMaxLag($abort)
{
global $wgShowHostnames;
wfProfileIn(__METHOD__);
$maxLag = $this->context->getRequest()->getVal('maxlag');
if (!is_null($maxLag)) {
$lb = wfGetLB();
// foo()->bar() is not supported in PHP4
list($host, $lag) = $lb->getMaxLag();
if ($lag > $maxLag) {
if ($abort) {
$resp = $this->context->getRequest()->response();
$resp->header('HTTP/1.1 503 Service Unavailable');
$resp->header('Retry-After: ' . max(intval($maxLag), 5));
$resp->header('X-Database-Lag: ' . intval($lag));
$resp->header('Content-Type: text/plain');
if ($wgShowHostnames) {
echo "Waiting for {$host}: {$lag} seconds lagged\n";
} else {
echo "Waiting for a database server: {$lag} seconds lagged\n";
}
}
wfProfileOut(__METHOD__);
if (!$abort) {
return false;
}
exit;
}
}
wfProfileOut(__METHOD__);
return true;
}
示例5: wfGetDB
function __construct(IContextSource $context, $userName = null, $search = '', $including = false)
{
global $wgMiserMode;
$this->mIncluding = $including;
if ($userName) {
$nt = Title::newFromText($userName, NS_USER);
if (!is_null($nt)) {
$this->mUserName = $nt->getText();
$this->mQueryConds['img_user_text'] = $this->mUserName;
}
}
if ($search != '' && !$wgMiserMode) {
$this->mSearch = $search;
$nt = Title::newFromURL($this->mSearch);
if ($nt) {
$dbr = wfGetDB(DB_SLAVE);
$this->mQueryConds[] = 'LOWER(img_name)' . $dbr->buildLike($dbr->anyString(), strtolower($nt->getDBkey()), $dbr->anyString());
}
}
if (!$including) {
if ($context->getRequest()->getText('sort', 'img_date') == 'img_date') {
$this->mDefaultDirection = true;
} else {
$this->mDefaultDirection = false;
}
} else {
$this->mDefaultDirection = true;
}
parent::__construct($context);
}
示例6: useExternalEngine
/**
* Check whether external edit or diff should be used.
*
* @param $context IContextSource context to use
* @param $type String can be either 'edit' or 'diff'
* @return Bool
*/
public static function useExternalEngine(IContextSource $context, $type)
{
global $wgUseExternalEditor;
if (!$wgUseExternalEditor) {
return false;
}
$pref = $type == 'diff' ? 'externaldiff' : 'externaleditor';
$request = $context->getRequest();
return !$request->getVal('internaledit') && ($context->getUser()->getOption($pref) || $request->getVal('externaledit'));
}
示例7: newFromContext
/**
* Fetch an appropriate changes list class for the specified context
* Some users might want to use an enhanced list format, for instance
*
* @param $context IContextSource to use
* @return ChangesList|EnhancedChangesList|OldChangesList derivative
*/
public static function newFromContext( IContextSource $context ) {
$user = $context->getUser();
$sk = $context->getSkin();
$list = null;
if ( wfRunHooks( 'FetchChangesList', array( $user, &$sk, &$list ) ) ) {
$new = $context->getRequest()->getBool( 'enhanced', $user->getOption( 'usenewrc' ) );
return $new ? new EnhancedChangesList( $context ) : new OldChangesList( $context );
} else {
return $list;
}
}
示例8: main
private function main()
{
global $wgUseFileCache, $wgTitle, $wgUseAjax;
wfProfileIn(__METHOD__);
$request = $this->context->getRequest();
// Send Ajax requests to the Ajax dispatcher.
if ($wgUseAjax && $request->getVal('action', 'view') == 'ajax') {
// Set a dummy title, because $wgTitle == null might break things
$title = Title::makeTitle(NS_MAIN, 'AJAX');
$this->context->setTitle($title);
$wgTitle = $title;
$dispatcher = new AjaxDispatcher();
$dispatcher->performAction();
wfProfileOut(__METHOD__);
return;
}
// Get title from request parameters,
// is set on the fly by parseTitle the first time.
$title = $this->getTitle();
$action = $this->getAction();
$wgTitle = $title;
if ($wgUseFileCache && $title->getNamespace() >= 0) {
wfProfileIn('main-try-filecache');
if (HTMLFileCache::useFileCache($this->context)) {
// Try low-level file cache hit
$cache = HTMLFileCache::newFromTitle($title, $action);
if ($cache->isCacheGood()) {
// Check incoming headers to see if client has this cached
$timestamp = $cache->cacheTimestamp();
if (!$this->context->getOutput()->checkLastModified($timestamp)) {
$cache->loadFromFileCache($this->context);
}
// Do any stats increment/watchlist stuff
$this->context->getWikiPage()->doViewUpdates($this->context->getUser());
// Tell OutputPage that output is taken care of
$this->context->getOutput()->disable();
wfProfileOut('main-try-filecache');
wfProfileOut(__METHOD__);
return;
}
}
wfProfileOut('main-try-filecache');
}
$this->performRequest();
// Now commit any transactions, so that unreported errors after
// output() don't roll back the whole DB transaction
wfGetLBFactory()->commitMasterChanges();
// Output everything!
$this->context->getOutput()->output();
wfProfileOut(__METHOD__);
}
示例9: main
private function main()
{
global $wgUseFileCache, $wgTitle, $wgUseAjax;
wfProfileIn(__METHOD__);
$request = $this->context->getRequest();
// Send Ajax requests to the Ajax dispatcher.
if ($wgUseAjax && $request->getVal('action', 'view') == 'ajax') {
// Set a dummy title, because $wgTitle == null might break things
// Wikia change - start
// @author macbre, wladek
$title = Wikia::createTitleFromRequest($request);
// Wikia change - end
$this->context->setTitle($title);
$wgTitle = $title;
$dispatcher = new AjaxDispatcher();
$dispatcher->performAction();
wfProfileOut(__METHOD__);
return;
}
// Get title from request parameters,
// is set on the fly by parseTitle the first time.
$title = $this->getTitle();
$action = $this->getAction();
$wgTitle = $title;
if ($wgUseFileCache && $title->getNamespace() >= 0) {
wfProfileIn('main-try-filecache');
if (HTMLFileCache::useFileCache($this->context)) {
// Try low-level file cache hit
$cache = HTMLFileCache::newFromTitle($title, $action);
if ($cache->isCacheGood()) {
// Check incoming headers to see if client has this cached
$timestamp = $cache->cacheTimestamp();
if (!$this->context->getOutput()->checkLastModified($timestamp)) {
$cache->loadFromFileCache($this->context);
}
// Do any stats increment/watchlist stuff
$this->context->getWikiPage()->doViewUpdates($this->context->getUser());
// Tell OutputPage that output is taken care of
$this->context->getOutput()->disable();
wfProfileOut('main-try-filecache');
wfProfileOut(__METHOD__);
return;
}
}
wfProfileOut('main-try-filecache');
}
$this->performRequest();
$this->finalCleanup();
wfProfileOut(__METHOD__);
}
示例10: main
private function main()
{
global $wgTitle;
$output = $this->context->getOutput();
$request = $this->context->getRequest();
// Send Ajax requests to the Ajax dispatcher.
if ($this->config->get('UseAjax') && $request->getVal('action') === 'ajax') {
// Set a dummy title, because $wgTitle == null might break things
$title = Title::makeTitle(NS_SPECIAL, 'Badtitle/performing an AJAX call in ' . __METHOD__);
$this->context->setTitle($title);
$wgTitle = $title;
$dispatcher = new AjaxDispatcher($this->config);
$dispatcher->performAction($this->context->getUser());
return;
}
// Get title from request parameters,
// is set on the fly by parseTitle the first time.
$title = $this->getTitle();
$action = $this->getAction();
$wgTitle = $title;
// Set DB query expectations for this HTTP request
$trxLimits = $this->config->get('TrxProfilerLimits');
$trxProfiler = Profiler::instance()->getTransactionProfiler();
$trxProfiler->setLogger(LoggerFactory::getInstance('DBPerformance'));
if ($request->hasSafeMethod()) {
$trxProfiler->setExpectations($trxLimits['GET'], __METHOD__);
} else {
$trxProfiler->setExpectations($trxLimits['POST'], __METHOD__);
}
// If the user has forceHTTPS set to true, or if the user
// is in a group requiring HTTPS, or if they have the HTTPS
// preference set, redirect them to HTTPS.
// Note: Do this after $wgTitle is setup, otherwise the hooks run from
// isLoggedIn() will do all sorts of weird stuff.
if ($request->getProtocol() == 'http' && preg_match('#^https://#', wfExpandUrl($request->getRequestURL(), PROTO_HTTPS)) && ($request->getSession()->shouldForceHTTPS() || $request->getCookie('forceHTTPS', '') || $request->getCookie('forceHTTPS') || $this->context->getUser()->isLoggedIn() && $this->context->getUser()->requiresHTTPS())) {
$oldUrl = $request->getFullRequestURL();
$redirUrl = preg_replace('#^http://#', 'https://', $oldUrl);
// ATTENTION: This hook is likely to be removed soon due to overall design of the system.
if (Hooks::run('BeforeHttpsRedirect', [$this->context, &$redirUrl])) {
if ($request->wasPosted()) {
// This is weird and we'd hope it almost never happens. This
// means that a POST came in via HTTP and policy requires us
// redirecting to HTTPS. It's likely such a request is going
// to fail due to post data being lost, but let's try anyway
// and just log the instance.
// @todo FIXME: See if we could issue a 307 or 308 here, need
// to see how clients (automated & browser) behave when we do
wfDebugLog('RedirectedPosts', "Redirected from HTTP to HTTPS: {$oldUrl}");
}
// Setup dummy Title, otherwise OutputPage::redirect will fail
$title = Title::newFromText('REDIR', NS_MAIN);
$this->context->setTitle($title);
// Since we only do this redir to change proto, always send a vary header
$output->addVaryHeader('X-Forwarded-Proto');
$output->redirect($redirUrl);
$output->output();
return;
}
}
if ($title->canExist() && HTMLFileCache::useFileCache($this->context)) {
// Try low-level file cache hit
$cache = new HTMLFileCache($title, $action);
if ($cache->isCacheGood()) {
// Check incoming headers to see if client has this cached
$timestamp = $cache->cacheTimestamp();
if (!$output->checkLastModified($timestamp)) {
$cache->loadFromFileCache($this->context);
}
// Do any stats increment/watchlist stuff, assuming user is viewing the
// latest revision (which should always be the case for file cache)
$this->context->getWikiPage()->doViewUpdates($this->context->getUser());
// Tell OutputPage that output is taken care of
$output->disable();
return;
}
}
// Actually do the work of the request and build up any output
$this->performRequest();
// GUI-ify and stash the page output in MediaWiki::doPreOutputCommit() while
// ChronologyProtector synchronizes DB positions or slaves accross all datacenters.
$buffer = null;
$outputWork = function () use($output, &$buffer) {
if ($buffer === null) {
$buffer = $output->output(true);
}
return $buffer;
};
// Now commit any transactions, so that unreported errors after
// output() don't roll back the whole DB transaction and so that
// we avoid having both success and error text in the response
$this->doPreOutputCommit($outputWork);
// Now send the actual output
print $outputWork();
}
示例11: getActionName
/**
* Get the action that will be executed, not necessarily the one passed
* passed through the "action" request parameter. Actions disabled in
* $wgActions will be replaced by "nosuchaction".
*
* @since 1.19
* @param $context IContextSource
* @return string: action name
*/
final public static function getActionName( IContextSource $context ) {
global $wgActions;
$request = $context->getRequest();
$actionName = $request->getVal( 'action', 'view' );
// Check for disabled actions
if ( isset( $wgActions[$actionName] ) && $wgActions[$actionName] === false ) {
$actionName = 'nosuchaction';
}
// Workaround for bug #20966: inability of IE to provide an action dependent
// on which submit button is clicked.
if ( $actionName === 'historysubmit' ) {
if ( $request->getBool( 'revisiondelete' ) ) {
$actionName = 'revisiondelete';
} else {
$actionName = 'view';
}
} elseif ( $actionName == 'editredlink' ) {
$actionName = 'edit';
}
// Trying to get a WikiPage for NS_SPECIAL etc. will result
// in WikiPage::factory throwing "Invalid or virtual namespace -1 given."
// For SpecialPages et al, default to action=view.
if ( !$context->canUseWikiPage() ) {
return 'view';
}
$action = Action::factory( $actionName, $context->getWikiPage(), $context );
if ( $action instanceof Action ) {
return $action->getName();
}
return 'nosuchaction';
}
示例12: getDebugInfo
/**
* Returns the HTML to add to the page for the toolbar
*
* @param IContextSource $context
* @return array
*/
public static function getDebugInfo(IContextSource $context)
{
if (!self::$enabled) {
return array();
}
global $wgVersion, $wgRequestTime;
$request = $context->getRequest();
// HHVM's reported memory usage from memory_get_peak_usage()
// is not useful when passing false, but we continue passing
// false for consistency of historical data in zend.
// see: https://github.com/facebook/hhvm/issues/2257#issuecomment-39362246
$realMemoryUsage = wfIsHHVM();
return array('mwVersion' => $wgVersion, 'phpEngine' => wfIsHHVM() ? 'HHVM' : 'PHP', 'phpVersion' => wfIsHHVM() ? HHVM_VERSION : PHP_VERSION, 'gitRevision' => GitInfo::headSHA1(), 'gitBranch' => GitInfo::currentBranch(), 'gitViewUrl' => GitInfo::headViewUrl(), 'time' => microtime(true) - $wgRequestTime, 'log' => self::$log, 'debugLog' => self::$debug, 'queries' => self::$query, 'request' => array('method' => $request->getMethod(), 'url' => $request->getRequestURL(), 'headers' => $request->getAllHeaders(), 'params' => $request->getValues()), 'memory' => $context->getLanguage()->formatSize(memory_get_usage($realMemoryUsage)), 'memoryPeak' => $context->getLanguage()->formatSize(memory_get_peak_usage($realMemoryUsage)), 'includes' => self::getFilesIncluded($context));
}
示例13: getDebugInfo
/**
* Returns the HTML to add to the page for the toolbar
*
* @param $context IContextSource
* @return array
*/
public static function getDebugInfo(IContextSource $context)
{
if (!self::$enabled) {
return array();
}
global $wgVersion, $wgRequestTime;
$request = $context->getRequest();
return array('mwVersion' => $wgVersion, 'phpVersion' => PHP_VERSION, 'gitRevision' => GitInfo::headSHA1(), 'gitBranch' => GitInfo::currentBranch(), 'gitViewUrl' => GitInfo::headViewUrl(), 'time' => microtime(true) - $wgRequestTime, 'log' => self::$log, 'debugLog' => self::$debug, 'queries' => self::$query, 'request' => array('method' => $request->getMethod(), 'url' => $request->getRequestURL(), 'headers' => $request->getAllHeaders(), 'params' => $request->getValues()), 'memory' => $context->getLanguage()->formatSize(memory_get_usage()), 'memoryPeak' => $context->getLanguage()->formatSize(memory_get_peak_usage()), 'includes' => self::getFilesIncluded($context));
}
示例14: main
private function main()
{
global $wgUseFileCache, $wgTitle, $wgUseAjax;
wfProfileIn(__METHOD__);
$request = $this->context->getRequest();
// Send Ajax requests to the Ajax dispatcher.
if ($wgUseAjax && $request->getVal('action', 'view') == 'ajax') {
// Set a dummy title, because $wgTitle == null might break things
$title = Title::makeTitle(NS_MAIN, 'AJAX');
$this->context->setTitle($title);
$wgTitle = $title;
$dispatcher = new AjaxDispatcher();
$dispatcher->performAction();
wfProfileOut(__METHOD__);
return;
}
// Get title from request parameters,
// is set on the fly by parseTitle the first time.
$title = $this->getTitle();
$action = $this->getAction();
$wgTitle = $title;
// If the user has forceHTTPS set to true, or if the user
// is in a group requiring HTTPS, or if they have the HTTPS
// preference set, redirect them to HTTPS.
// Note: Do this after $wgTitle is setup, otherwise the hooks run from
// isLoggedIn() will do all sorts of weird stuff.
if (($request->getCookie('forceHTTPS', '') || $request->getCookie('forceHTTPS') || $this->context->getUser()->isLoggedIn() && $this->context->getUser()->requiresHTTPS()) && $request->getProtocol() == 'http') {
$oldUrl = $request->getFullRequestURL();
$redirUrl = str_replace('http://', 'https://', $oldUrl);
if ($request->wasPosted()) {
// This is weird and we'd hope it almost never happens. This
// means that a POST came in via HTTP and policy requires us
// redirecting to HTTPS. It's likely such a request is going
// to fail due to post data being lost, but let's try anyway
// and just log the instance.
//
// @todo @fixme See if we could issue a 307 or 308 here, need
// to see how clients (automated & browser) behave when we do
wfDebugLog('RedirectedPosts', "Redirected from HTTP to HTTPS: {$oldUrl}");
}
// Setup dummy Title, otherwise OutputPage::redirect will fail
$title = Title::newFromText(NS_MAIN, 'REDIR');
$this->context->setTitle($title);
$output = $this->context->getOutput();
// Since we only do this redir to change proto, always send a vary header
$output->addVaryHeader('X-Forwarded-Proto');
$output->redirect($redirUrl);
$output->output();
wfProfileOut(__METHOD__);
return;
}
if ($wgUseFileCache && $title->getNamespace() >= 0) {
wfProfileIn('main-try-filecache');
if (HTMLFileCache::useFileCache($this->context)) {
// Try low-level file cache hit
$cache = HTMLFileCache::newFromTitle($title, $action);
if ($cache->isCacheGood()) {
// Check incoming headers to see if client has this cached
$timestamp = $cache->cacheTimestamp();
if (!$this->context->getOutput()->checkLastModified($timestamp)) {
$cache->loadFromFileCache($this->context);
}
// Do any stats increment/watchlist stuff
// Assume we're viewing the latest revision (this should always be the case with file cache)
$this->context->getWikiPage()->doViewUpdates($this->context->getUser());
// Tell OutputPage that output is taken care of
$this->context->getOutput()->disable();
wfProfileOut('main-try-filecache');
wfProfileOut(__METHOD__);
return;
}
}
wfProfileOut('main-try-filecache');
}
// Actually do the work of the request and build up any output
$this->performRequest();
// Either all DB and deferred updates should happen or none.
// The later should not be cancelled due to client disconnect.
ignore_user_abort(true);
// Now commit any transactions, so that unreported errors after
// output() don't roll back the whole DB transaction
wfGetLBFactory()->commitMasterChanges();
// Output everything!
$this->context->getOutput()->output();
wfProfileOut(__METHOD__);
}
示例15: save
/**
* Save submitted protection form
*
* @return bool Success
*/
function save()
{
# Permission check!
if ($this->disabled) {
$this->show();
return false;
}
$request = $this->mContext->getRequest();
$user = $this->mContext->getUser();
$out = $this->mContext->getOutput();
$token = $request->getVal('wpEditToken');
if (!$user->matchEditToken($token, ['protect', $this->mTitle->getPrefixedDBkey()])) {
$this->show(['sessionfailure']);
return false;
}
# Create reason string. Use list and/or custom string.
$reasonstr = $this->mReasonSelection;
if ($reasonstr != 'other' && $this->mReason != '') {
// Entry from drop down menu + additional comment
$reasonstr .= $this->mContext->msg('colon-separator')->text() . $this->mReason;
} elseif ($reasonstr == 'other') {
$reasonstr = $this->mReason;
}
$expiry = [];
foreach ($this->mApplicableTypes as $action) {
$expiry[$action] = $this->getExpiry($action);
if (empty($this->mRestrictions[$action])) {
continue;
// unprotected
}
if (!$expiry[$action]) {
$this->show(['protect_expiry_invalid']);
return false;
}
if ($expiry[$action] < wfTimestampNow()) {
$this->show(['protect_expiry_old']);
return false;
}
}
$this->mCascade = $request->getBool('mwProtect-cascade');
$status = $this->mArticle->doUpdateRestrictions($this->mRestrictions, $expiry, $this->mCascade, $reasonstr, $user);
if (!$status->isOK()) {
$this->show($out->parseInline($status->getWikiText()));
return false;
}
/**
* Give extensions a change to handle added form items
*
* @since 1.19 you can (and you should) return false to abort saving;
* you can also return an array of message name and its parameters
*/
$errorMsg = '';
if (!Hooks::run('ProtectionForm::save', [$this->mArticle, &$errorMsg, $reasonstr])) {
if ($errorMsg == '') {
$errorMsg = ['hookaborted'];
}
}
if ($errorMsg != '') {
$this->show($errorMsg);
return false;
}
WatchAction::doWatchOrUnwatch($request->getCheck('mwProtectWatch'), $this->mTitle, $user);
return true;
}