本文整理汇总了PHP中wfExpandUrl函数的典型用法代码示例。如果您正苦于以下问题:PHP wfExpandUrl函数的具体用法?PHP wfExpandUrl怎么用?PHP wfExpandUrl使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wfExpandUrl函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: isLocalSource
/**
* Check if the given local page title is a spam regex source.
* @param Title $title
* @return bool
*/
function isLocalSource($title)
{
global $wgDBname;
if ($title->getNamespace() == NS_MEDIAWIKI) {
$sources = array("Spam-blacklist", "Spam-whitelist");
if (in_array($title->getDBkey(), $sources)) {
return true;
}
}
$thisHttp = wfExpandUrl($title->getFullUrl('action=raw'), PROTO_HTTP);
$thisHttpRegex = '/^' . preg_quote($thisHttp, '/') . '(?:&.*)?$/';
foreach ($this->files as $fileName) {
$matches = array();
if (preg_match('/^DB: (\\w*) (.*)$/', $fileName, $matches)) {
if ($wgDBname == $matches[1]) {
if ($matches[2] == $title->getPrefixedDbKey()) {
// Local DB fetch of this page...
return true;
}
}
} elseif (preg_match($thisHttpRegex, $fileName)) {
// Raw view of this page
return true;
}
}
return false;
}
示例2: wfProxyCheck
/**
* Forks processes to scan the originating IP for an open proxy server
* MemCached can be used to skip IPs that have already been scanned
*/
function wfProxyCheck()
{
global $wgBlockOpenProxies, $wgProxyPorts, $wgProxyScriptPath;
global $wgMemc, $wgProxyMemcExpiry, $wgRequest;
global $wgProxyKey;
if (!$wgBlockOpenProxies) {
return;
}
$ip = $wgRequest->getIP();
# Get MemCached key
$mcKey = wfMemcKey('proxy', 'ip', $ip);
$mcValue = $wgMemc->get($mcKey);
$skip = (bool) $mcValue;
# Fork the processes
if (!$skip) {
$title = SpecialPage::getTitleFor('Blockme');
$iphash = md5($ip . $wgProxyKey);
$url = wfExpandUrl($title->getFullURL('ip=' . $iphash), PROTO_HTTP);
foreach ($wgProxyPorts as $port) {
$params = implode(' ', array(escapeshellarg($wgProxyScriptPath), escapeshellarg($ip), escapeshellarg($port), escapeshellarg($url)));
exec("php {$params} >" . wfGetNull() . " 2>&1 &");
}
# Set MemCached key
$wgMemc->set($mcKey, 1, $wgProxyMemcExpiry);
}
}
示例3: streamAppleTouch
function streamAppleTouch()
{
global $wgAppleTouchIcon;
wfResetOutputBuffers();
if ($wgAppleTouchIcon === false) {
# That's not very helpful, that's where we are already
header('HTTP/1.1 404 Not Found');
faviconShowError('$wgAppleTouchIcon is configured incorrectly, ' . 'it must be set to something other than false \\n');
return;
}
$req = RequestContext::getMain()->getRequest();
if ($req->getHeader('X-Favicon-Loop') !== false) {
header('HTTP/1.1 500 Internal Server Error');
faviconShowError('Proxy forwarding loop detected');
return;
}
$url = wfExpandUrl($wgAppleTouchIcon, PROTO_CANONICAL);
$client = MWHttpRequest::factory($url);
$client->setHeader('X-Favicon-Loop', '1');
$status = $client->execute();
if (!$status->isOK()) {
header('HTTP/1.1 500 Internal Server Error');
faviconShowError("Failed to fetch URL \"{$url}\"");
return;
}
$content = $client->getContent();
header('Content-Length: ' . strlen($content));
header('Content-Type: ' . $client->getResponseHeader('Content-Type'));
header('Cache-Control: public');
header('Expires: ' . gmdate('r', time() + 86400));
echo $content;
}
示例4: efOpenGraphMetaPageHook
function efOpenGraphMetaPageHook(OutputPage &$out, &$sk)
{
global $wgLogo, $wgSitename, $wgXhtmlNamespaces, $egFacebookAppId, $egFacebookAdmins;
$wgXhtmlNamespaces["og"] = "http://opengraphprotocol.org/schema/";
$title = $out->getTitle();
$isMainpage = $title->isMainPage();
$meta = array();
if ($isMainpage) {
$meta["og:type"] = "website";
$meta["og:title"] = $wgSitename;
} else {
$meta["og:type"] = "article";
$meta["og:site_name"] = $wgSitename;
// Try to chose the most appropriate title for showing in news feeds.
if (defined('NS_BLOG_ARTICLE') && $title->getNamespace() == NS_BLOG_ARTICLE || defined('NS_BLOG_ARTICLE_TALK') && $title->getNamespace() == NS_BLOG_ARTICLE_TALK) {
$meta["og:title"] = $title->getSubpageText();
} else {
$meta["og:title"] = $title->getText();
}
}
if (isset($out->mMainImage) && $out->mMainImage !== false) {
if (is_object($out->mMainImage)) {
$meta["og:image"] = wfExpandUrl($out->mMainImage->createThumb(100 * 3, 100));
} else {
// In some edge-cases we won't have defined an object but rather a full URL.
$meta["og:image"] = $out->mMainImage;
}
} elseif ($isMainpage) {
$meta["og:image"] = wfExpandUrl($wgLogo);
}
if (isset($out->mDescription)) {
// set by Description2 extension, install it if you want proper og:description support
$meta["og:description"] = $out->mDescription;
}
$meta["og:url"] = $title->getFullURL();
if ($egFacebookAppId) {
/* begin wikia change */
// $meta["fb:app_id"] = $egFacebookAppId;
// fb:app_id needs a prefix property declaring the namespace, so just add it directly
$out->addHeadItem("meta:property:fb:app_id", "\t" . Html::element('meta', array('property' => 'fb:app_id', 'content' => $egFacebookAppId, 'prefix' => "fb: http://www.facebook.com/2008/fbml")) . "\n");
/* end wikia change */
}
if ($egFacebookAdmins) {
$meta["fb:admins"] = $egFacebookAdmins;
}
/* begin wikia change */
wfRunHooks('OpenGraphMetaHeaders', array("meta" => &$meta, "title" => $title));
/* end wikia change */
foreach ($meta as $property => $value) {
if ($value) {
if (isset(OutputPage::$metaAttrPrefixes) && isset(OutputPage::$metaAttrPrefixes['property'])) {
$out->addMeta("property:{$property}", $value);
} else {
$out->addHeadItem("meta:property:{$property}", "\t" . Html::element('meta', array('property' => $property, 'content' => $value)) . "\n");
}
}
}
return true;
}
示例5: __construct
/**
* Main Constructer
*
* @access public
* @return void
*/
public function __construct()
{
global $wgServer, $wgScriptPath, $wgUser;
$achievementsPage = Title::newFromText('Special:Achievements');
$this->achievementsURL = $achievementsPage->getFullURL();
$this->urlPrefix = wfExpandUrl($wgServer . $wgScriptPath);
$this->wgUser = $wgUser;
}
示例6: setupLoginLink
/**
* If WikiFactory wgEnableNewAuth variable is set to true, then this method sets login url for the New Auth Flow login page.
* Also new class is set for the login button.
* Otherwise it sets url to the old Special:Login page.
*/
private function setupLoginLink()
{
if ($this->app->wg->EnableNewAuth) {
$this->loginUrl = '/join?redirect=' . urlencode(wfExpandUrl($this->app->wg->request->getRequestURL())) . $this->getUselangParam();
$this->loginButtonClass = 'new-login';
} else {
$this->loginUrl = SpecialPage::getTitleFor('UserLogin')->getLocalURL();
$this->loginButtonClass = '';
}
}
示例7: performUploadDone
public function performUploadDone($user)
{
$this->mUpload->finalizeFile();
$status = parent::performUpload($this->comment, $this->pageText, $this->watch, $user);
if ($status['result'] !== 'Success') {
return $status;
}
$file = $this->mUpload->getLocalFile();
return array('result' => 1, 'done' => 1, 'resultUrl' => wfExpandUrl($file->getDescriptionUrl()));
}
示例8: wfCSSRender
function wfCSSRender(&$parser, $css)
{
global $wgCSSPath, $wgStylePath, $wgCSSIdentifier;
$css = trim($css);
$title = Title::newFromText($css);
$rawProtection = "{$wgCSSIdentifier}=1";
$headItem = '<!-- Begin Extension:CSS -->';
if (is_object($title) && $title->exists()) {
# Article actually in the db
$params = "action=raw&ctype=text/css&{$rawProtection}";
$url = $title->getLocalURL($params);
$headItem .= HTML::linkedStyle($url);
} elseif ($css[0] == '/') {
# Regular file
$base = $wgCSSPath === false ? $wgStylePath : $wgCSSPath;
$url = wfAppendQuery($base . $css, $rawProtection);
# Verify the expanded URL is still using the base URL
if (strpos(wfExpandUrl($url), wfExpandUrl($base)) === 0) {
$headItem .= HTML::linkedStyle($url);
} else {
$headItem .= '<!-- Invalid/malicious path -->';
}
} else {
# Inline CSS; use data URI to prevent injection. JavaScript
# will use a canary to verify load and will safely convert to
# style tag if load fails.
# Generate random CSS color that isn't black or white.
$color = dechex(mt_rand(1, hexdec('fffffe')));
$color = str_pad($color, 6, '0', STR_PAD_LEFT);
# Prepend canary CSS to sanitized user CSS
$canaryId = "{$wgCSSIdentifier}-canary-{$color}";
$canaryCSS = "#{$canaryId}{background:#{$color} !important}";
$css = $canaryCSS . Sanitizer::checkCss($css);
# Encode data URI and append link tag
$dataPrefix = 'data:text/css;charset=UTF-8;base64,';
$url = $dataPrefix . base64_encode($css);
$headItem .= HTML::linkedStyle($url);
# Calculate URI prefix to match link tag
$hrefPrefix = $dataPrefix . base64_encode('#' . $canaryId);
$hrefPrefix = substr($url, 0, strlen($hrefPrefix));
# Add JS to verify the link tag loaded and fallback if needed
$parser->getOutput()->addModules('ext.CSS');
$headItem .= HTML::inlineScript(<<<INLINESCRIPT
jQuery( function( \$ ) {
\t\$( 'link[href^="{$hrefPrefix}"]' )
\t\t.cssExtensionDataURIFallback( '{$canaryId}', '{$color}' );
} );
INLINESCRIPT
);
}
$headItem .= '<!-- End Extension:CSS -->';
$parser->getOutput()->addHeadItem($headItem);
return '';
}
示例9: getPageImageHtml
/**
* @param integer $size the width of the thumbnail
* @return string
*/
private function getPageImageHtml($size = 750)
{
if ($this->item->hasImage()) {
$thumb = models\Image::getThumbnail($this->item->getFile(), $size);
if ($thumb && $thumb->getUrl()) {
$data = array('url' => wfExpandUrl($thumb->getUrl(), PROTO_CURRENT), 'wide' => $thumb->getWidth() > $thumb->getHeight());
return Template::render('CardImage', $data);
}
}
return '';
}
示例10: testWfExpandUrl
/** @dataProvider provideExpandableUrls */
public function testWfExpandUrl($fullUrl, $shortUrl, $defaultProto, $server, $canServer, $httpsMode, $message)
{
// Fake $wgServer and $wgCanonicalServer
$this->setMwGlobals(array('wgServer' => $server, 'wgCanonicalServer' => $canServer));
// Fake $_SERVER['HTTPS'] if needed
if ($httpsMode) {
$_SERVER['HTTPS'] = 'on';
} else {
unset($_SERVER['HTTPS']);
}
$this->assertEquals($fullUrl, wfExpandUrl($shortUrl, $defaultProto), $message);
}
示例11: execute
public function execute()
{
if ($this->getPageSet()->getGoodTitleCount() == 0) {
return;
}
$params = $this->extractRequestParams();
$query = $params['query'];
$protocol = ApiQueryExtLinksUsage::getProtocolPrefix($params['protocol']);
$this->addFields(array('el_from', 'el_to'));
$this->addTables('externallinks');
$this->addWhereFld('el_from', array_keys($this->getPageSet()->getGoodTitles()));
$whereQuery = $this->prepareUrlQuerySearchString($query, $protocol);
if ($whereQuery !== null) {
$this->addWhere($whereQuery);
}
// Don't order by el_from if it's constant in the WHERE clause
if (count($this->getPageSet()->getGoodTitles()) != 1) {
$this->addOption('ORDER BY', 'el_from');
}
// If we're querying all protocols, use DISTINCT to avoid repeating protocol-relative links twice
if ($protocol === null) {
$this->addOption('DISTINCT');
}
$this->addOption('LIMIT', $params['limit'] + 1);
$offset = isset($params['offset']) ? $params['offset'] : 0;
if ($offset) {
$this->addOption('OFFSET', $params['offset']);
}
$res = $this->select(__METHOD__);
$count = 0;
foreach ($res as $row) {
if (++$count > $params['limit']) {
// We've reached the one extra which shows that
// there are additional pages to be had. Stop here...
$this->setContinueEnumParameter('offset', $offset + $params['limit']);
break;
}
$entry = array();
$to = $row->el_to;
// expand protocol-relative urls
if ($params['expandurl']) {
$to = wfExpandUrl($to, PROTO_CANONICAL);
}
ApiResult::setContent($entry, $to);
$fit = $this->addPageSubItem($row->el_from, $entry);
if (!$fit) {
$this->setContinueEnumParameter('offset', $offset + $count - 1);
break;
}
}
}
示例12: testSubPageRedirect
public function testSubPageRedirect()
{
$ctx = new RequestContext();
SpecialPageFactory::executePath(Title::newFromText('Special:Search/foo_bar'), $ctx);
$url = $ctx->getOutput()->getRedirect();
// some older versions of hhvm have a bug that doesn't parse relative
// urls with a port, so help it out a little bit.
// https://github.com/facebook/hhvm/issues/7136
$url = wfExpandUrl($url, PROTO_CURRENT);
$parts = parse_url($url);
$this->assertEquals('/w/index.php', $parts['path']);
parse_str($parts['query'], $query);
$this->assertEquals('Special:Search', $query['title']);
$this->assertEquals('foo bar', $query['search']);
}
示例13: __construct
/**
* @param string $url Url to use. If protocol-relative, will be expanded to an http:// URL
* @param array $options (optional) extra params to pass (see Http::request())
* @param string $caller The method making this request, for profiling
* @param Profiler $profiler An instance of the profiler for profiling, or null
*/
protected function __construct($url, $options = [], $caller = __METHOD__, $profiler = null)
{
global $wgHTTPTimeout, $wgHTTPConnectTimeout;
$this->url = wfExpandUrl($url, PROTO_HTTP);
$this->parsedUrl = wfParseUrl($this->url);
if (isset($options['logger'])) {
$this->logger = $options['logger'];
} else {
$this->logger = new NullLogger();
}
if (!$this->parsedUrl || !Http::isValidURI($this->url)) {
$this->status = Status::newFatal('http-invalid-url', $url);
} else {
$this->status = Status::newGood(100);
// continue
}
if (isset($options['timeout']) && $options['timeout'] != 'default') {
$this->timeout = $options['timeout'];
} else {
$this->timeout = $wgHTTPTimeout;
}
if (isset($options['connectTimeout']) && $options['connectTimeout'] != 'default') {
$this->connectTimeout = $options['connectTimeout'];
} else {
$this->connectTimeout = $wgHTTPConnectTimeout;
}
if (isset($options['userAgent'])) {
$this->setUserAgent($options['userAgent']);
}
$members = ["postData", "proxy", "noProxy", "sslVerifyHost", "caInfo", "method", "followRedirects", "maxRedirects", "sslVerifyCert", "callback"];
foreach ($members as $o) {
if (isset($options[$o])) {
// ensure that MWHttpRequest::method is always
// uppercased. Bug 36137
if ($o == 'method') {
$options[$o] = strtoupper($options[$o]);
}
$this->{$o} = $options[$o];
}
}
if ($this->noProxy) {
$this->proxy = '';
// noProxy takes precedence
}
// Profile based on what's calling us
$this->profiler = $profiler;
$this->profileName = $caller;
}
示例14: request
/**
* Perform an HTTP request
*
* @param $method String: HTTP method. Usually GET/POST
* @param $url String: full URL to act on
* @param $options Array: options to pass to MWHttpRequest object.
* Possible keys for the array:
* - timeout Timeout length in seconds
* - postData An array of key-value pairs or a url-encoded form data
* - proxy The proxy to use.
* Will use $wgHTTPProxy (if set) otherwise.
* - noProxy Override $wgHTTPProxy (if set) and don't use any proxy at all.
* - sslVerifyHost (curl only) Verify hostname against certificate
* - sslVerifyCert (curl only) Verify SSL certificate
* - caInfo (curl only) Provide CA information
* - maxRedirects Maximum number of redirects to follow (defaults to 5)
* - followRedirects Whether to follow redirects (defaults to false).
* Note: this should only be used when the target URL is trusted,
* to avoid attacks on intranet services accessible by HTTP.
* @return Mixed: (bool)false on failure or a string on success
*/
public static function request($method, $url, $options = array())
{
$url = wfExpandUrl($url);
wfDebug("HTTP: {$method}: {$url}\n");
$options['method'] = strtoupper($method);
if (!isset($options['timeout'])) {
$options['timeout'] = 'default';
}
$req = MWHttpRequest::factory($url, $options);
$status = $req->execute();
if ($status->isOK()) {
return $req->getContent();
} else {
return false;
}
}
示例15: load
public function load($parser)
{
if ($this->loaded) {
return;
}
if (!$parser->getTitle()->mUrlform) {
return;
}
$file = $parser->getTitle()->mUrlform;
$path = __DIR__ . '/css/' . $file . '.css';
if (!file_exists($path)) {
return;
}
global $wgScriptPath;
$url = wfExpandUrl("{$wgScriptPath}/extensions/CSSLoader/css/{$file}.css");
$this->url = $url;
$this->loaded = true;
}