Add the other existing $skin.css/.js to the message files too to be consistent
[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 * @file
5 * @ingroup SpecialPage
6 */
7
8 /**
9 *
10 */
11 require_once( 'SpecialRecentchanges.php' );
12
13 /**
14 * Entrypoint
15 * @param string $par parent page we will look at
16 */
17 function wfSpecialRecentchangeslinked( $par = NULL ) {
18 global $wgUser, $wgOut, $wgLang, $wgContLang, $wgRequest, $wgTitle, $wgScript;
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 // The fields we are selecting
87 $fields = "rc_cur_id,rc_namespace,rc_title,
88 rc_user,rc_comment,rc_user_text,rc_timestamp,rc_minor,rc_log_type,rc_log_action,rc_params,rc_deleted,
89 rc_new, rc_id, rc_this_oldid, rc_last_oldid, rc_bot, rc_patrolled, rc_type, rc_old_len, rc_new_len";
90 $fields .= $uid ? ",wl_user" : "";
91
92 // Check if this should be a feed
93 $feed = false;
94 global $wgSitename, $wgFeedClasses, $wgContLanguageCode, $wgFeedLimit;
95 $feedFormat = $wgRequest->getVal( 'feed' );
96 if( $feedFormat && isset( $wgFeedClasses[$feedFormat] ) ) {
97 $feedTitle = $wgSitename . ' - ' . wfMsgForContent( 'recentchangeslinked-title', $nt->getPrefixedText() ) .
98 ' [' . $wgContLanguageCode . ']';
99 $feed = new $wgFeedClasses[$feedFormat]( $feedTitle,
100 htmlspecialchars( wfMsgForContent('recentchangeslinked') ), $wgTitle->getFullUrl() );
101 # Sanity check
102 if( $limit > $wgFeedLimit ) {
103 $limit = $wgFeedLimit;
104 }
105 }
106
107 // If target is a Category, use categorylinks and invert from and to
108 if( $nt->getNamespace() == NS_CATEGORY ) {
109 $catkey = $dbr->addQuotes( $nt->getDBkey() );
110 # The table clauses
111 $tables = "$categorylinks, $recentchanges";
112 $tables .= $uid ? " LEFT JOIN $watchlist ON wl_user={$uid} AND wl_title=rc_title AND wl_namespace=rc_namespace " : "";
113
114 $sql = "SELECT /* wfSpecialRecentchangeslinked */ $fields FROM $tables
115 WHERE rc_timestamp > '{$cutoff}' {$cmq}
116 AND cl_from=rc_cur_id
117 AND cl_to=$catkey
118 GROUP BY $fields ORDER BY rc_timestamp DESC LIMIT {$limit}"; // Shitty-ass GROUP BY by for postgres apparently
119 } else {
120 if( $showlinkedto ) {
121 $ns = $dbr->addQuotes( $nt->getNamespace() );
122 $dbkey = $dbr->addQuotes( $nt->getDBkey() );
123 $joinConds = "AND pl_namespace={$ns} AND pl_title={$dbkey} AND pl_from=rc_cur_id";
124 } else {
125 $joinConds = "AND pl_namespace=rc_namespace AND pl_title=rc_title AND pl_from=$id";
126 }
127 # The table clauses
128 $tables = "$pagelinks, $recentchanges";
129 $tables .= $uid ? " LEFT JOIN $watchlist ON wl_user={$uid} AND wl_title=rc_title AND wl_namespace=rc_namespace " : "";
130
131 $sql = "SELECT /* wfSpecialRecentchangeslinked */ $fields FROM $tables
132 WHERE rc_timestamp > '{$cutoff}' {$cmq}
133 {$joinConds}
134 GROUP BY $fields ORDER BY rc_timestamp DESC LIMIT {$limit}"; // Shitty-ass GROUP BY by for postgres apparently
135 }
136 # Actually do the query
137 $res = $dbr->query( $sql, __METHOD__ );
138 $count = $dbr->numRows( $res );
139 $rchanges = array();
140 # Output feeds now and be done with it!
141 if( $feed ) {
142 if( $count ) {
143 $counter = 1;
144 while ( $limit ) {
145 if ( 0 == $count ) { break; }
146 $obj = $dbr->fetchObject( $res );
147 --$count;
148 $rc = RecentChange::newFromRow( $obj );
149 $rc->counter = $counter++;
150 --$limit;
151 $rchanges[] = $obj;
152 }
153 }
154 require_once( "SpecialRecentchanges.php" );
155 $wgOut->disable();
156 rcDoOutputFeed( $rchanges, $feed );
157 return;
158 }
159
160 # Otherwise, carry on with regular output...
161 $wgOut->addHTML("&lt; ".$sk->makeLinkObj($nt, "", "redirect=no" )."<br />\n");
162 $note = wfMsgExt( "rcnote", array ( 'parseinline' ), $limit, $days, $wgLang->timeAndDate( wfTimestampNow(), true ) );
163 $wgOut->addHTML( "<hr />\n{$note}\n<br />" );
164
165 $note = rcDayLimitlinks( $days, $limit, "Recentchangeslinked",
166 "target=" . $nt->getPrefixedURL() . "&hideminor={$hideminor}&showlinkedto={$showlinkedto}",
167 false, $mlink );
168
169 $wgOut->addHTML( $note."\n" );
170
171 $list = ChangesList::newFromUser( $wgUser );
172 $s = $list->beginRecentChangesList();
173
174 if ( $count ) {
175 $counter = 1;
176 while ( $limit ) {
177 if ( 0 == $count ) { break; }
178 $obj = $dbr->fetchObject( $res );
179 --$count;
180 $rc = RecentChange::newFromRow( $obj );
181 $rc->counter = $counter++;
182 $s .= $list->recentChangesLine( $rc , !empty( $obj->wl_user) );
183 --$limit;
184 }
185 } else {
186 $wgOut->addWikiMsg('recentchangeslinked-noresult');
187 }
188 $s .= $list->endRecentChangesList();
189
190 $dbr->freeResult( $res );
191 $wgOut->addHTML( $s );
192 }