function getUsers()
{
    $users = array();
    $sql = "SELECT user_name, user_real_name, user_email from user";
    $res = wfQuery($sql, DB_SLAVE);
    while ($line = wfFetchObject($res, DB_SLAVE)) {
        if (strlen($line->user_email) == 0) {
            continue;
        }
        if (strlen($line->user_real_name) > 0) {
            $users[$line->user_real_name] = $line->user_email;
        } else {
            $users[$line->user_name] = $line->user_email;
        }
    }
    wfFreeResult($res, DB_SLAVE);
    return $users;
}
Exemplo n.º 2
0
$wgTitle = Title::newFromText("Rebuild links script");
set_time_limit(0);
$wgDBuser = "******";
$wgDBpassword = $wgDBadminpassword;
$sql = "DROP TABLE IF EXISTS watchlist";
wfQuery($sql, DB_MASTER);
$sql = "CREATE TABLE watchlist (\n  wl_user int(5) unsigned NOT NULL,\n  wl_page int(8) unsigned NOT NULL,\n  UNIQUE KEY (wl_user, wl_page)\n) ENGINE=MyISAM PACK_KEYS=1";
wfQuery($sql, DB_MASTER);
$lc = new LinkCache();
# Now, convert!
$sql = "SELECT user_id,user_watch FROM user";
$res = wfQuery($sql, DB_SLAVE);
$nu = wfNumRows($res);
$sql = "INSERT into watchlist (wl_user,wl_page) VALUES ";
$i = $n = 0;
while ($row = wfFetchObject($res)) {
    $list = explode("\n", $row->user_watch);
    $bits = array();
    foreach ($list as $title) {
        if ($id = $lc->addLink($title) and !$bits[$id]++) {
            $sql .= ($i++ ? "," : "") . "({$row->user_id},{$id})";
        }
    }
    if ($n++ % 100 == 0) {
        echo "{$n} of {$nu} users done...\n";
    }
}
echo "{$n} users done.\n";
if ($i) {
    wfQuery($sql, DB_MASTER);
}
Exemplo n.º 3
0
 /**
  * an array of edit links by default used for the tabs
  * @return array
  * @access private
  */
 function buildContentActionUrls()
 {
     global $wgContLang, $wgUseValidation, $wgDBprefix, $wgValidationForAnons;
     $fname = 'SkinTemplate::buildContentActionUrls';
     wfProfileIn($fname);
     global $wgUser, $wgRequest;
     $action = $wgRequest->getText('action');
     $section = $wgRequest->getText('section');
     $oldid = $wgRequest->getVal('oldid');
     $diff = $wgRequest->getVal('diff');
     $content_actions = array();
     if ($this->iscontent) {
         $nskey = $this->getNameSpaceKey();
         $content_actions[$nskey] = $this->tabAction($this->mTitle->getSubjectPage(), $nskey, !$this->mTitle->isTalkPage(), '', true);
         $content_actions['talk'] = $this->tabAction($this->mTitle->getTalkPage(), 'talk', $this->mTitle->isTalkPage(), '', true);
         wfProfileIn("{$fname}-edit");
         if ($this->mTitle->userCanEdit()) {
             $oid = $oldid && !isset($diff) ? '&oldid=' . IntVal($oldid) : false;
             $istalk = $this->mTitle->isTalkPage();
             $istalkclass = $istalk ? ' istalk' : '';
             $content_actions['edit'] = array('class' => ((($action == 'edit' or $action == 'submit') and $section != 'new') ? 'selected' : '') . $istalkclass, 'text' => wfMsg('edit'), 'href' => $this->mTitle->getLocalUrl('action=edit' . $oid));
             if ($istalk) {
                 $content_actions['addsection'] = array('class' => $section == 'new' ? 'selected' : false, 'text' => wfMsg('addsection'), 'href' => $this->mTitle->getLocalUrl('action=edit&section=new'));
             }
         } else {
             $oid = $oldid && !isset($diff) ? '&oldid=' . IntVal($oldid) : '';
             $content_actions['viewsource'] = array('class' => $action == 'edit' ? 'selected' : false, 'text' => wfMsg('viewsource'), 'href' => $this->mTitle->getLocalUrl('action=edit' . $oid));
         }
         wfProfileOut("{$fname}-edit");
         wfProfileIn("{$fname}-live");
         if ($this->mTitle->getArticleId()) {
             $content_actions['history'] = array('class' => $action == 'history' ? 'selected' : false, 'text' => wfMsg('history_short'), 'href' => $this->mTitle->getLocalUrl('action=history'));
             if ($wgUser->isAllowed('protect')) {
                 if (!$this->mTitle->isProtected()) {
                     $content_actions['protect'] = array('class' => $action == 'protect' ? 'selected' : false, 'text' => wfMsg('protect'), 'href' => $this->mTitle->getLocalUrl('action=protect'));
                 } else {
                     $content_actions['unprotect'] = array('class' => $action == 'unprotect' ? 'selected' : false, 'text' => wfMsg('unprotect'), 'href' => $this->mTitle->getLocalUrl('action=unprotect'));
                 }
             }
             if ($wgUser->isAllowed('delete')) {
                 $content_actions['delete'] = array('class' => $action == 'delete' ? 'selected' : false, 'text' => wfMsg('delete'), 'href' => $this->mTitle->getLocalUrl('action=delete'));
             }
             if ($this->mTitle->userCanMove()) {
                 $content_actions['move'] = array('class' => ($this->mTitle->getDbKey() == 'Movepage' and $this->mTitle->getNamespace == NS_SPECIAL) ? 'selected' : false, 'text' => wfMsg('move'), 'href' => $this->makeSpecialUrl("Movepage/{$this->thispage}"));
             }
         } else {
             //article doesn't exist or is deleted
             if ($wgUser->isAllowed('delete')) {
                 if ($n = $this->mTitle->isDeleted()) {
                     $content_actions['undelete'] = array('class' => false, 'text' => $n == 1 ? wfMsg('undelete_short1') : wfMsg('undelete_short', $n), 'href' => $this->makeSpecialUrl("Undelete/{$this->thispage}"));
                 }
             }
         }
         wfProfileOut("{$fname}-live");
         if ($this->loggedin) {
             if (!$this->mTitle->userIsWatching()) {
                 $content_actions['watch'] = array('class' => ($action == 'watch' or $action == 'unwatch') ? 'selected' : false, 'text' => wfMsg('watch'), 'href' => $this->mTitle->getLocalUrl('action=watch'));
             } else {
                 $content_actions['unwatch'] = array('class' => ($action == 'unwatch' or $action == 'watch') ? 'selected' : false, 'text' => wfMsg('unwatch'), 'href' => $this->mTitle->getLocalUrl('action=unwatch'));
             }
         }
         if ($wgUser->isLoggedIn() || $wgValidationForAnons) {
             # and $action != 'submit' ) {
             # Validate tab. TODO: add validation to logged-in user rights
             if ($wgUseValidation && ($action == "" || $action == 'view')) {
                 # && $wgUser->isAllowed('validate')){
                 if ($oldid) {
                     $oid = IntVal($oldid);
                 } else {
                     # Trying to get the current article revision through this weird stunt
                     $tid = $this->mTitle->getArticleID();
                     $tns = $this->mTitle->getNamespace();
                     $sql = "SELECT page_latest FROM {$wgDBprefix}page WHERE page_id={$tid} AND page_namespace={$tns}";
                     $res = wfQuery($sql, DB_READ);
                     if ($s = wfFetchObject($res)) {
                         $oid = $s->page_latest;
                     } else {
                         $oid = "";
                     }
                     # Something's wrong, like the article has been deleted in the last 10 ns
                 }
                 if ($oid != "") {
                     $oid = "&revision={$oid}";
                     $content_actions['validate'] = array('class' => $action == 'validate' ? 'selected' : false, 'text' => wfMsg('val_tab'), 'href' => $this->mTitle->getLocalUrl("action=validate{$oid}"));
                 }
             }
         }
     } else {
         /* show special page tab */
         $content_actions['article'] = array('class' => 'selected', 'text' => wfMsg('specialpage'), 'href' => $wgRequest->getRequestURL());
     }
     /* show links to different language variants */
     global $wgDisableLangConversion;
     $variants = $wgContLang->getVariants();
     if (!$wgDisableLangConversion && sizeof($variants) > 1) {
         $preferred = $wgContLang->getPreferredVariant();
         $actstr = '';
         if ($action) {
             $actstr = 'action=' . $action . '&';
         }
         $vcount = 0;
         foreach ($variants as $code) {
             $varname = $wgContLang->getVariantname($code);
             if ($varname == 'disable') {
                 continue;
             }
             $selected = $code == $preferred ? 'selected' : false;
             $content_actions['varlang-' . $vcount] = array('class' => $selected, 'text' => $varname, 'href' => $this->mTitle->getLocalUrl($actstr . 'variant=' . $code));
             $vcount++;
         }
     }
     wfRunHooks('SkinTemplateContentActions', array(&$content_actions));
     wfProfileOut($fname);
     return $content_actions;
 }
