Exemplo n.º 1
0
 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;
         }
     }
 }
Exemplo n.º 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;
     }
 }
Exemplo n.º 3
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;
 }
 /**
  * Article save complete is called when the article is saved. We use this
  * hook to track when translated articles are saved, and switch back to current user after saving article.
  */
 static function onSaveComplete(&$article, &$user, $text, $summary, $minor, $a, $b, &$flags, $revision)
 {
     global $wgLanguageCode, $wgUser;
     if ($flags & EDIT_NEW && self::isTranslatorUser()) {
         //Switch back to our user
         global $whgOurUser;
         $user = $whgOurUser;
         $wgUser = $whgOurUser;
         //Add translation link information to database
         $toTitle = $article->getTitle();
         if (preg_match("/\\[\\[en:([^\\]]+)\\]\\]/", $text, $matches)) {
             $fromTitle = urldecode($matches[1]);
             $fromTitle = str_replace(" ", "-", $fromTitle);
             $json = json_decode(self::getArticleRevisionInfo($fromTitle), true);
             $ak = array_keys($json['query']['pages']);
             $fromAID = $ak[0];
             $fromRevisionId = $json['query']['pages'][$fromAID]['revisions'][0]['revid'];
             $tl = new TranslationLink();
             $tl->fromAID = $fromAID;
             $tl->fromLang = "en";
             $tl->toLang = $wgLanguageCode;
             $tl->toAID = $toTitle->getArticleId();
             $tl->insert();
             TranslationLink::writeLog(TranslationLink::ACTION_SAVE, "en", $fromRevisionId, $fromAID, $fromTitle, $wgLanguageCode, $toTitle->getText(), $toTitle->getArticleId());
         } else {
             // Error, we should have an interwiki link on the page. We will still log it.
             TranslationLink::writeLog(TranslationLink::ACTION_SAVE, "en", NULL, NULL, NULL, $wgLanguageCode, $toTitle->getText(), $toTitle->getArticleId());
         }
     }
     return true;
 }
     $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";
 /**
  * EXECUTE
  **/
 function execute($par)
 {
     global $wgRequest, $wgOut, $wgUser, $wgLanguageCode, $isDevHost, $wgActiveLanguages;
     if ($wgUser->isBlocked()) {
         $wgOut->blockedPage();
         return;
     }
     $userGroups = $wgUser->getGroups();
     if ($wgUser->getID() == 0 || !(in_array('sysop', $userGroups) || in_array('staff', $userGroups)) || !(IS_SPARE_HOST || $isDevHost)) {
         $wgOut->setRobotpolicy('noindex,nofollow');
         $wgOut->showErrorPage('nosuchspecialpage', 'nospecialpagetext');
         return;
     }
     $action = $wgRequest->getVal('action', NULL);
     if ($wgRequest->wasPosted() && $_FILES['upload']) {
         ini_set('memory_limit', '2048M');
         $fileName = $_FILES['upload']['tmp_name'];
         $list = file_get_contents($fileName);
         set_time_limit(0);
         $lines = self::parseURLlist($list);
         self::httpDownloadHeaders();
         $urls = array();
         foreach ($lines as $line) {
             $urls[] = $line['url1'];
             $urls[] = $line['url2'];
         }
         $pageInfo = Misc::getPagesFromURLs($urls, array("page_title", "page_id"));
         $links = array();
         foreach ($lines as $line) {
             $link = new TranslationLink();
             $link->fromURL = $line['url1'];
             $link->toURL = $line['url2'];
             if (isset($pageInfo[$line['url1']]) && isset($pageInfo[$line['url2']])) {
                 $p1 = $pageInfo[$line['url1']];
                 $p2 = $pageInfo[$line['url2']];
                 $link->fromLang = $p1['lang'];
                 $link->fromAID = $p1['page_id'];
                 $link->toLang = $p2['lang'];
                 $link->toAID = $p2['page_id'];
             }
             $links[] = $link;
         }
         TranslationLink::batchUpdateTLStatus($links);
         TranslationLink::batchAddTranslationLinks($links);
         foreach ($links as $link) {
             if ($link->fromLang != NULL && $link->fromAID != NULL && $link->toLang != NULL && $link->toAID != NULL) {
                 TranslationLink::writeLog(TranslationLink::ACTION_SAVE, $link->fromLang, NULL, $link->fromAID, $link->getFromPage(), $link->toLang, $link->getToPage(), $link->toAID, "TRANSLATION_OVERRIDE");
             }
             if ($link->tlStatus == TranslationLink::TL_STATUS_SAVED) {
                 if ($link->oldTlStatus == TranslationLink::TL_STATUS_UPDATEABLE) {
                     $message = "Updated existing link";
                 } elseif ($link->oldTlStatus == TranslationLink::TL_STATUS_SAVED) {
                     $message = "Already saved";
                 } elseif ($link->oldTlStatus == TranslationLink::TL_STATUS_NEW) {
                     $message = "Saved Link";
                 } else {
                     $message = "Already saved";
                 }
             } elseif ($link->tlStatus == TranslationLink::TL_STATUS_NON_UPDATEABLE) {
                 $message = "Conflicting existings links, unable to save";
             } else {
                 $message = "Unable to save, URLs invalid or not found";
             }
             print $link->fromURL . "\t" . $link->toURL . "\t" . $message . "\n";
         }
         // Hack to override MediaWiki functionality
         exit;
         return true;
     } elseif ($action == null) {
         EasyTemplate::set_path(dirname(__FILE__));
         $tmpl = EasyTemplate::html("TranslationLinkOverride.tmpl.php");
         $wgOut->addHTML($tmpl);
         return true;
     } elseif ($action == "fetchlinks") {
         $id = $wgRequest->getVal('id', null);
         $lang = $wgRequest->getVal('lang', null);
         $this->fetchLinks($lang, $id);
         return true;
     } elseif ($action == "search") {
         EasyTemplate::set_path(dirname(__FILE__));
         $langs = $wgActiveLanguages;
         $langs[] = 'en';
         $tmpl = EasyTemplate::html("TranslationLinkOverride.delete.tmpl.php", array('langs' => $langs));
         $wgOut->addHTML($tmpl);
         return true;
     } elseif ($action == "dodelete") {
         $fromId = $wgRequest->getVal('fromId', null);
         $fromLang = $wgRequest->getVal('fromLang', null);
         $toId = $wgRequest->getVal('toId', null);
         $toLang = $wgRequest->getVal('toLang', null);
         $this->doDelete($fromLang, $fromId, $toLang, $toId);
     }
     return false;
 }
