* s~\t+$~~
[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, $wgOnlySysopsCanPatrol, $wgUseRCPatrol;
36 $usepatrol = ( $wgUseRCPatrol && $wgUser->isLoggedIn() &&
37 ( $wgUser->isAllowed('patrol') || !$wgOnlySysopsCanPatrol ) ) ? 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 formatResult( $skin, $result ) {
63 global $wgLang, $wgContLang, $wgUser, $wgOnlySysopsCanPatrol, $wgUseRCPatrol;
64 $u = $result->user;
65 $ut = $result->user_text;
66
67 $length = wfMsg( 'nbytes', $wgLang->formatNum( $result->length ) );
68
69 if ( $u == 0 ) { # not by a logged-in user
70 $userPage = Title::makeTitle( NS_SPECIAL, 'Contributions' );
71 $linkParams = 'target=' . urlencode( $ut );
72 } else {
73 $userPage = Title::makeTitle( NS_USER, $ut );
74 $linkParams = '';
75 }
76 $ul = $skin->makeLinkObj( $userPage, htmlspecialchars( $ut ), $linkParams );
77
78 $d = $wgLang->timeanddate( $result->timestamp, true );
79
80 # Since there is no diff link, we need to give users a way to
81 # mark the article as patrolled if it isn't already
82 $ns = $wgContLang->getNsText( $result->namespace );
83 if ( $wgUseRCPatrol && !is_null ( $result->usepatrol ) && $result->usepatrol &&
84 $result->patrolled == 0 && $wgUser->isLoggedIn() &&
85 ( $wgUser->isAllowed('patrol') || !$wgOnlySysopsCanPatrol ) )
86 $link = $skin->makeKnownLink( $ns . ':' . $result->title, '', "rcid={$result->rcid}" );
87 else
88 $link = $skin->makeKnownLink( $ns . ':' . $result->title, '' );
89
90 $s = "{$d} {$link} ({$length}) . . {$ul}";
91
92 $s .= $skin->commentBlock( $result->comment );
93
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' ) ) . ': ' . $text . "</p>\n<hr />\n<div>" .
102 nl2br( htmlspecialchars( $revision->getText() ) ) . "</div>";
103 }
104 }
105 return parent::feedItemDesc( $row );
106 }
107 }
108
109 /**
110 * constructor
111 */
112 function wfSpecialNewpages($par, $specialPage) {
113 global $wgRequest, $wgContLang;
114
115 list( $limit, $offset ) = wfCheckLimits();
116 $namespace = NS_MAIN;
117
118 if ( $par ) {
119 $bits = preg_split( '/\s*,\s*/', trim( $par ) );
120 foreach ( $bits as $bit ) {
121 if ( 'shownav' == $bit )
122 $shownavigation = true;
123 if ( is_numeric( $bit ) )
124 $limit = $bit;
125
126 if ( preg_match( '/^limit=(\d+)$/', $bit, $m ) )
127 $limit = intval($m[1]);
128 if ( preg_match( '/^offset=(\d+)$/', $bit, $m ) )
129 $offset = intval($m[1]);
130 if ( preg_match( '/^namespace=(.*)$/', $bit, $m ) ) {
131 $ns = $wgContLang->getNsIndex( $m[1] );
132 if( $ns !== false ) {
133 $namespace = $ns;
134 }
135 }
136 }
137 }
138 if ( ! isset( $shownavigation ) )
139 $shownavigation = ! $specialPage->including();
140
141 $npp = new NewPagesPage( $namespace );
142
143 if ( ! $npp->doFeed( $wgRequest->getVal( 'feed' ) ) )
144 $npp->doQuery( $offset, $limit, $shownavigation );
145 }
146
147 ?>