Exemplo n.º 4
0
 function getArticleList()
 {
     global $wgLang, $wgOut;
     $validationtypes = $wgLang->getValidationTypes();
     $wgOut->setPageTitle(wfMsg('val_article_lists'));
     $html = "";
     # Choices
     $choice = array();
     $maxw = 0;
     foreach ($validationtypes as $idx => $data) {
         $x = explode("|", $data, 4);
         if ($x[3] > $maxw) {
             $maxw = $x[3];
         }
     }
     foreach ($validationtypes as $idx => $data) {
         $choice[$idx] = array();
         for ($a = 0; $a < $maxw; $a++) {
             $var = "cb_{$idx}_{$a}";
             if (isset($_POST[$var])) {
                 $choice[$idx][$a] = $_POST[$var];
             } else {
                 if (!isset($_POST["doit"])) {
                     $choice[$idx][$a] = 1;
                 } else {
                     $choice[$idx][$a] = 0;
                 }
             }
             # De-selected
         }
     }
     # The form
     $html .= "<form method='post'>\n";
     $html .= "<table border='1' cellspacing='0' cellpadding='2'>";
     foreach ($validationtypes as $idx => $data) {
         $x = explode("|", $data, 4);
         $html .= "<tr>";
         $html .= "<th nowrap='nowrap'>{$x[0]}</th>";
         $html .= "<td align='right' nowrap='nowrap'>{$x[1]}</td>";
         for ($a = 0; $a < $maxw; $a++) {
             if ($a < $x[3]) {
                 $td = "<input type='checkbox' name='cb_{$idx}_{$a}' value='1'";
                 if ($choice[$idx][$a] == 1) {
                     $td .= " checked='checked'";
                 }
                 $td .= " />";
             } else {
                 $td = '';
             }
             $html .= "<td>{$td}</td>";
         }
         $html .= "<td nowrap='nowrap'>{$x[2]}</td>";
         $html .= "</tr>\n";
     }
     $html .= "<tr><td colspan='" . ($maxw + 2) . "'></td>\n";
     $html .= "<td align='right' valign='center'><input type='submit' name='doit' value=\"" . htmlspecialchars(wfMsg('ok')) . "\" /></td></tr>";
     $html .= "</table>\n";
     $html .= "</form>\n";
     # The query
     $articles = array();
     $sql = "SELECT DISTINCT val_title,val_timestamp,val_type,avg(val_value) AS avg FROM validate GROUP BY val_title,val_timestamp,val_type";
     $res = wfQuery($sql, DB_READ);
     while ($s = wfFetchObject($res)) {
         $articles[$s->val_title][$s->val_timestamp][$s->val_type] = $s;
     }
     # The list
     $html .= "<ul>\n";
     foreach ($articles as $dbkey => $timedata) {
         $title = Title::newFromDBkey($dbkey);
         $out = array();
         krsort($timedata);
         foreach ($timedata as $timestamp => $typedata) {
             $showit = true;
             foreach ($typedata as $type => $data) {
                 $avg = intval($data->avg + 0.5);
                 if ($choice[$type][$avg] == 0) {
                     $showit = false;
                 }
             }
             if ($showit) {
                 $out[] = "<li>" . $this->getVersionLink($title, $timestamp) . "</li>\n";
             }
         }
         if (count($out) > 0) {
             $html .= "<li>\n";
             $html .= htmlspecialchars($title->getText()) . "\n";
             $html .= "<ul>\n";
             $html .= implode("\n", $out);
             $html .= "</ul>\n</li>\n";
         }
     }
     $html .= "</ul>\n";
     return $html;
 }