Exemplo n.º 7
0
 public static function getPagestatData($pageId)
 {
     global $wgUser;
     $t = Title::newFromID($pageId);
     $skin = $wgUser->getSkin();
     $dbr = wfGetDB(DB_SLAVE);
     wfLoadExtensionMessages('Pagestats');
     $html = "<h3 style='margin-bottom:5px'>Staff-only data</h3>";
     $error = null;
     $titusData = self::getTitusData($pageId);
     if (!$titusData->titus) {
         $error = (string) json_encode($titusData);
         $html .= "<p>" . wfMsg('ps-error') . "</p>";
         $html .= "<hr style='margin:5px 0; '/>";
     } else {
         $titusData = $titusData->titus;
     }
     // pageview data
     $day30 = self::get30day($pageId, $dbr);
     $day1 = self::get1day($pageId, $dbr);
     $html .= "<p>{$day30} " . wfMsg('ps-pv-30day') . "</p>";
     $html .= "<p>{$day1} " . wfMsg('ps-pv-1day') . "</p>";
     if ($titusData) {
         // stu data
         $html .= "<hr style='margin:5px 0; '/>";
         $html .= "<p>" . wfMsg('ps-stu') . " {$titusData->ti_stu_10s_percentage_www}%&nbsp;&nbsp;{$titusData->ti_stu_3min_percentage_www}%&nbsp;&nbsp;{$titusData->ti_stu_10s_percentage_mobile}%</p>";
         $html .= "<p>" . wfMsg('ps-stu-views') . " {$titusData->ti_stu_views_www}&nbsp;&nbsp;{$titusData->ti_stu_views_mobile}</p>";
         if ($t) {
             $html .= "<p><a href='#' class='clearstu'>Clear Stu</a></p>";
         }
     }
     // accuracy data
     $data = self::getRatingData($pageId, 'rating', 'rat', $dbr);
     $html .= "<hr style='margin:5px 0;' />";
     $html .= "<p>Accuracy: {$data->percentage}% of {$data->total} votes</p>";
     if ($t) {
         $cl = Title::newFromText('Clearratings', NS_SPECIAL);
         $link = $skin->makeLinkObj($cl, 'Clear ratings', 'type=article&target=' . $pageId);
         $html .= "<p>{$link}</p>";
     }
     $haveBabelfishData = false;
     $languageCode = null;
     if ($titusData) {
         $languageCode = $titusData->ti_language_code;
         // 10k yes/no data
         $html .= "<hr style='margin:5px 0; '/>";
         $html .= "<p>" . wfMsg('ps-tk');
         $html .= $titusData->ti_is_top10k == 1 ? " yes" : " no";
         $html .= "&nbsp;&nbsp;</p>";
         $html .= $titusData->ti_is_top10k == 1 ? "<p>" . wfMsg('ps-tk-query') . " {$titusData->ti_top10k}&nbsp;&nbsp;</p>" : "";
         // fellow data
         $html .= "<hr style='margin:5px 0; '/>";
         $html .= "<p>" . wfMsg('ps-fellow') . " ";
         $html .= $titusData->ti_last_fellow_edit ?: "";
         $html .= "&nbsp;&nbsp;</p>";
         $html .= self::getFellowsTime($titusData->ti_last_fellow_edit_timestamp) ?: "";
         // babelfish rank
         $haveBabelfishData = true;
         $bfRank = $titusData->ti_babelfish_rank ?: "no data";
         $html .= "<hr style='margin:5px 0; '/>";
         $html .= "<p>" . wfMsg('ps-bfish') . ": {$bfRank}&nbsp;&nbsp;</p>";
     }
     // languages translated
     $lLinks = array();
     if ($languageCode) {
         try {
             $linksTo = TranslationLink::getLinksTo($languageCode, $pageId, true);
             foreach ($linksTo as $link) {
                 $href = $link->toURL;
                 $lLinks[] = "<a href='" . htmlspecialchars($href) . "'>{$link->toLang}</a>";
             }
         } catch (DBQueryError $e) {
             $lLinks[] = "<p>" . $e->getText() . "</p>";
         }
     }
     // only print the line if we have not printed it above with babelfish data
     if (!$haveBabelfishData) {
         $html .= "<hr style='margin:5px 0;' />";
     }
     $html .= "<p>Translated: " . implode($lLinks, ',') . "</p>";
     // article id
     $html .= "<hr style='margin:5px 0;' />";
     $html .= "<p>Article Id: {$pageId}</p>";
     return array("body" => $html, "error" => $error);
 }
