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