Ejemplo n.º 1
0
 public static function getMatchingEdits($username, $begin, $end, $count, $api = false)
 {
     global $dbr, $phptemp;
     $timeconds = array('rev_user_text' => $username);
     if ($begin) {
         $timeconds[] = 'UNIX_TIMESTAMP(rev_timestamp) > ' . $dbr->strencode(strtotime($begin));
     }
     if ($end) {
         $timeconds[] = 'UNIX_TIMESTAMP(rev_timestamp) < ' . $dbr->strencode(strtotime($end));
     }
     $contribs = $urls = array();
     foreach (AutoEditsBase::$AEBTypes as $name => $check) {
         $conds = $timeconds;
         $conds[] = 'rev_comment ' . $check['type'] . ' \'' . $check['query'] . '\'';
         try {
             $res = $dbr->select(array('revision_userindex'), array('COUNT(*) AS count'), $conds);
             $contribs[$name] = $res[0]['count'];
         } catch (Exception $e) {
             if ($api) {
                 return array('error' => 'dberror', 'info' => $e->getMessage());
             }
             WebTool::toDieMsg('mysqlerror', $e->getMessage());
         }
         $urls[$name] = $check['shortcut'];
     }
     $formattedpct = WebTool::number_format(($count ? array_sum($contribs) / $count : 0) * 100, 2);
     if ($api) {
         return array('counts' => $contribs, 'total' => array_sum($contribs), 'editcount' => $count, 'pct' => $formattedpct);
     } else {
         return array('counts' => $contribs, 'total' => WebTool::number_format(array_sum($contribs), 0), 'editcount' => WebTool::number_format($count, 0), 'pct' => $formattedpct, 'urls' => $urls);
     }
 }
Ejemplo n.º 2
0
<?php

