Show links to user page, talk page and contributions page on Special:Newpages
[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 formatResult( $skin, $result ) {
62 global $wgLang, $wgContLang, $wgUser, $wgUseRCPatrol;
63 $u = $result->user;
64 $ut = $result->user_text;
65
66 $length = wfMsg( 'nbytes', $wgLang->formatNum( $result->length ) );
67
68 $userLink = $skin->makeLinkObj( Title::makeTitle( NS_USER, $ut ), htmlspecialchars( $ut ) );
69 $talkLink = $skin->makeLinkObj( Title::makeTitle( NS_USER_TALK, $ut ), $wgLang->getNsText( NS_TALK ) );
70 $contLink = $skin->makeLinkObj( Title::makeTitle( NS_SPECIAL, 'Contributions' ), wfMsg( 'contribslink' ), 'target=' . urlencode( $ut ) );
71 $userTools = "$userLink ($talkLink | $contLink)";
72
73 $d = $wgLang->timeanddate( $result->timestamp, true );
74
75 # Since there is no diff link, we need to give users a way to
76 # mark the article as patrolled if it isn't already
77 $ns = $wgContLang->getNsText( $result->namespace );
78 if( $wgUseRCPatrol && !is_null( $result->usepatrol ) && $result->usepatrol && $result->patrolled == 0 && $wgUser->isAllowed( 'patrol' ) ) {
79 $link = $skin->makeKnownLink( $ns . ':' . $result->title, '', "rcid={$result->rcid}" );
80 } else {
81 $link = $skin->makeKnownLink( $ns . ':' . $result->title, '' );
82 }
83
84 $s = "{$d} {$link} ({$length}) . . {$userTools}";
85 $s .= $skin->commentBlock( $result->comment );
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 global $wgRequest, $wgContLang;
106
107 list( $limit, $offset ) = wfCheckLimits();
108 $namespace = NS_MAIN;
109
110 if ( $par ) {
111 $bits = preg_split( '/\s*,\s*/', trim( $par ) );
112 foreach ( $bits as $bit ) {
113 if ( 'shownav' == $bit )
114 $shownavigation = true;
115 if ( is_numeric( $bit ) )
116 $limit = $bit;
117
118 if ( preg_match( '/^limit=(\d+)$/', $bit, $m ) )
119 $limit = intval($m[1]);
120 if ( preg_match( '/^offset=(\d+)$/', $bit, $m ) )
121 $offset = intval($m[1]);
122 if ( preg_match( '/^namespace=(.*)$/', $bit, $m ) ) {
123 $ns = $wgContLang->getNsIndex( $m[1] );
124 if( $ns !== false ) {
125 $namespace = $ns;
126 }
127 }
128 }
129 }
130 if ( ! isset( $shownavigation ) )
131 $shownavigation = ! $specialPage->including();
132
133 $npp = new NewPagesPage( $namespace );
134
135 if ( ! $npp->doFeed( $wgRequest->getVal( 'feed' ) ) )
136 $npp->doQuery( $offset, $limit, $shownavigation );
137 }
138
139 ?>