protected function formatData(&$rows) { global $IP; require_once "{$IP}/extensions/wikihow/TranslationLink.php"; if (!empty($rows)) { $ids = array(); foreach ($rows as $i => $row) { $ids[] = $row->ct_page_id; } $links = TranslationLink::getLinks('en', $rows[0]->ct_lang_code, array("tl_from_aid in (" . implode(",", $ids) . ")")); $idLinkMap = array(); foreach ($links as $link) { $idLinkMap["{$link->fromAID}"] = $link->toURL; } $keep = array('ct_page_id', 'ct_page_title', 'ct_user_text', 'ct_completed_timestamp', 'ct_price', 'ct_translated_title'); foreach ($rows as $j => $row) { $articleClass = $this->config->getArticleClassName(); $a = $articleClass::newFromDBRow($row, $this->dbType); $row = get_object_vars($row); $row['ct_price'] = $a->getPrice(); $row['ct_completed_timestamp'] = $a->getCompletedDate(); $row['ct_translated_title'] = $idLinkMap["{$row['ct_page_id']}"]; foreach ($row as $k => $v) { if (!in_array($k, $keep)) { unset($row[$k]); } } $rows[$j] = $row; } } }
/** * Add a bunch of URLs to the database for adding their images to various languages * @param urls New-line seperated list of URLs or Article ids from POST * @param langs Comma-seperated list of languages to add the images on */ private function addImages($urls, $langs) { $urls = preg_split("@[\r\n]+@", Misc::getUrlDecodedData($urls)); $langs = preg_split("@,@", urldecode($langs)); $realUrls = array(); $langIds = array(); foreach ($urls as $url) { if (is_numeric($url)) { $langIds[] = array("lang" => "en", "id" => $url); } else { $realUrls[] = $url; } } $pagesA = Misc::getPagesFromURLs($realUrls, array('page_id', 'page_title')); $badURLs = array(); $results = array(); foreach ($realUrls as $url) { if (!isset($pagesA[$url])) { foreach ($langs as $lang) { ImageTransfer::addBadURL($url, $lang, "URL not found"); } $results[] = array('fromURL' => $url, 'toURL' => '', 'status' => 'Bad URL'); } } $pagesB = Misc::getPagesFromLangIds($langIds, array('page_id', 'page_title')); $pages = array_merge($pagesA, $pagesB); $fromIDs = array(); $urlLookup = array(); foreach ($pages as $page) { $fromIDs[] = $page['page_id']; $urlLookup[$page['page_id']] = Misc::getLangBaseURL('en') . '/' . $page['page_title']; } if (sizeof($fromIDs) == 0) { return array(); } // Fetch to cache the pages for later use in addImage $this->batchFetchPages("en", $fromIDs); $langTLs = array(); foreach ($langs as $lang) { $langTLs[$lang] = TranslationLink::getLinks("en", $lang, array("tl_from_aid in (" . implode(',', $fromIDs) . ")")); $newFromIds = array_map(function ($m) { return $m->fromAID; }, $langTLs[$lang]); foreach ($fromIDs as $id) { //Add error links if (!in_array($id, $newFromIds)) { $this->addImage($id, $lang, 0); if (isset($urlLookup[$id])) { $results[] = array('fromURL' => $urlLookup[$id], 'toURL' => '', 'status' => 'Could not find any translation link to ' . $lang); } } } TranslationLink::batchPopulateURLs($langTLs[$lang]); // Cache the other language pages too in a batch $langIds = array(); foreach ($langTLs[$lang] as $tl) { $langIds[] = $tls->toAID; } $this->batchFetchPages($lang, $langIds); } foreach ($langs as $lang) { foreach ($langTLs[$lang] as $tl) { if (!$this->addImage($tl->fromAID, $tl->toLang, $tl->toAID)) { $results[] = array('fromURL' => $tl->fromURL, 'toURL' => $tl->toURL, 'status' => 'Queued'); } else { $results[] = array('fromURL' => $tl->fromURL, 'toURL' => $tl->toURL, 'status' => 'Failed to queue'); } } } return $results; }
$ret = $link->addLink(true, $debug); if ($ret['status'] == 0) { print "One or more URL(s) invalid\n"; $invalidLink[] = array('urla' => $link->fromURL, 'urlb' => $link->toURL); } elseif ($ret['status'] == 1) { print "Already added\n"; } elseif ($ret['status'] == 2) { print "Overwriting existing link(s):" . implode(",", $ret['dup']) . "\n"; $anotherLink[] = array('urla' => $link->fromURL, 'urlb' => $link->toURL, 'dup' => $ret['dup']); $changes++; } else { print "Link added\n"; $changes++; } } $links = TranslationLink::getLinks($lang, $wgLanguageCode, array("tl_timestamp > '" . $lowDate . "'")); foreach ($links as $link) { if ($changes >= $MAX_CHANGES) { break; } print "Checking for proper interwiki links between " . $link->toURL . "(" . $link->toAID . ") and " . $link->fromURL . "(" . $link->fromAID . ")\n"; $ret = $link->addLink(false, $debug); if ($ret['status'] == 0) { print "One or more URL(s) invalid\n"; $invalidLink[] = array('urla' => $link->toURL, 'urlb' => $link->fromURL); } else { if ($ret['status'] == 1) { print "Already added\n"; } else { if ($ret['status'] == 2) { print "Overwriting existing link(s):" . implode(",", $ret['dup']) . "\n";