Page MenuHomePhabricator

(An Untitled Masterwork)
ActivePublic

Authored by stwalkerster on Apr 8 2016, 6:11 PM.
Tags
None
Referenced Files
F306:
Apr 8 2016, 6:11 PM
Subscribers
None
<?php
$db = new PDO('mysql:host=localhost;dbname=enwiki_p', 'u2204', '');
$statement = $db->prepare('select page_id, page_namespace, page_title from enwiki_p.categorylinks
inner join enwiki_p.page on page_id = cl_from
where cl_to = :categoryname');
$pageIds = array();
$visitedCategories = array();
function recurse(PDOStatement $statement, $catName, $recurseCount = 0)
{
global $pageIds, $visitedCategories;
// skip already visited
if(isset($visitedCategories[$catName])) return;
$visitedCategories[$catName] = $catName;
echo "$recurseCount : recursing into $catName" . PHP_EOL;
$statement->execute(array('categoryname' => $catName));
$data = $statement->fetchAll(PDO::FETCH_ASSOC);
foreach ($data as $row) {
if($row['page_namespace'] == 14)
{
recurse($statement, $row['page_title'], $recurseCount + 1);
}
$pageIds[$row['page_id']] = $row['page_id'];
}
}
recurse($statement, 'Philosophy');
echo count($pageIds);

Event Timeline

stwalkerster created this object with visibility "Public (No Login Required)".
import-bot changed the edit policy from "All Users" to "Community (Project)".Feb 3 2017, 3:03 PM