Manual:Pager.php
From Linux Web Expert
<translate> This page is outdated.</translate> |
MediaWiki-Datei: Pager.php | |
---|---|
Speicherort: | includes/pager/ |
Quellcode: | master • 1.41.1 • 1.40.3 • 1.39.7 |
Klassen: | Pager |
The IndexPager class provides useful functions for paging results of MySQL query fieldset results. The IndexPager class is used for example in the special page Special:Categories.
Verwendungsbeispiel
The first step to use the IndexPager in your special page extensions is creating a class named for example MyExtensionsPager
that extends one of these three classes:
AlphabeticPager
is used when you want to list your items in alphabetical order
ReverseChronologicalPager
is used when you want to list your items in a reverse chronological order
TablePager
is used when you want display items in table rows
Each of these three class (AlphabeticPager
, ReverseChronologicalPager
and TablePager
) extends the IndexPager
class.
Usually you should only have to override a few methods in your class:
getQueryInfo()
let the pager know the SQL query you want to execute. It should return an associative array with the following elements:
"tables" =>
table(s) used in the query,
"fields" =>
field(s) for passing to Database::select(), may be * (all fields in table),
"conds" =>
an array containing conditions for WHERE clause,
"options" =>
an array containing other options (such as GROUP BY).
formatRow( $row )
gets an argument,$row
, which is a row object from the result fieldset. The function should return a string containing the item formatted as you need.
getIndexField()
should return the name of the table field used for indexing and ordering results.
For example, if you want to list all pages in the NS0 using a pager, you should do something like that:
class AllPagesPager extends AlphabeticPager {
function getQueryInfo() {
return array(
'tables' => 'page',
'fields' => 'page_title',
'conds' => array( 'page_is_redirect' => '0', 'page_namespace' => '0' )
);
}
function getIndexField() {
return 'page_title';
}
function formatRow( $row ) {
$title = Title::newFromDBkey( $row->page_title );
$s = '<li><a href="' . $title->getFullURL() . '">' . $title->getText() . '</a></li>';
return $s;
}
}
In your special page body than you have to:
- create a new
AllPagesPager()
class - use the
getNavigationBar()
method for putting the navigation bar on the top and on the bottom of the page - use the
getBody()
method for putting the list of the items.
Zum Beispiel:
$pager = new AllPagesPager();
$wgOut->addHTML(
$pager->getNavigationBar() . '<ol>' .
$pager->getBody() . '</ol>' .
$pager->getNavigationBar()
);