/** * Constructor. * * @since 0.4 */ public function __construct() { parent::__construct(); $this->parser = xml_parser_create(); xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, 0); xml_set_object($this->parser, $this); xml_set_element_handler($this->parser, "startElementHandler", "endElementHandler"); xml_set_character_data_handler($this->parser, "segmentContentHandler"); }
public function execute() { global $wgUser; if (!$wgUser->isAllowed('managetms') || $wgUser->isBlocked()) { $this->dieUsageMsg(array('badaccess-groups')); } $params = $this->extractRequestParams(); // In MW 1.17 and above ApiBase::PARAM_REQUIRED can be used, this is for b/c with 1.16. foreach (array('source') as $requiredParam) { if (!isset($params[$requiredParam])) { $this->dieUsageMsg(array('missingparam', $requiredParam)); } } foreach ($params['source'] as $location) { $text = false; $dbr = wfGetDB(DB_SLAVE); $res = $dbr->select('live_translate_memories', array('memory_id', 'memory_local', 'memory_type'), array('memory_location' => $location), __METHOD__, array('LIMIT' => '1')); foreach ($res as $tm) { if ($tm->memory_local != '0') { // Obtain the contents of the article. $title = Title::newFromText($location, NS_MAIN); if (is_object($title) && $title->exists()) { $article = new Article($title); $text = $article->getContent(); } } else { // Make an HTTP request to get the file contents. False is returned on failiure. $text = Http::get($location); } if ($text !== false) { // If the text was obtained, parse it to a translation memory and import it into the db. $parser = LTTMParser::newFromType($tm->memory_type); $this->doTMImport($parser->parse($text), $tm->memory_id); } break; } } }