5 * @subpackage SpecialPage
11 * @subpackage SpecialPage
13 class NewPagesPage
extends QueryPage
{
18 function NewPagesPage( $namespace = NS_MAIN
, $username = '' ) {
19 $this->namespace = $namespace;
20 $this->username
= $username;
27 function isExpensive() {
28 # Indexed on RC, and will *not* work with querycache yet.
32 function makeUserWhere( &$dbo ) {
33 $title = Title
::makeTitleSafe( NS_USER
, $this->username
);
35 return ' AND rc_user_text = ' . $dbo->addQuotes( $title->getText() );
42 global $wgUser, $wgUseRCPatrol;
43 $usepatrol = ( $wgUseRCPatrol && $wgUser->isAllowed( 'patrol' ) ) ?
1 : 0;
44 $dbr =& wfGetDB( DB_SLAVE
);
45 extract( $dbr->tableNames( 'recentchanges', 'page', 'text' ) );
47 $uwhere = $this->makeUserWhere( $dbr );
49 # FIXME: text will break with compression
51 "SELECT 'Newpages' as type,
52 rc_namespace AS namespace,
56 rc_user_text AS user_text,
57 rc_comment as comment,
58 rc_timestamp AS timestamp,
59 rc_timestamp AS value,
60 '{$usepatrol}' as usepatrol,
61 rc_patrolled AS patrolled,
65 FROM $recentchanges,$page
66 WHERE rc_cur_id=page_id AND rc_new=1
67 AND rc_namespace=" . $this->namespace . " AND page_is_redirect=0
71 function preprocessResults( &$dbo, &$res ) {
72 # Do a batch existence check on the user and talk pages
73 $linkBatch = new LinkBatch();
74 while( $row = $dbo->fetchObject( $res ) ) {
75 $linkBatch->addObj( Title
::makeTitleSafe( NS_USER
, $row->user_text
) );
76 $linkBatch->addObj( Title
::makeTitleSafe( NS_USER_TALK
, $row->user_text
) );
78 $linkBatch->execute();
80 if( $dbo->numRows( $res ) > 0 )
81 $dbo->dataSeek( $res, 0 );
85 * Format a row, providing the timestamp, links to the page/history, size, user links, and a comment
87 * @param $skin Skin to use
88 * @param $result Result row
91 function formatResult( $skin, $result ) {
92 global $wgLang, $wgContLang;
93 $dm = $wgContLang->getDirMark();
95 $title = Title
::makeTitleSafe( $result->namespace, $result->title
);
96 $time = $wgLang->timeAndDate( $result->timestamp
, true );
97 $plink = $skin->makeKnownLinkObj( $title, '', $this->patrollable( $result ) ?
'rcid=' . $result->rcid
: '' );
98 $hist = $skin->makeKnownLinkObj( $title, wfMsgHtml( 'hist' ), 'action=history' );
99 $length = wfMsgHtml( 'nbytes', $wgLang->formatNum( htmlspecialchars( $result->length
) ) );
100 $ulink = $skin->userLink( $result->user
, $result->user_text
) . $skin->userToolLinks( $result->user
, $result->user_text
);
101 $comment = $skin->commentBlock( $result->comment
);
103 return "{$time} {$dm}{$plink} ({$hist}) {$dm}[{$length}] {$dm}{$ulink} {$comment}";
107 * Should a specific result row provide "patrollable" links?
109 * @param $result Result row
112 function patrollable( $result ) {
113 global $wgUser, $wgUseRCPatrol;
114 return $wgUseRCPatrol && $wgUser->isAllowed( 'patrol' ) && !$result->patrolled
;
117 function feedItemDesc( $row ) {
118 if( isset( $row->rev_id
) ) {
119 $revision = Revision
::newFromId( $row->rev_id
);
121 return '<p>' . htmlspecialchars( wfMsg( 'summary' ) ) . ': ' .
122 htmlspecialchars( $revision->getComment() ) . "</p>\n<hr />\n<div>" .
123 nl2br( htmlspecialchars( $revision->getText() ) ) . "</div>";
126 return parent
::feedItemDesc( $row );
130 * Show a form for filtering namespace and username
134 function getPageHeader() {
135 $self = Title
::makeTitle( NS_SPECIAL
, $this->getName() );
136 $form = wfOpenElement( 'form', array( 'method' => 'post', 'action' => $self->getLocalUrl() ) );
137 $form .= '<table><tr><td align="right">' . wfMsgHtml( 'namespace' ) . '</td>';
138 $form .= '<td>' . HtmlNamespaceSelector( $this->namespace ) . '</td><tr>';
139 $form .= '<tr><td align="right">' . wfMsgHtml( 'newpages-username' ) . '</td>';
140 $form .= '<td>' . wfInput( 'username', 30, $this->username
) . '</td></tr>';
141 $form .= '<tr><td></td><td>' . wfSubmitButton( wfMsg( 'allpagessubmit' ) ) . '</td></tr></table>';
142 $form .= wfHidden( 'offset', $this->offset
) . wfHidden( 'limit', $this->limit
) . '</form>';
151 function linkParameters() {
152 return( array( 'namespace' => $this->namespace, 'username' => $this->username
) );
160 function wfSpecialNewpages($par, $specialPage) {
161 global $wgRequest, $wgContLang;
163 list( $limit, $offset ) = wfCheckLimits();
164 $namespace = NS_MAIN
;
168 $bits = preg_split( '/\s*,\s*/', trim( $par ) );
169 foreach ( $bits as $bit ) {
170 if ( 'shownav' == $bit )
171 $shownavigation = true;
172 if ( is_numeric( $bit ) )
175 if ( preg_match( '/^limit=(\d+)$/', $bit, $m ) )
176 $limit = intval($m[1]);
177 if ( preg_match( '/^offset=(\d+)$/', $bit, $m ) )
178 $offset = intval($m[1]);
179 if ( preg_match( '/^namespace=(.*)$/', $bit, $m ) ) {
180 $ns = $wgContLang->getNsIndex( $m[1] );
181 if( $ns !== false ) {
187 if( $ns = $wgRequest->getInt( 'namespace', 0 ) )
189 if( $un = $wgRequest->getText( 'username' ) )
193 if ( ! isset( $shownavigation ) )
194 $shownavigation = ! $specialPage->including();
196 $npp = new NewPagesPage( $namespace, $username );
198 if ( ! $npp->doFeed( $wgRequest->getVal( 'feed' ), $limit ) )
199 $npp->doQuery( $offset, $limit, $shownavigation );