//Requires
require_once '/data/project/xtools/modules/WebTool.php';
require_once 'Counter.php';
//Load WebTool class
$wt = new WebTool('ec');
$wt->setLimits(650, 120);
$wt->getPageTemplate("form");
$purge = $wgRequest->getBool('purge');
if ($wgRequest->getSessionData('ec_purge')) {
    unset($_SESSION["ec_purge"]);
    $purge = true;
}
$extended = $wgRequest->getBool('extended', false);
$wi = $wt->wikiInfo;
$lang = $wi->lang;
$wiki = $wi->wiki;
$domain = $wi->domain;
$ui = $wt->getUserInfo();
$user = $ui->user;
//Show form if user is not set (or empty)
if (!$user || !$lang || !$wiki) {
    $wt->showPage();
}
//Create new Counter object
$ttl = 120;
$hash = "xtoolsCNT" . XTOOLS_REDIS_FLUSH_TOKEN . hash('crc32', $lang . $wiki . $user . $extended);
$lc = $redis->get($hash);
if ($lc === false || $purge) {
    $dbr = $wt->loadDatabase($lang, $wiki);
Ejemplo n.º 3
0
<?php

//Requires
require_once '/data/project/xtools/modules/WebTool.php';
require_once 'RFAde.php';
require_once 'Graph.php';
require_once PEACHY_BASE_SYS_DIR . '/Peachy/Init.php';
//Load WebTool class
$wt = new WebTool('rfap');
$wt->setLimits();
$wt->getPageTemplate('form');
$wt->assign('optionsProject', '<option selected value ="en.wikipedia.org">en.wikipedia</option><option value = "de.wikipedia.org" >de.wikipedia</option>');
$wi = $wt->wikiInfo;
$lang = $wi->lang;
$wiki = $wi->wiki;
$domain = $wi->domain;
$ui = $wt->getUserInfo($lang, $wiki);
$user = $ui->user;
//Show form if username is not set (or empty)
if (!$user || !$lang || !$domain) {
    $wt->showPage();
}
//Check if the user is an IP address
if (preg_match('/^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}$/', $name)) {
    $wt->error = "User cannot be an IP.";
    $wt->showPage();
}
$rfa['en'] = 'Requests_for_adminship';
$rfa['de'] = 'Adminkandidaturen';
$rfb['en'] = 'Requests_for_bureaucratship';
$rfb['de'] = 'Bürokratenkandidaturen';
Ejemplo n.º 4
0
<?php

//Requires
require_once '/data/project/xtools/modules/WebTool.php';
require_once 'RFAde.php';
require_once PEACHY_BASE_SYS_DIR . '/Peachy/Init.php';
$wt = new WebTool('rfa');
$wt->setLimits();
$wt->getPageTemplate('form');
$wi = $wt->wikiInfo;
$lang = $wi->lang;
$wiki = $wi->wiki;
$domain = $wi->domain;
$domain = $domain ? $domain : 'en.wikipedia.org';
switch ($domain) {
    case "en.wikipedia.org":
        $optionsProject = "\n\t\t\t\t\t<option selected value ='en.wikipedia'>en.wikipedia</option>\n\t\t\t\t\t<option value ='de.wikipedia'>de.wikipedia</option>\n\t\t\t\t\t";
        break;
    case "de.wikipedia.org":
        $optionsProject = "\n\t\t\t\t\t<option value ='en.wikipedia'>en.wikipedia</option>\n\t\t\t\t\t<option selected value ='de.wikipedia'>de.wikipedia</option>\n\t\t\t\t\t";
        break;
    default:
        $wt->toDie('nosupport', $domain);
}
$msgOnDeWiki = "on the German Wikipedia";
$msgOnEnWiki = "on the English Wikipedia";
if ($wt->uselang == "de") {
    $msgOnDeWiki = "in der deutschen Wikipedia";
    $msgOnEnWiki = "in der englischen Wikipedia";
}
$wt->assign('onEnWiki', $msgOnEnWiki);
Ejemplo n.º 5
0
<?php

//Requires
require_once '/data/project/xtools/modules/WebTool.php';
require_once 'RangeContribs.php';
//Load WebTool class
$wt = new WebTool('rangecontribs');
$wt->setLimits();
$wt->getPageTemplate("form");
$wt->assign('defaultBegin', date('Y') . "-01-01");
$wt->content = str_replace('{#tosearch#}', 'CIDR /<br />List', $wt->content);
//Checks for alternative requests for compatibility (ips = legacy)
$list = $wgRequest->getText('ips');
$list = $wgRequest->getText('list', $list);
$list = $wgRequest->getText('text', $list);
$limit = $wgRequest->getVal('limit', '20');
$display = $wgRequest->getVal('display');
$begin = $wt->checkDate($wgRequest->getVal('begin'));
$end = $wt->checkDate($wgRequest->getVal('end'));
$namespace = $wgRequest->getVal('namespace');
$wi = $wt->wikiInfo;
$lang = $wi->lang;
$wiki = $wi->wiki;
$domain = $wi->domain;
if (!$list || !$wiki || !$lang) {
    $wt->showPage();
}
if ($begin == 'error' || $end == 'error') {
    $wt->toDie('invalid_date');
}
//Create exec object
Ejemplo n.º 6
0
<h1>301 Moved Permanently</h1>
<p>This tool has moved to a new location.  You will be redirected to tools.wmflabs.org/xtools-articleinfo/index.php?<?php 
    echo $_SERVER['QUERY_STRING'];
    ?>
 shortly.</p>

</body>
</html>
<?php 
    die;
}
//Requires
set_include_path(get_include_path() . PATH_SEPARATOR . '/data/project/xtools/public_html/articleinfo');
require_once '/data/project/xtools/modules/WebTool.php';
//Load WebTool class
$wt = new WebTool('articleinfo');
$wt->setLimits(600, 45);
$wt->getPageTemplate("form");
$article = $wgRequest->getVal('article');
$article = $wgRequest->getVal('page', $article);
$pageid = $wgRequest->getVal('pageid', null);
$article = $pageid ? null : $article;
$begintime = $wgRequest->getVal('begin');
$endtime = $wgRequest->getVal('end');
$nofollow = !$wgRequest->getBool('nofollowredir');
$editorlimit = $wgRequest->getVal('editorlimit', 30);
$reloadpurge = $wgRequest->getVal('reloadpurge', null);
$wi = $wt->wikiInfo;
$lang = $wi->lang;
$wiki = $wi->wiki;
$domain = $wi->domain;
Ejemplo n.º 7
0
<?php

