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,
45 if( $shownavigation ) {
46 // Some hopefully reasonable limits...
48 /* int */ 'offset' => 20000,
49 /* int */ 'limit' => 500,
52 // Embedded? Be a lot more strict...
54 /* int */ 'offset' => 0,
55 /* int */ 'limit' => 200,
62 $bits = preg_split( '/\s*,\s*/', trim( $par ) );
63 foreach ( $bits as $bit ) {
64 if ( 'shownav' == $bit )
65 $shownavigation = true;
66 if ( 'hideliu' === $bit )
67 $options['hideliu'] = true;
68 if ( 'hidepatrolled' == $bit )
69 $options['hidepatrolled'] = true;
70 if ( 'hidebots' == $bit )
71 $options['hidebots'] = true;
72 if ( is_numeric( $bit ) )
73 $options['limit'] = intval( $bit );
76 if ( preg_match( '/^limit=(\d+)$/', $bit, $m ) )
77 $options['limit'] = intval($m[1]);
78 if ( preg_match( '/^offset=(\d+)$/', $bit, $m ) )
79 $options['offset'] = intval($m[1]);
80 if ( preg_match( '/^namespace=(.*)$/', $bit, $m ) ) {
81 $ns = $wgLang->getNsIndex( $m[1] );
83 $options['namespace'] = $ns;
89 // Override all values from requests, if specified
90 foreach ( $defaults as $v => $t ) {
92 $options[$v] = $wgRequest->getBool( $v, $options[$v] );
93 } elseif( is_int($t) ) {
94 $options[$v] = $wgRequest->getInt( $v, $options[$v] );
95 } elseif( is_string($t) ) {
96 $options[$v] = $wgRequest->getText( $v, $options[$v] );
100 // Validate limit and offset params
101 if ( $options['limit'] <= 0 ) {
102 $options['limit'] = $defaults['limit'];
104 if ( $options['limit'] > $max['limit'] ) {
105 $options['limit'] = $max['limit'];
108 if ( $options['offset'] < 0 ) {
109 $options['offset'] = $defaults['offset'];
111 if ( $options['offset'] > $max['offset'] ) {
112 $options['offset'] = $max['offset'];
115 $nondefaults = array();
116 foreach ( $options as $v => $t ) {
117 if ( $v === 'offset' ) continue; # Reset offset if parameters change
118 wfAppendToArrayIfNotDefault( $v, $t, $defaults, $nondefaults );
122 $this->options
= $options;
123 $this->nondefaults
= $nondefaults;
125 if ( !$this->doFeed( $wgRequest->getVal( 'feed' ), $options['limit'] ) ) {
126 $this->doQuery( $options['offset'], $options['limit'], $shownavigation );
130 function linkParameters() {
131 $nondefaults = $this->nondefaults
;
132 // QueryPage seems to handle limit and offset itself
133 if ( isset( $nondefaults['limit'] ) ) {
134 unset($nondefaults['limit']);
143 function isExpensive() {
144 # Indexed on RC, and will *not* work with querycache yet.
148 function makeUserWhere( $db ) {
149 global $wgGroupPermissions;
151 if ($this->options
['hidepatrolled']) {
152 $conds['rc_patrolled'] = 0;
154 if ($this->options
['hidebots']) {
155 $conds['rc_bot'] = 0;
157 if ($wgGroupPermissions['*']['createpage'] == true && $this->options
['hideliu']) {
158 $conds['rc_user'] = 0;
160 $title = Title
::makeTitleSafe( NS_USER
, $this->options
['username'] );
162 $conds['rc_user_text'] = $title->getText();
169 global $wgUser, $wgUseNPPatrol, $wgUseRCPatrol;
170 $usepatrol = ( $wgUseNPPatrol ||
$wgUseRCPatrol ) ?
1 : 0;
171 $dbr = wfGetDB( DB_SLAVE
);
172 list( $recentchanges, $page ) = $dbr->tableNamesN( 'recentchanges', 'page' );
175 $conds['rc_new'] = 1;
176 if ( $this->options
['namespace'] !== 'all' ) {
177 $conds['rc_namespace'] = intval( $this->options
['namespace'] );
179 $conds['page_is_redirect'] = 0;
180 $conds +
= $this->makeUserWhere( $dbr );
181 $condstext = $dbr->makeList( $conds, LIST_AND
);
183 # FIXME: text will break with compression
185 "SELECT 'Newpages' as type,
186 rc_namespace AS namespace,
190 rc_user_text AS user_text,
191 rc_comment as \"comment\",
192 rc_timestamp AS timestamp,
193 rc_timestamp AS value,
194 '{$usepatrol}' as usepatrol,
195 rc_patrolled AS patrolled,
198 page_latest as rev_id
199 FROM $recentchanges,$page
200 WHERE rc_cur_id=page_id AND $condstext";
203 function preprocessResults( $db, $res ) {
204 # Do a batch existence check on the user and talk pages
205 $linkBatch = new LinkBatch();
206 while( $row = $db->fetchObject( $res ) ) {
207 $linkBatch->add( NS_USER
, $row->user_text
);
208 $linkBatch->add( NS_USER_TALK
, $row->user_text
);
210 $linkBatch->execute();
212 if( $db->numRows( $res ) > 0 )
213 $db->dataSeek( $res, 0 );
217 * Format a row, providing the timestamp, links to the page/history, size, user links, and a comment
219 * @param $skin Skin to use
220 * @param $result Result row
223 function formatResult( $skin, $result ) {
224 global $wgLang, $wgContLang;
225 $dm = $wgContLang->getDirMark();
227 $title = Title
::makeTitleSafe( $result->namespace, $result->title
);
228 $time = $wgLang->timeAndDate( $result->timestamp
, true );
229 $plink = $skin->makeKnownLinkObj( $title, '', $this->patrollable( $result ) ?
'rcid=' . $result->rcid
: '' );
230 $hist = $skin->makeKnownLinkObj( $title, wfMsgHtml( 'hist' ), 'action=history' );
231 $length = wfMsgExt( 'nbytes', array( 'parsemag', 'escape' ), $wgLang->formatNum( htmlspecialchars( $result->length
) ) );
232 $ulink = $skin->userLink( $result->user
, $result->user_text
) . ' ' . $skin->userToolLinks( $result->user
, $result->user_text
);
233 $comment = $skin->commentBlock( $result->comment
);
235 return "{$time} {$dm}{$plink} ({$hist}) {$dm}[{$length}] {$dm}{$ulink} {$comment}";
239 * Should a specific result row provide "patrollable" links?
241 * @param $result Result row
244 function patrollable( $result ) {
245 global $wgUser, $wgUseRCPatrol, $wgUseNPPatrol;
246 return ( $wgUseRCPatrol ||
$wgUseNPPatrol )
247 && ( $wgUser->isAllowed( 'patrol' ) ||
$wgUser->isAllowed( 'patrolmarks' ) )
248 && !$result->patrolled
;
251 function feedItemDesc( $row ) {
252 if( isset( $row->rev_id
) ) {
253 $revision = Revision
::newFromId( $row->rev_id
);
255 return '<p>' . htmlspecialchars( wfMsg( 'summary' ) ) . ': ' .
256 htmlspecialchars( $revision->getComment() ) . "</p>\n<hr />\n<div>" .
257 nl2br( htmlspecialchars( $revision->getText() ) ) . "</div>";
260 return parent
::feedItemDesc( $row );
264 * Show a form for filtering namespace and username
268 function getPageHeader() {
269 global $wgScript, $wgContLang, $wgGroupPermissions, $wgUser, $wgUseRCPatrol, $wgUseNPPatrol;
270 $sk = $wgUser->getSkin();
271 $align = $wgContLang->isRTL() ?
'left' : 'right';
272 $self = SpecialPage
::getTitleFor( $this->getName() );
275 $showhide = array( wfMsgHtml( 'show' ), wfMsgHtml( 'hide' ));
277 $hidelinks = array();
279 if ( $wgGroupPermissions['*']['createpage'] === true ) {
280 $hidelinks['hideliu'] = 'rcshowhideliu';
282 if ( $wgUseNPPatrol ||
$wgUseRCPatrol ) {
283 $hidelinks['hidepatrolled'] = 'rcshowhidepatr';
285 $hidelinks['hidebots'] = 'rcshowhidebots';
288 foreach ( $hidelinks as $key => $msg ) {
289 $reversed = 1-$this->options
[$key];
290 $link = $sk->makeKnownLinkObj( $self, $showhide[$reversed],
291 wfArrayToCGI( array( $key => $reversed ), $this->nondefaults
)
293 $links[$key] = wfMsgHtml( $msg, $link );
296 $hl = implode( ' | ', $links );
298 // Store query values in hidden fields so that form submission doesn't lose them
300 foreach ( $this->nondefaults
as $key => $value ) {
301 if ( $key === 'namespace' ) continue;
302 if ( $key === 'username' ) continue;
303 $hidden[] = Xml
::hidden( $key, $value );
305 $hidden = implode( "\n", $hidden );
307 $form = Xml
::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) ) .
308 Xml
::hidden( 'title', $self->getPrefixedDBkey() ) .
309 Xml
::openElement( 'fieldset' ) .
310 Xml
::element( 'legend', null, wfMsg( 'newpages' ) ) .
311 Xml
::openElement( 'table', array( 'id' => 'mw-newpages-table' ) ) .
313 <td align=\"$align\">" .
314 Xml
::label( wfMsg( 'namespace' ), 'namespace' ) .
317 Xml
::namespaceSelector( $this->options
['namespace'], 'all' ) .
321 <td align=\"$align\">" .
322 Xml
::label( wfMsg( 'newpages-username' ), 'mw-np-username' ) .
325 Xml
::input( 'username', 30, $this->options
['username'], array( 'id' => 'mw-np-username' ) ) .
330 Xml
::submitButton( wfMsg( 'allpagessubmit' ) ) .
339 Xml
::closeElement( 'table' ) .
340 Xml
::closeElement( 'fieldset' ) .
342 Xml
::closeElement( 'form' );