function getTopCreators2($dbw, $cutoff, $start)
{
    global $table, $join, $where, $cond, $andcond;
    $result = "<ol>";
    $sql = "select nap_page from newarticlepatrol left join page on nap_page = page_id where page_namespace = 0\n\t\t\tand nap_timestamp > '{$cutoff}' and nap_timestamp < '{$start}'; ";
    wfDebug("Dashboard top creators: {$sql}\n");
    debugMsg("getting nap {$nap} ");
    $res = $dbw->query($sql, __METHOD__);
    $pages = array();
    $revisions = array();
    while ($row = $dbw->fetchObject($res)) {
        $pages[] = $row->nap_page;
    }
    debugMsg("getting min revisions on pages " . sizeof($pages) . " pages ");
    $count = 0;
    foreach ($pages as $page_id) {
        $revisions[$page_id] = selectField($table, array("min(rev_id)"), array("rev_page" => $page_id));
        $count++;
        if ($count % 100 == 0) {
            debugMsg("done {$count}");
        }
    }
    $users = array();
    debugMsg("getting users on newly created pages " . sizeof($revisions) . " revisions ");
    $count = 0;
    foreach ($revisions as $page_id => $rev_id) {
        if (empty($rev_id)) {
            #echo "<!---uh oh: {$page_id} has no min rev!-->";
            continue;
        }
        $u = selectField($dbw, "select rev_user_text from {$table} where rev_id={$rev_id}");
        if (!isset($users[$u])) {
            $users[$u] = 1;
        } else {
            $users[$u]++;
        }
        $count++;
        if ($count % 100 == 0) {
            debugMsg("done {$count}");
        }
    }
    debugMsg("sorting " . sizeof($users) . " users");
    asort($users, SORT_NUMERIC);
    $users = array_reverse($users);
    array_splice($users, 20);
    $yy = 0;
    debugMsg("outputting all of this now " . sizeof($users) . " users");
    foreach ($users as $u => $c) {
        $x = User::newFromName($u);
        $c = nf($c);
        if (!$x) {
            $result .= "<li>{$u} - {$c} new articles created</li>\n";
        } else {
            $result .= "<li> " . getUserLink($x) . " - {$c} new articles created" . getUserToolLinks($x) . "</li>\n";
        }
        $yy++;
        if ($yy == 20) {
            break;
        }
    }
    $result .= "</ol>";
    return $result;
}
Beispiel #2
0
function buildFormFromTable($db, $table, $prevTable, $submitURL, $data = "", $extras = "", $fillDataFromID = 0, $from = "")
{
    //
    // $formText = buildFormFromTable($db, $table, ...)
    //
    // Builds an html form for the specified table. The form will
    // include pull-downs for foreign table links. If anything fails,
    // $formText will comprise an informative message rather than
    // an actual table. You can include default values in 'd'.
    //
    // If d[id] is set, then this will be treated as an update rather
    // than an insert. The other values in d will over ride those from
    // the existing record, so be sure to unset those (or set them ="")
    // if you want to start with defaults from the db.
    //
    // if $fillDataFromID != 0, then it is sort of like an update- default
    // values will be pulled from the db from the specified id. Again, values
    // in d that are set and !="" will override those from the db, so be
    // sure to unset them if you want all defaults pulled from the db.
    //
    // Note that all the form fields are named "d[tableName][fieldName]".
    // Obviously, your function that processes the form data will need
    // to know this.
    // Eg:
    //
    //
    // Also, note that this function assumes that a new table form can be
    // displayed by submitting the form with "$table" set to the new table name.
    //
    $maxSelectLength = 30;
    //
    // GET FOREIGN TABLE LINKS
    //
    if (!($res = mysql_query('SELECT * FROM xLinks WHERE fromTable="' . $table . '"', $db))) {
        $formText = "MySQL error nr " . mysql_errno($db) . ": " . mysql_error($db);
        return $formText;
    }
    while ($row = mysql_fetch_array($res)) {
        $xlinks[$row['fromColumn']][-1] = "select from " . $row['toTable'];
        $xlinksTable[$row['fromColumn']] = $row['toTable'];
        // *** IS THERE A WAY TO SELECT JUST THE FIRST THREE COLUMNS?
        $res2 = mysql_query('SELECT * FROM ' . $row['toTable'], $db) or trigger_error("MySQL error nr " . mysql_errno($db) . ": " . mysql_error($db));
        while ($row2 = mysql_fetch_row($res2)) {
            // This will be a 2d array- the 2nd dim is a hash with the item ID # as the key.
            if (strlen($row2[1]) > $maxSelectLength) {
                $row2[1] = substr($row2[1], 0, $maxSelectLength) . "...";
            }
            $xlinks[$row['fromColumn']][$row2[0]] = "(" . $row2[0] . ") " . $row2[1];
            // We decide if we should show the third field based on it's length. If it's too long,
            // then it's probably not worth showing, unless the second field is empty.
            if (mysql_field_len($res2, 2) < 100 | strlen($row2[1]) == 0) {
                if (strlen($row2[2]) > $maxSelectLength) {
                    $row2[2] = substr($row2[2], 0, $maxSelectLength) . "...";
                }
                $xlinks[$row['fromColumn']][$row2[0]] .= " " . $row2[2];
            }
        }
    }
    $d = $data[$table];
    unset($data[$table]);
    // If the fillDataFromID var is set to a real ID, then try to fill in the data from this entry.
    // This will be like an update except that we'll zero out the ID later so that it becomes a new entry.
    if (isset($fillDataFromID) && $fillDataFromID != 0) {
        $d['id'] = $fillDataFromID;
    }
    // If the 'id' field is set and non-zero, then this is an update form.
    // Get the old data for fill-in the defaults.
    if (isset($d['id']) && $d['id'] != 0) {
        if (!($res = mysql_query("SELECT * FROM {$table} WHERE id=" . $d['id'], $db))) {
            $formText = "MySQL error nr " . mysql_errno($db) . ": " . mysql_error($db);
            return $formText;
        }
        // We no longer overwrite defaults sent in via $data
        while ($row = mysql_fetch_array($res)) {
            foreach ($row as $field => $value) {
                if (!isset($d[$field]) || $d[$field] == "") {
                    $d[$field] = $value;
                }
            }
            // end foreach
        }
        // end while
        // Zero the ID if we're cloning rather than updating
        if (isset($fillDataFromID) && $fillDataFromID != 0) {
            $d['id'] = 0;
        }
    }
    // end if
    //
    // BUILD HTML FORM
    //
    if (!($res = mysql_query("SHOW FIELDS FROM {$table}", $db))) {
        $formText = "MySQL error nr " . mysql_errno($db) . ": " . mysql_error($db);
        return $formText;
    }
    $formText = "";
    if ($d['id'] != 0) {
        $pos = strpos($submitURL, '?');
        if ($pos === false) {
            $formTopText = "<form method=POST name=\"" . $table . "_form\" action=\"{$submitURL}?updateId2=" . $d['id'] . "\">\n";
        } else {
            $formTopText = "<form method=POST name=\"" . $table . "_form\" action=\"{$submitURL}&updateId2=" . $d['id'] . "\">\n";
        }
    } else {
        $formTopText = "<form method=POST name=\"" . $table . "_form\" action=\"{$submitURL}\">\n";
    }
    //$formTopText = "<form method=POST name=\"".$table."_form\" action=\"http://snarp.stanford.edu/info.php\">\n";
    $formTopText .= "<table border=0 cellspacing=2 cellpadding=2>\n";
    $formTopText .= "<input type=hidden name=\"table\" value=\"{$table}\">\n";
    if (is_array($extras)) {
        foreach ($extras as $name => $value) {
            $formTopText .= "<input type=hidden name=\"{$name}\" value=\"{$value}\">\n";
        }
    }
    if (is_array($data)) {
        foreach ($data as $otherTableName => $otherTableArray) {
            foreach ($otherTableArray as $name => $value) {
                $formTopText .= "<input type=hidden name=\"d[{$otherTableName}][{$name}]\" value=\"{$value}\">\n";
            }
        }
    }
    if (isset($prevTable) && is_array($prevTable)) {
        foreach ($prevTable as $key => $val) {
            $formTopText .= "<input type=hidden name=prevTable[{$key}] value=\"{$val}\">\n";
        }
        array_push($prevTable, $table);
    } else {
        $prevTable = array($table);
    }
    while ($row = mysql_fetch_array($res)) {
        $name = $row['Field'];
        //mysql_field_name($fields, $i);
        $typeStr = $row['Type'];
        //mysql_field_type($fields, $i);
        if ($name == 'id') {
            if ($d[$name] != 0) {
                $formTopText .= textField("Updating row " . $name . ":", "d[{$table}][{$name}]", $d[$name], 6, 0);
                // Since it will be disabled, we can't count on it being submitted with
                // the form. So, we add a hidden field.
                $formTopText .= "<input type=hidden name=\"d[{$table}][{$name}]\" value=\"{$d[$name]}\">\n";
            }
            //else $formTopText .= textField($name.":", "junk", "<auto>", 6, 0);
        } elseif ($typeStr == 'date') {
            if (!isset($d[$name])) {
                $d[$name] = date("Y-m-d");
            }
            $formText .= textField(translateField($db, $table, $name) . " (YYYY-MM-DD):", "d[{$table}][{$name}]", $d[$name], 10);
        } elseif ($typeStr == 'datetime') {
            //      if(!isset($d[$name])) $d[$name] = date("Y-m-d H:00:00");
            if ($name == 'end') {
                $d[$name] = date("Y-m-d H:59:00");
            } else {
                $d[$name] = date("Y-m-d H:00:00");
            }
            $formText .= textField($name . " (YYYY-MM-DD HH:MM:SS):", "d[{$table}][{$name}]", $d[$name], 19);
        } elseif ($typeStr == 'text') {
            $formText .= textBox($name . ":", "d[{$table}][{$name}]", $d[$name], 10);
        } elseif (strncasecmp($typeStr, 'enum', 4) == 0) {
            $vals = explode("','", "'," . substr($typeStr, 5, -1) . ",'");
            $vals = array_slice($vals, 1, -1);
            $formText .= radioField($name . ":", "d[{$table}][{$name}]", $vals, $d[$name]);
        } elseif ($name == 'password') {
            $formText .= pwdField($name . ":", "d[{$table}][{$name}]", $d[$name], 16);
        } else {
            if (isset($xlinks[$name])) {
                if (!isset($d[$name]) || $d[$name] == '') {
                    $d[$name] = -1;
                }
                $newLink = "";
                foreach ($prevTable as $key => $val) {
                    $newLink .= "&prevTable[{$key}]={$val}";
                }
                // We put these at the beginning of formText so that all the pull-downs
                // appear at the top of the page.
                $formTopText .= selectField(translateField($db, $table, $name) . ":", "d[{$table}][{$name}]", $xlinks[$name], $d[$name], " <input type=submit name=\"" . $xlinksTable[$name] . "\" value=New>");
            } else {
                list($type, $size, $extra) = preg_split('(\\(|\\))', $typeStr);
                if ($size > 40) {
                    $formText .= textBox(translateField($db, $table, $name) . ":", "d[{$table}][{$name}]", $d[$name], round($size / 40));
                } else {
                    $formText .= textField(translateField($db, $table, $name) . ":", "d[{$table}][{$name}]", $d[$name], $size);
                }
            }
        }
    }
    $formText .= "</table><br><br>\n";
    $formText .= "&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp<input type=submit name=\"{$table}\" value=Submit>\n";
    $formText .= "&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp<input type=submit name=cancel value=Cancel>\n";
    if ($from == "buildSession3") {
        $formText .= "&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp<input type=submit name=index value='Back to Main Index'>\n";
    }
    $formText .= "</form>\n";
    return $formTopText . $formText;
}