/**
  * Gets a list of links that connect to a given URL, and return with Ajax 
  */
 function fetchLinks($lang, $id)
 {
     global $wgOut;
     $links = TranslationLink::getLinksTo($lang, $id);
     $json = array();
     foreach ($links as $link) {
         $json[] = array('fromLang' => $link->fromLang, 'fromID' => $link->fromAID, 'fromURL' => $link->fromURL, 'toLang' => $link->toLang, 'toID' => $link->toAID, 'toURL' => $link->toURL);
     }
     $wgOut->setArticleBodyOnly(true);
     $wgOut->addHTML(json_encode($json));
 }
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;
     }
 }
 /** 
  * Start a translation by fetching the article to be translated,
  * and logging it.
  */
 function startTranslation($fromTarget, $toTarget)
 {
     global $wgOut, $wgRequest, $wgLanguageCode;
     $target = urldecode($fromTarget);
     $text = self::getArticleRevisionInfo($target);
     $output = array();
     $wgOut->setArticleBodyOnly(true);
     $json = json_decode($text, true);
     $ak = array_keys($json['query']['pages']);
     $fromAID = intVal($ak[0]);
     //The article we are translating exists
     if ($fromAID > 0) {
         $exists = false;
         $links = TranslationLink::getLinksTo("en", $fromAID, $wgLanguageCode);
         foreach ($links as $link) {
             if ($link->toLang == $wgLanguageCode) {
                 $exists = true;
             }
         }
         if (!$exists) {
             $fromRevisionId = $json['query']['pages'][$fromAID]['revisions'][0]['revid'];
             $txt = $json['query']['pages'][$fromAID]['revisions'][0]['*'];
             if (preg_match("/#REDIRECT/", $txt)) {
                 $output['error'] = "It seems the article you are attempting to translate is a redirect. Please contact your project manager.";
                 $output['success'] = false;
             } else {
                 $output['success'] = true;
                 $output['aid'] = $fromAID;
                 $output['text'] = $txt;
                 TranslationLink::writeLog(TranslationLink::ACTION_NAME, 'en', $fromRevisionId, $fromAID, $target, $wgLanguageCode, $toTarget);
             }
         } else {
             $output['success'] = false;
             $output['error'] = "It seems the article was already translated. Please contact your project manager.";
         }
     } else {
         $output['success'] = false;
         $output['error'] = "No article at given URL. Please contact your project manager.";
     }
     $wgOut->addHTML(json_encode($output));
 }
Exemplo n.º 4
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.º 5
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;
 }