예제 #1
0
 function getIntlRedirect($lang, $pageid)
 {
     static $dbr = null;
     if (!$dbr) {
         $dbr = wfGetDB(DB_SLAVE);
     }
     $sql = 'SELECT rd_title FROM ' . Misc::getLangDB($lang) . '.redirect WHERE rd_from=' . intval($pageid) . ' AND rd_namespace=' . NS_MAIN;
     $res = $dbr->query($sql, __METHOD__);
     $row = $res ? $res->fetchObject() : null;
     return $row ? Misc::getLangBaseURL($lang) . '/' . $row->rd_title : '';
 }
예제 #2
0
 public function execute($par)
 {
     global $wgRequest, $wgOut, $wgUser, $wgLang, $wgLanguageCode;
     if ($wgUser->isBlocked()) {
         $wgOut->blockedPage();
         return;
     }
     $userGroups = $wgUser->getGroups();
     if ($wgUser->getID() == 0 || !(in_array('sysop', $userGroups) || in_array('staff', $userGroups))) {
         $wgOut->setRobotpolicy('noindex,nofollow');
         $wgOut->showErrorPage('nosuchspecialpage', 'nospecialpagetext');
         return;
     }
     if (!$wgRequest->wasPosted()) {
         EasyTemplate::set_path(dirname(__FILE__));
         $tmpl = EasyTemplate::html("RevertTool.tmpl.php", array('msg' => wfMsg("mass-revert-message"), 'msgName' => "mass-revert-message"));
         $wgOut->addHTML($tmpl);
         return true;
     } else {
         set_time_limit(0);
         $list = $wgRequest->getVal('page-list');
         $revertUser = $wgRequest->getVal('revert-user');
         $list = explode("\n", $list);
         $urls = array();
         if ($wgLanguageCode != "en") {
             $pages = Misc::getPagesFromURLs($list);
             foreach ($pages as $page) {
                 if ($page['lang'] == $wgLanguageCode) {
                     $urls[] = Misc::getLangBaseURL($page['lang']) . '/' . $page['page_title'];
                 } else {
                     $links = TranslationLink::getLinksTo($page['lang'], $page['page_id']);
                     foreach ($links as $link) {
                         if ($link->toLang == $wgLanguageCode) {
                             $urls[] = $link->toURL;
                         }
                     }
                 }
             }
         } else {
             $urls = $list;
         }
         $results = $this->revertList($urls, $revertUser);
         $wgOut->setArticleBodyOnly(true);
         $wgOut->addHTML(json_encode($results));
         return true;
     }
 }
 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";
     }
 }
예제 #4
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;
 }
예제 #5
0
 public static function getLangEndpoints()
 {
     global $wgActiveLanguages;
     $langs = array();
     foreach (array_merge($wgActiveLanguages, array('en')) as $langCode) {
         $langs[$langCode] = array('code' => $langCode, 'endpoint' => Misc::getLangBaseURL($langCode) . '/api.php');
     }
     return $langs;
 }
