2b00ef3f8f963c60bd5b0d3d83fb156e7390cece
[lhc/web/wiklou.git] / includes / specials / SpecialRecentchangeslinked.php
1 <?php
2
3 /**
4 * This is to display changes made to all articles linked in an article.
5 * @ingroup SpecialPage
6 */
7 class SpecialRecentchangeslinked extends SpecialRecentchanges {
8
9 function __construct(){
10 SpecialPage::SpecialPage( 'Recentchangeslinked' );
11 }
12
13 public function getDefaultOptions() {
14 $opts = parent::getDefaultOptions();
15 $opts->add( 'target', '' );
16 $opts->add( 'showlinkedto', false );
17 return $opts;
18 }
19
20 public function parseParameters( $par, FormOptions $opts ) {
21 $opts['target'] = $par;
22 }
23
24 public function feedSetup(){
25 global $wgRequest;
26 $opts = parent::feedSetup();
27 $opts['target'] = $wgRequest->getVal( 'target' );
28 return $opts;
29 }
30
31 public function getFeedObject( $feedFormat ){
32 $feed = new ChangesFeed( $feedFormat, false );
33 $feedObj = $feed->getFeedObject(
34 wfMsgForContent( 'recentchangeslinked-title', $this->mTargetTitle->getPrefixedText() ),
35 wfMsgForContent( 'recentchangeslinked' )
36 );
37 return array( $feed, $feedObj );
38 }
39
40 public function doMainQuery( $conds, $opts ) {
41 global $wgUser, $wgOut;
42
43 $target = $opts['target'];
44 $showlinkedto = $opts['showlinkedto'];
45 $limit = $opts['limit'];
46
47 if ( $target === '' ) {
48 return false;
49 }
50 $title = Title::newFromURL( $target );
51 if( !$title || $title->getInterwiki() != '' ){
52 global $wgOut;
53 $wgOut->wrapWikiMsg( '<div class="errorbox">$1</div><br clear="both" />', 'allpagesbadtitle' );
54 return false;
55 }
56 $this->mTargetTitle = $title;
57
58 $wgOut->setPageTitle( wfMsg( 'recentchangeslinked-title', $title->getPrefixedText() ) );
59
60 $dbr = wfGetDB( DB_SLAVE, 'recentchangeslinked' );
61 $id = $title->getArticleId();
62
63 $tables = array( 'recentchanges' );
64 $select = array( $dbr->tableName( 'recentchanges' ) . '.*' );
65 $join_conds = array();
66
67 if( $title->getNamespace() == NS_CATEGORY ) {
68 $tables[] = 'categorylinks';
69 $conds['cl_to'] = $title->getDBkey();
70 $join_conds['categorylinks'] = array( 'LEFT JOIN', 'cl_from=rc_cur_id' );
71 } else {
72 if( $showlinkedto ) {
73 if( $title->getNamespace() == NS_TEMPLATE ){
74 $tables[] = 'templatelinks';
75 $conds['tl_namespace'] = $title->getNamespace();
76 $conds['tl_title'] = $title->getDBkey();
77 $join_conds['templatelinks'] = array( 'LEFT JOIN', 'tl_from=rc_cur_id' );
78 } else {
79 $tables[] = 'pagelinks';
80 $conds['pl_namespace'] = $title->getNamespace();
81 $conds['pl_title'] = $title->getDBkey();
82 $join_conds['pagelinks'] = array( 'LEFT JOIN', 'pl_from=rc_cur_id' );
83 }
84 } else {
85 $tables[] = 'pagelinks';
86 $conds['pl_from'] = $id;
87 $join_conds['pagelinks'] = array( 'LEFT JOIN', 'pl_namespace = rc_namespace AND pl_title = rc_title' );
88 }
89 }
90
91 if( $uid = $wgUser->getId() ) {
92 $tables[] = 'watchlist';
93 $join_conds['watchlist'] = array( 'LEFT JOIN', "wl_user={$uid} AND wl_title=rc_title AND wl_namespace=rc_namespace" );
94 $select[] = 'wl_user';
95 }
96
97 $res = $dbr->select( $tables, $select, $conds, __METHOD__,
98 array( 'ORDER BY' => 'rc_timestamp DESC', 'LIMIT' => $limit ), $join_conds );
99
100 if( $dbr->numRows( $res ) == 0 )
101 $this->mResultEmpty = true;
102
103 return $res;
104 }
105
106 function getExtraOptions( $opts ){
107 $opts->consumeValues( array( 'showlinkedto', 'target' ) );
108 $extraOpts = array();
109 $extraOpts['namespace'] = $this->namespaceFilterForm( $opts );
110 $extraOpts['target'] = array( wfMsg( 'recentchangeslinked-page' ),
111 Xml::input( 'target', 40, $opts['target'] ) .
112 Xml::check( 'showlinkedto', $opts['showlinkedto'], array('id' => 'showlinkedto') ) . ' ' .
113 Xml::label( wfMsg("recentchangeslinked-to"), 'showlinkedto' ) );
114 $extraOpts['submit'] = Xml::submitbutton( wfMsg('allpagessubmit') );
115 return $extraOpts;
116 }
117
118 function setTopText( &$out, $opts ){}
119
120 function setBottomText( &$out, $opts ){
121 if( isset( $this->mTargetTitle ) && is_object( $this->mTargetTitle ) ){
122 global $wgUser;
123 $out->setFeedAppendQuery( "target=" . urlencode( $this->mTargetTitle->getPrefixedDBkey() ) );
124 $out->addHTML("&lt; ".$wgUser->getSkin()->makeLinkObj( $this->mTargetTitle, "", "redirect=no" )."<hr />\n");
125 }
126 if( isset( $this->mResultEmpty ) && $this->mResultEmpty ){
127 $out->addWikiMsg( 'recentchangeslinked-noresult' );
128 }
129 }
130 }