4 * @addtogroup SpecialPage
8 * implements Special:Newpages
9 * @addtogroup SpecialPage
11 class NewPagesPage
extends QueryPage
{
18 function NewPagesPage( $namespace = NS_MAIN
, $username = '', $hideliu = false, $hidepatrolled = false ) {
19 $this->namespace = $namespace;
20 $this->username
= $username;
21 $this->hideliu
= $hideliu;
22 $this->hidepatrolled
= $hidepatrolled;
29 function isExpensive() {
30 # Indexed on RC, and will *not* work with querycache yet.
34 function makeUserWhere( &$dbo ) {
35 global $wgGroupPermissions;
37 if ($this->hidepatrolled
)
38 $where = ' AND rc_patrolled = 0';
39 if ($wgGroupPermissions['*']['createpage'] == true && $this->hideliu
) {
40 return $where . ' AND rc_user = 0';
42 $title = Title
::makeTitleSafe( NS_USER
, $this->username
);
44 return $where . ' AND rc_user_text = ' . $dbo->addQuotes( $title->getText() );
51 private function makeNamespaceWhere() {
52 return $this->namespace !== 'all'
53 ?
' AND rc_namespace = ' . intval( $this->namespace )
58 global $wgUser, $wgUseNPPatrol;
59 $usepatrol = ( $wgUseNPPatrol ) ?
1 : 0;
60 $dbr = wfGetDB( DB_SLAVE
);
61 list( $recentchanges, $page ) = $dbr->tableNamesN( 'recentchanges', 'page' );
63 $nsfilter = $this->makeNamespaceWhere();
64 $uwhere = $this->makeUserWhere( $dbr );
66 # FIXME: text will break with compression
68 "SELECT 'Newpages' as type,
69 rc_namespace AS namespace,
73 rc_user_text AS user_text,
74 rc_comment as \"comment\",
75 rc_timestamp AS timestamp,
76 rc_timestamp AS value,
77 '{$usepatrol}' as usepatrol,
78 rc_patrolled AS patrolled,
82 FROM $recentchanges,$page
83 WHERE rc_cur_id=page_id AND rc_new=1
85 AND page_is_redirect = 0
89 function preprocessResults( &$dbo, &$res ) {
90 # Do a batch existence check on the user and talk pages
91 $linkBatch = new LinkBatch();
92 while( $row = $dbo->fetchObject( $res ) ) {
93 $linkBatch->addObj( Title
::makeTitleSafe( NS_USER
, $row->user_text
) );
94 $linkBatch->addObj( Title
::makeTitleSafe( NS_USER_TALK
, $row->user_text
) );
96 $linkBatch->execute();
98 if( $dbo->numRows( $res ) > 0 )
99 $dbo->dataSeek( $res, 0 );
103 * Format a row, providing the timestamp, links to the page/history, size, user links, and a comment
105 * @param $skin Skin to use
106 * @param $result Result row
109 function formatResult( $skin, $result ) {
110 global $wgLang, $wgContLang;
111 $dm = $wgContLang->getDirMark();
113 $title = Title
::makeTitleSafe( $result->namespace, $result->title
);
114 $time = $wgLang->timeAndDate( $result->timestamp
, true );
115 $plink = $skin->makeKnownLinkObj( $title, '', $this->patrollable( $result ) ?
'rcid=' . $result->rcid
: '' );
116 $hist = $skin->makeKnownLinkObj( $title, wfMsgHtml( 'hist' ), 'action=history' );
117 $length = wfMsgExt( 'nbytes', array( 'parsemag', 'escape' ), $wgLang->formatNum( htmlspecialchars( $result->length
) ) );
118 $ulink = $skin->userLink( $result->user
, $result->user_text
) . ' ' . $skin->userToolLinks( $result->user
, $result->user_text
);
119 $comment = $skin->commentBlock( $result->comment
);
121 return "{$time} {$dm}{$plink} ({$hist}) {$dm}[{$length}] {$dm}{$ulink} {$comment}";
125 * Should a specific result row provide "patrollable" links?
127 * @param $result Result row
130 function patrollable( $result ) {
131 global $wgUser, $wgUseNPPatrol;
132 return $wgUseNPPatrol && $wgUser->isAllowed( 'patrol' ) && !$result->patrolled
;
135 function feedItemDesc( $row ) {
136 if( isset( $row->rev_id
) ) {
137 $revision = Revision
::newFromId( $row->rev_id
);
139 return '<p>' . htmlspecialchars( wfMsg( 'summary' ) ) . ': ' .
140 htmlspecialchars( $revision->getComment() ) . "</p>\n<hr />\n<div>" .
141 nl2br( htmlspecialchars( $revision->getText() ) ) . "</div>";
144 return parent
::feedItemDesc( $row );
148 * Show a form for filtering namespace and username
152 function getPageHeader() {
153 global $wgScript, $wgContLang, $wgGroupPermissions, $wgUser, $wgUseNPPatrol;
154 $align = $wgContLang->isRTL() ?
'left' : 'right';
155 $self = SpecialPage
::getTitleFor( $this->getName() );
158 $showhide = array( wfMsg( 'show' ), wfMsg( 'hide' ));
159 $liuLink = $wgUser->getSkin()->makeKnownLink( $wgContLang->specialPage( 'Newpages' ),
160 htmlspecialchars( $showhide[1-$this->hideliu
] ), wfArrayToCGI( array( 'hideliu' => 1-$this->hideliu
), $nondefaults ) );
161 $patrLink = $wgUser->getSkin()->makeKnownLink( $wgContLang->specialPage( 'Newpages' ),
162 htmlspecialchars( $showhide[1-$this->hidepatrolled
] ), wfArrayToCGI( array( 'hidepatrolled' => 1-$this->hidepatrolled
), $nondefaults ) );
164 if( $wgGroupPermissions['*']['createpage'] == true )
165 $links[] = wfMsgHtml( 'rcshowhideliu', $liuLink );
167 $links[] = wfMsgHtml( 'rcshowhidepatr', $patrLink );
168 $hl = implode( ' | ', $links );
170 $form = Xml
::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) ) .
171 Xml
::hidden( 'title', $self->getPrefixedDBkey() ) .
172 Xml
::openElement( 'table' ) .
174 <td align=\"$align\">" .
175 Xml
::label( wfMsg( 'namespace' ), 'namespace' ) .
178 Xml
::namespaceSelector( intval( $this->namespace ), 'all' ) .
182 <td align=\"$align\">" .
183 Xml
::label( wfMsg( 'newpages-username' ), 'mw-np-username' ) .
186 Xml
::input( 'username', 30, $this->username
, array( 'id' => 'mw-np-username' ) ) .
188 </tr><tr><td></td><td>" . $hl . "</td></tr>
191 Xml
::submitButton( wfMsg( 'allpagessubmit' ) ) .
194 Xml
::closeElement( 'table' ) .
195 Xml
::hidden( 'offset', $this->offset
) .
196 Xml
::hidden( 'limit', $this->limit
) .
197 Xml
::closeElement( 'form' );
206 function linkParameters() {
207 return( array( 'namespace' => $this->namespace, 'username' => $this->username
, 'hideliu' => $this->hideliu
, 'hidepatrolled' => $this->hidepatrolled
) );
215 function wfSpecialNewpages($par, $specialPage) {
216 global $wgRequest, $wgContLang;
218 list( $limit, $offset ) = wfCheckLimits();
219 $namespace = NS_MAIN
;
222 $hidepatrolled = false;
225 $bits = preg_split( '/\s*,\s*/', trim( $par ) );
226 foreach ( $bits as $bit ) {
227 if ( 'shownav' == $bit )
228 $shownavigation = true;
229 if ( 'hideliu' == $bit )
231 if ( 'hidepatrolled' == $bit )
232 $hidepatrolled = true;
233 if ( is_numeric( $bit ) )
237 if ( preg_match( '/^limit=(\d+)$/', $bit, $m ) )
238 $limit = intval($m[1]);
239 if ( preg_match( '/^offset=(\d+)$/', $bit, $m ) )
240 $offset = intval($m[1]);
241 if ( preg_match( '/^namespace=(.*)$/', $bit, $m ) ) {
242 $ns = $wgContLang->getNsIndex( $m[1] );
243 if( $ns !== false ) {
249 if( $ns = $wgRequest->getText( 'namespace', NS_MAIN
) )
251 if( $un = $wgRequest->getText( 'username' ) )
253 if( $hliu = $wgRequest->getBool( 'hideliu' ) )
255 if( $hpatrolled = $wgRequest->getBool( 'hidepatrolled' ) )
256 $hidepatrolled = $hpatrolled;
260 if ( ! isset( $shownavigation ) )
261 $shownavigation = ! $specialPage->including();
263 $npp = new NewPagesPage( $namespace, $username, $hideliu, $hidepatrolled );
265 if ( ! $npp->doFeed( $wgRequest->getVal( 'feed' ), $limit ) )
266 $npp->doQuery( $offset, $limit, $shownavigation );