Manual:Pager.php

This page is a translated version of the page Manual:Pager.php and the translation is 29% complete.

IndexPager クラスは、MySQL クエリ フィールドセットの結果のページングに役立つ関数を提供します。 IndexPager クラスは、例えば特別ページ Special:Categories で使用されます。

使用例

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.

例:

$pager = new AllPagesPager();
$wgOut->addHTML(
	$pager->getNavigationBar() . '<ol>' .
	$pager->getBody() . '</ol>' .
	$pager->getNavigationBar()
);


関連項目