Skip to content

Commit

Permalink
move functions to class
Browse files Browse the repository at this point in the history
  • Loading branch information
NovemLinguae committed May 9, 2024
1 parent 5175ceb commit abceaa9
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 34 deletions.
47 changes: 34 additions & 13 deletions Task7RFACount/src/RFACount.php
Original file line number Diff line number Diff line change
@@ -1,23 +1,44 @@
<?php

function countRFAs( $wikicode ) {
preg_match_all( '/\{\{Wikipedia:Requests for adminship\/[^\}]+\}\}/i', $wikicode, $matches );
class RFACount {
public function doRFA( $wapi, $rfaPageWikitext ) {
$count = $this->countRFAs( $rfaPageWikitext );

// don't count {{Wikipedia:Requests for adminship/Header}} and {{Wikipedia:Requests for adminship/bureaucratship}}
$count = count( $matches[0] ) - 2;
$wikicodeToWrite =
"$count<noinclude>
{{Documentation}}
</noinclude>";
$editSummary = "set RFA count to $count (NovemBot Task 7)";
$wapi->edit( 'User:Amalthea/RfX/RfA count', $wikicodeToWrite, $editSummary );
}

public function doRFB( $wapi, $rfaPageWikitext ) {
$count = $this->countRFBs( $rfaPageWikitext );

// if we get an impossible count, just return zero
if ( $count < 0 ) {
$count = 0;
$wikicodeToWrite = $count;
$editSummary = "set RFB count to $count (NovemBot Task 7)";
$wapi->edit( 'User:Amalthea/RfX/RfB count', $wikicodeToWrite, $editSummary );
}

return $count;
}
private function countRFAs( $wikicode ) {
preg_match_all( '/\{\{Wikipedia:Requests for adminship\/[^\}]+\}\}/i', $wikicode, $matches );

// don't count {{Wikipedia:Requests for adminship/Header}} and {{Wikipedia:Requests for adminship/bureaucratship}}
$count = count( $matches[0] ) - 2;

function countRFBs( $wikicode ) {
preg_match_all( '/\{\{Wikipedia:Requests for bureaucratship\/[^\}]+\}\}/i', $wikicode, $matches );
// if we get an impossible count, just return zero
if ( $count < 0 ) {
$count = 0;
}

$count = count( $matches[0] );
return $count;
}

private function countRFBs( $wikicode ) {
preg_match_all( '/\{\{Wikipedia:Requests for bureaucratship\/[^\}]+\}\}/i', $wikicode, $matches );

return $count;
$count = count( $matches[0] );

return $count;
}
}
24 changes: 3 additions & 21 deletions Task7RFACount/src/index.php
Original file line number Diff line number Diff line change
@@ -1,24 +1,5 @@
<?php

function doRFA( $wapi, $rfaPageWikitext ) {
$count = countRFAs( $rfaPageWikitext );

$wikicodeToWrite =
"$count<noinclude>
{{Documentation}}
</noinclude>";
$editSummary = "set RFA count to $count (NovemBot Task 7)";
$wapi->edit( 'User:Amalthea/RfX/RfA count', $wikicodeToWrite, $editSummary );
}

function doRFB( $wapi, $rfaPageWikitext ) {
$count = countRFBs( $rfaPageWikitext );

$wikicodeToWrite = $count;
$editSummary = "set RFB count to $count (NovemBot Task 7)";
$wapi->edit( 'User:Amalthea/RfX/RfB count', $wikicodeToWrite, $editSummary );
}

require_once 'config.php';
require_once 'css.php';
require_once 'botclasses.php';
Expand Down Expand Up @@ -53,12 +34,13 @@ function doRFB( $wapi, $rfaPageWikitext ) {
$h = new Helper();
$eh = new EchoHelper( $h );
$wapi = new WikiAPIWrapper( $config['wikiUsername'], $config['wikiPassword'], $eh );
$rfaCount = new RFACount();

$eh->echoAndFlush( "PHP version: " . PHP_VERSION, 'variable' );

$rfaPageWikitext = $wapi->getpage( 'Wikipedia:Requests for adminship' );

doRFA( $wapi, $rfaPageWikitext );
doRFB( $wapi, $rfaPageWikitext );
$rfaCount->doRFA( $wapi, $rfaPageWikitext );
$rfaCount->doRFB( $wapi, $rfaPageWikitext );

$eh->echoAndFlush( '', 'complete' );

0 comments on commit abceaa9

Please sign in to comment.