I am trying to find corresponding text records for a category.
For example if I have the ID 5 for a "categorylinks" record, how would I find which texts go into that category?
I am trying to find corresponding text records for a category.
For example if I have the ID 5 for a "categorylinks" record, how would I find which texts go into that category?
Edit: I'm still not sure if you are asking for the text of a category page or the text of the pages in a category so here's both:
Text of a category page:
select old_text from text, revision, page, categorylinks
where rev_text_id = old_id
and rev_id = page_latest
and page_namespace = 14
and page_title = cl_to
and cl_from = <cl_from entry in categorylinks table>
Text of a page in a category:
select old_text from text, revision, page, categorylinks
where rev_text_id = old_id
and rev_id = page_latest
and page_id = cl_from
and cl_to = <cl_to entry in categorylinks table>
More explanation:
Basically, in categorylinks, the cl_title
is the title of the category page. So you can look that up in the page table using page_title
and page_namespace
= 14 (the category namespace). Once you have the correct page, the page_latest
field for that row equals the rev_id
in the revision table. This gives you the latest revision for the category page. The revision table has a rev_text_id
field which equals the old_id
field in the text table. old_text
in the text table is your text.
Any time you want the text for a page it basically works like this. Find the page database record. Then: page.page_latest = revision.rev_id and revision.rev_text_id = text.old_id
.
See also: The MediaWiki database schema.