/** * 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; }