<commit_before><?php
/**
 Copyright 2016 <NAME> II

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

 http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
 */

use com_brucemyers\Util\Config;
use com_brucemyers\CleanupWorklistBot\CleanupWorklistBot;
use com_brucemyers\Util\CSVString;
use com_brucemyers\MediaWiki\WikidataWiki;
use com_brucemyers\MediaWiki\WikidataSPARQL;
use com_brucemyers\Util\Logger;

$webdir = dirname(__FILE__);
// Marker so include files can tell if they are called directly.
$GLOBALS['included'] = true;
$GLOBALS['botname'] = 'CleanupWorklistBot';
//error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);
//ini_set("display_errors", 1);

require $webdir . DIRECTORY_SEPARATOR . 'bootstrap.php';

$params = array();

$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : '';

get_params();

switch ($action) {
	case 'getCSV':
		getCSV();
		exit;
}

$navels = get_navels();

display_form($navels);

/**
 * Display replag
 *
 */
function display_form($navels)
{
	global $params;
	$edit_types = array(
		-1 => 'Label additions',
		-2 => 'Description additions',
		-3 => 'Alias additions',
		-4 => 'Site link additions',
		-5 => 'Merges',
	    -6 => 'Lexeme: form additions',
	    -7 => 'Lexeme: form representations',
	    -8 => 'Lexeme: form grammatical features',
	    -9 => 'Lexeme: sense additions',
	    -10 => 'Lexeme: sense glosses'
	);

    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
	    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	    <meta name="robots" content="noindex, nofollow" />
	    <title>Wikidata Navel Gazer</title>
    	<link rel='stylesheet' type='text/css' href='css/catwl.css' />
	    <script type='text/javascript' src='js/jquery-2.1.1.min.js'></script>
		<script type='text/javascript' src='js/jquery.tablesorter.min.js'></script>
	</head>
	<body>
		<script type='text/javascript'>
			$(document).ready(function()
			    {
				<?php if (! empty($params['username'])) { ?>
		        	$('.tablesorter').tablesorter({sortList: [[0,0]]});
			    <?php } elseif (! empty($params['property'])) { ?>
		        	$('.tablesorter').tablesorter({sortList: [[1,1]]});
				<?php } elseif (! empty($params['langadd'])) { ?>
		        	$('.tablesorter').tablesorter({sortList: [[2,1]]});
		        <?php } ?>
			    }
			);
		</script>
		<div style="display: table; margin: 0 auto;">
		<h2>Wikidata Navel Gazer<sup>[1]</sup><?php
		if (! empty($params['username'])) echo ' - ' . $params['username'];
		elseif (! empty($params['property'])) {
			if ($params['property'] < 0) {
				if (isset($edit_types[$params['property']])) echo ' - ' . $edit_types[$params['property']];
			} else {
				echo ' - P' . $params['property'];
			}
		}
		?></h2>
		<h3>users statement addition counts</h3>
        <form action="NavelGazer.php" method="post">
        <table class="form">
        <tr><td><b>Username</b></td><td><input id="username" name="username" type="text" size="10" value="<?php echo $params['username'] ?>" /></td></tr>
        <tr><td colspan='2'>or</td></tr>
        <tr><td><b>Property</b></td><td><input id="property" name="property" type="text" size="10" value="<?php if (! empty($params['property'])) echo 'P' . $params['property'] ?>" /> example: P31</td></tr>
        <tr><td>Pseudo properties</td><td><?php
         	foreach ($edit_types as $key => $edit_type) {
         		if ($key != -1) echo ', ';
        		if ($key == -3 || $key == -6 || $key == -8) echo '<br />';
        		echo "P$key = {$edit_type}";
        	}
        ?></td></tr>
        <tr><td colspan='2'>or</td></tr>
        <tr><td><b>Language code</b></td><td><input id="langadd" name="langadd" type="text" size="10" value="<?php echo $params['langadd'] ?>" /> (label, description, alias, sitelink additions)</td></tr>
        <tr><td colspan='2'><hr /></td></tr>
        <tr><td><b>Property label language code</b></td><td><input id="lang" name="lang" type="text" size="4" value="<?php echo $params['lang'] ?>" /></td></tr>
        <tr><td colspan='2'><input type="submit" value="Submit" /></td></tr>
        </table>
        </form>
        <script type="text/javascript">
            if (document.getElementById) {
                var e = document.getElementById('username');
                e.focus();
                e.select();
            }
        </script>
        <br />
<?php
	if (! empty($navels)) {
		if (empty($navels['data'])) {
		    if (! empty($params['username'])) echo 'User does not have any property additions';
		    elseif (! empty($params['property'])) echo 'Property not found';
		    else echo 'Language not found';

		} elseif (! empty($params['username'])) {
			if (! empty($params['property'])) echo "Clear the Username field to do a property search<br />\n";
			echo $navels['dataasof'] . "<sup>[2]</sup><br /><br />\n";

			$misc = array();

			foreach ($navels['data'] as $key => $row) {
				if ($row[0] < 0) {
				    $misc[] = $edit_types[$row[0]] . ": " . intl_num_format($row[1]) . " (last month: " . intl_num_format($row[2]) . "<br />\n";
					unset($navels['data'][$key]);
				}
			}

			if (! empty($misc)) {
				sort($misc);
				foreach ($misc as $statement) {
					echo $statement;
				}
			}

			echo "<table class='wikitable tablesorter'><thead><tr><th>Property</th><th>Datatype</th><th>Total count</th><th>Last month</th></tr></thead><tbody>\n";

			usort($navels['data'], function($a, $b) {
				return strcmp(strtolower($a[3]), strtolower($b[3]));
			});

			$propaddcnttot = 0;
			$propaddcntmth = 0;

			foreach ($navels['data'] as $row) {
			    $propaddcnttot += $row[1];
			    $propaddcntmth += $row[2];<commit_msg>Navel gazer - grand total property additions<commit_after><?php
/**
 Copyright 2016 Myers Enterprises II

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

 http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
 */

use com_brucemyers\Util\Config;
use com_brucemyers\CleanupWorklistBot\CleanupWorklistBot;
use com_brucemyers\Util\CSVString;
use com_brucemyers\MediaWiki\WikidataWiki;
use com_brucemyers\MediaWiki\WikidataSPARQL;
use com_brucemyers\Util\Logger;

$webdir = dirname(__FILE__);
// Marker so include files can tell if they are called directly.
$GLOBALS['included'] = true;
$GLOBALS['botname'] = 'CleanupWorklistBot';
//error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);
//ini_set("display_errors", 1);

require $webdir . DIRECTORY_SEPARATOR . 'bootstrap.php';

$params = array();

$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : '';

get_params();

switch ($action) {
	case 'getCSV':
		getCSV();
		exit;
}

$navels = get_navels();

display_form($navels);

/**
 * Display replag
 *
 */
function display_form($navels)
{
	global $params;
	$edit_types = array(
		-1 => 'Label additions',
		-2 => 'Description additions',
		-3 => 'Alias additions',
		-4 => 'Site link additions',
		-5 => 'Merges',
	    -6 => 'Lexeme: form additions',
	    -7 => 'Lexeme: form representations',
	    -8 => 'Lexeme: form grammatical features',
	    -9 => 'Lexeme: sense additions',
	    -10 => 'Lexeme: sense glosses'
	);

    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
	    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	    <meta name="robots" content="noindex, nofollow" />
	    <title>Wikidata Navel Gazer</title>
    	<link rel='stylesheet' type='text/css' href='css/catwl.css' />
	    <script type='text/javascript' src='js/jquery-2.1.1.min.js'></script>
		<script type='text/javascript' src='js/jquery.tablesorter.min.js'></script>
	</head>
	<body>
		<script type='text/javascript'>
			$(document).ready(function()
			    {
				<?php if (! empty($params['username'])) { ?>
		        	$('.tablesorter').tablesorter({sortList: [[0,0]]});
			    <?php } elseif (! empty($params['property'])) { ?>
		        	$('.tablesorter').tablesorter({sortList: [[1,1]]});
				<?php } elseif (! empty($params['langadd'])) { ?>
		        	$('.tablesorter').tablesorter({sortList: [[2,1]]});
		        <?php } ?>
			    }
			);
		</script>
		<div style="display: table; margin: 0 auto;">
		<h2>Wikidata Navel Gazer<sup>[1]</sup><?php
		if (! empty($params['username'])) echo ' - ' . $params['username'];
		elseif (! empty($params['property'])) {
			if ($params['property'] < 0) {
				if (isset($edit_types[$params['property']])) echo ' - ' . $edit_types[$params['property']];
			} else {
				echo ' - P' . $params['property'];
			}
		}
		?></h2>
		<h3>users statement addition counts</h3>
        <form action="NavelGazer.php" method="post">
        <table class="form">
        <tr><td><b>Username</b></td><td><input id="username" name="username" type="text" size="10" value="<?php echo $params['username'] ?>" /></td></tr>
        <tr><td colspan='2'>or</td></tr>
        <tr><td><b>Property</b></td><td><input id="property" name="property" type="text" size="10" value="<?php if (! empty($params['property'])) echo 'P' . $params['property'] ?>" /> example: P31</td></tr>
        <tr><td>Pseudo properties</td><td><?php
         	foreach ($edit_types as $key => $edit_type) {
         		if ($key != -1) echo ', ';
        		if ($key == -3 || $key == -6 || $key == -8) echo '<br />';
        		echo "P$key = {$edit_type}";
        	}
        ?></td></tr>
        <tr><td colspan='2'>or</td></tr>
        <tr><td><b>Language code</b></td><td><input id="langadd" name="langadd" type="text" size="10" value="<?php echo $params['langadd'] ?>" /> (label, description, alias, sitelink additions)</td></tr>
        <tr><td colspan='2'><hr /></td></tr>
        <tr><td><b>Property label language code</b></td><td><input id="lang" name="lang" type="text" size="4" value="<?php echo $params['lang'] ?>" /></td></tr>
        <tr><td colspan='2'><input type="submit" value="Submit" /></td></tr>
        </table>
        </form>
        <script type="text/javascript">
            if (document.getElementById) {
                var e = document.getElementById('username');
                e.focus();
                e.select();
            }
        </script>
        <br />
<?php
	if (! empty($navels)) {
		if (empty($navels['data'])) {
		    if (! empty($params['username'])) echo 'User does not have any property additions';
		    elseif (! empty($params['property'])) echo 'Property not found';
		    else echo 'Language not found';

		} elseif (! empty($params['username'])) {
			if (! empty($params['property'])) echo "Clear the Username field to do a property search<br />\n";
			echo $navels['dataasof'] . "<sup>[2]</sup><br /><br />\n";

			$misc = array();

			foreach ($navels['data'] as $key => $row) {
				if ($row[0] < 0) {
				    $misc[] = $edit_types[$row[0]] . ": " . intl_num_format($row[1]) . " (last month: " . intl_num_format($row[2]) . ")<br />\n";
					unset($navels['data'][$key]);
				}
			}

			if (! empty($misc)) {
				sort($misc);
				foreach ($misc as $statement) {
					echo $statement;
				}
			}

			echo "<table class='wikitable tablesorter'><thead><tr><th>Property</th><th>Datatype</th><th>Total count</th><th>Last month</th></tr></thead><tbody>\n";

			usort($navels['data'], function($a, $b) {
				return strcmp(strtolower($a[3]), strtolower($b[3]));
			});

			$propaddcnttot = 0;
			$propaddcntmth = 0;

			foreach ($navels['data'] as $row) {
			    $propaddcnttot += $row[1];
			    $propaddcntmth += $row[2];
{'fraction_non_alphanumeric': 0.20636327023761578, 'fraction_numerical': 0.012404349577124446, 'mean_word_length': 3.407525736599219, 'pattern_counts': {'":': 2, '<': 254, '<?xml version=': 0, '>': 272, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2062148', 'n_tokens_mistral': 4544, 'n_tokens_neox': 4134, 'n_words': 937}