//Requires
require_once '/data/project/xtools/modules/WebTool.php';
require_once 'Counter.php';
require_once PEACHY_BASE_SYS_DIR . '/Peachy/Init.php';
//Load WebTool class
$wt = new WebTool('topedits');
$wt->setLimits();
$wt->getPageTemplate('form');
$namespace = $wgRequest->getVal('namespace');
//kompatibility
$page = $wgRequest->getVal('page');
$page = $wgRequest->getVal('article', $page);
$wi = $wt->wikiInfo;
$lang = $wi->lang;
$wiki = $wi->wiki;
$domain = $wi->domain;
$uinput = explode("|", $wgRequest->getVal('user'));
foreach ($uinput as $uitem) {
    $tmpui = $wt->getUserInfo($lang, $wiki, $uitem);
    if ($tmpui->userid || $tmpui->isIP) {
        $users["list"][] = $tmpui;
        $users["names"][] = "'" . $tmpui->userDb . "'";
    }
}
$perflog->stack[] = $users;
$ui = $users["list"][0];
$user = $ui->user;
//Show form if &article parameter is not set (or empty)
if (!$user && (!$page || !$lang || !$wiki || strval($namespace) == "")) {
Ejemplo n.º 8
0
<?php

require_once '/data/project/xtools/modules/WebTool.php';
require_once 'Agent.php';
$wt = new WebTool('config');
$action = $wgRequest->getVal('action', null);
$method = $_SERVER["REQUEST_METHOD"];
if ($method == "POST") {
    if ($action == "clearconfig") {
        $redis->del('xagconfig' . session_id());
        exit;
    }
    if ($action == "loadconfig") {
        if ($result = $redis->get('xagconfig' . session_id())) {
            header('Content-Type: application/json; charset=utf-8');
            echo $result;
        } else {
            header("HTTP/1.0 404 Not found");
        }
        exit;
    }
    if ($action == "saveconfig") {
        $conf = $wgRequest->getText('config', null);
        if ($check = json_decode($conf)) {
            $redis->setex('xagconfig' . session_id(), 86400, $conf);
            print_r($check);
        } else {
            header("HTTP/1.0 500 Internal Server Error");
        }
        exit(0);
    }
Ejemplo n.º 9
0
<?php

//Requires
require_once '/data/project/xtools/modules/WebTool.php';
//Load WebTool class
$wt = new WebTool('autoblock');
$wt->setLimits();
$wt->getPageTemplate('form');
$wt->assign('defaultUser', '%');
$wi = $wt->wikiInfo;
$lang = $wi->lang;
$wiki = $wi->wiki;
$domain = $wi->domain;
$user = $wgRequest->getVal('user');
#	$ui = $wt->getUserInfo();
#		$user = $ui->user;
//Show form if &article parameter is not set (or empty)
if (!$user) {
    $wt->showPage();
}
if (!$domain) {
    $wt->error = "No wiki or project specified - default project set to: en.wikipedia";
    $lang = "en";
    $wiki = "wikipedia";
    $domain = "en.wikipedia.org";
}
$dbr = $wt->loadDatabase($lang, $wiki);
$userdb = $dbr->strencode($user);
$query = "\n   \t\tSELECT ipb_id, ipb_by_text, UNIX_TIMESTAMP(ipb_expiry) as ipb_expiry, ipb_user \n   \t\tFROM ipblocks \n   \t\tWHERE ipb_auto = 1 AND ipb_reason LIKE '%{$userdb}%'\n   \t";
$result = $dbr->query($query);
$list = '<tr><th>#</th><th>id</th><th>expiry</th><th>admin</th><th>action</th></tr>';
Ejemplo n.º 10
0
<?php

try {
    $gtime = microtime(true);
    $ptime = microtime(true);
    # throw new Exception('db-stuff again');
    //Requires
    require_once '/data/project/xtools/modules/WebTool.php';
    require_once 'ArticleInfo.php';
    $b1 = number_format(microtime(true) - $ptime, 3);
    $ptime = microtime(true);
    $wt = new WebTool('api');
    $wt->setLimits(500, 5);
    $b2 = number_format(microtime(true) - $ptime, 3);
    $ptime = microtime(true);
    //get webrequest data
    $db = $wgRequest->getVal('db');
    $pageid = (int) $wgRequest->getVal('pageid');
    $pagetitle = $wgRequest->getVal('pagetitle');
    $uselang = $wgRequest->getVal('uselang');
    $nsid = (int) $wgRequest->getVal('nsid');
    $wditemid = $wgRequest->getVal('wditemid');
    $test = $wgRequest->getVal('test');
    $mode = $wgRequest->getVal('mode');
    //get xtools cookie val; if 3rd party cookies are deactivated in browser this will be null
    $reenable = $wgRequest->getVal('reenable', null);
    $wditemid = substr($wditemid, 0, 1) == 'Q' ? $wditemid : null;
    //get config data
    $conf = new stdClass();
    $conf->status = 'enabled';
    $conf->mode = 'verbose';
Ejemplo n.º 11
0
		<select name="redirects">
			<option value="none">Include redirects and non-redirects</option>
			<option value="onlyredirects">Only include redirects</option>
			<option value="noredirects">Exclude redirects</option>
		</select><br />
	';
$content->assign('selectns', $selectns);
$content->assign('selectredir', $selectredir);
//Show form if &article parameter is not set (or empty)
if (!$wgRequest->getSafeVal('getBool', 'user')) {
    $content->assign('form', $curlang);
    WebTool::assignContent();
}
//Get username & userid, quit if not exist
$userData = PagesBase::getUserData($dbr, $wgRequest->getSafeVal('user'));
if (!$userData) {
    WebTool::toDie("No such user");
}
$result = PagesBase::getCreatedPages($dbr, $userData["user_id"], $wgRequest->getSafeVal('lang'), $wgRequest->getSafeVal('wiki'), $wgRequest->getSafeVal('namespace'), $wgRequest->getSafeVal('redirects'));
$filtertextNS = $result->filterns == "all" ? " in all namespaces." : " in namespace " . $wgRequest->getSafeVal('namespace') . ".";
#print_r($result->namespaces);
$content->assign('showresult', true);
$content->assign('graphs', true);
$content->assign('totalcreated', "User " . $userData["user_name"] . " has created {$result->total} pages on " . $wgRequest->getSafeVal('lang') . "." . $wgRequest->getSafeVal('wiki') . $filtertextNS);
$content->assign('filterredir', $result->filterredir);
$content->assign('namespaces', $result->namespaces);
$content->assign('nstotals', $result->listnum);
$content->assign('nsnames', $result->listns);
$content->assign('list', $result->list);
WebTool::assignContent();
Ejemplo n.º 12
0
<?php

#phpinfo();
//Requires
require_once 'WebTool.php';
$wt = new WebTool('test');
$wt->loadDBCredentials();
echo "Hallo";
#print_r($wt->metap);
foreach ($wt->metap as $db => $row) {
    $slice = $row["slice"];
    if ($db == "centralauth") {
        continue;
    }
    #	if ( in_array( $db, array("bgwiki","afwiki","abwiki","acewiki","amwiki", "angwiki") ) || $db == "commonswiki" ) { continue; }
    $queries[$slice][] = "\n\t\t\t(SELECT rev_timestamp, '{$db}' as wiki, page_namespace, page_title, rev_id\n\t\t\tFROM {$db}_p.revision_userindex\n\t\t\tJOIN {$db}_p.page on page_id = rev_page\n\t\t\twhere  rev_user_text = 'Hedonil' AND rev_timestamp > '20140628210110'\n\t\t\tLimit 10)\n\t";
}
#	print_r($queries);
foreach ($queries as $slice => $slarr) {
    $stime = microtime(true);
    $dbr = new Database2($slice, $dbUser, $dbPwd, '');
    $dur = number_format(microtime(true) - $stime, 3);
    $query = implode(" UNION ", $slarr);
    echo $query;
    $res = $dbr->query($query);
    $anz = count($res);
    echo "{$slice} --- {$db} --- {$anz} --- {$dur}  <br/>\n";
    $dbr->close();
}
Ejemplo n.º 13
0
<?php

//Requires
require_once '/data/project/xtools/modules/WebTool.php';
//Load WebTool class
$wt = new WebTool('sc');
$wt->setLimits();
$wt->getPageTemplate("form");
$ui = $wt->getUserInfo();
$user = $ui->user;
$wi = $wt->wikiInfo;
$lang = $wi->lang;
$wiki = $wi->wiki;
//Show form if &article parameter is not set (or empty)
if (!$user) {
    $wt->showPage();
}
$dbr = $wt->loadDatabase($lang, $wiki);
$obj = getEditCounts($dbr, $user);
$wt->content = '
		<br />
		<table class="leantable table-condensed xt-table" >
			<tr><td>{#username#}: </td><td><a href="//' . $lang . '.' . $wiki . '.org/wiki/User:'******'" >' . $user . '</a></td></tr>
			<tr><td>{#userid#}: </td><td>' . $obj->id . '</td></tr>
			<tr><td>{#groups#}: </td><td>' . $obj->groups . '</td></tr>
			<tr><td>{#deleted_edits#}: </td><td>' . $wt->numFmt($obj->deleted) . '</td></tr>
			<tr><td>{#live#}: </td><td>' . $wt->numFmt($obj->live) . '</td></tr>
			<tr><td>{#total#}: </td><td><b>' . $wt->numFmt($obj->live + $obj->deleted) . '</b></td></tr>
		</table>
	';
$wt->showPage();
Ejemplo n.º 14
0
<?php

//Requires
require_once '/data/project/xtools/modules/WebTool.php';
require_once 'Agent.php';
//Load WebTool class
$wt = new WebTool('echo');
$wt->setLimits();
$wt->content = getPageTemplate('result');
$purge = $wgRequest->getBool('purge', false);
$wi = $wt->wikiInfo;
$lang = $wi->lang;
$wiki = $wi->wiki;
$domain = $wi->domain;
$list = '<p style="text-align:center"><br/>&nbsp;You are not logged in. <a href="https://' . XTOOLS_BASE_WEB_DIR . '/oauthredirector.php?action=login&returnto=https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] . '" >Log in</a> with secure Wikimedia OAuth.<br/>If necessary, refresh your browser with F5 afterwards.<br />&nbsp;</p>';
//Show form if &article parameter is not set (or empty)
if ($wt->OAuthObject->isAuthorized()) {
    $resArr = getCrossWikiMessage($wt, 'all', 50, $purge);
    $wt->statusLink['message'] = $resArr["list"];
    $msgArr = $resArr["msgArr"];
    uasort($msgArr, function ($al, $bl) {
        $a = $al["timestamp"];
        $b = $bl["timestamp"];
        if ($a == $b) {
            return 0;
        }
        return $a < $b ? 1 : -1;
    });
    #$perflog->stack[] = $msgArr;
    $list = '
				<tr>
Ejemplo n.º 15
0
<?php

//Requires
require_once '/data/project/xtools/modules/WebTool.php';
require_once 'Counter.php';
require_once 'Graph.php';
//Load WebTool class
$wt = new WebTool('pages');
$wt->setLimits();
$wt->getPageTemplate('form');
$namespace = $wgRequest->getVal('namespace');
$redirects = $wgRequest->getVal('redirects');
$limit = intval($wgRequest->getVal('limit', 100));
$movedeletes = $wgRequest->getBool('movedeletes', false);
$wi = $wt->wikiInfo;
$lang = $wi->lang;
$wiki = $wi->wiki;
$domain = $wi->domain;
$ui = $wt->getUserInfo();
$user = $ui->user;
//Show form if &article parameter is not set (or empty)
if (!$user || !$wiki || !$lang) {
    $wt->showPage();
}
//Get username & userid, quit if not exist
$ttl = 120;
$hash = "xtoolsPages" . XTOOLS_REDIS_FLUSH_TOKEN . '002' . hash('crc32', $lang . $wiki . $user);
$hash2 = "xtoolsPages" . XTOOLS_REDIS_FLUSH_TOKEN . '002' . hash('crc32', $user . $domain . $namespace . $redirects . $movedeletes);
$lc = $redis->get($hash);
$lc2 = $redis->get($hash2);
if ($lc === false || $lc2 === false) {
Ejemplo n.º 16
0
 public static function parseHistory(&$history, $start, $end, &$site, &$pageClass, $api = false)
 {
     if (!$api) {
         $logsi = $site->logs(null, false, $pageClass->get_title(), strtotime($start), strtotime($end), 'older', false, array('type', 'timestamp', 'user', 'details'));
         $logs = array();
         foreach ($logsi as $log) {
             if (in_array($log['type'], array('delete', 'move', 'protect')) && !in_array($log['action'], array('revision'))) {
                 if (!isset($logs[date('nY', strtotime($log['timestamp']))][$log['action']])) {
                     $logs[date('nY', strtotime($log['timestamp']))][$log['action']] = 0;
                 }
                 $logs[date('nY', strtotime($log['timestamp']))][$log['action']]++;
             }
         }
         unset($logsi);
         foreach ($logs as $date => $log) {
             arsort($log);
             $logs[$date] = actionParse($date, $log);
         }
     }
     //Now we can start our master array. This one will be HUGE!
     $data = array('first_edit' => array('timestamp' => $history[0]['rev_timestamp'], 'user' => $history[0]['rev_user_text']), 'year_count' => array(), 'count' => 0, 'editors' => array(), 'anons' => array(), 'year_count' => array(), 'minor_count' => 0, 'count_history' => array('today' => 0, 'week' => 0, 'month' => 0, 'year' => 0));
     $first_edit_parse = date_parse($data['first_edit']['timestamp']);
     //And now comes the logic for filling said master array
     foreach ($history as $id => $rev) {
         $data['last_edit'] = $rev['rev_timestamp'];
         $data['count']++;
         //Sometimes, with old revisions (2001 era), the revisions from 2002 come before 2001
         if (strtotime($rev['rev_timestamp']) < strtotime($data['first_edit']['timestamp'])) {
             $data['first_edit'] = array('timestamp' => $rev['rev_timestamp'], 'user' => htmlspecialchars($rev['rev_user_text']));
             $first_edit_parse = date_parse($data['first_edit']['timestamp']);
         }
         $timestamp = date_parse($rev['rev_timestamp']);
         //Fill in the blank arrays for the year and 12 months
         if (!isset($data['year_count'][$timestamp['year']])) {
             $data['year_count'][$timestamp['year']] = array('all' => 0, 'minor' => 0, 'anon' => 0, 'months' => array());
             for ($i = 1; $i <= 12; $i++) {
                 $data['year_count'][$timestamp['year']]['months'][$i] = array('all' => 0, 'minor' => 0, 'anon' => 0, 'size' => array());
             }
         }
         //Increment counts
         $data['year_count'][$timestamp['year']]['all']++;
         $data['year_count'][$timestamp['year']]['months'][$timestamp['month']]['all']++;
         $data['year_count'][$timestamp['year']]['months'][$timestamp['month']]['size'][] = number_format($rev['rev_len'] / 1024, 2);
         //Now to fill in various user stats
         $username = htmlspecialchars($rev['rev_user_text']);
         if (!isset($data['editors'][$username])) {
             $data['editors'][$username] = array('all' => 0, 'minor' => 0, 'first' => date('d F Y, H:i:s', strtotime($rev['rev_timestamp'])), 'last' => null, 'atbe' => null, 'minorpct' => 0, 'size' => array(), 'urlencoded' => str_replace(array('+'), array('_'), urlencode($rev['rev_user_text'])));
         }
         //Increment these counts...
         $data['editors'][$username]['all']++;
         $data['editors'][$username]['last'] = date('d F Y, H:i:s', strtotime($rev['rev_timestamp']));
         $data['editors'][$username]['size'][] = number_format($rev['rev_len'] / 1024, 2);
         if (!$rev['rev_user']) {
             //Anonymous, increase counts
             $data['anons'][] = $username;
             $data['year_count'][$timestamp['year']]['anon']++;
             $data['year_count'][$timestamp['year']]['months'][$timestamp['month']]['anon']++;
         }
         if ($rev['rev_minor_edit']) {
             //Logged in, increase counts
             $data['minor_count']++;
             $data['year_count'][$timestamp['year']]['minor']++;
             $data['year_count'][$timestamp['year']]['months'][$timestamp['month']]['minor']++;
             $data['editors'][$username]['minor']++;
         }
         //Increment "edits per <time>" counts
         if (strtotime($rev['rev_timestamp']) > strtotime('-1 day')) {
             $data['count_history']['today']++;
         }
         if (strtotime($rev['rev_timestamp']) > strtotime('-1 week')) {
             $data['count_history']['week']++;
         }
         if (strtotime($rev['rev_timestamp']) > strtotime('-1 month')) {
             $data['count_history']['month']++;
         }
         if (strtotime($rev['rev_timestamp']) > strtotime('-1 year')) {
             $data['count_history']['year']++;
         }
     }
     //Fill in years with no edits
     for ($year = $first_edit_parse['year']; $year <= date('Y'); $year++) {
         if (!isset($data['year_count'][$year])) {
             $data['year_count'][$year] = array('all' => 0, 'minor' => 0, 'anon' => 0, 'months' => array());
             for ($i = 1; $i <= 12; $i++) {
                 $data['year_count'][$year]['months'][$i] = array('all' => 0, 'minor' => 0, 'anon' => 0, 'size' => array());
             }
         }
     }
     //Add more general statistics
     $data['totaldays'] = floor((strtotime($data['last_edit']) - strtotime($data['first_edit']['timestamp'])) / 60 / 60 / 24);
     $data['average_days_per_edit'] = number_format($data['totaldays'] / $data['count'], 2);
     $data['edits_per_month'] = $data['totaldays'] ? number_format($data['count'] / ($data['totaldays'] / (365 / 12)), 2) : 0;
     $data['edits_per_year'] = $data['totaldays'] ? number_format($data['count'] / ($data['totaldays'] / 365), 2) : 0;
     $data['edits_per_editor'] = number_format($data['count'] / count($data['editors']), 2);
     $data['editor_count'] = count($data['editors']);
     $data['anon_count'] = count($data['anons']);
     //Various sorts
     arsort($data['editors']);
     ksort($data['year_count']);
     //Fix the year counts
     $num = 0;
     $cum = 0;
     $scum = 0;
     foreach ($data['year_count'] as $year => $months) {
         //Unset months before the first edit and after the last edit
         foreach ($months['months'] as $month => $tmp) {
             if ($year == $first_edit_parse['year']) {
                 if ($month < $first_edit_parse['month']) {
                     unset($data['year_count'][$year]['months'][$month]);
                 }
             }
             if ($year == date('Y')) {
                 if ($month > date('m')) {
                     unset($data['year_count'][$year]['months'][$month]);
                 }
             }
         }
         //Calculate anon/minor percentages
         $data['year_count'][$year]['pcts']['anon'] = $data['year_count'][$year]['all'] ? number_format($data['year_count'][$year]['anon'] / $data['year_count'][$year]['all'] * 100, 2) : 0.0;
         $data['year_count'][$year]['pcts']['minor'] = $data['year_count'][$year]['all'] ? number_format($data['year_count'][$year]['minor'] / $data['year_count'][$year]['all'] * 100, 2) : 0.0;
         //Continue with more stats...
         foreach ($data['year_count'][$year]['months'] as $month => $tmp) {
             //More percentages...
             $data['year_count'][$year]['months'][$month]['pcts']['anon'] = $tmp['all'] ? number_format($tmp['anon'] / $tmp['all'] * 100, 2) : 0.0;
             $data['year_count'][$year]['months'][$month]['pcts']['minor'] = $tmp['all'] ? number_format($tmp['minor'] / $tmp['all'] * 100, 2) : 0.0;
             //XID and cumulative are used in the flash graph
             $data['year_count'][$year]['months'][$month]['xid'] = $num;
             $data['year_count'][$year]['months'][$month]['cumulative'] = $cum + $tmp['all'];
             if (count($tmp['size'])) {
                 $data['year_count'][$year]['months'][$month]['size'] = number_format(array_sum($tmp['size']) / count($tmp['size']), 2);
             } else {
                 $data['year_count'][$year]['months'][$month]['size'] = 0;
             }
             $data['year_count'][$year]['months'][$month]['sizecumulative'] = $scum + $data['year_count'][$year]['months'][$month]['size'];
             $num++;
             $cum += $tmp['all'];
             $scum += $data['year_count'][$year]['months'][$month]['size'];
         }
     }
     //Top 10% info
     $data['top_ten'] = array('editors' => array(), 'count' => 0);
     $data['top_fifty'] = array();
     //Now to fix the user info...
     $tmp = $tmp2 = 0;
     foreach ($data['editors'] as $editor => $info) {
         //Is the user in the top 10%?
         if ($tmp <= (int) (count($data['editors']) * 0.1)) {
             $data['top_ten']['editors'][] = $editor;
             $data['top_ten']['count'] += $info['all'];
             $tmp++;
         }
         //Is the user in the 50 highest editors?
         if ($tmp < 50) {
             $data['top_fifty'][] = $editor;
         }
         $data['editors'][$editor]['minorpct'] = $info['all'] ? number_format($info['minor'] / $info['all'] * 100, 2) : 0.0;
         if ($info['all'] > 1) {
             $data['editors'][$editor]['atbe'] = WebTool::getTimeString((int) ((strtotime($info['last']) - strtotime($info['first'])) / $info['all']));
         }
         if (count($info['size'])) {
             $data['editors'][$editor]['size'] = number_format(array_sum($info['size']) / count($info['size']), 2);
         } else {
             $data['editors'][$editor]['size'] = 0;
         }
         $tmp2++;
     }
     return $data;
 }
Ejemplo n.º 17
0
<?php

//Requires
require_once '/data/project/xtools/modules/WebTool.php';
require_once PEACHY_BASE_SYS_DIR . '/Peachy/Init.php';
//Load WebTool class
$wt = new WebTool('blame');
$wt->setLimits();
$wt->getPageTemplate('form');
//Get params from query string
$article = $wgRequest->getVal('article');
$article = $wgRequest->getVal('page', $article);
$nofollowredir = $wgRequest->getBool('nofollowredir');
$text = $wgRequest->getText('text');
$wi = $wt->wikiInfo;
$lang = $wi->lang;
$wiki = $wi->wiki;
$domain = $wi->domain;
//Show form if &article parameter is not set (or empty)
if ($lang == "" || $wiki == "" || $article == "" || $text == "") {
    $wt->showPage();
}
// execute the main logic
$pgVerbose = array();
$site = Peachy::newWiki(null, null, null, "http://{$wi->domain}/w/api.php");
$pageClass = $site->initPage($article, null, !$nofollowredir);
$title = $pageClass->get_title();
$list = getBlameResult($pageClass, $text);
$wt->content = getPageTemplate('result');
$wt->assign('list', $list);
$wt->assign('domain', $domain);
Ejemplo n.º 18
0
<?php

//Requires
require_once '/data/project/xtools/modules/WebTool.php';
//Load WebTool class
$wt = new WebTool('adminstats');
$wt->setLimits();
$wt->getPageTemplate("form");
$datenow = new DateTime();
$datefromdefault = date_format($datenow->sub(new DateInterval("P100D")), "Y-m-d");
$wt->assign('defaultBegin', $datefromdefault);
$datefrom = $wgRequest->getVal('begin', null);
$dateto = $wt->checkDate($wgRequest->getVal('end'));
$wi = $wt->getWikiInfo();
$lang = $wi->lang;
$wiki = $wi->wiki;
$domain = $wi->domain;
$perflog->add('domain', 0, $domain);
$perflog->add('datefrom', 0, $datefrom);
//Show form if domain parameter is not set (or empty)
if (!$domain || !$datefrom) {
    $wt->showPage();
    exit;
}
if ($datefrom == 'default') {
    $datefrom = $datefromdefault;
}
$datefrom = $wt->checkDate($datefrom);
$datediff = '–';
if ($datefrom) {
    $dt = new DateTime($dateto);
Ejemplo n.º 19
0
<?php

//Requires
require_once '/data/project/xtools/modules/WebTool.php';
require_once 'Counter.php';
//Load WebTool class
$wt = new WebTool('Automated Edits', 'autoedits', array());
$wt->setLimits();
$wt->getPageTemplate("form");
$wi = $wt->wikiInfo;
$lang = $wi->lang;
$wiki = $wi->wiki;
$domain = $wi->domain;
$ui = $wt->getUserInfo();
$user = $ui->user;
$begin = $wt->checkDate($wgRequest->getVal('begin'));
$end = $wt->checkDate($wgRequest->getVal('end'));
//Show form if &article parameter is not set (or empty)
if (!$lang || !$wiki || !$user) {
    $wt->showPage();
}
$dbr = $wt->loadDatabase($lang, $wiki);
$cnt = new Counter($dbr, $user, $domain, true);
//Start doing the DB request
$data = $cnt->calcAutoEditsDB($dbr, $begin, $end);
$list = '';
foreach ($data["tools"] as $toolname => $count) {
    $list .= '
				<tr>
				<td><a href="//en.wikipedia.org/wiki/' . Counter::$AEBTypes[$toolname]["shortcut"] . '">' . $toolname . '</a></td>
				<td class="tdnum" >' . $wt->numFmt($count) . '</td>
Ejemplo n.º 20
0
<?php

//Requires
require_once '/data/project/xtools/modules/WebTool.php';
require_once 'base.php';
//Load WebTool class
$wt = new WebTool('Bash', 'bash', array());
$base = new BashBase();
$wt->content = getPageTemplate('form');
$search = $wgRequest->getVal('search');
$isRegex = $wgRequest->getBool('regex');
//Show form if &article parameter is not set (or empty)
if (!$wgRequest->getVal('action')) {
    $wt->showPage();
}
switch ($wgRequest->getVal('action')) {
    case 'random':
        $quote = $base->getRandomQuote();
        $otherurl = "//tools.wmflabs.org" . $_SERVER['REQUEST_URI'];
        $pageResult = '
				<h3>{#quote_number#} ' . $quote['id'] . '</h3>
				<pre>' . $quote['quote'] . '</pre>
				<a href="' . $otherurl . '"> - {#more#} - </a>
			';
        break;
    case 'showall':
        $quotes = $base->getAllQuotes();
        $pageResult = '<h3>{#quote_showall#}</h3>';
        foreach ($quotes as $id => $quote) {
            $pageResult .= '
						<h3>{#quote_number#} ' . $id . '</h3>
Ejemplo n.º 21
0
chmod('data/' . md5($pageClass->get_title() . '-' . $pageClass->get_id()) . '.xml', 0775);
$content->assign("monthgraph", true);
$content->assign("monthpixels", getMonthPixels($data['year_count']));
$content->assign("evenyears", getEvenYears(array_keys($data['year_count'])));
$content->assign("sizegraph", true);
$sizegraph->assign("data", $data['year_count']);
$content->assign("sizegraphdata", md5($pageClass->get_title() . '-' . $pageClass->get_id() . '-line'));
file_put_contents('data/' . md5($pageClass->get_title() . '-' . $pageClass->get_id() . '-line') . '.xml', $sizegraph->fetch('sizegraph.tpl'));
chmod('data/' . md5($pageClass->get_title() . '-' . $pageClass->get_id() . '-line') . '.xml', 0775);
$content->assign("usertable", true);
$content->assign("userdata", $data['editors']);
$content->assign("topteneditors", $data['top_fifty']);
$content->assign("url", $url);
$content->assign("lang", $lang);
$content->assign("wiki", $wiki);
WebTool::finishScript();
//Script finished, now we're on to the functions
//Calculate how many pixels each year should get for the Edits per Year table
function getYearPixels(&$data)
{
    $month_total_edits = array();
    foreach ($data as $year => $tmp) {
        $month_total_edits[$year] = $tmp['all'];
    }
    $max_width = max($month_total_edits);
    $pixels = array();
    foreach ($data as $year => $tmp) {
        if ($tmp['all'] == 0) {
            $pixels[$year] = array();
        }
        $processarray = array('all' => $tmp['all'], 'anon' => $tmp['anon'], 'minor' => $tmp['minor']);
Ejemplo n.º 22
0
<?php

//Requires
require_once '/data/project/xtools/modules/WebTool.php';
//Load WebTool class
$wt = new WebTool('Edit summary', 'editsummary', array());
$wt->setLimits();
#	$wt->content = getPageTemplate( 'form' );
$wt->assign("lang", "en");
$wt->assign("wiki", "wikipedia");
$namespace = $wgRequest->getVal('namespace');
$redirects = $wgRequest->getVal('redirects');
$wi = $wt->getWikiInfo();
$lang = $wi->lang;
$wiki = $wi->wiki;
$domain = $wi->domain;
$dbr = $wt->loadDatabase($lang, $wiki);
$ui = $wt->getUserInfo();
$user = $wt->user;
#print_r($dbr);
//Get array of namespaces
function getNamespaces()
{
    global $http, $name, $lang, $wiki;
    $namespaces = $http->get('http://' . $lang . '.' . $wiki . '.org/w/api.php?action=query&meta=siteinfo&siprop=namespaces&format=php', false);
    $namespaces = unserialize($namespaces);
    $namespaces = $namespaces['query']['namespaces'];
    if (!$namespaces[0]) {
        toDie('Not a valid wiki.');
    }
    unset($namespaces[-2]);