4 * @addtogroup SpecialPage
8 * implements Special:Newpages
9 * @addtogroup SpecialPage
11 class NewPagesPage
extends QueryPage
{
17 function NewPagesPage( $namespace = NS_MAIN
, $username = '', $hideliu= false ) {
18 $this->namespace = $namespace;
19 $this->username
= $username;
20 $this->hideliu
= $hideliu;
27 function isExpensive() {
28 # Indexed on RC, and will *not* work with querycache yet.
32 function makeUserWhere( &$dbo ) {
33 global $wgGroupPermissions;
34 if ($wgGroupPermissions['*']['createpage'] == true && $this->hideliu
) {
35 return ' AND rc_user = 0';
37 $title = Title
::makeTitleSafe( NS_USER
, $this->username
);
39 return ' AND rc_user_text = ' . $dbo->addQuotes( $title->getText() );
46 private function makeNamespaceWhere() {
47 return $this->namespace !== 'all'
48 ?
' AND rc_namespace = ' . intval( $this->namespace )
53 global $wgUser, $wgUseNPPatrol;
54 $usepatrol = ( $wgUseNPPatrol && $wgUser->isAllowed( 'patrol' ) ) ?
1 : 0;
55 $dbr = wfGetDB( DB_SLAVE
);
56 list( $recentchanges, $page ) = $dbr->tableNamesN( 'recentchanges', 'page' );
58 $nsfilter = $this->makeNamespaceWhere();
59 $uwhere = $this->makeUserWhere( $dbr );
61 # FIXME: text will break with compression
63 "SELECT 'Newpages' as type,
64 rc_namespace AS namespace,
68 rc_user_text AS user_text,
69 rc_comment as \"comment\",
70 rc_timestamp AS timestamp,
71 rc_timestamp AS value,
72 '{$usepatrol}' as usepatrol,
73 rc_patrolled AS patrolled,
77 FROM $recentchanges,$page
78 WHERE rc_cur_id=page_id AND rc_new=1
80 AND page_is_redirect = 0
84 function preprocessResults( &$dbo, &$res ) {
85 # Do a batch existence check on the user and talk pages
86 $linkBatch = new LinkBatch();
87 while( $row = $dbo->fetchObject( $res ) ) {
88 $linkBatch->addObj( Title
::makeTitleSafe( NS_USER
, $row->user_text
) );
89 $linkBatch->addObj( Title
::makeTitleSafe( NS_USER_TALK
, $row->user_text
) );
91 $linkBatch->execute();
93 if( $dbo->numRows( $res ) > 0 )
94 $dbo->dataSeek( $res, 0 );
98 * Format a row, providing the timestamp, links to the page/history, size, user links, and a comment
100 * @param $skin Skin to use
101 * @param $result Result row
104 function formatResult( $skin, $result ) {
105 global $wgLang, $wgContLang;
106 $dm = $wgContLang->getDirMark();
108 $title = Title
::makeTitleSafe( $result->namespace, $result->title
);
109 $time = $wgLang->timeAndDate( $result->timestamp
, true );
110 $plink = $skin->makeKnownLinkObj( $title, '', $this->patrollable( $result ) ?
'rcid=' . $result->rcid
: '' );
111 $hist = $skin->makeKnownLinkObj( $title, wfMsgHtml( 'hist' ), 'action=history' );
112 $length = wfMsgExt( 'nbytes', array( 'parsemag', 'escape' ), $wgLang->formatNum( htmlspecialchars( $result->length
) ) );
113 $ulink = $skin->userLink( $result->user
, $result->user_text
) . ' ' . $skin->userToolLinks( $result->user
, $result->user_text
);
114 $comment = $skin->commentBlock( $result->comment
);
116 return "{$time} {$dm}{$plink} ({$hist}) {$dm}[{$length}] {$dm}{$ulink} {$comment}";
120 * Should a specific result row provide "patrollable" links?
122 * @param $result Result row
125 function patrollable( $result ) {
126 global $wgUser, $wgUseNPPatrol;
127 return $wgUseNPPatrol && $wgUser->isAllowed( 'patrol' ) && !$result->patrolled
;
130 function feedItemDesc( $row ) {
131 if( isset( $row->rev_id
) ) {
132 $revision = Revision
::newFromId( $row->rev_id
);
134 return '<p>' . htmlspecialchars( wfMsg( 'summary' ) ) . ': ' .
135 htmlspecialchars( $revision->getComment() ) . "</p>\n<hr />\n<div>" .
136 nl2br( htmlspecialchars( $revision->getText() ) ) . "</div>";
139 return parent
::feedItemDesc( $row );
143 * Show a form for filtering namespace and username
147 function getPageHeader() {
148 global $wgScript, $wgContLang, $wgGroupPermissions;
149 $align = $wgContLang->isRTL() ?
'left' : 'right';
150 $self = SpecialPage
::getTitleFor( $this->getName() );
151 $form = Xml
::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) ) .
152 Xml
::hidden( 'title', $self->getPrefixedDBkey() ) .
153 Xml
::openElement( 'table' ) .
155 <td align=\"$align\">" .
156 Xml
::label( wfMsg( 'namespace' ), 'namespace' ) .
159 Xml
::namespaceSelector( intval( $this->namespace ), 'all' ) .
163 <td align=\"$align\">" .
164 Xml
::label( wfMsg( 'newpages-username' ), 'mw-np-username' ) .
167 Xml
::input( 'username', 30, $this->username
, array( 'id' => 'mw-np-username' ) ) .
170 if ($wgGroupPermissions['*']['createpage'] == true) {
171 $form = $form . "<tr><td></td>
172 <td colspan=\"2\">" . Xml
::checkLabel( wfMsgHtml( 'rcshowhideliu', wfMsg( 'hide' ) ),
173 'hideliu', 'hideliu', $this->hideliu
, array( 'id' => 'mw-np-hideliu' ) ) . "
179 Xml
::submitButton( wfMsg( 'allpagessubmit' ) ) .
182 Xml
::closeElement( 'table' ) .
183 Xml
::hidden( 'offset', $this->offset
) .
184 Xml
::hidden( 'limit', $this->limit
) .
185 Xml
::closeElement( 'form' );
194 function linkParameters() {
195 return( array( 'namespace' => $this->namespace, 'username' => $this->username
, 'hideliu' => $this->hideliu
) );
203 function wfSpecialNewpages($par, $specialPage) {
204 global $wgRequest, $wgContLang;
206 list( $limit, $offset ) = wfCheckLimits();
207 $namespace = NS_MAIN
;
212 $bits = preg_split( '/\s*,\s*/', trim( $par ) );
213 foreach ( $bits as $bit ) {
214 if ( 'shownav' == $bit )
215 $shownavigation = true;
216 if ( 'hideliu' == $bit )
218 if ( is_numeric( $bit ) )
222 if ( preg_match( '/^limit=(\d+)$/', $bit, $m ) )
223 $limit = intval($m[1]);
224 if ( preg_match( '/^offset=(\d+)$/', $bit, $m ) )
225 $offset = intval($m[1]);
226 if ( preg_match( '/^namespace=(.*)$/', $bit, $m ) ) {
227 $ns = $wgContLang->getNsIndex( $m[1] );
228 if( $ns !== false ) {
234 if( $ns = $wgRequest->getText( 'namespace', NS_MAIN
) )
236 if( $un = $wgRequest->getText( 'username' ) )
238 if( $hliu = $wgRequest->getBool( 'hideliu' ) )
243 if ( ! isset( $shownavigation ) )
244 $shownavigation = ! $specialPage->including();
246 $npp = new NewPagesPage( $namespace, $username, $hideliu );
248 if ( ! $npp->doFeed( $wgRequest->getVal( 'feed' ), $limit ) )
249 $npp->doQuery( $offset, $limit, $shownavigation );