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=null ) {
27 $this->specialPage
= $specialPage;
30 public function execute( $par ) {
31 global $wgRequest, $wgLang;
33 $shownavigation = is_object( $this->specialPage
) && !$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 // Validate limit and offset params
87 if ( $options['limit'] <= 0 ) {
88 $options['limit'] = $defaults['limit'];
91 if ( $options['offset'] < 0 ) {
92 $options['offset'] = $defaults['offset'];
95 $nondefaults = array();
96 foreach ( $options as $v => $t ) {
97 if ( $v === 'offset' ) continue; # Reset offset if parameters change
98 wfAppendToArrayIfNotDefault( $v, $t, $defaults, $nondefaults );
102 $this->options
= $options;
103 $this->nondefaults
= $nondefaults;
105 if ( !$this->doFeed( $wgRequest->getVal( 'feed' ), $options['limit'] ) ) {
106 $this->doQuery( $options['offset'], $options['limit'], $shownavigation );
110 function linkParameters() {
111 $nondefaults = $this->nondefaults
;
112 // QueryPage seems to handle limit and offset itself
113 if ( isset( $nondefaults['limit'] ) ) {
114 unset($nondefaults['limit']);
123 function isExpensive() {
124 # Indexed on RC, and will *not* work with querycache yet.
128 function makeUserWhere( $db ) {
129 global $wgGroupPermissions;
131 if ($this->options
['hidepatrolled']) {
132 $conds['rc_patrolled'] = 0;
134 if ($this->options
['hidebots']) {
135 $conds['rc_bot'] = 0;
137 if ($wgGroupPermissions['*']['createpage'] == true && $this->options
['hideliu']) {
138 $conds['rc_user'] = 0;
140 $title = Title
::makeTitleSafe( NS_USER
, $this->options
['username'] );
142 $conds['rc_user_text'] = $title->getText();
149 global $wgUser, $wgUseNPPatrol, $wgUseRCPatrol;
150 $usepatrol = ( $wgUseNPPatrol ||
$wgUseRCPatrol ) ?
1 : 0;
151 $dbr = wfGetDB( DB_SLAVE
);
152 list( $recentchanges, $page ) = $dbr->tableNamesN( 'recentchanges', 'page' );
155 $conds['rc_new'] = 1;
156 if ( $this->options
['namespace'] !== 'all' ) {
157 $conds['rc_namespace'] = intval( $this->options
['namespace'] );
159 $conds['page_is_redirect'] = 0;
160 $conds +
= $this->makeUserWhere( $dbr );
161 $condstext = $dbr->makeList( $conds, LIST_AND
);
163 # FIXME: text will break with compression
165 "SELECT 'Newpages' as type,
166 rc_namespace AS namespace,
170 rc_user_text AS user_text,
171 rc_comment as \"comment\",
172 rc_timestamp AS timestamp,
173 rc_timestamp AS value,
174 '{$usepatrol}' as usepatrol,
175 rc_patrolled AS patrolled,
178 page_latest as rev_id
179 FROM $recentchanges,$page
180 WHERE rc_cur_id=page_id AND $condstext";
183 function preprocessResults( $db, $res ) {
184 # Do a batch existence check on the user and talk pages
185 $linkBatch = new LinkBatch();
186 while( $row = $db->fetchObject( $res ) ) {
187 $linkBatch->add( NS_USER
, $row->user_text
);
188 $linkBatch->add( NS_USER_TALK
, $row->user_text
);
190 $linkBatch->execute();
192 if( $db->numRows( $res ) > 0 )
193 $db->dataSeek( $res, 0 );
197 * Format a row, providing the timestamp, links to the page/history, size, user links, and a comment
199 * @param $skin Skin to use
200 * @param $result Result row
203 function formatResult( $skin, $result ) {
204 global $wgLang, $wgContLang;
205 $dm = $wgContLang->getDirMark();
207 $title = Title
::makeTitleSafe( $result->namespace, $result->title
);
208 $time = $wgLang->timeAndDate( $result->timestamp
, true );
209 $plink = $skin->makeKnownLinkObj( $title, '', $this->patrollable( $result ) ?
'rcid=' . $result->rcid
: '' );
210 $hist = $skin->makeKnownLinkObj( $title, wfMsgHtml( 'hist' ), 'action=history' );
211 $length = wfMsgExt( 'nbytes', array( 'parsemag', 'escape' ), $wgLang->formatNum( htmlspecialchars( $result->length
) ) );
212 $ulink = $skin->userLink( $result->user
, $result->user_text
) . ' ' . $skin->userToolLinks( $result->user
, $result->user_text
);
213 $comment = $skin->commentBlock( $result->comment
);
215 return "{$time} {$dm}{$plink} ({$hist}) {$dm}[{$length}] {$dm}{$ulink} {$comment}";
219 * Should a specific result row provide "patrollable" links?
221 * @param $result Result row
224 function patrollable( $result ) {
225 global $wgUser, $wgUseRCPatrol, $wgUseNPPatrol;
226 return ( $wgUseRCPatrol ||
$wgUseNPPatrol )
227 && $wgUser->isAllowed( 'patrol' )
228 && !$result->patrolled
;
231 function feedItemDesc( $row ) {
232 if( isset( $row->rev_id
) ) {
233 $revision = Revision
::newFromId( $row->rev_id
);
235 return '<p>' . htmlspecialchars( wfMsg( 'summary' ) ) . ': ' .
236 htmlspecialchars( $revision->getComment() ) . "</p>\n<hr />\n<div>" .
237 nl2br( htmlspecialchars( $revision->getText() ) ) . "</div>";
240 return parent
::feedItemDesc( $row );
244 * Show a form for filtering namespace and username
248 function getPageHeader() {
249 global $wgScript, $wgContLang, $wgGroupPermissions, $wgUser, $wgUseRCPatrol, $wgUseNPPatrol;
250 $sk = $wgUser->getSkin();
251 $align = $wgContLang->isRTL() ?
'left' : 'right';
252 $self = SpecialPage
::getTitleFor( $this->getName() );
255 $showhide = array( wfMsgHtml( 'show' ), wfMsgHtml( 'hide' ));
257 $hidelinks = array();
259 if ( $wgGroupPermissions['*']['createpage'] === true ) {
260 $hidelinks['hideliu'] = 'rcshowhideliu';
262 if ( $wgUseNPPatrol ||
$wgUseRCPatrol ) {
263 $hidelinks['hidepatrolled'] = 'rcshowhidepatr';
265 $hidelinks['hidebots'] = 'rcshowhidebots';
268 foreach ( $hidelinks as $key => $msg ) {
269 $reversed = 1-$this->options
[$key];
270 $link = $sk->makeKnownLinkObj( $self, $showhide[$reversed],
271 wfArrayToCGI( array( $key => $reversed ), $this->nondefaults
)
273 $links[$key] = wfMsgHtml( $msg, $link );
276 $hl = implode( ' | ', $links );
278 // Store query values in hidden fields so that form submission doesn't lose them
280 foreach ( $this->nondefaults
as $key => $value ) {
281 if ( $key === 'namespace' ) continue;
282 if ( $key === 'username' ) continue;
283 $hidden[] = Xml
::hidden( $key, $value );
285 $hidden = implode( "\n", $hidden );
287 $form = Xml
::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) ) .
288 Xml
::hidden( 'title', $self->getPrefixedDBkey() ) .
289 Xml
::openElement( 'table' ) .
291 <td align=\"$align\">" .
292 Xml
::label( wfMsg( 'namespace' ), 'namespace' ) .
295 Xml
::namespaceSelector( $this->options
['namespace'], 'all' ) .
299 <td align=\"$align\">" .
300 Xml
::label( wfMsg( 'newpages-username' ), 'mw-np-username' ) .
303 Xml
::input( 'username', 30, $this->options
['username'], array( 'id' => 'mw-np-username' ) ) .
308 Xml
::submitButton( wfMsg( 'allpagessubmit' ) ) .
311 "<tr><td></td><td>" . $hl . "</td></tr>" .
312 Xml
::closeElement( 'table' ) .
314 Xml
::closeElement( 'form' );