Пример #1
0
<?php

require_once 'commandLine.inc';
$ignore_cats = array("Featured Articles", "Merge", "Cleanup", "Stub");
$pages = array();
$dbr = wfGetDB(DB_SLAVE);
$res = $dbr->select(array('firstedit', 'page'), array('fe_user', 'fe_user_text', 'fe_page'), array('fe_page=page_id', 'page_namespace' => NS_MAIN, 'fe_user > 0'), "init_followcats", array("LIMIT" => 30000));
echo $dbr->lastQuery() . "\n";
while ($row = $dbr->fetchObject($res)) {
    $pages[$row->fe_page] = $row;
}
$bots = WikihowUser::getBotIDs();
echo "Got " . sizeof($pages) . " articles\n";
foreach ($pages as $p) {
    $res = $dbr->select('categorylinks', array('cl_to'), array('cl_from' => $p->fe_page));
    while ($row = $dbr->fetchObject($res)) {
        if (in_array($p->fe_user, $bots)) {
            continue;
        }
        $cat = Title::makeTitle(NS_CATEGORY, $row->cl_to);
        $u = User::newFromName($p->fe_user_text);
        $t = Title::newFromID($p->fe_page);
        if (!$t || !$cat || !$u) {
            continue;
        }
        if (!in_array($cat->getText(), $ignore_cats) && !preg_match("@NFD@", $cat->getText())) {
            Follow::followCat($t, $cat->getText(), $u);
            echo "{$u->getName()} is following {$cat->getText()} because of {$t->getFullText()}\n";
        }
    }
}
Пример #2
0
function wfTrackThingsToFollow(&$article, &$user, $text, $summary)
{
    if ($user->getID() == 0 || preg_match("@Reverted edits by@", $summary)) {
        // anons can't follow things, for now, and ignore rollbacks
        return true;
    }
    $t = $article->getTitle();
    $last_rev = $article->getRevisionFetched();
    $this_rev = $article->mRevision;
    if ($t->getNamespace() == NS_USER_TALK) {
        // did the user post a non-talk page message?
        $follow = false;
        if (!$last_rev && !preg_match("@\\{\\{@", $text)) {
            $follow = true;
        } elseif ($last_rev) {
            $oldtext = $last_rev->loadText();
            // how many templates in the old one?
            $oldcount = preg_match_all("@\\{\\{[^\\}]*\\}\\}@U", $oldtext, $matches);
            $newcount = preg_match_all("@\\{\\{[^\\}]*\\}\\}@U", $text, $matches);
            if ($newcount <= $oldcount) {
                $follow = true;
            } else {
                return true;
            }
        }
        $u = User::newFromName($t->getText());
        if ($u && $u->getID() > 0) {
            $follow = true;
        } else {
            return true;
        }
        if (!$follow) {
            return true;
        }
        $dbw = wfGetDB(DB_MASTER);
        $sql = "INSERT INTO follow (fo_user, fo_user_text, fo_type, fo_target_id, fo_target_name, fo_weight, fo_timestamp) " . " VALUES ({$user->getID()}, " . $dbw->addQuotes($user->getName()) . ", 'usertalk', {$u->getID()}, " . $dbw->addQuotes($u->getName()) . ", 1, " . $dbw->addQuotes(wfTimestampNow()) . ") ON DUPLICATE KEY UPDATE  " . " fo_weight = fo_weight + 1, fo_timestamp = " . $dbw->addQuotes(wfTimestampNow());
        #echo $sql; exit;
        $dbw->query($sql);
        #print_r($article); exit;
    } else {
        if ($t->getNamespace() == NS_MAIN) {
            // check for change in categories
            preg_match_all("@\\[\\[Category:.*\\]\\]@Ui", $text, $newcats);
            $oldtext = $last_rev->loadText();
            if ($oldtext) {
                preg_match_all("@\\[\\[Category:.*\\]\\]@Ui", $oldtext, $oldcats);
                #print_r($newcats); print_r($oldcats); exit;
                foreach ($newcats[0] as $n) {
                    if (!in_array($n, $oldcats[0])) {
                        Follow::followCat($t, $n);
                    }
                }
            } else {
                foreach ($newcats as $n) {
                    Follow::followCat($t, $n);
                }
            }
        }
    }
    return true;
}