4
* Class definition file for the Newest Pages extension
5
* This doesn't use recent changes so the items don't expire
7
* @addtogroup Extensions
8
* @author Rob Church <robchur@gmail.com>
9
* @copyright © 2006 Rob Church
10
* @licence GNU General Public Licence 2.0
13
class NewestPages extends IncludableSpecialPage {
16
var $namespace = NULL;
17
var $redirects = NULL;
19
public function __construct() {
20
IncludableSpecialPage::SpecialPage( 'Newestpages', '', true, false, 'default', true );
23
public function execute( $par ) {
24
global $wgRequest, $wgOut, $wgContLang;
26
wfLoadExtensionMessages( 'NewestPages' );
28
# Decipher input passed to the page
29
$this->decipherParams( $par );
30
$this->setOptions( $wgRequest );
32
$dbr =& wfGetDB( DB_SLAVE );
33
$page = $dbr->tableName( 'page' );
34
$nsf = $this->getNsFragment();
35
$redir = $this->redirects ? '' : ' AND page_is_redirect = 0';
36
$res = $dbr->query( "SELECT page_namespace, page_title, page_is_redirect FROM $page WHERE {$nsf}{$redir} ORDER BY page_id DESC LIMIT 0,{$this->limit}" );
37
$count = $dbr->numRows( $res );
39
# Don't show the navigation if we're including the page
40
if( !$this->mIncluding ) {
42
if( $this->namespace > 0 ) {
43
$wgOut->addWikiText( wfMsgExt( 'newestpages-ns-header', array( 'parsemag' ), $this->limit, $wgContLang->getFormattedNsText( $this->namespace ) ) );
45
$wgOut->addWikiText( wfMsgExt( 'newestpages-header', array( 'parsemag' ), $this->limit ) );
47
$wgOut->addHTML( $this->makeNamespaceForm() );
48
$wgOut->addHTML( '<p>' . $this->makeLimitLinks() );
49
$wgOut->addHTML( '<br />' . $this->makeRedirectToggle() . '</p>' );
54
if( !$this->mIncluding )
55
$wgOut->addWikiText( wfMsgExt( 'newestpages-showing', array( 'parsemag' ), $count ) );
56
$wgOut->addHTML( "<ol>" );
57
while( $row = $dbr->fetchObject( $res ) )
58
$wgOut->addHTML( $this->makeListItem( $row ) );
59
$wgOut->addHTML( "</ol>" );
61
$wgOut->addWikiText( wfMsg( 'newestpages-none' ) );
63
$dbr->freeResult( $res );
66
function setOptions( &$req ) {
67
global $wgNewestPagesLimit;
68
if( !isset( $this->limit ) )
69
$this->limit = $this->sanitiseLimit( $req->getInt( 'limit', $wgNewestPagesLimit ) );
70
if( !isset( $this->namespace ) )
71
$this->namespace = $this->extractNamespace( $req->getVal( 'namespace', -1 ) );
72
if( !isset( $this->redirects ) )
73
$this->redirects = (bool)$req->getInt( 'redirects', 1 );
76
function sanitiseLimit( $limit ) {
77
return min( (int)$limit, 5000 );
80
function decipherParams( $par ) {
82
$bits = explode( '/', $par );
83
foreach( $bits as $bit ) {
84
if( is_numeric( $bit ) ) {
85
$this->limit = $this->sanitiseLimit( $bit );
87
$this->namespace = $this->extractNamespace( $bit );
93
function extractNamespace( $namespace ) {
95
if( is_numeric( $namespace ) ) {
97
} elseif( $wgContLang->getNsIndex( $namespace ) !== false ) {
98
return $wgContLang->getNsIndex( $namespace );
99
} elseif( $namespace == '-' ) {
106
function getNsFragment() {
107
$this->namespace = (int)$this->namespace;
108
return $this->namespace > -1 ? "page_namespace = {$this->namespace}" : "page_namespace != 8";
111
function makeListItem( $row ) {
113
$title = Title::makeTitleSafe( $row->page_namespace, $row->page_title );
114
if( !is_null( $title ) ) {
115
$skin = $wgUser->getSkin();
116
$link = $row->page_is_redirect
117
? '<span class="allpagesredirect">' . $skin->makeKnownLinkObj( $title ) . '</span>'
118
: $skin->makeKnownLinkObj( $title );
119
return( "<li>{$link}</li>\n" );
121
return( "<!-- Invalid title " . htmlspecialchars( $row->page_title ) . " in namespace " . htmlspecialchars( $row->page_namespace ) . " -->\n" );
125
function makeLimitLinks() {
128
$limits = array( 10, 20, 30, 50, 100, 150 );
129
foreach( $limits as $limit ) {
130
if( $limit != $this->limit ) {
131
$links[] = $this->makeSelfLink( $limit, 'limit', $limit );
133
$links[] = (string)$limit;
136
return( wfMsgHtml( 'newestpages-limitlinks', $wgLang->pipeList( $links ) ) );
139
function makeRedirectToggle() {
140
$label = wfMsgHtml( $this->redirects ? 'newestpages-hideredir' : 'newestpages-showredir' );
141
return $this->makeSelfLink( $label, 'redirects', (int)!$this->redirects );
144
function makeSelfLink( $label, $oname = false, $oval = false ) {
146
$skin =& $wgUser->getSkin();
147
$self = Title::makeTitle( NS_SPECIAL, $this->getName() );
148
$attr['limit'] = $this->limit;
149
$attr['namespace'] = $this->namespace;
150
if( !$this->redirects )
151
$attr['redirects'] = 0;
153
$attr[$oname] = $oval;
154
foreach( $attr as $aname => $aval )
155
$attribs[] = "{$aname}={$aval}";
156
return $skin->makeKnownLinkObj( $self, $label, implode( '&', $attribs ) );
159
function makeNamespaceForm() {
160
$self = Title::makeTitle( NS_SPECIAL, $this->getName() );
161
$form = Xml::openElement( 'form', array( 'method' => 'post', 'action' => $self->getLocalUrl() ) );
162
$form .= Xml::label( wfMsg( 'newestpages-namespace' ), 'namespace' ) . ' ';
163
$form .= Xml::namespaceSelector( $this->namespace, 'all' );
164
$form .= Xml::hidden( 'limit', $this->limit );
165
$form .= Xml::hidden( 'redirects', $this->redirects );
166
$form .= Xml::submitButton( wfMsg( 'newestpages-submit' ) ) . '</form>';