Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F306
No One
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Authored By
stwalkerster
Apr 8 2016, 6:11 PM
2016-04-08 18:11:53 (UTC+0)
Size
1012 B
Referenced Files
None
Subscribers
None
View Options
<?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
);
File Metadata
Details
Attached
Mime Type
text/plain; charset=utf-8
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
275
Default Alt Text
(1012 B)
Attached To
Mode
P12 (An Untitled Masterwork)
Attached
Detach File
Event Timeline
Log In to Comment