* Duck warning when being run from maintenance/updateSpecialPages.php
[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 value,
47 rc_user AS user,
48 rc_user_text AS user_text,
49 rc_comment as comment,
50 rc_timestamp AS timestamp,
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 formatResult( $skin, $result ) {
62 global $wgLang, $wgContLang, $wgUser, $wgOnlySysopsCanPatrol, $wgUseRCPatrol;
63 $u = $result->user;
64 $ut = $result->user_text;
65
66 $length = wfMsg( 'nbytes', $wgLang->formatNum( $result->length ) );
67
68 if ( $u == 0 ) { # not by a logged-in user
69 $userPage = Title::makeTitle( NS_SPECIAL, 'Contributions' );
70 $linkParams = 'target=' . urlencode( $ut );
71 } else {
72 $userPage = Title::makeTitle( NS_USER, $ut );
73 $linkParams = '';
74 }
75 $ul = $skin->makeLinkObj( $userPage, htmlspecialchars( $ut ), $linkParams );
76
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 &&
83 $result->patrolled == 0 && $wgUser->isLoggedIn() &&
84 ( $wgUser->isAllowed('patrol') || !$wgOnlySysopsCanPatrol ) )
85 $link = $skin->makeKnownLink( $ns . ':' . $result->title, '', "rcid={$result->rcid}" );
86 else
87 $link = $skin->makeKnownLink( $ns . ':' . $result->title, '' );
88
89 $s = "{$d} {$link} ({$length}) . . {$ul}";
90
91 $s .= $skin->commentBlock( $result->comment );
92
93 return $s;
94 }
95
96 function feedItemDesc( $row ) {
97 if( isset( $row->rev_id ) ) {
98 $revision = Revision::newFromId( $row->rev_id );
99 if( $revision ) {
100 return '<p>' . htmlspecialchars( wfMsg( 'summary' ) ) . ': ' . $text . "</p>\n<hr />\n<div>" .
101 nl2br( htmlspecialchars( $revision->getText() ) ) . "</div>";
102 }
103 }
104 return parent::feedItemDesc( $row );
105 }
106 }
107
108 /**
109 * constructor
110 */
111 function wfSpecialNewpages($par, $specialPage) {
112 global $wgRequest, $wgContLang;
113
114 list( $limit, $offset ) = wfCheckLimits();
115
116 if ( $par ) {
117 $bits = preg_split( '/\s*,\s*/', trim( $par ) );
118 foreach ( $bits as $bit ) {
119 if ( 'shownav' == $bit )
120 $shownavigation = true;
121 if ( is_numeric( $bit ) )
122 $limit = $bit;
123
124 if ( preg_match( '/^limit=(\d+)$/', $bit, $m ) )
125 $limit = intval($m[1]);
126 if ( preg_match( '/^offset=(\d+)$/', $bit, $m ) )
127 $offset = intval($m[1]);
128 if ( preg_match( '/^namespace=(.*)$/', $bit, $m ) )
129 $namespace = $wgContLang->getNsIndex( $m[1] );
130 }
131 }
132 if ( ! isset( $shownavigation ) )
133 $shownavigation = ! $specialPage->including();
134
135 $npp = new NewPagesPage( isset( $namespace ) ? $namespace : NS_MAIN );
136
137 if ( ! $npp->doFeed( $wgRequest->getVal( 'feed' ) ) )
138 $npp->doQuery( $offset, $limit, $shownavigation );
139 }
140
141 ?>