Jump to content

User:SQLBot/tagger.php

From Wikipedia, the free encyclopedia
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.
<?php
$query = 'select distinct page_title, page_latest from categorylinks join page on page_id = cl_from where page_namespace = 1 and cl_type = "page" AND cl_to LIKE "Unassessed%rticles" order by rand() limit 50;';
$ts_pw = posix_getpwuid(posix_getuid());
$ts_mycnf = parse_ini_file($ts_pw['dir'] . "/replica.my.cnf");

$mysqli = mysqli_connect( 'enwiki.web.db.svc.eqiad.wmflabs', $ts_mycnf['user'], $ts_mycnf['password'], 'enwiki_p' );

if (mysqli_connect_errno()) {
	printf("Connect failed: %s\n", mysqli_connect_error());
	exit();
}

$result = mysqli_query( $mysqli, $query );

function getOres( $revid ) {
	$oresbase = "https://ores.wikimedia.org/v3/scores/enwiki/$revid?models=wp10";
	$oresresult = json_decode( file_get_contents( $oresbase ), TRUE );
	$class = $oresresult['enwiki']['scores'][$revid]['wp10']['score']['prediction'];
	return( $class );
}

$out = "";
while ( $row = $result->fetch_array( MYSQLI_ASSOC ) ) {
	$rev = $row['page_latest'];
	$article = "Talk:" . $row['page_title'];
	$ores = getOres( $rev );
	echo "# [[$article]] is predicted to be $ores-class\n";
}

?>