Some more PHP5 stuff
[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 private
20 $namespace;
21
22 function NewPagesPage( $namespace = NS_MAIN ) {
23 $this->namespace = $namespace;
24 }
25
26 function getName() {
27 return 'Newpages';
28 }
29
30 function isExpensive() {
31 # Indexed on RC, and will *not* work with querycache yet.
32 return false;
33 }
34
35 function getSQL() {
36 global $wgUser, $wgUseRCPatrol;
37 $usepatrol = ( $wgUseRCPatrol && $wgUser->isAllowed( 'patrol' ) ) ? 1 : 0;
38 $dbr =& wfGetDB( DB_SLAVE );
39 extract( $dbr->tableNames( 'recentchanges', 'page', 'text' ) );
40
41 # FIXME: text will break with compression
42 return
43 "SELECT 'Newpages' as type,
44 rc_namespace AS namespace,
45 rc_title AS title,
46 rc_cur_id AS cur_id,
47 rc_user AS user,
48 rc_user_text AS user_text,
49 rc_comment as comment,
50 rc_timestamp AS timestamp,
51 rc_timestamp AS value,
52 '{$usepatrol}' as usepatrol,
53 rc_patrolled AS patrolled,
54 rc_id AS rcid,
55 page_len as length,
56 page_latest as rev_id
57 FROM $recentchanges,$page
58 WHERE rc_cur_id=page_id AND rc_new=1
59 AND rc_namespace=" . $this->namespace . " AND page_is_redirect=0";
60 }
61
62 function preprocessResults( &$dbo, &$res ) {
63 # Do a batch existence check on the user and talk pages
64 $linkBatch = new LinkBatch();
65 while( $row = $dbo->fetchObject( $res ) ) {
66 $linkBatch->addObj( Title::makeTitleSafe( NS_USER, $row->user_text ) );
67 $linkBatch->addObj( Title::makeTitleSafe( NS_USER_TALK, $row->user_text ) );
68 }
69 $linkBatch->execute();
70 # Seek to start
71 if( $dbo->numRows( $res ) > 0 )
72 $dbo->dataSeek( $res, 0 );
73 }
74
75 function formatResult( $skin, $result ) {
76 global $wgLang, $wgContLang, $wgUser, $wgUseRCPatrol;
77 $u = $result->user;
78 $ut = $result->user_text;
79 $dirmark = $wgContLang->getDirMark(); // To keep text in correct order
80
81 $length = wfMsgExt( 'nbytes', array('parsemag', 'escape'),
82 $wgLang->formatNum( $result->length ) );
83 $d = $wgLang->timeanddate( $result->timestamp, true );
84
85 # Since there is no diff link, we need to give users a way to
86 # mark the article as patrolled if it isn't already
87 $ns = $wgContLang->getNsText( $result->namespace );
88 if( $wgUseRCPatrol && !is_null( $result->usepatrol ) && $result->usepatrol && $result->patrolled == 0 && $wgUser->isAllowed( 'patrol' ) ) {
89 $link = $skin->makeKnownLink( $ns . ':' . $result->title, '', "rcid={$result->rcid}" );
90 } else {
91 $link = $skin->makeKnownLink( $ns . ':' . $result->title, '' );
92 }
93
94 $userLink = $skin->userLink( $u, $ut );
95 $userTools = $skin->userToolLinks( $u, $ut );
96
97 $s = "{$d} {$dirmark}{$link} {$dirmark}({$length}) . . " .
98 "{$dirmark}{$userLink}{$dirmark}{$userTools}";
99 $s .= $dirmark . $skin->commentBlock( $result->comment );
100 return $s;
101 }
102
103 function feedItemDesc( $row ) {
104 if( isset( $row->rev_id ) ) {
105 $revision = Revision::newFromId( $row->rev_id );
106 if( $revision ) {
107 return '<p>' . htmlspecialchars( wfMsg( 'summary' ) ) . ': ' .
108 htmlspecialchars( $revision->getComment() ) . "</p>\n<hr />\n<div>" .
109 nl2br( htmlspecialchars( $revision->getText() ) ) . "</div>";
110 }
111 }
112 return parent::feedItemDesc( $row );
113 }
114
115 /**
116 * Show a namespace selection form for filtering
117 *
118 * @return string
119 */
120 function getPageHeader() {
121 $thisTitle = Title::makeTitle( NS_SPECIAL, $this->getName() );
122 $form = wfOpenElement( 'form', array(
123 'method' => 'post',
124 'action' => $thisTitle->getLocalUrl() ) );
125 $form .= wfElement( 'label', array( 'for' => 'namespace' ),
126 wfMsg( 'namespace' ) ) . ' ';
127 $form .= HtmlNamespaceSelector( $this->namespace );
128 # Preserve the offset and limit
129 $form .= wfElement( 'input', array(
130 'type' => 'hidden',
131 'name' => 'offset',
132 'value' => $this->offset ) );
133 $form .= wfElement( 'input', array(
134 'type' => 'hidden',
135 'name' => 'limit',
136 'value' => $this->limit ) );
137 $form .= wfElement( 'input', array(
138 'type' => 'submit',
139 'name' => 'submit',
140 'id' => 'submit',
141 'value' => wfMsg( 'allpagessubmit' ) ) );
142 $form .= wfCloseElement( 'form' );
143 return( $form );
144 }
145
146 /**
147 * Link parameters
148 *
149 * @return array
150 */
151 function linkParameters() {
152 return( array( 'namespace' => $this->namespace ) );
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
166 if ( $par ) {
167 $bits = preg_split( '/\s*,\s*/', trim( $par ) );
168 foreach ( $bits as $bit ) {
169 if ( 'shownav' == $bit )
170 $shownavigation = true;
171 if ( is_numeric( $bit ) )
172 $limit = $bit;
173
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 }
189
190 if ( ! isset( $shownavigation ) )
191 $shownavigation = ! $specialPage->including();
192
193 $npp = new NewPagesPage( $namespace );
194
195 if ( ! $npp->doFeed( $wgRequest->getVal( 'feed' ), $limit ) )
196 $npp->doQuery( $offset, $limit, $shownavigation );
197 }
198
199 ?>