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