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