function printSharedImageText() { global $wgRepositoryBaseUrl, $wgFetchCommonsDescriptions, $wgOut, $wgUser; $url = $wgRepositoryBaseUrl . urlencode($this->mTitle->getDBkey()); $sharedtext = "<div class='sharedUploadNotice'>" . wfMsgWikiHtml("sharedupload"); if ($wgRepositoryBaseUrl && !$wgFetchCommonsDescriptions) { $sk = $wgUser->getSkin(); $title = Title::makeTitle(NS_SPECIAL, 'Upload'); $link = $sk->makeKnownLinkObj($title, wfMsgHtml('shareduploadwiki-linktext'), array('wpDestFile' => urlencode($this->img->getName()))); $sharedtext .= " " . wfMsgWikiHtml('shareduploadwiki', $link); } $sharedtext .= "</div>"; $wgOut->addHTML($sharedtext); if ($wgRepositoryBaseUrl && $wgFetchCommonsDescriptions) { require_once "HttpFunctions.php"; $ur = ini_set('allow_url_fopen', true); $text = wfGetHTTP($url . '?action=render'); ini_set('allow_url_fopen', $ur); if ($text) { $this->mExtraDescription = $text; } } }
function getHTTP($url) { // Use wfGetHTTP from MW 1.5 if it is available include_once 'HttpFunctions.php'; if (function_exists('wfGetHTTP')) { $text = wfGetHTTP($url); } else { $url_fopen = ini_set('allow_url_fopen', 1); $text = file_get_contents($url); ini_set('allow_url_fopen', $url_fopen); } return $text; }
function buildUpRegexes() { global $IP; /* todo cache, anyone? could check for SpamBlacklist extension, and if enabled, get it from cache it creates */ /* for each line in the spam blacklist, apply a regex */ $lines = array(); $lines = array_merge($lines, explode("\n", wfGetHTTP(CLEANUPSPAM_FILE))); /* omit comments and such */ $lines = array_filter(array_map('trim', preg_replace('/#.*$/', '', $lines))); $regexStart = '/[a-z0-9_\\-.]*('; $regexEnd = ')/Si'; $regexes = array(); /* now, produce a massive regex */ foreach ($lines as $line) { $regexes[] = $regexStart . $line . $regexEnd; } return $regexes; }
function getHTTP($url) { // Use wfGetHTTP from MW 1.5 if it is available global $IP; include_once "{$IP}/includes/HttpFunctions.php"; wfSuppressWarnings(); if (class_exists('HTTP')) { $text = HTTP::Get($url); } else { if (function_exists('wfGetHTTP')) { $text = wfGetHTTP($url); } else { $url_fopen = ini_set('allow_url_fopen', 1); $text = file_get_contents($url); ini_set('allow_url_fopen', $url_fopen); } } wfRestoreWarnings(); return $text; }
function printSharedImageText() { global $wgRepositoryBaseUrl, $wgFetchCommonsDescriptions, $wgOut; $url = $wgRepositoryBaseUrl . urlencode($this->mTitle->getDBkey()); $sharedtext = "<div class='sharedUploadNotice'>" . wfMsg("sharedupload"); if ($wgRepositoryBaseUrl && !$wgFetchCommonsDescriptions) { $sharedtext .= " " . wfMsg("shareduploadwiki", $url); } $sharedtext .= "</div>"; $wgOut->addWikiText($sharedtext); if ($wgRepositoryBaseUrl && $wgFetchCommonsDescriptions) { require_once "HttpFunctions.php"; $ur = ini_set('allow_url_fopen', true); $text = wfGetHTTP($url . '?action=render'); ini_set('allow_url_fopen', $ur); if ($text) { $this->mExtraDescription = $text; } } }
/** * Contact the MWDaemon search server and return a wrapper * object with the set of results. Results may be cached. * * @param string $method The protocol verb to use * @param string $query * @param int $limit * @return array * @access public * @static */ function newFromQuery($method, $query, $namespaces = array(), $limit = 10, $offset = 0, $case = 'ignore') { $fname = 'LuceneSearchSet::newFromQuery'; wfProfileIn($fname); global $wgLuceneHost, $wgLucenePort, $wgLuceneSearchVersion; global $wgDBname, $wgMemc; $enctext = rawurlencode(trim($query)); $searchPath = "/{$method}/{$wgDBname}/{$enctext}?" . wfArrayToCGI(array('namespaces' => implode(',', $namespaces), 'offset' => $offset, 'limit' => $limit, 'case' => $case)); global $wgOut; $wgOut->addHtml("<!-- querying {$searchPath} -->\n"); // Cache results for fifteen minutes; they'll be read again // on reloads and paging. $key = wfMemcKey('lucene', $wgLuceneSearchVersion, md5($searchPath)); $resultSet = $wgMemc->get($key); if (is_object($resultSet)) { wfDebug("{$fname}: got cached lucene results for key {$key}\n"); wfProfileOut($fname); return $resultSet; } if (is_array($wgLuceneHost)) { $hosts = $wgLuceneHost; } else { $hosts = array($wgLuceneHost); } $remaining = count($hosts); $pick = mt_rand(0, count($hosts) - 1); $data = false; while ($data === false && $remaining-- > 0) { // Start at a random position in the list, and rotate through // until we find a host that works or run out of hosts. $pick = ($pick + 1) % count($hosts); $host = $hosts[$pick]; $searchUrl = "http://{$host}:{$wgLucenePort}{$searchPath}"; wfDebug("Fetching search data from {$searchUrl}\n"); wfSuppressWarnings(); wfProfileIn($fname . '-contact-' . $host); $data = wfGetHTTP($searchUrl); wfProfileOut($fname . '-contact-' . $host); wfRestoreWarnings(); if ($data === false) { wfDebug("Failed on {$searchUrl}!\n"); } } if ($data === false || $data === '') { // Network error or server error wfProfileOut($fname); return false; } else { $inputLines = explode("\n", trim($data)); $resultLines = array_map('trim', $inputLines); } $suggestion = null; $totalHits = null; if ($method == 'search') { # This method outputs a summary line first. $totalHits = array_shift($resultLines); if ($totalHits === false) { # I/O error? this shouldn't happen wfDebug("Couldn't read summary line...\n"); } else { $totalHits = intval($totalHits); wfDebug("total [{$totalHits}] hits\n"); if ($totalHits == 0) { # No results, but we got a suggestion... $suggestion = urldecode(array_shift($resultLines)); wfDebug("no results; suggest: [{$suggestion}]\n"); } } } $resultSet = new LuceneSearchSet($resultLines, $totalHits, $suggestion); wfDebug($fname . ": caching lucene results for key {$key}\n"); global $wgLuceneCacheExpiry; $wgMemc->add($key, $resultSet, $wgLuceneCacheExpiry); wfProfileOut($fname); return $resultSet; }