예제 #6
0
    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])) {
        foreach ($errorURLs[$creator] as $url) {
            $msg .= "<tr><td>" . $url . "</td><td></td><td>URL Not Found</td></tr>\n";
        }
    }
    if (isset($errors[$creator])) {
        foreach ($errors[$creator] as $it) {
            $fromPage = $lip[$it->fromLang][$it->fromAID];
            $toPage = $lip[$it->toLang][$it->toAID];
            $msg .= "<tr><td>" . Misc::getLangBaseURL($fromPage['lang']) . "/" . $fromPage['page_title'] . "</td><td>" . (isset($toPage['page_title']) ? Misc::getLangBaseURL($toPage['lang']) . "/" . $toPage['page_title'] : "") . "</td><td>" . $it->error . "</td></tr>\n";
        }
    }
    if (isset($successes[$creator])) {
        foreach ($successes[$creator] as $it) {
            $fromPage = $lip[$it->fromLang][$it->fromAID];
            $toPage = $lip[$it->toLang][$it->toAID];
            $msg .= "<tr><td>" . Misc::getLangBaseURL($fromPage['lang']) . "/" . $fromPage['page_title'] . "</td><td>" . Misc::getLangBaseURL($toPage['lang']) . "/" . $toPage['page_title'] . "</td><td>" . ($it->error != '' ? $it->error : "Success") . "</td></tr>\n";
        }
    }
    $msg .= "</table>";
    $from = new MailAddress("*****@*****.**");
    $to = new MailAddress($email);
    $subject = "Image Transfers Complete";
    $content_type = "text/html; charset={$wgOutputEncoding}";
    print "Sending email:\n from:alerts@wikihow.com\nto:{$email}\nSubject:{$subject}\n{$msg}";
    UserMailer::send($to, $from, $subject, $msg, false, $content_type);
}
<?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";
}
 /**
  * Add interwiki links between page A, and page B
  * @param forward Do a forward link? Otherwise, we do a link from toAID to fromAID
  * @param dryRun Run through adding the links without actually adding the links. Instead, just output as if we added the links. 
  * @return array('status'=>,'dup'=>) Status is 0 unable to add, 1 already added, 2 Overrode other links in same language  3 add successfully. dup is an array of other links to the same language, which are overriden if dryRun is set to to false
  */
 function addLink($forward, $dryRun = true)
 {
     global $wgServer, $wgUser, $wgLanguageCode;
     $ret = array('status' => 0, 'dup' => array());
     // Make sure we are adding a link between working URLs
     if (intVal($this->fromAID) <= 0 || intVal($this->toAID) <= 0) {
         return $ret;
     }
     if ($this->fromURL == NULL || $this->toURL == NULL) {
         return $ret;
     }
     if ($forward) {
         $fromURL = urldecode($this->fromURL);
         $toURL = urldecode($this->toURL);
         $fromAID = $this->fromAID;
         $toAID = $this->toAID;
         $fromLang = $this->fromLang;
         $toLang = $this->toLang;
     } else {
         $fromURL = urldecode($this->toURL);
         $toURL = urldecode($this->fromURL);
         $toAID = $this->fromAID;
         $fromAID = $this->toAID;
         $fromLang = $this->toLang;
         $toLang = $this->fromLang;
     }
     // We can only add links for our language code
     if (!preg_match('@' . preg_quote(Misc::getLangBaseURL($wgLanguageCode), "@") . '/(.+)@', $fromURL, $matches)) {
         return $ret;
     }
     $fromPage = Misc::fullUrlToPartial($fromURL);
     $toPage = Misc::fullUrlToPartial($toURL);
     $fromTitle = Title::newFromId($fromAID);
     if (!$fromTitle || $fromTitle->getNamespace() != NS_MAIN) {
         return $ret;
     }
     $r = Revision::newFromTitle($fromTitle);
     if (!$r) {
         return $ret;
     }
     $text = $r->getText();
     $linkText = "\n[[" . $toLang . ":" . str_replace("-", " ", $toPage) . "]]";
     $linkTextRE = "\\[\\[" . $toLang . ":(?:" . preg_quote($toPage, "/") . "|" . preg_quote(urlencode($toPage), "/") . ")\\]\\]";
     $linkTextRE = str_replace("\\-", "[ -]", $linkTextRE);
     //Duplicate
     if (preg_match("/" . $linkTextRE . "/", $text, $matches)) {
         $ret['status'] = 1;
         return $ret;
     } elseif (preg_match_all("/\\[\\[" . $toLang . ":[^\\]]+\\]\\]/i", $text, $matches)) {
         $ret['status'] = 2;
         $ret['dup'] = $matches[0];
         foreach ($matches[0] as $match) {
             $text = preg_replace("@[\r\n]*" . preg_quote($match) . "@", "", $text);
             $text = str_replace($match, "", $text);
         }
     } else {
         $ret['status'] = 3;
     }
     $text .= $linkText;
     $article = new Article($fromTitle);
     if (!$dryRun) {
         $article->doEdit($text, wfMsg('addll-editsummary'));
         self::writeLog(self::ACTION_SAVE, $fromLang, $r->getId(), $fromAID, $fromPage, $toLang, $toPage, $toAID, "interwiki");
     }
     return $ret;
 }