function execute($par) { global $wgUser, $wgOut, $wgLang, $wgTitle, $wgMemc, $wgDBname; global $wgRequest, $wgSitename, $wgLanguageCode, $IP; global $wgScript, $wgFilterCallback, $wgScriptPath; $this->setHeaders(); require_once "{$IP}/extensions/wikihow/EditPageWrapper.php"; require_once "{$IP}/includes/EditPage.php"; $target = isset($par) ? $par : $wgRequest->getVal('target'); if (!$target) { $wgOut->addHTML("No target specified. In order to thank a group of authors, a page must be provided."); return; } $title = Title::newFromDBKey($target); $me = Title::makeTitle(NS_SPECIAL, "ThankAuthors"); if (!$wgRequest->getVal('token')) { $sk = $wgUser->getSkin(); $talk_page = $title->getTalkPage(); $token = $this->getToken1(); $thanks_msg = wfMsg('thank-you-kudos', $title->getFullURL(), wfMsg('howto', $title->getText())); // add the form HTML $wgOut->addHTML(<<<EOHTML \t\t\t\t<script type='text/javascript'> \t\t\t\t\tfunction submitThanks () { \t\t\t\t\t\tvar message = \$('#details').val(); \t\t\t\t\t\tif(message == "") { \t\t\t\t\t\t\talert("Please enter a message."); \t\t\t\t\t\t\treturn false; \t\t\t\t\t\t} \t\t\t\t\t\tvar url = '{$me->getFullURL()}?token=' + \$('#token')[0].value + '&target=' + \$('#target')[0].value + '&details=' + \$('#details')[0].value; \t\t\t\t\t\tvar form = \$('#thanks_form'); \t\t\t\t\t\tform.html(\$('#thanks_response').html()); \t\t\t\t\t\t\$.get(url); \t\t\t\t\t\treturn true; \t\t\t\t\t} \t\t\t\t</script> \t\t\t\t<div id="thanks_response" style="display:none;">{$thanks_msg}</div> \t\t\t\t<div id="thanks_form"><div class="section_text"> EOHTML ); $wgOut->addWikiText(wfMsg('enjoyed-reading-article', $title->getFullText(), $talk_page->getFullText())); $wgOut->addHTML("<input id=\"target\" type=\"hidden\" name=\"target\" value=\"{$target}\"/>\n\t\t\t\t<input id=\"token\" type=\"hidden\" name=\"{$token}\" value=\"{$token}\"/>\n\t\t\t\t"); $wgOut->addHTML("<br />\n\t\t\t\t<textarea style='width:98%;' id=\"details\" rows=\"5\" cols=\"100\" name=\"details\"></textarea><br/>\n\t\t\t\t<br /><button onclick='submitThanks();' class='button primary'>" . wfMsg('submit') . "</button>\n\t\t\t\t</div></div>"); } else { // this is a post, accept the POST data and create the // Request article wfLoadExtensionMessages('PostComment'); $wgOut->setArticleBodyOnly(true); $user = $wgUser->getName(); $real_name = User::whoIsReal($wgUser->getID()); if ($real_name == "") { $real_name = $user; } $dateStr = $wgLang->timeanddate(wfTimestampNow()); $comment = $wgRequest->getVal("details"); $text = $title->getFullText(); wfDebug("STA: got text..."); // filter out links $preg = "/[^\\s]*\\.[a-z][a-z][a-z]?[a-z]?/i"; $matches = array(); if (preg_match($preg, $comment, $matches) > 0) { $wgOut->addHTML(wfMsg('no_urls_in_kudos', $matches[0])); return; } $comment = strip_tags($comment); $formattedComment = wfMsg('postcomment_formatted_thanks', $dateStr, $user, $real_name, $comment, $text); wfDebug("STA: comment {$formattedComment}\n"); wfDebug("STA: Checking blocks..."); $tmp = ""; if ($wgUser->isBlocked()) { $this->blockedIPpage(); return; } if (!$wgUser->getID() && $wgWhitelistEdit) { $this->userNotLoggedInPage(); return; } if ($target == "Spam-Blacklist") { $wgOut->readOnlyPage(); return; } wfDebug("STA: checking read only\n"); if (wfReadOnly()) { $wgOut->readOnlyPage(); return; } wfDebug("STA: checking rate limiter\n"); if ($wgUser->pingLimiter('userkudos')) { $wgOut->rateLimited(); return; } wfDebug("STA: checking blacklist\n"); if ($wgFilterCallback && $wgFilterCallback($title, $comment, "")) { // Error messages or other handling should be // performed by the filter function return; } wfDebug("STA: checking tokens\n"); $usertoken = $wgRequest->getVal('token'); $token1 = $this->getToken1(); $token2 = $this->getToken2(); if ($usertoken != $token1 && $usertoken != $token2) { wfDebug("STA: User kudos token doesn't match user: {$usertoken} token1: {$token1} token2: {$token2}"); return; } wfDebug("STA: going through contributors\n"); $article = new Article($title); //$contributors = $article->getContributors(0, 0, true); $contributors = ArticleAuthors::getAuthors($article->getID()); foreach ($contributors as $k => $v) { $u = User::newFromName($k); $id = $u->getID(); //$id = $c->getID(); //$u = $c; wfDebug("STA: going through contributors {$u} {$id}\n"); if ($id == "0") { continue; } // forget the anon users. //notify via the echo notification system if (class_exists('EchoEvent')) { EchoEvent::create(array('type' => 'kudos', 'title' => $title, 'extra' => array('kudoed-user-id' => $id), 'agent' => $wgUser)); } $t = Title::newFromText("User_kudos:" . $u); $a = new Article($t); $update = $t->getArticleID() > 0; $text = ""; if ($update) { $text = $a->getContent(true); $text .= "\n\n" . $formattedComment; if ($wgFilterCallback && $wgFilterCallback($t, $text, $text)) { // Error messages or other handling should be // performed by the filter function return; } } if ($update) { $a->updateArticle($text, "", true, false, false, '', false); } else { $a->insertNewArticle($text, "", true, false, false, false, false); } } wfDebug("STA: done\n"); $wgOut->addHTML("Done."); $wgOut->redirect(''); } }
function notifyMod(&$article, &$editUser, &$revision) { global $wgMemc; // getContributors() not part of Article any more // $authors = $article->getContributors(1); $authors = ArticleAuthors::getAuthors($article->getID()); foreach ($authors as $k => $v) { $origAuthor = $k; break; } // Don't send an email if the author of the revision is the creator of the article //if ($editUser->getName() == $authors->current()->getName()) { if ($editUser->getName() == $origAuthor) { return true; } // Don't create a mod email if there isn't a revision created if (is_null($revision)) { return true; } // Don't send an email if it's a rollback. if (preg_match("@Reverted edits by@", $revision->getComment())) { return true; } // Don't send an email if the edit was made by a bot if ($editUser && in_array("bot", $editUser->getGroups())) { return true; } $t = $article->getTitle(); $dbr = wfGetDB(DB_SLAVE); $res = $dbr->select(array('email_notifications'), array('en_watch', 'en_user', 'en_watch_email', 'en_last_emailsent'), array('en_page' => $t->getArticleID()), __METHOD__); if ($row = $dbr->fetchObject($res)) { $key = wfMemcKey('authoremailnotif', $t->getArticleID()); $recentEmail = $wgMemc->get($key); if (!is_string($recentEmail)) { $recentEmail = false; } // They're watching this, right? $sendEmail = $row->en_watch == 1; // See how long it's been since we've sent an email. If it's been more than a day, send an email if (!is_null($row->en_watch_email)) { $last = strtotime($row->en_watch_email . " UTC"); if (time() - $last > 86400) { $sendEmail = $sendEmail && !$recentEmail; } } $recipientUser = User::newFromID($row->en_user); if ($sendEmail) { $dbw = wfGetDB(DB_MASTER); $dbw->update('email_notifications', array('en_watch_email' => wfTimestampNow(), 'en_last_emailsent' => wfTimestampNow()), array('en_page' => $t->getArticleID(), 'en_user' => $recipientUser->getID()), __METHOD__); // Set a flag that lets us know a recent email was set // This is to prevent us from sending multiple emails if there are db delays in replication $wgMemc->set($key, 'true', time() + 60 * 30); AuthorEmailNotification::sendModEmail($t, $recipientUser, $revision, $editUser); } } else { wfDebug("AEN DEBUG: notifyMod" . $t->getArticleID() . " was modified but notification email not sent.\n"); } return true; }
static function getAuthors($title) { $authorsKeys = ArticleAuthors::getAuthors($title->getArticleID()); $authors = array_keys($authorsKeys); //$authors = array_slice($authors, 0, min($authors, 100)); return $authors; }