* Support for getting new pages from other namespaces than NS_MAIN
[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 ) {
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 if ( $wgUseRCPatrol && !is_null ( $result->usepatrol ) && $result->usepatrol &&
82 $result->patrolled == 0 && $wgUser->isLoggedIn() &&
83 ( $wgUser->isAllowed('patrol') || !$wgOnlySysopsCanPatrol ) )
84 $link = $skin->makeKnownLink( $result->title, '', "rcid={$result->rcid}" );
85 else
86 $link = $skin->makeKnownLink( $result->title, '' );
87
88 $s = "{$d} {$link} ({$length}) . . {$ul}";
89
90 $s .= $skin->commentBlock( $result->comment );
91
92 return $s;
93 }
94
95 function feedItemDesc( $row ) {
96 if( isset( $row->rev_id ) ) {
97 $revision = Revision::newFromId( $row->rev_id );
98 if( $revision ) {
99 return '<p>' . htmlspecialchars( wfMsg( 'summary' ) ) . ': ' . $text . "</p>\n<hr />\n<div>" .
100 nl2br( htmlspecialchars( $revision->getText() ) ) . "</div>";
101 }
102 }
103 return parent::feedItemDesc( $row );
104 }
105 }
106
107 /**
108 * constructor
109 */
110 function wfSpecialNewpages($par, $specialPage) {
111 global $wgRequest, $wgContLang;
112
113 list( $limit, $offset ) = wfCheckLimits();
114
115 if ( $par ) {
116 $bits = preg_split( '/\s*,\s*/', trim( $par ) );
117 foreach ( $bits as $bit ) {
118 if ( 'shownav' == $bit )
119 $shownavigation = true;
120 if ( is_numeric( $bit ) )
121 $limit = $bit;
122
123 if ( preg_match( '/^limit=(\d+)$/', $bit, $m ) )
124 $limit = intval($m[1]);
125 if ( preg_match( '/^offset=(\d+)$/', $bit, $m ) )
126 $offset = intval($m[1]);
127 if ( preg_match( '/^namespace=(.*)$/', $bit, $m ) )
128 $namespace = $wgContLang->getNsIndex( $m[1] );
129 }
130 }
131 if ( ! isset( $shownavigation ) )
132 $shownavigation = ! $specialPage->including();
133
134 $npp = new NewPagesPage( isset( $namespace ) ? $namespace : NS_MAIN );
135
136 if ( ! $npp->doFeed( $wgRequest->getVal( 'feed' ) ) )
137 $npp->doQuery( $offset, $limit, $shownavigation );
138 }
139
140 ?>