示例#1
0
 /**
  * @param string $repoDir The root directory of the repo where .git can be found
  * @param bool $usePrecomputed Use precomputed information if available
  * @see precomputeValues
  */
 public function __construct($repoDir, $usePrecomputed = true)
 {
     $this->cacheFile = self::getCacheFilePath($repoDir);
     wfDebugLog('gitinfo', "Computed cacheFile={$this->cacheFile} for {$repoDir}");
     if ($usePrecomputed && $this->cacheFile !== null && is_readable($this->cacheFile)) {
         $this->cache = FormatJson::decode(file_get_contents($this->cacheFile), true);
         wfDebugLog('gitinfo', "Loaded git data from cache for {$repoDir}");
     }
     if (!$this->cacheIsComplete()) {
         wfDebugLog('gitinfo', "Cache incomplete for {$repoDir}");
         $this->basedir = $repoDir . DIRECTORY_SEPARATOR . '.git';
         if (is_readable($this->basedir) && !is_dir($this->basedir)) {
             $GITfile = file_get_contents($this->basedir);
             if (strlen($GITfile) > 8 && substr($GITfile, 0, 8) === 'gitdir: ') {
                 $path = rtrim(substr($GITfile, 8), "\r\n");
                 if ($path[0] === '/' || substr($path, 1, 1) === ':') {
                     // Path from GITfile is absolute
                     $this->basedir = $path;
                 } else {
                     $this->basedir = $repoDir . DIRECTORY_SEPARATOR . $path;
                 }
             }
         }
     }
 }
 public function execute()
 {
     $filename = $this->getArg(0);
     if (!is_readable($filename)) {
         $this->error("Error: Unable to read {$filename}", 1);
     }
     $json = FormatJson::decode(file_get_contents($filename), true);
     if ($json === null) {
         $this->error("Error: Invalid JSON", 1);
     }
     if (!isset($json['manifest_version'])) {
         $json['manifest_version'] = 1;
     }
     if ($json['manifest_version'] == ExtensionRegistry::MANIFEST_VERSION) {
         $this->output("Already at the latest version: {$json['manifest_version']}\n");
         return;
     }
     while ($json['manifest_version'] !== ExtensionRegistry::MANIFEST_VERSION) {
         $json['manifest_version'] += 1;
         $func = "updateTo{$json['manifest_version']}";
         $this->{$func}($json);
     }
     file_put_contents($filename, FormatJson::encode($json, "\t", FormatJson::ALL_OK) . "\n");
     $this->output("Updated to {$json['manifest_version']}...\n");
 }
 public function execute()
 {
     $params = $this->extractRequestParams();
     $this->requireOnlyOneParameter($params, 'vars', 'rcid', 'logid');
     // "Anti-DoS"
     if (!$this->getUser()->isAllowed('abusefilter-modify')) {
         $this->dieUsageMsg('permissiondenied');
     }
     if ($params['vars']) {
         $vars = FormatJson::decode($params['vars'], true);
     } elseif ($params['rcid']) {
         $dbr = wfGetDB(DB_SLAVE);
         $row = $dbr->selectRow('recentchanges', '*', array('rc_id' => $params['rcid']), __METHOD__);
         if (!$row) {
             $this->dieUsageMsg(array('nosuchrcid', $params['rcid']));
         }
         $vars = AbuseFilter::getVarsFromRCRow($row);
     } elseif ($params['logid']) {
         $dbr = wfGetDB(DB_SLAVE);
         $row = $dbr->selectRow('abuse_filter_log', '*', array('afl_id' => $params['logid']), __METHOD__);
         if (!$row) {
             $this->dieUsage("There is no abuselog entry with the id ``{$params['logid']}''", 'nosuchlogid');
         }
         $vars = AbuseFilter::loadVarDump($row->afl_var_dump);
     }
     if (AbuseFilter::checkSyntax($params['filter']) !== true) {
         $this->dieUsage('The filter has invalid syntax', 'badsyntax');
     }
     $result = AbuseFilter::checkConditions($params['filter'], $vars);
     $this->getResult()->addValue(null, $this->getModuleName(), array('result' => $result));
 }
 protected function fetchScriptList()
 {
     $data = ['action' => 'query', 'format' => 'json', 'list' => 'allpages', 'apnamespace' => '8', 'aplimit' => '500', 'continue' => ''];
     $baseUrl = $this->getArg(0);
     $pages = [];
     while (true) {
         $url = wfAppendQuery($baseUrl, $data);
         $strResult = Http::get($url, [], __METHOD__);
         $result = FormatJson::decode($strResult, true);
         $page = null;
         foreach ($result['query']['allpages'] as $page) {
             if (substr($page['title'], -3) === '.js') {
                 strtok($page['title'], ':');
                 $pages[] = strtok('');
             }
         }
         if ($page !== null) {
             $this->output("Fetched list up to {$page['title']}\n");
         }
         if (isset($result['continue'])) {
             // >= 1.21
             $data = array_replace($data, $result['continue']);
         } elseif (isset($result['query-continue']['allpages'])) {
             // <= 1.20
             $data = array_replace($data, $result['query-continue']['allpages']);
         } else {
             break;
         }
     }
     return $pages;
 }
