make Special:Newpages includable
[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
20 function getName() {
21 return "Newpages";
22 }
23
24 function isExpensive() {
25 # Indexed on RC, and will *not* work with querycache yet.
26 return false;
27 #return parent::isExpensive();
28 }
29
30 function getSQL() {
31 global $wgUser, $wgOnlySysopsCanPatrol, $wgUseRCPatrol;
32 $usepatrol = ( $wgUseRCPatrol && $wgUser->isLoggedIn() &&
33 ( $wgUser->isAllowed('patrol') || !$wgOnlySysopsCanPatrol ) ) ? 1 : 0;
34 $dbr =& wfGetDB( DB_SLAVE );
35 extract( $dbr->tableNames( 'recentchanges', 'page', 'text' ) );
36
37 # FIXME: text will break with compression
38 return
39 "SELECT 'Newpages' as type,
40 rc_namespace AS namespace,
41 rc_title AS title,
42 rc_cur_id AS value,
43 rc_user AS user,
44 rc_user_text AS user_text,
45 rc_comment as comment,
46 rc_timestamp AS timestamp,
47 '{$usepatrol}' as usepatrol,
48 rc_patrolled AS patrolled,
49 rc_id AS rcid,
50 page_len as length,
51 page_latest as rev_id
52 FROM $recentchanges,$page
53 WHERE rc_cur_id=page_id AND rc_new=1
54 AND rc_namespace=".NS_MAIN." AND page_is_redirect=0";
55 }
56
57 function formatResult( $skin, $result ) {
58 global $wgLang, $wgContLang, $wgUser, $wgOnlySysopsCanPatrol, $wgUseRCPatrol;
59 $u = $result->user;
60 $ut = $result->user_text;
61
62 $length = wfMsg( "nbytes", $wgLang->formatNum( $result->length ) );
63
64 if ( $u == 0 ) { # not by a logged-in user
65 $ul = $ut;
66 }
67 else {
68 $ul = $skin->makeLink( $wgContLang->getNsText(NS_USER) . ":{$ut}", $ut );
69 }
70
71 $d = $wgLang->timeanddate( $result->timestamp, true );
72
73 # Since there is no diff link, we need to give users a way to
74 # mark the article as patrolled if it isn't already
75 if ( $wgUseRCPatrol && !is_null ( $result->usepatrol ) && $result->usepatrol &&
76 $result->patrolled == 0 && $wgUser->isLoggedIn() &&
77 ( $wgUser->isAllowed('patrol') || !$wgOnlySysopsCanPatrol ) )
78 $link = $skin->makeKnownLink( $result->title, '', "rcid={$result->rcid}" );
79 else
80 $link = $skin->makeKnownLink( $result->title, '' );
81
82 $s = "{$d} {$link} ({$length}) . . {$ul}";
83
84 $s .= $skin->commentBlock( $result->comment );
85
86 return $s;
87 }
88
89 function feedItemDesc( $row ) {
90 if( isset( $row->rev_id ) ) {
91 $revision = Revision::newFromId( $row->rev_id );
92 if( $revision ) {
93 return '<p>' . htmlspecialchars( wfMsg( 'summary' ) ) . ': ' . $text . "</p>\n<hr />\n<div>" .
94 nl2br( htmlspecialchars( $revision->getText() ) ) . "</div>";
95 }
96 }
97 return parent::feedItemDesc( $row );
98 }
99 }
100
101 /**
102 * constructor
103 */
104 function wfSpecialNewpages($par, $specialPage)
105 {
106 global $wgRequest;
107 list( $limit, $offset ) = wfCheckLimits();
108 if( $par ) {
109 $bits = preg_split( '/\s*,\s*/', trim( $par ) );
110 foreach ( $bits as $bit ) {
111 if ( 'shownav' == $bit ) $shownavigation = 1;
112 if ( is_numeric( $bit ) ) {
113 $limit = $bit;
114 }
115
116 if ( preg_match( '/^limit=(\d+)$/', $bit, $m ) ) {
117 $limit = intval($m[1]);
118 }
119 if ( preg_match( '/^offset=(\d+)$/', $bit, $m ) ) {
120 $offset = intval($m[1]);
121 }
122 }
123 }
124 if(!isset($shownavigation)) {
125 $shownavigation=!$specialPage->including();
126 }
127
128 $npp = new NewPagesPage();
129
130 if( !$npp->doFeed( $wgRequest->getVal( 'feed' ) ) ) {
131 $npp->doQuery( $offset, $limit, $shownavigation );
132 }
133 }
134
135 ?>