/usr/share/mediawiki-extensions/base/NewestPages/NewestPages.page.php is in mediawiki-extensions-base 2.5.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 | <?php
/**
* Class definition file for the Newest Pages extension
* This doesn't use recent changes so the items don't expire
*
* @addtogroup Extensions
* @author Rob Church <robchur@gmail.com>
* @copyright © 2006 Rob Church
* @licence GNU General Public Licence 2.0
*/
class NewestPages extends IncludableSpecialPage {
var $limit = NULL;
var $namespace = NULL;
var $redirects = NULL;
public function __construct() {
IncludableSpecialPage::SpecialPage( 'Newestpages', '', true, false, 'default', true );
}
public function execute( $par ) {
global $wgRequest, $wgOut, $wgContLang;
wfLoadExtensionMessages( 'NewestPages' );
# Decipher input passed to the page
$this->decipherParams( $par );
$this->setOptions( $wgRequest );
$dbr =& wfGetDB( DB_SLAVE );
$page = $dbr->tableName( 'page' );
$nsf = $this->getNsFragment();
$redir = $this->redirects ? '' : ' AND page_is_redirect = 0';
$res = $dbr->query( "SELECT page_namespace, page_title, page_is_redirect FROM $page WHERE {$nsf}{$redir} ORDER BY page_id DESC LIMIT {$this->limit} OFFSET 0" );
$count = $dbr->numRows( $res );
# Don't show the navigation if we're including the page
if( !$this->mIncluding ) {
$this->setHeaders();
if( $this->namespace > 0 ) {
$wgOut->addWikiText( wfMsgExt( 'newestpages-ns-header', array( 'parsemag' ), $this->limit, $wgContLang->getFormattedNsText( $this->namespace ) ) );
} else {
$wgOut->addWikiText( wfMsgExt( 'newestpages-header', array( 'parsemag' ), $this->limit ) );
}
$wgOut->addHTML( $this->makeNamespaceForm() );
$wgOut->addHTML( '<p>' . $this->makeLimitLinks() );
$wgOut->addHTML( '<br />' . $this->makeRedirectToggle() . '</p>' );
}
if( $count > 0 ) {
# Make list
if( !$this->mIncluding )
$wgOut->addWikiText( wfMsgExt( 'newestpages-showing', array( 'parsemag' ), $count ) );
$wgOut->addHTML( "<ol>" );
while( $row = $dbr->fetchObject( $res ) )
$wgOut->addHTML( $this->makeListItem( $row ) );
$wgOut->addHTML( "</ol>" );
} else {
$wgOut->addWikiText( wfMsg( 'newestpages-none' ) );
}
$dbr->freeResult( $res );
}
function setOptions( &$req ) {
global $wgNewestPagesLimit;
if( !isset( $this->limit ) )
$this->limit = $this->sanitiseLimit( $req->getInt( 'limit', $wgNewestPagesLimit ) );
if( !isset( $this->namespace ) )
$this->namespace = $this->extractNamespace( $req->getVal( 'namespace', -1 ) );
if( !isset( $this->redirects ) )
$this->redirects = (bool)$req->getInt( 'redirects', 1 );
}
function sanitiseLimit( $limit ) {
return min( (int)$limit, 5000 );
}
function decipherParams( $par ) {
if( $par ) {
$bits = explode( '/', $par );
foreach( $bits as $bit ) {
if( is_numeric( $bit ) ) {
$this->limit = $this->sanitiseLimit( $bit );
} else {
$this->namespace = $this->extractNamespace( $bit );
}
}
}
}
function extractNamespace( $namespace ) {
global $wgContLang;
if( is_numeric( $namespace ) ) {
return $namespace;
} elseif( $wgContLang->getNsIndex( $namespace ) !== false ) {
return $wgContLang->getNsIndex( $namespace );
} elseif( $namespace == '-' ) {
return NS_MAIN;
} else {
return -1;
}
}
function getNsFragment() {
$this->namespace = (int)$this->namespace;
return $this->namespace > -1 ? "page_namespace = {$this->namespace}" : "page_namespace != 8";
}
function makeListItem( $row ) {
global $wgUser;
$title = Title::makeTitleSafe( $row->page_namespace, $row->page_title );
if( !is_null( $title ) ) {
$skin = $wgUser->getSkin();
$link = $row->page_is_redirect
? '<span class="allpagesredirect">' . $skin->makeKnownLinkObj( $title ) . '</span>'
: $skin->makeKnownLinkObj( $title );
return( "<li>{$link}</li>\n" );
} else {
return( "<!-- Invalid title " . htmlspecialchars( $row->page_title ) . " in namespace " . htmlspecialchars( $row->page_namespace ) . " -->\n" );
}
}
function makeLimitLinks() {
global $wgLang;
$limits = array( 10, 20, 30, 50, 100, 150 );
foreach( $limits as $limit ) {
if( $limit != $this->limit ) {
$links[] = $this->makeSelfLink( $limit, 'limit', $limit );
} else {
$links[] = (string)$limit;
}
}
return( wfMsgHtml( 'newestpages-limitlinks', $wgLang->pipeList( $links ) ) );
}
function makeRedirectToggle() {
$label = wfMsgHtml( $this->redirects ? 'newestpages-hideredir' : 'newestpages-showredir' );
return $this->makeSelfLink( $label, 'redirects', (int)!$this->redirects );
}
function makeSelfLink( $label, $oname = false, $oval = false ) {
global $wgUser;
$skin =& $wgUser->getSkin();
$self = Title::makeTitle( NS_SPECIAL, $this->getName() );
$attr['limit'] = $this->limit;
$attr['namespace'] = $this->namespace;
if( !$this->redirects )
$attr['redirects'] = 0;
if( $oname )
$attr[$oname] = $oval;
foreach( $attr as $aname => $aval )
$attribs[] = "{$aname}={$aval}";
return $skin->makeKnownLinkObj( $self, $label, implode( '&', $attribs ) );
}
function makeNamespaceForm() {
$self = Title::makeTitle( NS_SPECIAL, $this->getName() );
$form = Xml::openElement( 'form', array( 'method' => 'post', 'action' => $self->getLocalUrl() ) );
$form .= Xml::label( wfMsg( 'newestpages-namespace' ), 'namespace' ) . ' ';
$form .= Xml::namespaceSelector( $this->namespace, 'all' );
$form .= Xml::hidden( 'limit', $this->limit );
$form .= Xml::hidden( 'redirects', $this->redirects );
$form .= Xml::submitButton( wfMsg( 'newestpages-submit' ) ) . '</form>';
return $form;
}
}
|