Beispiel #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;
 }
//We add interwiki links as the interwiki user
global $wgUser;
$wgUser = User::newFromName("InterwikiBot");
$ourPageTable = Misc::getLangDB($wgLanguageCode) . ".page";
$lowDate = wfTimestamp(TS_MW, strtotime("-30 day", strtotime(date('Ymd', time()))));
$links = TranslationLink::batchGetRemovedLinks($wgLanguageCode, true);
TranslationLink::batchPopulateURLs($links);
foreach ($links as $link) {
    if ($link->removeLink(true, $debug)) {
        print "Removing link between " . $link->fromURL . "(" . $link->fromAID . ") and " . $link->toURL . "(" . $link->toAID . ")\n";
    } else {
        print "Failed to remove link between " . $link->fromURL . "(" . $link->fromAID . ") and " . $link->toURL . "(" . $link->toAID . ")\n";
    }
}
$links = TranslationLink::batchGetRemovedLinks($wgLanguageCode, false);
TranslationLink::batchPopulateURLs($links);
foreach ($links as $link) {
    if ($link->removeLink(false, $debug)) {
        print "Removing link between " . $link->toURL . "(" . $link->toAID . ") and " . $link->fromURL . "(" . $link->fromAID . ")\n";
    } else {
        print "Failed to remove link between " . $link->toURL . "(" . $link->toAID . ") and " . $link->fromURL . "(" . $link->fromAID . ")\n";
    }
}
foreach ($allLangs as $lang) {
    // We don't add interwiki links from a language to itself
    if ($lang == $wgLanguageCode) {
        continue;
    }
    $anotherLink = array();
    $invalidLink = array();
    $links = TranslationLink::getLinks($wgLanguageCode, $lang, array("tl_timestamp > '" . $lowDate . "'"));