示例#5
0
 /**
  * Tests JSON pretty-printing.
  * @covers JsonSchemaContent::preSaveTransform
  */
 function testPreSaveTransform()
 {
     $transformed = new JsonSchemaContent(self::VALID_JSON_SCHEMA);
     $prettyJson = $transformed->preSaveTransform(new Title(), new User(), new ParserOptions())->getNativeData();
     $this->assertContains("\n", $prettyJson, 'Transformed JSON is beautified.');
     $this->assertEquals(FormatJson::decode($prettyJson), FormatJson::decode(self::VALID_JSON_SCHEMA), 'Beautification does not alter JSON value.');
 }
示例#6
0
 public function execute()
 {
     global $wgUser;
     if (!$wgUser->isAllowed('surveysubmit') || $wgUser->isBlocked()) {
         $this->dieUsageMsg(array('badaccess-groups'));
     }
     $params = $this->extractRequestParams();
     if (!(isset($params['id']) xor isset($params['name']))) {
         $this->dieUsage(wfMsg('survey-err-id-xor-name'), 'id-xor-name');
     }
     if (isset($params['name'])) {
         $survey = Survey::newFromName($params['name'], null, false);
         if ($survey === false) {
             $this->dieUsage(wfMsgExt('survey-err-survey-name-unknown', 'parsemag', $params['name']), 'survey-name-unknown');
         }
     } else {
         $survey = Survey::newFromId($params['id'], null, false);
         if ($survey === false) {
             $this->dieUsage(wfMsgExt('survey-err-survey-id-unknown', 'parsemag', $params['id']), 'survey-id-unknown');
         }
     }
     $submission = new SurveySubmission(array('survey_id' => $survey->getId(), 'page_id' => 0, 'user_name' => $GLOBALS['wgUser']->getName(), 'time' => wfTimestampNow()));
     foreach (FormatJson::decode($params['answers']) as $answer) {
         $submission->addAnswer(SurveyAnswer::newFromArray((array) $answer));
     }
     $submission->writeToDB();
 }
 protected function getUntranslatedPages($apiUrl, $category, $targetDomain)
 {
     $this->output("Fetching pages from {$category} not present in {$targetDomain} ...");
     $pages = array();
     $params = array('action' => 'query', 'format' => 'json', 'generator' => 'categorymembers', 'gcmtitle' => "Category:{$category}", 'gcmnamespace' => 0, 'gcmlimit' => 500, 'gcmsort' => 'timestamp', 'prop' => 'langlinks', 'lllang' => $targetDomain, 'lllimit' => 500, 'continue' => '');
     while (true) {
         $url = $apiUrl . http_build_query($params);
         $json = Http::get($url);
         $data = FormatJson::decode($json, true);
         if (!isset($data['query'])) {
             $this->output("\t[FAIL]\n");
             return array();
         }
         $pagesInCategory = $data['query']['pages'];
         foreach ($pagesInCategory as $pageId => $page) {
             if (!isset($page['langlinks'])) {
                 $pages[] = $page['title'];
             }
         }
         if (!isset($data['continue']) || count($pages) > 5000) {
             break;
         } else {
             unset($params['llcontinue']);
             unset($params['gcmcontinue']);
             $params += $data['continue'];
         }
     }
     $this->output("\t[OK]\n");
     return $pages;
 }
 public function execute()
 {
     global $wgUser;
     $result = $this->getResult();
     $params = $this->extractRequestParams();
     $token = array();
     if ($wgUser->isAnon()) {
         if (!isset($params['anontoken'])) {
             $this->dieUsageMsg(array('missingparam', 'anontoken'));
         } elseif (strlen($params['anontoken']) != 32) {
             $this->dieUsage('The anontoken is not 32 characters', 'invalidtoken');
         }
         $token = $params['anontoken'];
     } else {
         $token = '';
     }
     $dbr = wfGetDB(DB_SLAVE);
     $dbw = wfGetDB(DB_MASTER);
     // Check if the incoming survey is valid
     $surveyCount = $dbr->selectRow('research_tools_surveys', 'rts_id', array('rts_id' => $params['survey']), __METHOD__);
     if ($surveyCount === false) {
         $this->dieUsage('The survey is unknown', 'invalidsurvey');
     }
     // Find an existing response from this user for this survey
     $response = $dbr->selectRow('research_tools_survey_responses', 'rtsr_id', array('rtsr_user_text' => $wgUser->getName(), 'rtsr_user_anon_token' => $token, 'rtsr_survey' => $params['survey']), __METHOD__);
     if ($response !== false) {
         // Delete any of the previous answers (they questions may have changed)
         $dbw->delete('research_tools_survey_answers', array('rtsa_response' => $response->rtsr_id), __METHOD__);
     }
     // Decode JSON answer data
     $answers = FormatJson::decode($params['answers'], true);
     if (!is_array($answers)) {
         $this->dieUsage('Invalid answer data', 'invalidanswers');
     }
     // Verify questions exist
     foreach ($answers as $question => $answer) {
         $question = $dbr->selectRow('research_tools_survey_questions', 'rtsq_id', array('rtsq_survey' => $params['survey'], 'rtsq_id' => $question), __METHOD__);
         if ($question === false) {
             $this->dieUsage('A question is unknown', 'invalidquestion');
         }
     }
     if ($response === false) {
         // Insert a new response row
         $dbw->insert('research_tools_survey_responses', array('rtsr_time' => wfTimestamp(TS_MW), 'rtsr_user_text' => $wgUser->getName(), 'rtsr_user_anon_token' => $token, 'rtsr_survey' => $params['survey']), __METHOD__);
         $response = $dbw->insertId();
     } else {
         $response = $response->rtsr_id;
         // Update the timestamp of the existing response row
         $dbw->update('research_tools_survey_responses', array('rtsr_time' => wfTimestamp(TS_MW)), array('rtsr_id' => $response), __METHOD__);
     }
     // Insert answers for the response
     $answerRows = array();
     foreach ($answers as $question => $answer) {
         // Build row data
         $answerRows[] = array('rtsa_response' => $response, 'rtsa_question' => $question, 'rtsa_value_integer' => is_numeric($answer) ? intval($answer) : null, 'rtsa_value_text' => is_numeric($answer) ? '' : $answer);
     }
     $dbw->insert('research_tools_survey_answers', $answerRows, __METHOD__);
     // Add success to result
     $result->addValue(null, $this->getModuleName(), array('result' => 'Success'));
 }
 /**
  * Check, if the user solved the captcha.
  *
  * Based on reference implementation:
  * https://github.com/google/recaptcha#php
  *
  * @return boolean
  */
 function passCaptcha()
 {
     global $wgRequest, $wgReCaptchaSecretKey, $wgReCaptchaSendRemoteIP;
     $url = 'https://www.google.com/recaptcha/api/siteverify';
     // Build data to append to request
     $data = array('secret' => $wgReCaptchaSecretKey, 'response' => $wgRequest->getVal('g-recaptcha-response'));
     if ($wgReCaptchaSendRemoteIP) {
         $data['remoteip'] = $wgRequest->getIP();
     }
     $url = wfAppendQuery($url, $data);
     $request = MWHttpRequest::factory($url, array('method' => 'GET'));
     $status = $request->execute();
     if (!$status->isOK()) {
         $this->error = 'http';
         $this->logStatusError($status);
         return false;
     }
     $response = FormatJson::decode($request->getContent(), true);
     if (!$response) {
         $this->error = 'json';
         $this->logStatusError($this->error);
         return false;
     }
     if (isset($response['error-codes'])) {
         $this->error = 'recaptcha-api';
         $this->logCheckError($response['error-codes']);
         return false;
     }
     return $response['success'];
 }
 /**
  * Pretty-print JSON
  *
  * @return bool|null|string
  */
 public function beautifyJSON()
 {
     $decoded = FormatJson::decode($this->getNativeData(), true);
     if (!is_array($decoded)) {
         return null;
     }
     return FormatJson::encode($decoded, true);
 }
