[Mediawiki-l] how to get all page titles from within a script

Jim Wilson wilson.jim.r at gmail.com
Wed Sep 12 20:28:07 UTC 2007


This should do what you want where $namespace is either an exact namespace
(like NS_MAIN) or an array of namespaces - like array(NS_MAIN, NS_CATEGORY):

$dbr =& wfGetDB( DB_SLAVE );
$res = $dbr->select(
    'page_title',
    'page',
    array( 'page_namespace' => $namespace ),
    __METHOD__,
    array( 'ORDER BY' => 'page_title' )
);
while ($obj = $dbr->fetchObject($res)) {
    $title = Title::newFromDBKey($obj->page_title);
    // do whatever you want with $title here
}
$dbr->freeResult($res);

Disclaimer: I have not tested the above code - having written it from
memory. YMMV :)

-- Jim R. Wilson (jimbojw)

On 9/12/07, Christensen, Courtney <ChristensenC at battelle.org> wrote:
>
> (Hope this doesn't post twice I sent it to the bounce address the first
> time.)
>
>
> Hi again,
>
> I'm using mediawiki 1.9.2 and I am writing an extension.  This extension
> is supposed to take a list from several wiki pages and put information
> from the list into an infobox on a calling page.  I tried looking at the
> all pages special page, but I was rather intimidated by the way it was
> requesting the list of pages.  I tried looking at the list of Hooks on
> the mediawiki site.  It is entirely possible that I am just dense, but I
> don't seem to be able to find a way to get an array of titles to
> process.
>
> I feel like there should be an easy function getAllTitlesInNamespace().
> But I haven't found it.  Does anyone have a suggestion for getting all
> the page titles in the Main namespace?
>
> Thanks very much!
> Courtney Christensen
>
> _______________________________________________
> MediaWiki-l mailing list
> MediaWiki-l at lists.wikimedia.org
> http://lists.wikimedia.org/mailman/listinfo/mediawiki-l
>


More information about the MediaWiki-l mailing list