Use Doxygen @addtogroup instead of phpdoc @package && @subpackage
[lhc/web/wiklou.git] / includes / SpecialNewpages.php
1 <?php
2 /**
3 *
4 * @addtogroup SpecialPage
5 */
6
7 /**
8 *
9 * @addtogroup SpecialPage
10 */
11 class NewPagesPage extends QueryPage {
12
13 var $namespace;
14 var $username = '';
15
16 function NewPagesPage( $namespace = NS_MAIN, $username = '' ) {
17 $this->namespace = $namespace;
18 $this->username = $username;
19 }
20
21 function getName() {
22 return 'Newpages';
23 }
24
25 function isExpensive() {
26 # Indexed on RC, and will *not* work with querycache yet.
27 return false;
28 }
29
30 function makeUserWhere( &$dbo ) {
31 $title = Title::makeTitleSafe( NS_USER, $this->username );
32 if( $title ) {
33 return ' AND rc_user_text = ' . $dbo->addQuotes( $title->getText() );
34 } else {
35 return '';
36 }
37 }
38
39 function getSQL() {
40 global $wgUser, $wgUseRCPatrol;
41 $usepatrol = ( $wgUseRCPatrol && $wgUser->isAllowed( 'patrol' ) ) ? 1 : 0;
42 $dbr =& wfGetDB( DB_SLAVE );
43 list( $recentchanges, $page ) = $dbr->tableNamesN( 'recentchanges', 'page' );
44
45 $uwhere = $this->makeUserWhere( $dbr );
46
47 # FIXME: text will break with compression
48 return
49 "SELECT 'Newpages' as type,
50 rc_namespace AS namespace,
51 rc_title AS title,
52 rc_cur_id AS cur_id,
53 rc_user AS user,
54 rc_user_text AS user_text,
55 rc_comment as comment,
56 rc_timestamp AS timestamp,
57 rc_timestamp AS value,
58 '{$usepatrol}' as usepatrol,
59 rc_patrolled AS patrolled,
60 rc_id AS rcid,
61 page_len as length,
62 page_latest as rev_id
63 FROM $recentchanges,$page
64 WHERE rc_cur_id=page_id AND rc_new=1
65 AND rc_namespace=" . $this->namespace . " AND page_is_redirect=0
66 {$uwhere}";
67 }
68
69 function preprocessResults( &$dbo, &$res ) {
70 # Do a batch existence check on the user and talk pages
71 $linkBatch = new LinkBatch();
72 while( $row = $dbo->fetchObject( $res ) ) {
73 $linkBatch->addObj( Title::makeTitleSafe( NS_USER, $row->user_text ) );
74 $linkBatch->addObj( Title::makeTitleSafe( NS_USER_TALK, $row->user_text ) );
75 }
76 $linkBatch->execute();
77 # Seek to start
78 if( $dbo->numRows( $res ) > 0 )
79 $dbo->dataSeek( $res, 0 );
80 }
81
82 /**
83 * Format a row, providing the timestamp, links to the page/history, size, user links, and a comment
84 *
85 * @param $skin Skin to use
86 * @param $result Result row
87 * @return string
88 */
89 function formatResult( $skin, $result ) {
90 global $wgLang, $wgContLang;
91 $dm = $wgContLang->getDirMark();
92
93 $title = Title::makeTitleSafe( $result->namespace, $result->title );
94 $time = $wgLang->timeAndDate( $result->timestamp, true );
95 $plink = $skin->makeKnownLinkObj( $title, '', $this->patrollable( $result ) ? 'rcid=' . $result->rcid : '' );
96 $hist = $skin->makeKnownLinkObj( $title, wfMsgHtml( 'hist' ), 'action=history' );
97 $length = wfMsgExt( 'nbytes', array( 'parsemag', 'escape' ), $wgLang->formatNum( htmlspecialchars( $result->length ) ) );
98 $ulink = $skin->userLink( $result->user, $result->user_text ) . ' ' . $skin->userToolLinks( $result->user, $result->user_text );
99 $comment = $skin->commentBlock( $result->comment );
100
101 return "{$time} {$dm}{$plink} ({$hist}) {$dm}[{$length}] {$dm}{$ulink} {$comment}";
102 }
103
104 /**
105 * Should a specific result row provide "patrollable" links?
106 *
107 * @param $result Result row
108 * @return bool
109 */
110 function patrollable( $result ) {
111 global $wgUser, $wgUseRCPatrol;
112 return $wgUseRCPatrol && $wgUser->isAllowed( 'patrol' ) && !$result->patrolled;
113 }
114
115 function feedItemDesc( $row ) {
116 if( isset( $row->rev_id ) ) {
117 $revision = Revision::newFromId( $row->rev_id );
118 if( $revision ) {
119 return '<p>' . htmlspecialchars( wfMsg( 'summary' ) ) . ': ' .
120 htmlspecialchars( $revision->getComment() ) . "</p>\n<hr />\n<div>" .
121 nl2br( htmlspecialchars( $revision->getText() ) ) . "</div>";
122 }
123 }
124 return parent::feedItemDesc( $row );
125 }
126
127 /**
128 * Show a form for filtering namespace and username
129 *
130 * @return string
131 */
132 function getPageHeader() {
133 $self = SpecialPage::getTitleFor( $this->getName() );
134 $form = Xml::openElement( 'form', array( 'method' => 'post', 'action' => $self->getLocalUrl() ) );
135 $form .= '<table><tr><td align="right">' . Xml::label( wfMsg( 'namespace' ), 'namespace' ) . '</td>';
136 $form .= '<td>' . Xml::namespaceSelector( $this->namespace ) . '</td><tr>';
137 $form .= '<tr><td align="right">' . Xml::label( wfMsg( 'newpages-username' ), 'mw-np-username' ) . '</td>';
138 $form .= '<td>' . Xml::input( 'username', 30, $this->username, array( 'id' => 'mw-np-username' ) ) . '</td></tr>';
139 $form .= '<tr><td></td><td>' . Xml::submitButton( wfMsg( 'allpagessubmit' ) ) . '</td></tr></table>';
140 $form .= Xml::hidden( 'offset', $this->offset ) . Xml::hidden( 'limit', $this->limit ) . '</form>';
141 return $form;
142 }
143
144 /**
145 * Link parameters
146 *
147 * @return array
148 */
149 function linkParameters() {
150 return( array( 'namespace' => $this->namespace, 'username' => $this->username ) );
151 }
152
153 }
154
155 /**
156 * constructor
157 */
158 function wfSpecialNewpages($par, $specialPage) {
159 global $wgRequest, $wgContLang;
160
161 list( $limit, $offset ) = wfCheckLimits();
162 $namespace = NS_MAIN;
163 $username = '';
164
165 if ( $par ) {
166 $bits = preg_split( '/\s*,\s*/', trim( $par ) );
167 foreach ( $bits as $bit ) {
168 if ( 'shownav' == $bit )
169 $shownavigation = true;
170 if ( is_numeric( $bit ) )
171 $limit = $bit;
172
173 $m = array();
174 if ( preg_match( '/^limit=(\d+)$/', $bit, $m ) )
175 $limit = intval($m[1]);
176 if ( preg_match( '/^offset=(\d+)$/', $bit, $m ) )
177 $offset = intval($m[1]);
178 if ( preg_match( '/^namespace=(.*)$/', $bit, $m ) ) {
179 $ns = $wgContLang->getNsIndex( $m[1] );
180 if( $ns !== false ) {
181 $namespace = $ns;
182 }
183 }
184 }
185 } else {
186 if( $ns = $wgRequest->getInt( 'namespace', 0 ) )
187 $namespace = $ns;
188 if( $un = $wgRequest->getText( 'username' ) )
189 $username = $un;
190 }
191
192 if ( ! isset( $shownavigation ) )
193 $shownavigation = ! $specialPage->including();
194
195 $npp = new NewPagesPage( $namespace, $username );
196
197 if ( ! $npp->doFeed( $wgRequest->getVal( 'feed' ), $limit ) )
198 $npp->doQuery( $offset, $limit, $shownavigation );
199 }
200
201 ?>