示例#11
0
 /**
  * @param string $json JSON representation of the restrictions
  * @return MWRestrictions
  */
 public static function newFromJson($json)
 {
     $restrictions = FormatJson::decode($json, true);
     if (!is_array($restrictions)) {
         throw new InvalidArgumentException('Invalid restrictions JSON');
     }
     return new self($restrictions);
 }
 /**
 	@brief Perform API request and return the resulting structure.
 	@note If $query contains 'token' => 'null', then 'token'
 		will be set to the current value of $editToken.
 */
 public function query($query)
 {
     $query['format'] = 'json';
     if (array_key_exists('token', $query) && is_null($query['token'])) {
         $query['token'] = $this->editToken;
     }
     $req = $this->t->httpPost($this->apiUrl, $query);
     return FormatJson::decode($req->getContent(), true);
 }
示例#13
0
 public function parse($contents)
 {
     $messages = FormatJson::decode($contents, true);
     unset($messages['@metadata']);
     if ($this->code) {
         return array($this->code => $messages);
     }
     // Assuming that the array is keyed by language codes
     return $messages;
 }
示例#14
0
 /**
  * @param object $row bot_passwords database row
  * @param bool $isSaved Whether the bot password was read from the database
  * @param int $flags IDBAccessObject read flags
  */
 protected function __construct($row, $isSaved, $flags = self::READ_NORMAL)
 {
     $this->isSaved = $isSaved;
     $this->flags = $flags;
     $this->centralId = (int) $row->bp_user;
     $this->appId = $row->bp_app_id;
     $this->token = $row->bp_token;
     $this->restrictions = MWRestrictions::newFromJson($row->bp_restrictions);
     $this->grants = FormatJson::decode($row->bp_grants);
 }
