Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Paste
P12
(An Untitled Masterwork)
Active
Public
Actions
Authored by
stwalkerster
on Apr 8 2016, 6:11 PM.
Edit Paste
Archive Paste
View Raw File
Subscribe
Mute Notifications
Tags
None
Referenced Files
F306:
Apr 8 2016, 6:11 PM
2016-04-08 18:11:53 (UTC+0)
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 paste.
Apr 8 2016, 6:11 PM
2016-04-08 18:11:53 (UTC+0)
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
2017-02-03 15:03:54 (UTC+0)
Log In to Comment