* Add form to RCLinked and add to sp:specialpages
[lhc/web/wiklou.git] / includes / SpecialRecentchangeslinked.php
1 <?php
2 /**
3 * This is to display changes made to all articles linked in an article.
4 * @addtogroup SpecialPage
5 */
6
7 /**
8 *
9 */
10 require_once( 'SpecialRecentchanges.php' );
11
12 /**
13 * Entrypoint
14 * @param string $par parent page we will look at
15 */
16 function wfSpecialRecentchangeslinked( $par = NULL ) {
17 global $wgUser, $wgOut, $wgLang, $wgContLang, $wgRequest, $wgTitle, $wgScript;
18 $fname = 'wfSpecialRecentchangeslinked';
19
20 $days = $wgRequest->getInt( 'days' );
21 $target = isset($par) ? $par : $wgRequest->getText( 'target' );
22 $hideminor = $wgRequest->getBool( 'hideminor' ) ? 1 : 0;
23
24 $wgOut->setPagetitle( wfMsg( 'recentchangeslinked' ) );
25 $sk = $wgUser->getSkin();
26
27 $wgOut->addHTML(
28 Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) ) .
29 Xml::openElement( 'fieldset' ) .
30 Xml::element( 'legend', array(), wfMsg( 'recentchangeslinked' ) ) . "\n" .
31 Xml::inputLabel( wfMsg( 'recentchangeslinked-page' ), 'target', 'recentchangeslinked-target', 40, $target ) .
32 Xml::hidden( 'title', $wgTitle->getPrefixedText() ). "\n" .
33 Xml::submitButton( wfMsg( 'allpagessubmit' ) ) . "\n" .
34 Xml::closeElement( 'fieldset' ) .
35 Xml::closeElement( 'form' ) . "\n"
36 );
37
38 if ( !$target ) {
39 return;
40 }
41 $nt = Title::newFromURL( $target );
42 if( !$nt ) {
43 $wgOut->showErrorPage( 'notargettitle', 'notargettext' );
44 return;
45 }
46 $id = $nt->getArticleId();
47
48 $wgOut->setPageTitle( wfMsg( 'recentchangeslinked-title', $nt->getPrefixedText() ) );
49 $wgOut->setSyndicated();
50 $wgOut->setFeedAppendQuery( "target=" . urlencode( $target ) );
51
52 if ( ! $days ) {
53 $days = (int)$wgUser->getOption( 'rcdays', 7 );
54 }
55 list( $limit, /* offset */ ) = wfCheckLimits( 100, 'rclimit' );
56
57 $dbr = wfGetDB( DB_SLAVE,'recentchangeslinked' );
58 $cutoff = $dbr->timestamp( time() - ( $days * 86400 ) );
59
60 $hideminor = ($hideminor ? 1 : 0);
61 if ( $hideminor ) {
62 $mlink = $sk->makeKnownLink( $wgContLang->specialPage( 'Recentchangeslinked' ),
63 wfMsg( 'show' ), 'target=' . htmlspecialchars( $nt->getPrefixedURL() ) .
64 "&days={$days}&limit={$limit}&hideminor=0" );
65 } else {
66 $mlink = $sk->makeKnownLink( $wgContLang->specialPage( "Recentchangeslinked" ),
67 wfMsg( "hide" ), "target=" . htmlspecialchars( $nt->getPrefixedURL() ) .
68 "&days={$days}&limit={$limit}&hideminor=1" );
69 }
70 if ( $hideminor ) {
71 $cmq = 'AND rc_minor=0';
72 } else { $cmq = ''; }
73
74 list($recentchanges, $categorylinks, $pagelinks, $watchlist) =
75 $dbr->tableNamesN( 'recentchanges', 'categorylinks', 'pagelinks', "watchlist" );
76
77 $uid = $wgUser->getID();
78
79 $GROUPBY = "
80 GROUP BY rc_cur_id,rc_namespace,rc_title,
81 rc_user,rc_comment,rc_user_text,rc_timestamp,rc_minor,rc_log_type,rc_log_action,rc_params,rc_deleted,
82 rc_new, rc_id, rc_this_oldid, rc_last_oldid, rc_bot, rc_patrolled, rc_type, rc_old_len, rc_new_len
83 " . ($uid ? ",wl_user" : "") . "
84 ORDER BY rc_timestamp DESC
85 LIMIT {$limit}";
86
87 // If target is a Category, use categorylinks and invert from and to
88 if( $nt->getNamespace() == NS_CATEGORY ) {
89 $catkey = $dbr->addQuotes( $nt->getDBkey() );
90 $sql = "SELECT /* wfSpecialRecentchangeslinked */
91 rc_id,
92 rc_cur_id,
93 rc_namespace,
94 rc_title,
95 rc_this_oldid,
96 rc_last_oldid,
97 rc_user,
98 rc_comment,
99 rc_user_text,
100 rc_timestamp,
101 rc_minor,
102 rc_bot,
103 rc_new,
104 rc_patrolled,
105 rc_type,
106 rc_old_len,
107 rc_new_len,
108 rc_log_type,
109 rc_log_action,
110 rc_params,
111 rc_deleted
112 " . ($uid ? ",wl_user" : "") . "
113 FROM $categorylinks, $recentchanges
114 " . ($uid ? "LEFT OUTER JOIN $watchlist ON wl_user={$uid} AND wl_title=rc_title AND wl_namespace=rc_namespace " : "") . "
115 WHERE rc_timestamp > '{$cutoff}'
116 {$cmq}
117 AND cl_from=rc_cur_id
118 AND cl_to=$catkey
119 $GROUPBY
120 ";
121 } else {
122 $sql =
123 "SELECT /* wfSpecialRecentchangeslinked */
124 rc_id,
125 rc_cur_id,
126 rc_namespace,
127 rc_title,
128 rc_user,
129 rc_comment,
130 rc_user_text,
131 rc_this_oldid,
132 rc_last_oldid,
133 rc_timestamp,
134 rc_minor,
135 rc_bot,
136 rc_new,
137 rc_patrolled,
138 rc_type,
139 rc_old_len,
140 rc_new_len,
141 rc_log_type,
142 rc_log_action,
143 rc_params,
144 rc_deleted
145 " . ($uid ? ",wl_user" : "") . "
146 FROM $pagelinks, $recentchanges
147 " . ($uid ? " LEFT OUTER JOIN $watchlist ON wl_user={$uid} AND wl_title=rc_title AND wl_namespace=rc_namespace " : "") . "
148 WHERE rc_timestamp > '{$cutoff}'
149 {$cmq}
150 AND pl_namespace=rc_namespace
151 AND pl_title=rc_title
152 AND pl_from=$id
153 $GROUPBY
154 ";
155 }
156 $res = $dbr->query( $sql, $fname );
157
158 $wgOut->addHTML("&lt; ".$sk->makeLinkObj($nt, "", "redirect=no" )."<br />\n");
159 $note = wfMsgExt( "rcnote", array ( 'parseinline' ), $limit, $days, $wgLang->timeAndDate( wfTimestampNow(), true ) );
160 $wgOut->addHTML( "<hr />\n{$note}\n<br />" );
161
162 $note = rcDayLimitlinks( $days, $limit, "Recentchangeslinked",
163 "target=" . $nt->getPrefixedURL() . "&hideminor={$hideminor}",
164 false, $mlink );
165
166 $wgOut->addHTML( $note."\n" );
167
168 $list = ChangesList::newFromUser( $wgUser );
169 $s = $list->beginRecentChangesList();
170 $count = $dbr->numRows( $res );
171
172 $rchanges = array();
173 if ( $count ) {
174 $counter = 1;
175 while ( $limit ) {
176 if ( 0 == $count ) { break; }
177 $obj = $dbr->fetchObject( $res );
178 --$count;
179 $rc = RecentChange::newFromRow( $obj );
180 $rc->counter = $counter++;
181 $s .= $list->recentChangesLine( $rc , !empty( $obj->wl_user) );
182 --$limit;
183 $rchanges[] = $obj;
184 }
185 } else {
186 $wgOut->addWikiMsg('recentchangeslinked-noresult');
187 }
188 $s .= $list->endRecentChangesList();
189
190 $dbr->freeResult( $res );
191 $wgOut->addHTML( $s );
192
193 global $wgSitename, $wgFeedClasses, $wgContLanguageCode;
194 $feedFormat = $wgRequest->getVal( 'feed' );
195 if( $feedFormat && isset( $wgFeedClasses[$feedFormat] ) ) {
196 $feedTitle = $wgSitename . ' - ' . wfMsgForContent( 'recentchangeslinked-title', $nt->getPrefixedText() ) . ' [' . $wgContLanguageCode . ']';
197 $feed = new $wgFeedClasses[$feedFormat]( $feedTitle,
198 htmlspecialchars( wfMsgForContent('recentchangeslinked') ), $wgTitle->getFullUrl() );
199
200 require_once( "SpecialRecentchanges.php" );
201 $wgOut->disable();
202 rcDoOutputFeed( $rchanges, $feed );
203 }
204 }
205
206