function getAllExclusions()
 {
     global $wgOut, $wgActiveLanguages;
     $wgOut->setArticleBodyOnly(true);
     $dbr = wfGetDB(DB_SLAVE);
     $ids = array();
     $this->getPageIdsForLanguage($dbr, $ids, "en");
     foreach ($wgActiveLanguages as $languageCode) {
         $this->getPageIdsForLanguage($dbr, $ids, $languageCode);
     }
     $pages = Misc::getPagesFromLangIds($ids);
     $date = date('Y-m-d');
     header('Content-type: application/force-download');
     header('Content-disposition: attachment; filename="adexclusions_' . $date . '.xls"');
     foreach ($pages as $page) {
         echo Misc::getLangBaseURL($page["lang"]) . "/" . $page["page_title"] . "\n";
     }
 }
예제 #2
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;
 }
예제 #3
0
        while ($n < count($fromPages)) {
            $deleted .= textFromPage($fromPages[$n]) . " to " . textFromPage($toPages[$n]) . "\n";
            $n += 1;
        }
    }
    $sql = "select tl_from_lang, tl_from_aid, tl_to_lang, tl_to_aid FROM " . $langDB . ".daily_edits de" . " JOIN wikidb_112.translation_link tl on (tl.tl_from_aid=de.de_page_id AND tl_from_lang='{$lang}') or (tl.tl_to_lang='{$lang}' AND tl.tl_to_aid=de.de_page_id)" . " JOIN " . $langDB . ".page p on p.page_id=de.de_page_id" . " WHERE de_timestamp > '{$lowDate}' and p.page_is_redirect=1 and de_edit_type=" . DailyEdits::EDIT_TYPE;
    $res = $dbh->query($sql);
    $fromIds = array();
    $toIds = array();
    while ($row = $dbh->fetchObject($res)) {
        $fromIds[] = array('lang' => $row->tl_from_lang, 'id' => $row->tl_from_aid);
        $toIds[] = array('lang' => $row->tl_to_lang, 'id' => $row->tl_to_aid);
    }
    if (count($fromIds) > 0) {
        $fromPages = Misc::getPagesFromLangIds($fromIds);
        $toPages = Misc::getPagesFromLangIds($toIds);
        $n = 0;
        while ($n < count($fromPages)) {
            $redirected .= textFromPage($fromPages[$n]) . " to " . textFromPage($toPages[$n]) . "\n";
            $n += 1;
        }
    }
}
if ($moved != "" || $deleted != "" || $redirected != "") {
    $msg = substr($lowDate, 0, 4) . "-" . substr($lowDate, 4, 2) . "-" . substr($lowDate, 6, 2) . " to " . substr($today, 0, 4) . "-" . substr($today, 4, 2) . "-" . substr($today, 6, 2) . "\n";
    if ($redirected != "") {
        $msg .= "\nOne or both articles in each of the following translation links were redirected:\n" . $redirected;
    }
    if ($moved != "") {
        $msg .= "\nOne or both articles in each of the following translation links were moved:\n" . $moved;
    }
예제 #4
0
    print "Running live in {$wgLanguageCode}\n";
}
global $wgUser;
$wgUser = User::newFromName("AlfredoBot");
$dbr = wfGetDB(DB_SLAVE);
$its = ImageTransfer::getUpdatesForLang($wgLanguageCode);
$errors = array();
$successes = array();
$creators = array();
$langIds = array();
foreach ($its as $it) {
    $langIds[] = array('lang' => $it->fromLang, 'id' => $it->fromAID);
    $langIds[] = array('lang' => $it->toLang, 'id' => $it->toAID);
}
//Look up URLs of ids
$pages = Misc::getPagesFromLangIds($langIds);
$lip = array();
foreach ($pages as $page) {
    $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";
    }
<?php

// Get all alfredo articles, that have an extra intro space
require_once "commandLine.inc";
$dbr = wfGetDB(DB_SLAVE);
$sql = "select distinct itj_to_aid from wikidb_112.image_transfer_job where itj_to_lang=" . $dbr->addQuotes($wgLanguageCode);
$res = $dbr->query($sql, __METHOD__);
$ids = array();
foreach ($res as $row) {
    $ids[] = $row->itj_to_aid;
}
$lookupIds = array();
foreach ($ids as $id) {
    if ($id != 0) {
        $t = Title::newFromId($id);
        if ($t) {
            $r = Revision::newFromTitle($t);
            if ($r && preg_match("@^ +[^\\s\\[]@", $r->getText(), $matches)) {
                print $r->getText();
                $lookupIds[] = array('lang' => $wgLanguageCode, 'id' => $id);
            }
        }
    }
}
$pages = Misc::getPagesFromLangIds($lookupIds);
foreach ($pages as $page) {
    print Misc::getLangBaseURL($wgLanguageCode) . '/' . $page['page_title'] . "\n";
}
 /**
  * Set the fromURL and toURL for a bunch of links
  */
 static function batchPopulateURLs(&$links)
 {
     $bl = array();
     foreach ($links as $link) {
         $bl[] = array('id' => $link->fromAID, 'lang' => $link->fromLang);
         $bl[] = array('id' => $link->toAID, 'lang' => $link->toLang);
     }
     $pages = Misc::getPagesFromLangIds($bl);
     $ll = array();
     foreach ($pages as $b) {
         if (isset($b['page_title'])) {
             $ll[$b['lang'] . $b['page_id']] = Misc::getLangBaseURL($b['lang']) . '/' . $b['page_title'];
         }
     }
     foreach ($links as &$link) {
         if (isset($ll[$link->fromLang . $link->fromAID])) {
             $link->fromURL = $ll[$link->fromLang . $link->fromAID];
         }
         if (isset($ll[$link->toLang . $link->toAID])) {
             $link->toURL = $ll[$link->toLang . $link->toAID];
         }
     }
 }