示例#15
0
 /**
  * Load information stored in the database about modules.
  *
  * This method grabs modules dependencies from the database and updates modules
  * objects.
  *
  * This is not inside the module code because it is much faster to
  * request all of the information at once than it is to have each module
  * requests its own information. This sacrifice of modularity yields a substantial
  * performance improvement.
  *
  * @param array $modules List of module names to preload information for
  * @param ResourceLoaderContext $context Context to load the information within
  */
 public function preloadModuleInfo(array $modules, ResourceLoaderContext $context)
 {
     if (!count($modules)) {
         // Or else Database*::select() will explode, plus it's cheaper!
         return;
     }
     $dbr = wfGetDB(DB_SLAVE);
     $skin = $context->getSkin();
     $lang = $context->getLanguage();
     // Get file dependency information
     $res = $dbr->select('module_deps', array('md_module', 'md_deps'), array('md_module' => $modules, 'md_skin' => $skin), __METHOD__);
     // Set modules' dependencies
     $modulesWithDeps = array();
     foreach ($res as $row) {
         $module = $this->getModule($row->md_module);
         if ($module) {
             $module->setFileDependencies($skin, FormatJson::decode($row->md_deps, true));
             $modulesWithDeps[] = $row->md_module;
         }
     }
     // Register the absence of a dependency row too
     foreach (array_diff($modules, $modulesWithDeps) as $name) {
         $module = $this->getModule($name);
         if ($module) {
             $this->getModule($name)->setFileDependencies($skin, array());
         }
     }
     // Get message blob mtimes. Only do this for modules with messages
     $modulesWithMessages = array();
     foreach ($modules as $name) {
         $module = $this->getModule($name);
         if ($module && count($module->getMessages())) {
             $modulesWithMessages[] = $name;
         }
     }
     $modulesWithoutMessages = array_flip($modules);
     // Will be trimmed down by the loop below
     if (count($modulesWithMessages)) {
         $res = $dbr->select('msg_resource', array('mr_resource', 'mr_timestamp'), array('mr_resource' => $modulesWithMessages, 'mr_lang' => $lang), __METHOD__);
         foreach ($res as $row) {
             $module = $this->getModule($row->mr_resource);
             if ($module) {
                 $module->setMsgBlobMtime($lang, wfTimestamp(TS_UNIX, $row->mr_timestamp));
                 unset($modulesWithoutMessages[$row->mr_resource]);
             }
         }
     }
     foreach (array_keys($modulesWithoutMessages) as $name) {
         $module = $this->getModule($name);
         if ($module) {
             $module->setMsgBlobMtime($lang, 0);
         }
     }
 }
 protected function parseResponse(TranslationQueryResponse $reply)
 {
     $body = $reply->getBody();
     $response = FormatJson::decode($body);
     if (!is_object($response)) {
         throw new TranslationWebServiceException('Invalid json: ' . serialize($body));
     }
     $text = preg_replace('~^<div>(.*)</div>$~', '\\1', $response->contents);
     $text = $this->unwrapUntranslatable($text);
     return trim($text);
 }
 protected function parseResponse(TranslationQueryResponse $reply)
 {
     $body = $reply->getBody();
     $parsed = FormatJson::decode($body, true);
     if (!is_array($parsed)) {
         throw new TranslationWebServiceException('Invalid json: ' . serialize($body));
     }
     if (!isset($parsed['ttmserver'])) {
         throw new TranslationWebServiceException('Unexpected reply from remote server');
     }
     return $parsed['ttmserver'];
 }
 protected function parseResponse(TranslationQueryResponse $reply)
 {
     $body = $reply->getBody();
     $response = FormatJson::decode($body);
     if (!is_object($response)) {
         throw new TranslationWebServiceException('Invalid json: ' . serialize($body));
     } elseif ($response->code !== 200) {
         throw new TranslationWebServiceException($response->message);
     }
     $text = Sanitizer::decodeCharReferences($response->text[0]);
     $text = $this->unwrapUntranslatable($text);
     return trim($text);
 }
 /**
  * @param array $data
  * @return array Parsed data.
  */
 public function readFromVariable($data)
 {
     $authors = AmdFFS::extractAuthors($data);
     $data = AmdFFS::extractMessagePart($data);
     $messages = (array) FormatJson::decode($data, true);
     $metadata = array();
     // Take care of regular language bundles, as well as the root bundle.
     if (isset($messages['root'])) {
         $messages = $this->group->getMangler()->mangle($messages['root']);
     } else {
         $messages = $this->group->getMangler()->mangle($messages);
     }
     return array('MESSAGES' => $messages, 'AUTHORS' => $authors, 'METADATA' => $metadata);
 }
 /**
  * Get the files this module depends on indirectly for a given skin.
  * Currently these are only image files referenced by the module's CSS.
  *
  * @param $skin String: Skin name
  * @return Array: List of files
  */
 public function getFileDependencies($skin)
 {
     // Try in-object cache first
     if (isset($this->fileDeps[$skin])) {
         return $this->fileDeps[$skin];
     }
     // Use file cache instead of db ( for mwEmbed minimal config and minimal framework code )
     $deps = mweGetFromFileCache(implode(array('module_deps', 'md_deps', 'md_module_' . $this->getName(), 'md_skin_' . $skin)));
     if (!is_null($deps)) {
         $this->fileDeps[$skin] = (array) FormatJson::decode($deps, true);
     } else {
         $this->fileDeps[$skin] = array();
     }
     return $this->fileDeps[$skin];
 }
 function showEntry($row)
 {
     global $wgOut;
     $wgOut->addHTML("<hr/>");
     $wgOut->addHTML("<table><tbody>");
     $data = FormatJson::decode($row->ch_data, true);
     $header = wfMsg('community-applications-application-title', $row->ch_id, $data['family-name'], $data['given-name']);
     $wgOut->addHTML(Xml::element('h2', null, $header));
     foreach ($data as $key => $value) {
         $html = Xml::element('td', null, $key);
         $html .= Xml::element('td', null, $value);
         $html = Xml::tags('tr', null, $html) . "\n";
         $wgOut->addHTML($html);
     }
     $wgOut->addHTML("</tbody></table>");
 }
 /**
  * @param array $data
  * @return array Parsed data.
  */
 public function readFromVariable($data)
 {
     $messages = (array) FormatJson::decode($data, true);
     $authors = array();
     $metadata = array();
     if (isset($messages['@metadata']['authors'])) {
         $authors = (array) $messages['@metadata']['authors'];
         unset($messages['@metadata']['authors']);
     }
     if (isset($messages['@metadata'])) {
         $metadata = $messages['@metadata'];
     }
     unset($messages['@metadata']);
     $messages = $this->group->getMangler()->mangle($messages);
     return array('MESSAGES' => $messages, 'AUTHORS' => $authors, 'METADATA' => $metadata);
 }
 /**
  * Hook: LocalisationCacheRecache
  */
 public static function onRecache(LocalisationCache $lc, $code, array &$cache)
 {
     $dir = LocalisationUpdate::getDirectory();
     if (!$dir) {
         return true;
     }
     $codeSequence = array_merge(array($code), $cache['fallbackSequence']);
     foreach ($codeSequence as $csCode) {
         $fileName = "{$dir}/" . self::getFilename($csCode);
         if (is_readable($fileName)) {
             $data = FormatJson::decode(file_get_contents($fileName), true);
             $cache['messages'] = array_merge($cache['messages'], $data);
         }
         $cache['deps'][] = new FileDependency($fileName);
     }
     return true;
 }
 function wfJsonI18nShimc4861ceea00d327d($cache, $code, &$cachedData)
 {
     $codeSequence = array_merge([$code], $cachedData['fallbackSequence']);
     foreach ($codeSequence as $csCode) {
         $fileName = __DIR__ . "/i18n/{$csCode}.json";
         if (is_readable($fileName)) {
             $data = FormatJson::decode(file_get_contents($fileName), true);
             foreach (array_keys($data) as $key) {
                 if ($key === '' || $key[0] === '@') {
                     unset($data[$key]);
                 }
             }
             $cachedData['messages'] = array_merge($data, $cachedData['messages']);
         }
         $cachedData['deps'][] = new FileDependency($fileName);
     }
     return true;
 }
 function wfJsonI18nShimc0319b6f58a1c872($cache, $code, &$cachedData)
 {
     $codeSequence = array_merge(array($code), $cachedData['fallbackSequence']);
     foreach ($codeSequence as $csCode) {
         $fileName = dirname(__FILE__) . "/../i18n/{$csCode}.json";
         if (is_readable($fileName)) {
             $data = FormatJson::decode(file_get_contents($fileName), true);
             foreach (array_keys($data) as $key) {
                 if ($key === '' || $key[0] === '@') {
                     unset($data[$key]);
                 }
             }
             $cachedData['messages'] = array_merge($data, $cachedData['messages']);
         }
         $cachedData['deps'][] = new FileDependency($fileName);
     }
     return true;
 }
