* Made special page names case-insensitive and localisable. Care has been taken to...
[lhc/web/wiklou.git] / includes / SpecialNewpages.php
1 <?php
2 /**
3 *
4 * @package MediaWiki
5 * @subpackage SpecialPage
6 */
7
8 /**
9 *
10 * @package MediaWiki
11 * @subpackage SpecialPage
12 */
13 class NewPagesPage extends QueryPage {
14
15 var $namespace;
16 var $username = '';
17
18 function NewPagesPage( $namespace = NS_MAIN, $username = '' ) {
19 $this->namespace = $namespace;
20 $this->username = $username;
21 }
22
23 function getName() {
24 return 'Newpages';
25 }
26
27 function isExpensive() {
28 # Indexed on RC, and will *not* work with querycache yet.
29 return false;
30 }
31
32 function makeUserWhere( &$dbo ) {
33 $title = Title::makeTitleSafe( NS_USER, $this->username );
34 if( $title ) {
35 return ' AND rc_user_text = ' . $dbo->addQuotes( $title->getText() );
36 } else {
37 return '';
38 }
39 }
40
41 function getSQL() {
42 global $wgUser, $wgUseRCPatrol;
43 $usepatrol = ( $wgUseRCPatrol && $wgUser->isAllowed( 'patrol' ) ) ? 1 : 0;
44 $dbr =& wfGetDB( DB_SLAVE );
45 extract( $dbr->tableNames( 'recentchanges', 'page', 'text' ) );
46
47 $uwhere = $this->makeUserWhere( $dbr );
48
49 # FIXME: text will break with compression
50 return
51 "SELECT 'Newpages' as type,
52 rc_namespace AS namespace,
53 rc_title AS title,
54 rc_cur_id AS cur_id,
55 rc_user AS user,
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,
62 rc_id AS rcid,
63 page_len as length,
64 page_latest as rev_id
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
68 {$uwhere}";
69 }
70
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 ) );
77 }
78 $linkBatch->execute();
79 # Seek to start
80 if( $dbo->numRows( $res ) > 0 )
81 $dbo->dataSeek( $res, 0 );
82 }
83
84 /**
85 * Format a row, providing the timestamp, links to the page/history, size, user links, and a comment
86 *
87 * @param $skin Skin to use
88 * @param $result Result row
89 * @return string
90 */
91 function formatResult( $skin, $result ) {
92 global $wgLang, $wgContLang;
93 $dm = $wgContLang->getDirMark();
94
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 );
102
103 return "{$time} {$dm}{$plink} ({$hist}) {$dm}[{$length}] {$dm}{$ulink} {$comment}";
104 }
105
106 /**
107 * Should a specific result row provide "patrollable" links?
108 *
109 * @param $result Result row
110 * @return bool
111 */
112 function patrollable( $result ) {
113 global $wgUser, $wgUseRCPatrol;
114 return $wgUseRCPatrol && $wgUser->isAllowed( 'patrol' ) && !$result->patrolled;
115 }
116
117 function feedItemDesc( $row ) {
118 if( isset( $row->rev_id ) ) {
119 $revision = Revision::newFromId( $row->rev_id );
120 if( $revision ) {
121 return '<p>' . htmlspecialchars( wfMsg( 'summary' ) ) . ': ' .
122 htmlspecialchars( $revision->getComment() ) . "</p>\n<hr />\n<div>" .
123 nl2br( htmlspecialchars( $revision->getText() ) ) . "</div>";
124 }
125 }
126 return parent::feedItemDesc( $row );
127 }
128
129 /**
130 * Show a form for filtering namespace and username
131 *
132 * @return string
133 */
134 function getPageHeader() {
135 $self = SpecialPage::getTitleFor( $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>';
143 return $form;
144 }
145
146 /**
147 * Link parameters
148 *
149 * @return array
150 */
151 function linkParameters() {
152 return( array( 'namespace' => $this->namespace, 'username' => $this->username ) );
153 }
154
155 }
156
157 /**
158 * constructor
159 */
160 function wfSpecialNewpages($par, $specialPage) {
161 global $wgRequest, $wgContLang;
162
163 list( $limit, $offset ) = wfCheckLimits();
164 $namespace = NS_MAIN;
165 $username = '';
166
167 if ( $par ) {
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 ) )
173 $limit = $bit;
174
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 ) {
182 $namespace = $ns;
183 }
184 }
185 }
186 } else {
187 if( $ns = $wgRequest->getInt( 'namespace', 0 ) )
188 $namespace = $ns;
189 if( $un = $wgRequest->getText( 'username' ) )
190 $username = $un;
191 }
192
193 if ( ! isset( $shownavigation ) )
194 $shownavigation = ! $specialPage->including();
195
196 $npp = new NewPagesPage( $namespace, $username );
197
198 if ( ! $npp->doFeed( $wgRequest->getVal( 'feed' ), $limit ) )
199 $npp->doQuery( $offset, $limit, $shownavigation );
200 }
201
202 ?>