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