function doJobLoop(){
	global $wgJobTypeConfig, $wahJobDelay, $wahRunOnce, $wahStatusOutput;

	//look for jobs (sleep for $wahJobDelay if none found)
	$job = WahJobManager :: getNewJob(false, 'Internal');
	if(!$job && $wahRunOnce == false){
		if($wahStatusOutput)
			print "no jobs found waiting $wahJobDelay \n";
		sleep($wahJobDelay);
		return doJobLoop();
	}elseif(!$job  && $wahRunOnce == true){
		if($wahStatusOutput)
			print "no job found \n";
		return ;
	}

	$jobSet = WahJobManager ::getJobSetById( $job->job_set_id );
	$jobDetails = FormatJson::decode( $job->job_json ) ;

	//get the title (so we can access the source file)
	$fTitle = Title::newFromText( $job->title, $job->ns );
	$file = wfLocalFile( $fTitle );
	$thumbPath = $file->getThumbPath( $jobSet->set_encodekey );
	//make sure the directory is ready:
	wfMkdirParents( $thumbPath, null, __METHOD__ );

	$destTarget = $thumbPath . '.ogg';
	//issue the encoding command
	if($wahStatusOutput) print "Running Encode Command...\n";
	wahDoEncode($file->getPath(), $destTarget, $jobDetails->encodeSettings );

	//once done with encode update the status:
	WahJobManager :: updateJobDone($job);
	//update set done (if only one item in the set)
	$wjm = WahJobManager::newFromSet( $jobSet );
	$percDone = $wjm->getDonePerc();
	if( $percDone == 1 ){
		WahJobManager :: updateSetDone( $jobSet );
	}else{
		if($wahStatusOutput)
			print "job not complete? (might be mixing chunkDuration types?) ";
	}
}
 public function fetchDirectory($pattern)
 {
     $p = '~^https://raw.github\\.com/(?P<org>[^/]+)/(?P<repo>[^/]+)/(?P<branch>[^/]+)/(?P<path>.+)/.+$~';
     preg_match($p, $pattern, $m);
     $json = Http::get("https://api.github.com/repos/{$m['org']}/{$m['repo']}/contents/{$m['path']}");
     if (!$json) {
         throw new Exception("Unable to get directory listing for {$m['org']}/{$m['repo']}");
     }
     $files = array();
     $json = FormatJson::decode($json, true);
     foreach ($json as $fileinfo) {
         $fileurl = dirname($pattern) . '/' . $fileinfo['name'];
         $file = $this->fetchFile($fileurl);
         if ($file) {
             $files[$fileurl] = $file;
         }
     }
     return $files;
 }
