In fixSlaveDesync.php, don't check slaves that have zero load.
[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 $dirmark = $wgContLang->getDirMark(); // To keep text in correct order
79
80 $length = wfMsgExt( 'nbytes', array('parsemag', 'escape'),
81 $wgLang->formatNum( $result->length ) );
82 $d = $wgLang->timeanddate( $result->timestamp, true );
83
84 # Since there is no diff link, we need to give users a way to
85 # mark the article as patrolled if it isn't already
86 $ns = $wgContLang->getNsText( $result->namespace );
87 if( $wgUseRCPatrol && !is_null( $result->usepatrol ) && $result->usepatrol && $result->patrolled == 0 && $wgUser->isAllowed( 'patrol' ) ) {
88 $link = $skin->makeKnownLink( $ns . ':' . $result->title, '', "rcid={$result->rcid}" );
89 } else {
90 $link = $skin->makeKnownLink( $ns . ':' . $result->title, '' );
91 }
92
93 $userLink = $skin->userLink( $u, $ut );
94 $userTools = $skin->userToolLinks( $u, $ut );
95
96 $s = "{$d} {$dirmark}{$link} {$dirmark}({$length}) . . " .
97 "{$dirmark}{$userLink}{$dirmark}{$userTools}";
98 $s .= $dirmark . $skin->commentBlock( $result->comment );
99 return $s;
100 }
101
102 function feedItemDesc( $row ) {
103 if( isset( $row->rev_id ) ) {
104 $revision = Revision::newFromId( $row->rev_id );
105 if( $revision ) {
106 return '<p>' . htmlspecialchars( wfMsg( 'summary' ) ) . ': ' .
107 htmlspecialchars( $revision->getComment() ) . "</p>\n<hr />\n<div>" .
108 nl2br( htmlspecialchars( $revision->getText() ) ) . "</div>";
109 }
110 }
111 return parent::feedItemDesc( $row );
112 }
113
114 /**
115 * Show a namespace selection form for filtering
116 *
117 * @return string
118 */
119 function getPageHeader() {
120 $thisTitle = Title::makeTitle( NS_SPECIAL, $this->getName() );
121 $form = wfOpenElement( 'form', array(
122 'method' => 'post',
123 'action' => $thisTitle->getLocalUrl() ) );
124 $form .= wfElement( 'label', array( 'for' => 'namespace' ),
125 wfMsg( 'namespace' ) ) . ' ';
126 $form .= HtmlNamespaceSelector( $this->namespace );
127 # Preserve the offset and limit
128 $form .= wfElement( 'input', array(
129 'type' => 'hidden',
130 'name' => 'offset',
131 'value' => $this->offset ) );
132 $form .= wfElement( 'input', array(
133 'type' => 'hidden',
134 'name' => 'limit',
135 'value' => $this->limit ) );
136 $form .= wfElement( 'input', array(
137 'type' => 'submit',
138 'name' => 'submit',
139 'id' => 'submit',
140 'value' => wfMsg( 'allpagessubmit' ) ) );
141 $form .= wfCloseElement( 'form' );
142 return( $form );
143 }
144
145 /**
146 * Link parameters
147 *
148 * @return array
149 */
150 function linkParameters() {
151 return( array( 'namespace' => $this->namespace ) );
152 }
153
154 }
155
156 /**
157 * constructor
158 */
159 function wfSpecialNewpages($par, $specialPage) {
160 global $wgRequest, $wgContLang;
161
162 list( $limit, $offset ) = wfCheckLimits();
163 $namespace = NS_MAIN;
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 if ( preg_match( '/^limit=(\d+)$/', $bit, $m ) )
174 $limit = intval($m[1]);
175 if ( preg_match( '/^offset=(\d+)$/', $bit, $m ) )
176 $offset = intval($m[1]);
177 if ( preg_match( '/^namespace=(.*)$/', $bit, $m ) ) {
178 $ns = $wgContLang->getNsIndex( $m[1] );
179 if( $ns !== false ) {
180 $namespace = $ns;
181 }
182 }
183 }
184 } else {
185 if( $ns = $wgRequest->getInt( 'namespace', 0 ) )
186 $namespace = $ns;
187 }
188
189 if ( ! isset( $shownavigation ) )
190 $shownavigation = ! $specialPage->including();
191
192 $npp = new NewPagesPage( $namespace );
193
194 if ( ! $npp->doFeed( $wgRequest->getVal( 'feed' ), $limit ) )
195 $npp->doQuery( $offset, $limit, $shownavigation );
196 }
197
198 ?>