37de1b6822e116a9a0e19669da7bae6d1e40286a
[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, $res->user_text ) );
66 $linkBatch->addObj( Title::makeTitleSafe( NS_USER_TALK, $res->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 = wfMsgHtml( 'nbytes', htmlspecialchars( $wgLang->formatNum( $result->length ) ) );
80 $d = $wgLang->timeanddate( $result->timestamp, true );
81
82 # Since there is no diff link, we need to give users a way to
83 # mark the article as patrolled if it isn't already
84 $ns = $wgContLang->getNsText( $result->namespace );
85 if( $wgUseRCPatrol && !is_null( $result->usepatrol ) && $result->usepatrol && $result->patrolled == 0 && $wgUser->isAllowed( 'patrol' ) ) {
86 $link = $skin->makeKnownLink( $ns . ':' . $result->title, '', "rcid={$result->rcid}" );
87 } else {
88 $link = $skin->makeKnownLink( $ns . ':' . $result->title, '' );
89 }
90
91 $userTools = $skin->userLink( $u, $ut ) . $skin->userToolLinks( $u, $ut );
92
93 $s = "{$d} {$link} ({$length}) . . {$userTools}";
94 $s .= $skin->commentBlock( $result->comment );
95 return $s;
96 }
97
98 function feedItemDesc( $row ) {
99 if( isset( $row->rev_id ) ) {
100 $revision = Revision::newFromId( $row->rev_id );
101 if( $revision ) {
102 return '<p>' . htmlspecialchars( wfMsg( 'summary' ) ) . ': ' . $text . "</p>\n<hr />\n<div>" .
103 nl2br( htmlspecialchars( $revision->getText() ) ) . "</div>";
104 }
105 }
106 return parent::feedItemDesc( $row );
107 }
108 }
109
110 /**
111 * constructor
112 */
113 function wfSpecialNewpages($par, $specialPage) {
114 global $wgRequest, $wgContLang;
115
116 list( $limit, $offset ) = wfCheckLimits();
117 $namespace = NS_MAIN;
118
119 if ( $par ) {
120 $bits = preg_split( '/\s*,\s*/', trim( $par ) );
121 foreach ( $bits as $bit ) {
122 if ( 'shownav' == $bit )
123 $shownavigation = true;
124 if ( is_numeric( $bit ) )
125 $limit = $bit;
126
127 if ( preg_match( '/^limit=(\d+)$/', $bit, $m ) )
128 $limit = intval($m[1]);
129 if ( preg_match( '/^offset=(\d+)$/', $bit, $m ) )
130 $offset = intval($m[1]);
131 if ( preg_match( '/^namespace=(.*)$/', $bit, $m ) ) {
132 $ns = $wgContLang->getNsIndex( $m[1] );
133 if( $ns !== false ) {
134 $namespace = $ns;
135 }
136 }
137 }
138 }
139 if ( ! isset( $shownavigation ) )
140 $shownavigation = ! $specialPage->including();
141
142 $npp = new NewPagesPage( $namespace );
143
144 if ( ! $npp->doFeed( $wgRequest->getVal( 'feed' ) ) )
145 $npp->doQuery( $offset, $limit, $shownavigation );
146 }
147
148 ?>