Exemplo n.º 8
0
 public function calc(&$dbr, &$r, &$t, &$pageRow)
 {
     global $wgLanguageCode;
     global $wgActiveLanguages;
     // Languages supported by Titus language_links
     $langs = $wgActiveLanguages;
     $langs[] = "en";
     // Added template fields to each language
     $ret = array();
     $links = array();
     foreach ($langs as $l) {
         $ret["ti_tl_" . $l] = "";
         $ret["ti_tl_" . $l . "_id"] = "";
     }
     $links = array_merge($links, TranslationLink::getLinksTo($wgLanguageCode, $pageRow->page_id));
     foreach ($links as $l) {
         if ($l->fromAID == $pageRow->page_id && $wgLanguageCode == $l->fromLang && in_array($l->toLang, $langs)) {
             if (isset($l->toURL)) {
                 $ret["ti_tl_" . $l->toLang] = $dbr->strencode($this->fixURL($l->toURL));
             }
             $ret["ti_tl_" . $l->toLang . "_id"] = intVal($l->toAID);
         } elseif ($l->toAID == $pageRow->page_id && $wgLanguageCode == $l->toLang && in_array($l->fromLang, $langs)) {
             if (isset($l->fromURL)) {
                 $ret["ti_tl_" . $l->fromLang] = $dbr->strencode($this->fixURL($l->fromURL));
             }
             $ret["ti_tl_" . $l->fromLang . "_id"] = intVal($l->fromAID);
         }
     }
     return $ret;
 }