예제 #1
0
 /**
  * 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;
 }
예제 #2
0
    $lip[$page['lang']][$page['page_id']] = $page;
}
foreach ($its as $it) {
    $fromPage = $lip[$it->fromLang][$it->fromAID];
    $toPage = $lip[$it->toLang][$it->toAID];
    print "Adding images to article:" . Misc::getLangBaseURL($toPage['lang']) . '/' . $toPage['page_title'] . ' (' . $it->toLang . ' ' . $it->toAID . ') based off ' . Misc::getLangBaseURL($fromPage['lang']) . '/' . $fromPage['page_title'] . ' (' . $it->fromLang . ' ' . $it->fromAID . ")\n";
    if (!$it->addImages($dryRun)) {
        print "Failed with error:" . $it->error . "\n";
        $errors[$it->creator][] = $it;
    } else {
        $successes[$it->creator][] = $it;
        print "Success\n";
    }
    $creators[] = $it->creator;
}
$errorURLs = ImageTransfer::getErrorURLsByCreator($wgLanguageCode, $dryRun);
if (!empty($errorURLs)) {
    foreach ($errorURLs as $creator => $urls) {
        $creators[] = $creator;
    }
}
$creators = array_unique($creators);
// Send email to each person who entered images about what happened with them
foreach ($creators as $creator) {
    $user = User::newFromName($creator);
    $email = $user->getEmail();
    if ($email == NULL || $email == "") {
        next;
    }
    $msg = "<table><thead><tr><td>Inputted URL</td><td>Translated URL</td><td>Error</td></tr></thead>\n";
    if (isset($errorURLs[$creator])) {