User talk:SQL/ACE2019 e

Page contents not supported in other languages.
Source: Wikipedia, the free encyclopedia.

Details

  • Updates every 5 mins

Code

This is very quick and dirty code, uncommented, poorly formatted, and written in a hurry. Someone might need it someday, so posting.

Extended content
<?php
$api = json_decode( file_get_contents( "https://en.wikipedia.org/w/api.php?action=parse&page=Wikipedia:Requests%20for%20comment/Arbitration%20Committee%20Elections%20December%202019/Electoral%20Commission&prop=sections&format=json" ), true );
$api = $api['parse']['sections'];
$endorse = array();
$users = array();
foreach( $api as $section ) {
	if( strpos( $section['anchor'], "Users_endorsing_" ) !== FALSE ) {
		$user = substr( $section['line'], 16);
		$index = $section['index'];
		$endorse[$user] = array();
		$endorse[$user]['index'] = $index;
		$endorse[$user]['name'] = $user;
		$text = json_decode( file_get_contents( "https://en.wikipedia.org/w/api.php?action=parse&page=Wikipedia:Requests%20for%20comment/Arbitration%20Committee%20Elections%20December%202019/Electoral%20Commission&section=$index&prop=wikitext&format=json" ), TRUE );
		$text = explode( "\n", $text['parse']['wikitext']['*'] );
		$endorse[$user]['count'] = 0;
		foreach( $text as $t ) {
			$first = substr( $t, 0, 1 );
			if( $first == "#" ) { $endorse[$user]['count']++; }			
		}
		//print_r( $text );
	}
	if( isset( $user ) ) {$users[$user] = $endorse[$user]['count'];}
}
arsort( $users );
print_r( $users );

$count = 0;
$max = count( $users );
$table = '{| class="wikitable"
|+ ACE2019 Endorsements
|-
! User
! Endorsements
|-
';
foreach( $users as $u=>$c ) {
	$table .= "| $u
| $c
";
	if( $count < $max -1	) {
		$table .= "|-\n";
	} else {
		$table .= "|}\n";
	}
	$count++;
}
echo $table;
//BotPasswords
$user = "nope"; 
$password = "noayman";

echo "\nLogging into enwiki...\n";
$cookies = @tempnam( '../cookies/', 'cookie.txt' );
$loginurl = "https://en.wikipedia.org/w/api.php?format=json&action=query&meta=tokens&type=login";
$ch = curl_init( $loginurl );
$login = array();
$postString = http_build_query( $login, '', '&' );
curl_setopt( $ch, CURLOPT_POST, 1 );
curl_setopt( $ch, CURLOPT_COOKIEJAR, $cookies );
curl_setopt( $ch, CURLOPT_COOKIEFILE, $cookies );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, TRUE );
$response = curl_exec( $ch );
curl_close( $ch );
$reply = json_decode( $response, TRUE );
$logintoken = $reply['query']['tokens']['logintoken'];
$login = array();
$login['lgname'] = $user;
$login['lgpassword'] = $password;
$login['lgtoken'] = $logintoken;
$login['lgdomain'] = "en.wikipedia.org";
//print_r($login);
$loginurl = "https://en.wikipedia.org/w/api.php?format=json&action=login";
$ch = curl_init( $loginurl );
$postString = http_build_query( $login, '', '&' );
curl_setopt( $ch, CURLOPT_POST, 1 );
curl_setopt( $ch, CURLOPT_COOKIEJAR, $cookies );
curl_setopt( $ch, CURLOPT_COOKIEFILE, $cookies );
curl_setopt( $ch, CURLOPT_POSTFIELDS, $postString );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, TRUE );
$response = curl_exec( $ch );
curl_close( $ch );
$reply = json_decode( $response, TRUE );
if ( $reply['login']['result'] != "Success" )
{
    print_r( $reply );
    die( "\n\nSOMETHING HAPPENED\n\n" );
}
$loginurl = "https://en.wikipedia.org/w/api.php?format=json&action=query&meta=tokens&type=csrf";
$ch = curl_init( $loginurl );
$login = array();
$postString = http_build_query( $login, '', '&' );
curl_setopt( $ch, CURLOPT_POST, 1 );
curl_setopt( $ch, CURLOPT_COOKIEJAR, $cookies );
curl_setopt( $ch, CURLOPT_COOKIEFILE, $cookies );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, TRUE );
$response = curl_exec( $ch );
curl_close( $ch );
$reply = json_decode( $response, TRUE );
$csrftoken = $reply['query']['tokens']['csrftoken'];
echo "Posting table!\n";

function putPage ( $page, $text, $csrftoken, $cookies, $summary ) {
	$login = array();
	$login['text'] = $text;
	$login['token'] = $csrftoken;
	$login['title'] = $page;
	$login['summary'] = $summary;
	$loginurl = "https://en.wikipedia.org/w/api.php?format=json&action=edit";
	$ch = curl_init( $loginurl );
	$postString = http_build_query( $login, '', '&' );
	curl_setopt( $ch, CURLOPT_POST, 1 );
	curl_setopt( $ch, CURLOPT_COOKIEJAR, $cookies );
	curl_setopt( $ch, CURLOPT_COOKIEFILE, $cookies );
	curl_setopt( $ch, CURLOPT_POSTFIELDS, $postString );
	curl_setopt( $ch, CURLOPT_RETURNTRANSFER, TRUE );
	$response = curl_exec( $ch );
	curl_close( $ch );
	$reply = json_decode( $response, TRUE );
	print_r( $reply );
	return( $reply );
}
putPage( "User:SQL/ACE2019_e", $table, $csrftoken, $cookies, "Updating ACE2019 Election Endorsement Table" );
?>