4 * @addtogroup SpecialPage
8 * implements Special:Newpages
9 * @addtogroup SpecialPage
11 class NewPagesPage
extends QueryPage
{
20 function NewPagesPage( $namespace=NS_MAIN
, $username='', $hideliu=false, $hidepatrolled=false, $hidebots=false, $defaults=array()) {
21 $this->namespace = $namespace;
22 $this->username
= $username;
23 $this->hideliu
= $hideliu;
24 $this->hidepatrolled
= $hidepatrolled;
25 $this->hidebots
= $hidebots;
26 $this->defaults
= $defaults;
33 function isExpensive() {
34 # Indexed on RC, and will *not* work with querycache yet.
38 function makeUserWhere( &$dbo ) {
39 global $wgGroupPermissions;
41 if ($this->hidepatrolled
)
42 $where .= ' AND rc_patrolled = 0';
44 $where .= ' AND rc_bot = 0';
45 if ($wgGroupPermissions['*']['createpage'] == true && $this->hideliu
) {
46 $where .= ' AND rc_user = 0';
48 $title = Title
::makeTitleSafe( NS_USER
, $this->username
);
50 $where .= ' AND rc_user_text = ' . $dbo->addQuotes( $title->getText() );
56 private function makeNamespaceWhere() {
57 return $this->namespace !== 'all'
58 ?
' AND rc_namespace = ' . intval( $this->namespace )
63 global $wgUser, $wgUseNPPatrol, $wgUseRCPatrol;
64 $usepatrol = ( $wgUseNPPatrol ||
$wgUseRCPatrol ) ?
1 : 0;
65 $dbr = wfGetDB( DB_SLAVE
);
66 list( $recentchanges, $page ) = $dbr->tableNamesN( 'recentchanges', 'page' );
68 $nsfilter = $this->makeNamespaceWhere();
69 $uwhere = $this->makeUserWhere( $dbr );
71 # FIXME: text will break with compression
73 "SELECT 'Newpages' as type,
74 rc_namespace AS namespace,
78 rc_user_text AS user_text,
79 rc_comment as \"comment\",
80 rc_timestamp AS timestamp,
81 rc_timestamp AS value,
82 '{$usepatrol}' as usepatrol,
83 rc_patrolled AS patrolled,
87 FROM $recentchanges,$page
88 WHERE rc_cur_id=page_id AND rc_new=1
90 AND page_is_redirect = 0
94 function preprocessResults( &$dbo, &$res ) {
95 # Do a batch existence check on the user and talk pages
96 $linkBatch = new LinkBatch();
97 while( $row = $dbo->fetchObject( $res ) ) {
98 $linkBatch->addObj( Title
::makeTitleSafe( NS_USER
, $row->user_text
) );
99 $linkBatch->addObj( Title
::makeTitleSafe( NS_USER_TALK
, $row->user_text
) );
101 $linkBatch->execute();
103 if( $dbo->numRows( $res ) > 0 )
104 $dbo->dataSeek( $res, 0 );
108 * Format a row, providing the timestamp, links to the page/history, size, user links, and a comment
110 * @param $skin Skin to use
111 * @param $result Result row
114 function formatResult( $skin, $result ) {
115 global $wgLang, $wgContLang;
116 $dm = $wgContLang->getDirMark();
118 $title = Title
::makeTitleSafe( $result->namespace, $result->title
);
119 $time = $wgLang->timeAndDate( $result->timestamp
, true );
120 $plink = $skin->makeKnownLinkObj( $title, '', $this->patrollable( $result ) ?
'rcid=' . $result->rcid
: '' );
121 $hist = $skin->makeKnownLinkObj( $title, wfMsgHtml( 'hist' ), 'action=history' );
122 $length = wfMsgExt( 'nbytes', array( 'parsemag', 'escape' ), $wgLang->formatNum( htmlspecialchars( $result->length
) ) );
123 $ulink = $skin->userLink( $result->user
, $result->user_text
) . ' ' . $skin->userToolLinks( $result->user
, $result->user_text
);
124 $comment = $skin->commentBlock( $result->comment
);
126 return "{$time} {$dm}{$plink} ({$hist}) {$dm}[{$length}] {$dm}{$ulink} {$comment}";
130 * Should a specific result row provide "patrollable" links?
132 * @param $result Result row
135 function patrollable( $result ) {
136 global $wgUser, $wgUseRCPatrol, $wgUseNPPatrol;
137 return ( $wgUseRCPatrol ||
$wgUseNPPatrol )
138 && $wgUser->isAllowed( 'patrol' )
139 && !$result->patrolled
;
142 function feedItemDesc( $row ) {
143 if( isset( $row->rev_id
) ) {
144 $revision = Revision
::newFromId( $row->rev_id
);
146 return '<p>' . htmlspecialchars( wfMsg( 'summary' ) ) . ': ' .
147 htmlspecialchars( $revision->getComment() ) . "</p>\n<hr />\n<div>" .
148 nl2br( htmlspecialchars( $revision->getText() ) ) . "</div>";
151 return parent
::feedItemDesc( $row );
155 * Show a form for filtering namespace and username
159 function getPageHeader() {
160 global $wgScript, $wgContLang, $wgGroupPermissions, $wgUser, $wgUseRCPatrol, $wgUseNPPatrol;
161 $align = $wgContLang->isRTL() ?
'left' : 'right';
162 $self = SpecialPage
::getTitleFor( $this->getName() );
165 $showhide = array( wfMsg( 'show' ), wfMsg( 'hide' ));
167 $nondefaults = array();
168 wfAppendToArrayIfNotDefault( 'hidepatrolled', $this->hidepatrolled
, $this->defaults
, $nondefaults);
169 wfAppendToArrayIfNotDefault( 'hideliu', $this->hideliu
, $this->defaults
, $nondefaults);
170 wfAppendToArrayIfNotDefault( 'hidebots', $this->hidebots
, $this->defaults
, $nondefaults);
171 wfAppendToArrayIfNotDefault( 'namespace', $this->namespace, $this->defaults
, $nondefaults);
172 wfAppendToArrayIfNotDefault( 'limit', $this->limit
, $this->defaults
, $nondefaults);
173 wfAppendToArrayIfNotDefault( 'offset', $this->offset
, $this->defaults
, $nondefaults);
174 wfAppendToArrayIfNotDefault( 'username', $this->username
, $this->defaults
, $nondefaults);
176 $liuLink = $wgUser->getSkin()->makeKnownLink( $wgContLang->specialPage( 'Newpages' ),
177 htmlspecialchars( $showhide[1-$this->hideliu
] ), wfArrayToCGI( array( 'hideliu' => 1-$this->hideliu
), $nondefaults ) );
178 $patrLink = $wgUser->getSkin()->makeKnownLink( $wgContLang->specialPage( 'Newpages' ),
179 htmlspecialchars( $showhide[1-$this->hidepatrolled
] ), wfArrayToCGI( array( 'hidepatrolled' => 1-$this->hidepatrolled
), $nondefaults ) );
180 $botsLink = $wgUser->getSkin()->makeKnownLink( $wgContLang->specialPage( 'Newpages' ),
181 htmlspecialchars( $showhide[1-$this->hidebots
] ), wfArrayToCGI( array( 'hidebots' => 1-$this->hidebots
), $nondefaults ) );
183 if( $wgGroupPermissions['*']['createpage'] == true )
184 $links[] = wfMsgHtml( 'rcshowhideliu', $liuLink );
185 if( $wgUseNPPatrol ||
$wgUseRCPatrol )
186 $links[] = wfMsgHtml( 'rcshowhidepatr', $patrLink );
187 $links[] = wfMsgHtml( 'rcshowhidebots', $botsLink );
188 $hl = implode( ' | ', $links );
190 $form = Xml
::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) ) .
191 Xml
::hidden( 'title', $self->getPrefixedDBkey() ) .
192 Xml
::openElement( 'table' ) .
194 <td align=\"$align\">" .
195 Xml
::label( wfMsg( 'namespace' ), 'namespace' ) .
198 Xml
::namespaceSelector( intval( $this->namespace ), 'all' ) .
202 <td align=\"$align\">" .
203 Xml
::label( wfMsg( 'newpages-username' ), 'mw-np-username' ) .
206 Xml
::input( 'username', 30, $this->username
, array( 'id' => 'mw-np-username' ) ) .
208 </tr><tr><td></td><td>" . $hl . "</td></tr>
211 Xml
::submitButton( wfMsg( 'allpagessubmit' ) ) .
214 Xml
::closeElement( 'table' ) .
215 Xml
::hidden( 'offset', $this->offset
) .
216 Xml
::hidden( 'limit', $this->limit
) .
217 Xml
::closeElement( 'form' );
226 function linkParameters() {
227 return( array( 'namespace' => $this->namespace, 'username' => $this->username
, 'hideliu' => $this->hideliu
, 'hidepatrolled' => $this->hidepatrolled
) );
235 function wfSpecialNewpages($par, $specialPage) {
236 global $wgRequest, $wgContLang;
239 list( $limit, $offset ) = wfCheckLimits();
242 /* bool */ 'hideliu' => false,
243 /* bool */ 'hidepatrolled' => false,
244 /* bool */ 'hidebots' => false,
245 /* text */ 'namespace' => NS_MAIN
,
246 /* text */ 'username' => '',
247 /* int */ 'offset' => $offset,
248 /* int */ 'limit' => $limit,
254 $bits = preg_split( '/\s*,\s*/', trim( $par ) );
255 foreach ( $bits as $bit ) {
256 if ( 'shownav' == $bit )
257 $shownavigation = true;
258 if ( 'hideliu' == $bit )
260 if ( 'hidepatrolled' == $bit )
261 $hidepatrolled = true;
262 if ( 'hidebots' == $bit )
264 if ( is_numeric( $bit ) )
268 if ( preg_match( '/^limit=(\d+)$/', $bit, $m ) )
269 $limit = intval($m[1]);
270 if ( preg_match( '/^offset=(\d+)$/', $bit, $m ) )
271 $offset = intval($m[1]);
272 if ( preg_match( '/^namespace=(.*)$/', $bit, $m ) ) {
273 $ns = $wgContLang->getNsIndex( $m[1] );
274 if( $ns !== false ) {
280 if( $ns = $wgRequest->getInt( 'namespace', NS_MAIN
) )
282 if( $un = $wgRequest->getText( 'username' ) )
284 if( $hliu = $wgRequest->getBool( 'hideliu' ) )
286 if( $hpatrolled = $wgRequest->getBool( 'hidepatrolled' ) )
287 $hidepatrolled = $hpatrolled;
288 if( $hbots = $wgRequest->getBool( 'hidebots' ) )
292 if ( ! isset( $shownavigation ) )
293 $shownavigation = ! $specialPage->including();
295 $npp = new NewPagesPage( $namespace, $username, $hideliu, $hidepatrolled, $hidebots, $defaults );
297 if ( ! $npp->doFeed( $wgRequest->getVal( 'feed' ), $limit ) )
298 $npp->doQuery( $offset, $limit, $shownavigation );