]> scripts.mit.edu Git - autoinstalls/mediawiki.git/blob - includes/SpecialRecentchangeslinked.php
MediaWiki 1.11.0
[autoinstalls/mediawiki.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;
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         if (is_null($target)) {
28                 $wgOut->errorpage( 'notargettitle', 'notargettext' );
29                 return;
30         }
31         $nt = Title::newFromURL( $target );
32         if( !$nt ) {
33                 $wgOut->errorpage( 'notargettitle', 'notargettext' );
34                 return;
35         }
36         $id = $nt->getArticleId();
37
38         $wgOut->setPageTitle( wfMsg( 'recentchangeslinked-title', $nt->getPrefixedText() ) );
39         $wgOut->setSubtitle( htmlspecialchars( wfMsg( 'rclsub', $nt->getPrefixedText() ) ) );
40
41         if ( ! $days ) {
42                 $days = (int)$wgUser->getOption( 'rcdays', 7 );
43         }
44         list( $limit, /* offset */ ) = wfCheckLimits( 100, 'rclimit' );
45
46         $dbr = wfGetDB( DB_SLAVE,'recentchangeslinked' );
47         $cutoff = $dbr->timestamp( time() - ( $days * 86400 ) );
48
49         $hideminor = ($hideminor ? 1 : 0);
50         if ( $hideminor ) {
51                 $mlink = $sk->makeKnownLink( $wgContLang->specialPage( 'Recentchangeslinked' ),
52                   wfMsg( 'show' ), 'target=' . htmlspecialchars( $nt->getPrefixedURL() ) .
53                   "&days={$days}&limit={$limit}&hideminor=0" );
54         } else {
55                 $mlink = $sk->makeKnownLink( $wgContLang->specialPage( "Recentchangeslinked" ),
56                   wfMsg( "hide" ), "target=" . htmlspecialchars( $nt->getPrefixedURL() ) .
57                   "&days={$days}&limit={$limit}&hideminor=1" );
58         }
59         if ( $hideminor ) {
60                 $cmq = 'AND rc_minor=0';
61         } else { $cmq = ''; }
62
63         list($recentchanges, $categorylinks, $pagelinks, $watchlist) = 
64             $dbr->tableNamesN( 'recentchanges', 'categorylinks', 'pagelinks', "watchlist" );
65
66         $uid = $wgUser->getID();
67
68         $GROUPBY = "
69         GROUP BY rc_cur_id,rc_namespace,rc_title,
70                 rc_user,rc_comment,rc_user_text,rc_timestamp,rc_minor,rc_deleted,
71                 rc_new, rc_id, rc_this_oldid, rc_last_oldid, rc_bot, rc_patrolled, rc_type, rc_old_len, rc_new_len
72 " . ($uid ? ",wl_user" : "") . "
73                 ORDER BY rc_timestamp DESC
74         LIMIT {$limit}";
75
76         // If target is a Category, use categorylinks and invert from and to
77         if( $nt->getNamespace() == NS_CATEGORY ) {
78                 $catkey = $dbr->addQuotes( $nt->getDBKey() );
79                 $sql = "SELECT /* wfSpecialRecentchangeslinked */
80                                 rc_id,
81                                 rc_cur_id,
82                                 rc_namespace,
83                                 rc_title,
84                                 rc_this_oldid,
85                                 rc_last_oldid,
86                                 rc_user,
87                                 rc_comment,
88                                 rc_user_text,
89                                 rc_timestamp,
90                                 rc_minor,
91                                 rc_bot,
92                                 rc_new,
93                                 rc_patrolled,
94                                 rc_type,
95                                 rc_old_len,
96                                 rc_new_len,
97                                 rc_deleted
98 " . ($uid ? ",wl_user" : "") . "
99             FROM $categorylinks, $recentchanges
100 " . ($uid ? "LEFT OUTER JOIN $watchlist ON wl_user={$uid} AND wl_title=rc_title AND wl_namespace=rc_namespace " : "") . "
101            WHERE rc_timestamp > '{$cutoff}'
102              {$cmq}
103              AND cl_from=rc_cur_id
104              AND cl_to=$catkey
105 $GROUPBY
106  ";
107         } else {
108                 $sql =
109 "SELECT /* wfSpecialRecentchangeslinked */
110                         rc_id,
111                         rc_cur_id,
112                         rc_namespace,
113                         rc_title,
114                         rc_user,
115                         rc_comment,
116                         rc_user_text,
117                         rc_this_oldid,
118                         rc_last_oldid,
119                         rc_timestamp,
120                         rc_minor,
121                         rc_bot,
122                         rc_new,
123                         rc_patrolled,
124                         rc_type,
125                         rc_old_len,
126                         rc_new_len,
127                         rc_deleted
128 " . ($uid ? ",wl_user" : "") . "
129    FROM $pagelinks, $recentchanges
130 " . ($uid ? " LEFT OUTER JOIN $watchlist ON wl_user={$uid} AND wl_title=rc_title AND wl_namespace=rc_namespace " : "") . "
131    WHERE rc_timestamp > '{$cutoff}'
132         {$cmq}
133      AND pl_namespace=rc_namespace
134      AND pl_title=rc_title
135      AND pl_from=$id
136 $GROUPBY
137 ";
138         }
139         $res = $dbr->query( $sql, $fname );
140
141         $wgOut->addHTML("&lt; ".$sk->makeLinkObj($nt, "", "redirect=no" )."<br />\n");
142         $note = wfMsgExt( "rcnote", array ( 'parseinline' ), $limit, $days, $wgLang->timeAndDate( wfTimestampNow(), true ) );
143         $wgOut->addHTML( "<hr />\n{$note}\n<br />" );
144
145         $note = rcDayLimitlinks( $days, $limit, "Recentchangeslinked",
146                                  "target=" . $nt->getPrefixedURL() . "&hideminor={$hideminor}",
147                                  false, $mlink );
148
149         $wgOut->addHTML( $note."\n" );
150
151         $list = ChangesList::newFromUser( $wgUser );
152         $s = $list->beginRecentChangesList();
153         $count = $dbr->numRows( $res );
154
155         if ( $count ) {
156                 $counter = 1;
157                 while ( $limit ) {
158                         if ( 0 == $count ) { break; }
159                         $obj = $dbr->fetchObject( $res );
160                         --$count;
161                         $rc = RecentChange::newFromRow( $obj );
162                         $rc->counter = $counter++;
163                         $s .= $list->recentChangesLine( $rc , !empty( $obj->wl_user) );
164                         --$limit;
165                 }
166         } else {
167                 $wgOut->addWikiText( wfMsg('recentchangeslinked-noresult') );
168         }
169         $s .= $list->endRecentChangesList();
170
171         $dbr->freeResult( $res );
172         $wgOut->addHTML( $s );
173 }
174
175