<?php
/**
 *
 * @package MediaWiki
 * @subpackage SpecialPage
 */

/**
 *
 */
require_once( 'QueryPage.php' );

/**
 *
 * @package MediaWiki
 * @subpackage SpecialPage
 */
class RestrictedPagesPage extends QueryPage {

	function getName() {
		return "Restrictedpages";
	}

	function isExpensive() {
		return false;
	}
	
	function isSyndicated() { return false; }
	
	function getPageHeader() {
		global $wgRegexRestrict;

		$string = '<p>'.wfMsg('restrictedpagespagetext');
		if (! empty($wgRegexRestrict) ) {
			$string .= "</p>\n<p>".wfMsg('regexrestrictedpagespagetext');
			foreach( $wgRegexRestrict as $k => $v ) $string .= "<strong>{$v}</strong>, ";
			$string = substr( $string, 0, -2);
		}
		
		$string .= "</p>\n<br />";
		
		return $string;
	}

	function getSQL() {
		global $wgEnableRestrict, $wgUser;

		$db =& wfGetDB( DB_SLAVE );
		$page = $db->tableName( 'page' );
		return
			"SELECT 'Restrictedpages' as type,
				page_namespace as namespace,
			        page_title as title,
				page_title as value
			FROM $page
			WHERE page_namespace=".NS_MAIN." AND page_is_redirect=0 AND page_restrictions LIKE '%view=1%'";
	}
	
	function sortDescending() {
		return false;
	}

	function formatResult( $skin, $result ) {
		global $wgLang, $wgContLang;

		$d = $wgLang->timeanddate( wfTimestamp( TS_MW, $result->value ), true );
		$link = $skin->makeKnownLink( $result->title, $wgContLang->convert( $result->title) );
		return "{$link} ({$d})";
	}
}

function wfSpecialRestrictedpages() {
	list( $limit, $offset ) = wfCheckLimits();

	$app = new RestrictedPagesPage();

	$app->doQuery( $offset, $limit );
}

?>
