4 * This is to display changes made to all articles linked in an article.
7 class SpecialRecentchangeslinked
extends SpecialRecentchanges
{
10 function __construct(){
11 SpecialPage
::SpecialPage( 'Recentchangeslinked' );
12 $this->includable( true );
15 public function getDefaultOptions() {
16 $opts = parent
::getDefaultOptions();
17 $opts->add( 'target', '' );
18 $opts->add( 'showlinkedto', false );
19 $opts->add( 'tagfilter', '' );
23 public function parseParameters( $par, FormOptions
$opts ) {
24 $opts['target'] = $par;
27 public function feedSetup() {
29 $opts = parent
::feedSetup();
30 $opts['target'] = $wgRequest->getVal( 'target' );
34 public function getFeedObject( $feedFormat ){
35 $feed = new ChangesFeed( $feedFormat, false );
36 $feedObj = $feed->getFeedObject(
37 wfMsgForContent( 'recentchangeslinked-title', $this->getTargetTitle()->getPrefixedText() ),
38 wfMsgForContent( 'recentchangeslinked-feed' )
40 return array( $feed, $feedObj );
43 public function doMainQuery( $conds, $opts ) {
44 global $wgUser, $wgOut;
46 $target = $opts['target'];
47 $showlinkedto = $opts['showlinkedto'];
48 $limit = $opts['limit'];
50 if ( $target === '' ) {
53 $title = Title
::newFromURL( $target );
54 if( !$title ||
$title->getInterwiki() != '' ){
55 $wgOut->wrapWikiMsg( "<div class=\"errorbox\">\n$1</div><br style=\"clear: both\" />", 'allpagesbadtitle' );
59 $wgOut->setPageTitle( wfMsg( 'recentchangeslinked-title', $title->getPrefixedText() ) );
62 * Ordinary links are in the pagelinks table, while transclusions are
63 * in the templatelinks table, categorizations in categorylinks and
64 * image use in imagelinks. We need to somehow combine all these.
65 * Special:Whatlinkshere does this by firing multiple queries and
66 * merging the results, but the code we inherit from our parent class
67 * expects only one result set so we use UNION instead.
70 $dbr = wfGetDB( DB_SLAVE
, 'recentchangeslinked' );
71 $id = $title->getArticleId();
72 $ns = $title->getNamespace();
73 $dbkey = $title->getDBkey();
75 $tables = array( 'recentchanges' );
76 $select = array( $dbr->tableName( 'recentchanges' ) . '.*' );
77 $join_conds = array();
78 $query_options = array();
80 // left join with watchlist table to highlight watched rows
81 if( $uid = $wgUser->getId() ) {
82 $tables[] = 'watchlist';
83 $select[] = 'wl_user';
84 $join_conds['watchlist'] = array( 'LEFT JOIN', "wl_user={$uid} AND wl_title=rc_title AND wl_namespace=rc_namespace" );
86 if ( $wgUser->isAllowed( 'rollback' ) ) {
88 $join_conds['page'] = array('LEFT JOIN', 'rc_cur_id=page_id');
89 $select[] = 'page_latest';
92 ChangeTags
::modifyDisplayQuery( $tables, $select, $conds, $join_conds,
93 $query_options, $opts['tagfilter'] );
95 // XXX: parent class does this, should we too?
96 // wfRunHooks('SpecialRecentChangesQuery', array( &$conds, &$tables, &$join_conds, $opts ) );
98 if( $ns == NS_CATEGORY
&& !$showlinkedto ) {
99 // special handling for categories
100 // XXX: should try to make this less klugy
101 $link_tables = array( 'categorylinks' );
102 $showlinkedto = true;
104 // for now, always join on these tables; really should be configurable as in whatlinkshere
105 $link_tables = array( 'pagelinks', 'templatelinks' );
106 // imagelinks only contains links to pages in NS_FILE
107 if( $ns == NS_FILE ||
!$showlinkedto ) $link_tables[] = 'imagelinks';
110 if( $id == 0 && !$showlinkedto )
111 return false; // nonexistent pages can't link to any pages
113 // field name prefixes for all the various tables we might want to join with
114 $prefix = array( 'pagelinks' => 'pl', 'templatelinks' => 'tl', 'categorylinks' => 'cl', 'imagelinks' => 'il' );
116 $subsql = array(); // SELECT statements to combine with UNION
118 foreach( $link_tables as $link_table ) {
119 $pfx = $prefix[$link_table];
121 // imagelinks and categorylinks tables have no xx_namespace field, and have xx_to instead of xx_title
122 if( $link_table == 'imagelinks' ) $link_ns = NS_FILE
;
123 else if( $link_table == 'categorylinks' ) $link_ns = NS_CATEGORY
;
126 if( $showlinkedto ) {
127 // find changes to pages linking to this page
129 if( $ns != $link_ns ) continue; // should never happen, but check anyway
130 $subconds = array( "{$pfx}_to" => $dbkey );
132 $subconds = array( "{$pfx}_namespace" => $ns, "{$pfx}_title" => $dbkey );
134 $subjoin = "rc_cur_id = {$pfx}_from";
136 // find changes to pages linked from this page
137 $subconds = array( "{$pfx}_from" => $id );
138 if( $link_table == 'imagelinks' ||
$link_table == 'categorylinks' ) {
139 $subconds["rc_namespace"] = $link_ns;
140 $subjoin = "rc_title = {$pfx}_to";
142 $subjoin = "rc_namespace = {$pfx}_namespace AND rc_title = {$pfx}_title";
146 if( $dbr->unionSupportsOrderAndLimit())
147 $order = array( 'ORDER BY' => 'rc_timestamp DESC' );
152 $query = $dbr->selectSQLText(
153 array_merge( $tables, array( $link_table ) ),
157 $order +
$query_options,
158 $join_conds +
array( $link_table => array( 'INNER JOIN', $subjoin ) )
161 if( $dbr->unionSupportsOrderAndLimit())
162 $query = $dbr->limitResult( $query, $limit );
167 if( count($subsql) == 0 )
168 return false; // should never happen
169 if( count($subsql) == 1 && $dbr->unionSupportsOrderAndLimit() )
172 // need to resort and relimit after union
173 $sql = $dbr->unionQueries($subsql, false).' ORDER BY rc_timestamp DESC';
174 $sql = $dbr->limitResult($sql, $limit, false);
177 $res = $dbr->query( $sql, __METHOD__
);
179 if( $res->numRows() == 0 )
180 $this->mResultEmpty
= true;
185 function getExtraOptions( $opts ){
186 $opts->consumeValues( array( 'showlinkedto', 'target', 'tagfilter' ) );
187 $extraOpts = array();
188 $extraOpts['namespace'] = $this->namespaceFilterForm( $opts );
189 $extraOpts['target'] = array( wfMsgHtml( 'recentchangeslinked-page' ),
190 Xml
::input( 'target', 40, str_replace('_',' ',$opts['target']) ) .
191 Xml
::check( 'showlinkedto', $opts['showlinkedto'], array('id' => 'showlinkedto') ) . ' ' .
192 Xml
::label( wfMsg("recentchangeslinked-to"), 'showlinkedto' ) );
193 $tagFilter = ChangeTags
::buildTagFilterSelector( $opts['tagfilter'] );
195 $extraOpts['tagfilter'] = $tagFilter;
199 function getTargetTitle() {
200 if ( $this->rclTargetTitle
=== null ) {
201 $opts = $this->getOptions();
202 if ( isset( $opts['target'] ) && $opts['target'] !== '' ) {
203 $this->rclTargetTitle
= Title
::newFromText( $opts['target'] );
205 $this->rclTargetTitle
= false;
208 return $this->rclTargetTitle
;
211 function setTopText( OutputPage
$out, FormOptions
$opts ) {
213 $skin = $wgUser->getSkin();
214 $target = $this->getTargetTitle();
216 $out->setSubtitle( wfMsg( 'recentchangeslinked-backlink', $skin->link( $target,
217 $target->getPrefixedText(), array(), array( 'redirect' => 'no' ) ) ) );
220 public function getFeedQuery() {
221 $target = $this->getTargetTitle();
223 return "target=" . urlencode( $target->getPrefixedDBkey() );
229 function setBottomText( OutputPage
$out, FormOptions
$opts ) {
230 if( isset( $this->mResultEmpty
) && $this->mResultEmpty
){
231 $out->addWikiMsg( 'recentchangeslinked-noresult' );