Skip to content

Commit

Permalink
fix #63 User whitelist
Browse files Browse the repository at this point in the history
  • Loading branch information
NovemLinguae committed Dec 29, 2021
1 parent 755c26e commit 4ab2f55
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 9 deletions.
19 changes: 18 additions & 1 deletion src/WikiAPIWrapper.php
Expand Up @@ -30,7 +30,24 @@ function categorymembers($category) {
$this->eh->echoAndFlush($message, 'api_read');
return $output;
}


function getUnreadPings() {
$output = $this->wapi->query('?action=query&format=json&meta=notifications&notfilter=!read');
$message = "Getting list of pings";
$message .= "\n\n" . var_export($output, true);
$this->eh->echoAndFlush($message, 'api_read');
return $output;
}

function markAllPingsRead() {
$csrfToken = $this->wapi->query('?action=query&format=json&meta=tokens');
$csrfToken = $csrfToken['query']['tokens']['csrftoken'];
$output = $this->wapi->query("?action=echomarkread&format=json&all=1", ['token' => $csrfToken]);
$message = "Marking all pings read";
$message .= "\n\n" . var_export($output, true);
$this->eh->echoAndFlush($message, 'api_read');
}

// TODO: does page title need underscores?
function edit(string $namespace_and_title, string $wikicode, string $topicPageTitle, string $goodOrFeatured): void {
global $READ_ONLY_TEST_MODE, $SECONDS_BETWEEN_API_EDITS;
Expand Down
37 changes: 29 additions & 8 deletions src/index.php
Expand Up @@ -57,15 +57,36 @@
$message .= "\n\n" . var_export($pagesToPromote, true);
$eh->echoAndFlush($message, 'message');
} else {
$pagesToPromote = $wapi->categorymembers($TRACKING_CATEGORY_NAME);
}

// Remove Wikipedia:Wikipedia:Featured and good topic candidates from list of pages to process. Sometimes this page shows up in the category because it transcludes the nomination pages. We only want to process the nomination pages.
$pagesToPromote = $h->deleteArrayValue($pagesToPromote, 'Wikipedia:Featured and good topic candidates');
// example: ["Novem Linguae", "GamerPro64", "Sturmvogel 66", "Aza24"]
$whitelist = $wapi->getpage('User:Novem_Linguae/Scripts/NovemBotTask1Whitelist.js');
$whitelist = json_decode($whitelist);

$listOfPings = $wapi->getUnreadPings();
$listOfPings = $listOfPings['query']['notifications']['list'];
$pagesToPromote = [];
foreach ( $listOfPings as $key => $value ) {
// make sure pinger is on whitelist
$pingSender = $value['agent']['name'];
if ( in_array($pingSender, $whitelist) ) {
// make sure pinging page has {{Featured topic box}}
$pingTitle = $value['title']['full'];
$archivePageWikicode = $wapi->getpage($pingTitle);
$containsFeaturedTopicBox = false;
try {
$containsFeaturedTopicBox = $p->getTopicBoxWikicode($archivePageWikicode, $pingTitle);
} catch (Exception $e) {}
if ( $containsFeaturedTopicBox ) {
// add to list of pages to promote
$pagesToPromote[] = $pingTitle;
}
}
}

// Remove Wikipedia:Featured and good topic candidates/Good log* and Wikipedia:Featured and good topic candidates/Feated log*. These sometimes show up in the tracking category via some kind of transclusion glitch.
$pagesToPromote = $h->deleteArrayValuesBeginningWith($pagesToPromote, 'Wikipedia:Featured and good topic candidates/Good log');
$pagesToPromote = $h->deleteArrayValuesBeginningWith($pagesToPromote, 'Wikipedia:Featured and good topic candidates/Featured log');
//if ( ! $READ_ONLY_TEST_MODE ) {
// mark all pings read
$wapi->markAllPingsRead();
//}
}

$eh->html_var_export($pagesToPromote, 'variable');

Expand Down

0 comments on commit 4ab2f55

Please sign in to comment.