示例#28
0
 /** 
  * Execute a shell command to obtain the parse tree of a string of wikitext
  *
  * @param String wikitext
  * @return Array ret Array of two keys, 'contents' with script output, 'errors' with errors if any.
  */
 public function getParseTree($text)
 {
     global $wgVisualEditorParserCmd, $wgServer, $wgScriptPath;
     // TODO This is probably not very portable to non-Unix OS. There's a lot of code in wfShellExec to make
     // that portable and secure on Windows etc. In any case the existing PHP-based parser calls out to an external script to do
     // HTML-tidy anyway, in a similar manner, without any shell escapes...
     $cmd = join(" ", array($wgVisualEditorParserCmd, '--wgScriptPath', wfEscapeShellArg($wgServer . $wgScriptPath)));
     $parserIn = 0;
     $parserOut = 1;
     $parserErr = 2;
     $descriptorSpec = array($parserIn => array('pipe', 'r'), $parserOut => array('pipe', 'w'), $parserErr => array('pipe', 'w'));
     $pipes = array();
     $process = proc_open($cmd, $descriptorSpec, $pipes);
     $ret = array('contents' => null);
     if (is_resource($process)) {
         // Theoretically, this style of communication could cause a deadlock
         // here. If the stdout buffer fills up, then writes to stdin could
         // block.
         //
         // TODO This might be an opportune time to give the parser all the subtemplates it's going to need,
         // such that we can. The DB does have a mapping of title to templates used.
         // Would need a convention for indicating multiple files in the text we write to the parser, like mime multipart
         fwrite($pipes[$parserIn], $text);
         fclose($pipes[$parserIn]);
         $ret['contents'] = FormatJson::decode(self::readFilehandle($pipes[$parserOut]));
         $errors = self::readFilehandle($pipes[$parserErr]);
         if ($errors != '' and $errors != null) {
             $ret['errors'] = $errors;
         }
         $retval = proc_close($process);
         if ($retval != 0) {
             wfWarn("Parser process returned {$retval}");
             if (!$ret['errors']) {
                 $ret['errors'] = 'External parser process returned error code, check server logs';
             }
         }
     } else {
         wfWarn("Unable to start external parser process");
         $ret['errors'] = "Unable to start external parser process, check server logs";
     }
     return $ret;
 }
 function wfJsonI18nShim823c3b92006b1243($cache, $code, &$cachedData)
 {
     $codeSequence = array_merge(array($code), $cachedData['fallbackSequence']);
     foreach ($codeSequence as $csCode) {
         // modified by jamesmontalvo3 since this file was moved
         global $egApprovedRevsIP;
         $fileName = $egApprovedRevsIP . "i18n/{$csCode}.json";
         if (is_readable($fileName)) {
             $data = FormatJson::decode(file_get_contents($fileName), true);
             foreach (array_keys($data) as $key) {
                 if ($key === '' || $key[0] === '@') {
                     unset($data[$key]);
                 }
             }
             $cachedData['messages'] = array_merge($data, $cachedData['messages']);
         }
         $cachedData['deps'][] = new FileDependency($fileName);
     }
     return true;
 }
示例#30
-1
 /**
  * Process a newJob req:
  */
 function proccessJobReq()
 {
     if (isset($this->mParams['jobset']) && $this->mParams['jobset']) {
         $job = WahJobManager::getNewJob($this->mParams['jobset']);
     } else {
         $job = WahJobManager::getNewJob();
     }
     if (!$job) {
         return $this->getResult()->addValue(null, $this->getModuleName(), array('nojobs' => true));
     } else {
         $job4Client = array();
         //unpack the $job_json
         $job4Client['job_json'] = FormatJson::decode($job->job_json);
         //we set the job key to job_id _ sha1
         $job4Client['job_key'] = $job->job_id . '_' . sha1($job->job_json);
         $job4Client['job_title'] = $job->title;
         $job4Client['job_ns'] = $job->ns;
         $job4Client['job_set_id'] = $job->job_set_id;
         $tTitle = Title::newFromText($job->title, $job->ns);
         $job4Client['job_fullTitle'] = $tTitle->getFullText();
         //@@todo avoid an api round trip return url here:
         //$job4Client['job_url'] = $file->getFullURL();
         $this->getResult()->addValue(null, $this->getModuleName(), array('job' => $job4Client));
     }
 }