/**
 * This doesn't really work anymore, because self-links are now displayed as
 * unlinked bold text, and are not entered into the link table.
 *
 * @deprecated
 */
function wfSpecialSelfLinks()
{
    global $wgUser, $wgOut, $wgLang, $wgTitle;
    $fname = 'wfSpecialSelfLinks';
    list($limit, $offset) = wfCheckLimits();
    $sql = "SELECT page_namespace,page_title FROM page,links " . "WHERE l_from=l_to AND l_to=page_id " . "LIMIT {$offset}, {$limit}";
    $res = wfQuery($sql, DB_SLAVE, $fname);
    $top = getMaintenancePageBacklink('selflinks');
    $top .= '<p>' . wfMsg('selflinkstext') . "</p><br />\n";
    $top .= wfShowingResults($offset, $limit);
    $wgOut->addHTML("<p>{$top}\n");
    $sl = wfViewPrevNext($offset, $limit, 'REPLACETHIS');
    $sl = str_replace('REPLACETHIS', sns() . ":Maintenance&subfunction=selflinks", $sl);
    $wgOut->addHTML("<br />{$sl}\n");
    $sk = $wgUser->getSkin();
    $s = '<ol start=' . ($offset + 1) . '>';
    while ($obj = wfFetchObject($res)) {
        $title = Title::makeTitle($obj->page_namespace, $obj->page_title);
        $s .= "<li>" . $sk->makeKnownLinkObj($title) . "</li>\n";
    }
    wfFreeResult($res);
    $s .= '</ol>';
    $wgOut->addHTML($s);
    $wgOut->addHTML("<p>{$sl}\n");
}
Exemplo n.º 6
0
 function fixUserOptions()
 {
     print "Fixing user options...";
     $res = wfQuery("SELECT user_id,user_options FROM user", DB_MASTER);
     $total = wfNumRows($res);
     $n = 0;
     print " ({$total} total)\n";
     while ($row = wfFetchObject($res)) {
         $id = intval($row->user_id);
         $option = wfStrencode($this->rewriteUserOptions($row->user_options));
         wfQuery("UPDATE user SET user_options='{$option}' WHERE user_id={$id} LIMIT 1", DB_MASTER);
         if (++$n % 50 == 0) {
             print "{$n}\n";
         }
     }
     wfFreeResult($res);
 }