4 * @addtogroup SpecialPage
11 function wfSpecialNewPages( $par, $specialPage ) {
12 $page = new NewPagesPage( $specialPage );
13 $page->execute( $par );
17 * implements Special:Newpages
18 * @addtogroup SpecialPage
20 class NewPagesPage
extends QueryPage
{
22 protected $options = array();
23 protected $nondefaults = array();
24 protected $specialPage;
26 public function __construct( $specialPage ) {
27 $this->specialPage
= $specialPage;
30 public function execute( $par ) {
31 global $wgRequest, $wgLang;
33 $shownavigation = !$this->specialPage
->including();
36 /* bool */ 'hideliu' => false,
37 /* bool */ 'hidepatrolled' => false,
38 /* bool */ 'hidebots' => false,
39 /* text */ 'namespace' => "0",
40 /* text */ 'username' => '',
41 /* int */ 'offset' => 0,
42 /* int */ 'limit' => 50,
48 $bits = preg_split( '/\s*,\s*/', trim( $par ) );
49 foreach ( $bits as $bit ) {
50 if ( 'shownav' == $bit )
51 $shownavigation = true;
52 if ( 'hideliu' === $bit )
53 $options['hideliu'] = true;
54 if ( 'hidepatrolled' == $bit )
55 $options['hidepatrolled'] = true;
56 if ( 'hidebots' == $bit )
57 $options['hidebots'] = true;
58 if ( is_numeric( $bit ) )
59 $options['limit'] = intval( $bit );
62 if ( preg_match( '/^limit=(\d+)$/', $bit, $m ) )
63 $options['limit'] = intval($m[1]);
64 if ( preg_match( '/^offset=(\d+)$/', $bit, $m ) )
65 $options['offset'] = intval($m[1]);
66 if ( preg_match( '/^namespace=(.*)$/', $bit, $m ) ) {
67 $ns = $wgLang->getNsIndex( $m[1] );
69 $options['namespace'] = $ns;
75 // Override all values from requests, if specified
76 foreach ( $defaults as $v => $t ) {
78 $options[$v] = $wgRequest->getBool( $v, $options[$v] );
79 } elseif( is_int($t) ) {
80 $options[$v] = $wgRequest->getInt( $v, $options[$v] );
81 } elseif( is_string($t) ) {
82 $options[$v] = $wgRequest->getText( $v, $options[$v] );
86 $nondefaults = array();
87 foreach ( $options as $v => $t ) {
88 if ( $v === 'offset' ) continue; # Reset offset if parameters change
89 wfAppendToArrayIfNotDefault( $v, $t, $defaults, $nondefaults );
93 $this->options
= $options;
94 $this->nondefaults
= $nondefaults;
96 if ( !$this->doFeed( $wgRequest->getVal( 'feed' ), $options['limit'] ) ) {
97 $this->doQuery( $options['offset'], $options['limit'], $shownavigation );
101 function linkParameters() {
102 $nondefaults = $this->nondefaults
;
103 // QueryPage seems to handle limit and offset itself
104 if ( isset( $nondefaults['limit'] ) ) {
105 unset($nondefaults['limit']);
114 function isExpensive() {
115 # Indexed on RC, and will *not* work with querycache yet.
119 function makeUserWhere( $db ) {
120 global $wgGroupPermissions;
122 if ($this->options
['hidepatrolled']) {
123 $conds['rc_patrolled'] = 0;
125 if ($this->options
['hidebots']) {
126 $conds['rc_bot'] = 0;
128 if ($wgGroupPermissions['*']['createpage'] == true && $this->options
['hideliu']) {
129 $conds['rc_user'] = 0;
131 $title = Title
::makeTitleSafe( NS_USER
, $this->options
['username'] );
133 $conds['rc_user_text'] = $title->getText();
141 global $wgUser, $wgUseNPPatrol, $wgUseRCPatrol;
142 $usepatrol = ( $wgUseNPPatrol ||
$wgUseRCPatrol ) ?
1 : 0;
143 $dbr = wfGetDB( DB_SLAVE
);
144 list( $recentchanges, $page ) = $dbr->tableNamesN( 'recentchanges', 'page' );
147 $conds['rc_new'] = 1;
148 if ( $this->options
['namespace'] !== 'all' ) {
149 $conds['rc_namespace'] = intval( $this->options
['namespace'] );
151 $conds['page_is_redirect'] = 0;
152 $conds +
= $this->makeUserWhere( $dbr );
153 $condstext = $dbr->makeList( $conds, LIST_AND
);
155 # FIXME: text will break with compression
157 "SELECT 'Newpages' as type,
158 rc_namespace AS namespace,
162 rc_user_text AS user_text,
163 rc_comment as \"comment\",
164 rc_timestamp AS timestamp,
165 rc_timestamp AS value,
166 '{$usepatrol}' as usepatrol,
167 rc_patrolled AS patrolled,
170 page_latest as rev_id
171 FROM $recentchanges,$page
172 WHERE rc_cur_id=page_id AND $condstext";
175 function preprocessResults( $db, $res ) {
176 # Do a batch existence check on the user and talk pages
177 $linkBatch = new LinkBatch();
178 while( $row = $db->fetchObject( $res ) ) {
179 $linkBatch->add( NS_USER
, $row->user_text
);
180 $linkBatch->add( NS_USER_TALK
, $row->user_text
);
182 $linkBatch->execute();
184 if( $db->numRows( $res ) > 0 )
185 $db->dataSeek( $res, 0 );
189 * Format a row, providing the timestamp, links to the page/history, size, user links, and a comment
191 * @param $skin Skin to use
192 * @param $result Result row
195 function formatResult( $skin, $result ) {
196 global $wgLang, $wgContLang;
197 $dm = $wgContLang->getDirMark();
199 $title = Title
::makeTitleSafe( $result->namespace, $result->title
);
200 $time = $wgLang->timeAndDate( $result->timestamp
, true );
201 $plink = $skin->makeKnownLinkObj( $title, '', $this->patrollable( $result ) ?
'rcid=' . $result->rcid
: '' );
202 $hist = $skin->makeKnownLinkObj( $title, wfMsgHtml( 'hist' ), 'action=history' );
203 $length = wfMsgExt( 'nbytes', array( 'parsemag', 'escape' ), $wgLang->formatNum( htmlspecialchars( $result->length
) ) );
204 $ulink = $skin->userLink( $result->user
, $result->user_text
) . ' ' . $skin->userToolLinks( $result->user
, $result->user_text
);
205 $comment = $skin->commentBlock( $result->comment
);
207 return "{$time} {$dm}{$plink} ({$hist}) {$dm}[{$length}] {$dm}{$ulink} {$comment}";
211 * Should a specific result row provide "patrollable" links?
213 * @param $result Result row
216 function patrollable( $result ) {
217 global $wgUser, $wgUseRCPatrol, $wgUseNPPatrol;
218 return ( $wgUseRCPatrol ||
$wgUseNPPatrol )
219 && $wgUser->isAllowed( 'patrol' )
220 && !$result->patrolled
;
223 function feedItemDesc( $row ) {
224 if( isset( $row->rev_id
) ) {
225 $revision = Revision
::newFromId( $row->rev_id
);
227 return '<p>' . htmlspecialchars( wfMsg( 'summary' ) ) . ': ' .
228 htmlspecialchars( $revision->getComment() ) . "</p>\n<hr />\n<div>" .
229 nl2br( htmlspecialchars( $revision->getText() ) ) . "</div>";
232 return parent
::feedItemDesc( $row );
236 * Show a form for filtering namespace and username
240 function getPageHeader() {
241 global $wgScript, $wgContLang, $wgGroupPermissions, $wgUser, $wgUseRCPatrol, $wgUseNPPatrol;
242 $sk = $wgUser->getSkin();
243 $align = $wgContLang->isRTL() ?
'left' : 'right';
244 $self = SpecialPage
::getTitleFor( $this->getName() );
247 $showhide = array( wfMsgHtml( 'show' ), wfMsgHtml( 'hide' ));
249 $hidelinks = array();
251 if ( $wgGroupPermissions['*']['createpage'] === true ) {
252 $hidelinks['hideliu'] = 'rcshowhideliu';
254 if ( $wgUseNPPatrol ||
$wgUseRCPatrol ) {
255 $hidelinks['hidepatrolled'] = 'rcshowhidepatr';
257 $hidelinks['hidebots'] = 'rcshowhidebots';
260 foreach ( $hidelinks as $key => $msg ) {
261 $reversed = 1-$this->options
[$key];
262 $link = $sk->makeKnownLinkObj( $self, $showhide[$reversed],
263 wfArrayToCGI( array( $key => $reversed ), $this->nondefaults
)
265 $links[$key] = wfMsgHtml( $msg, $link );
268 $hl = implode( ' | ', $links );
270 // Store query values in hidden fields so that form submission doesn't lose them
272 foreach ( $this->nondefaults
as $key => $value ) {
273 if ( $key === 'namespace' ) continue;
274 if ( $key === 'username' ) continue;
275 $hidden[] = Xml
::hidden( $key, $value );
277 $hidden = implode( "\n", $hidden );
279 $form = Xml
::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) ) .
280 Xml
::hidden( 'title', $self->getPrefixedDBkey() ) .
281 Xml
::openElement( 'table' ) .
283 <td align=\"$align\">" .
284 Xml
::label( wfMsg( 'namespace' ), 'namespace' ) .
287 Xml
::namespaceSelector( $this->options
['namespace'], 'all' ) .
291 <td align=\"$align\">" .
292 Xml
::label( wfMsg( 'newpages-username' ), 'mw-np-username' ) .
295 Xml
::input( 'username', 30, $this->options
['username'], array( 'id' => 'mw-np-username' ) ) .
300 Xml
::submitButton( wfMsg( 'allpagessubmit' ) ) .
303 "<tr><td></td><td>" . $hl . "</td></tr>" .
304 Xml
::closeElement( 'table' ) .
306 Xml
::closeElement( 'form' );