00001 <?php
00002
00007 class SpecialRecentchangeslinked extends SpecialRecentchanges {
00008
00009 function __construct(){
00010 SpecialPage::SpecialPage( 'Recentchangeslinked' );
00011 $this->includable( true );
00012 }
00013
00014 public function getDefaultOptions() {
00015 $opts = parent::getDefaultOptions();
00016 $opts->add( 'target', '' );
00017 $opts->add( 'showlinkedto', false );
00018 $opts->add( 'tagfilter', '' );
00019 return $opts;
00020 }
00021
00022 public function parseParameters( $par, FormOptions $opts ) {
00023 $opts['target'] = $par;
00024 }
00025
00026 public function feedSetup() {
00027 global $wgRequest;
00028 $opts = parent::feedSetup();
00029 # Feed is cached on limit,hideminor,target; other params would randomly not work
00030 $opts['target'] = $wgRequest->getVal( 'target' );
00031 return $opts;
00032 }
00033
00034 public function getFeedObject( $feedFormat ){
00035 $feed = new ChangesFeed( $feedFormat, false );
00036 $feedObj = $feed->getFeedObject(
00037 wfMsgForContent( 'recentchangeslinked-title', $this->mTargetTitle->getPrefixedText() ),
00038 wfMsgForContent( 'recentchangeslinked' )
00039 );
00040 return array( $feed, $feedObj );
00041 }
00042
00043 public function doMainQuery( $conds, $opts ) {
00044 global $wgUser, $wgOut;
00045
00046 $target = $opts['target'];
00047 $showlinkedto = $opts['showlinkedto'];
00048 $limit = $opts['limit'];
00049
00050 if ( $target === '' ) {
00051 return false;
00052 }
00053 $title = Title::newFromURL( $target );
00054 if( !$title || $title->getInterwiki() != '' ){
00055 $wgOut->wrapWikiMsg( '<div class="errorbox">$1</div><br clear="both" />', 'allpagesbadtitle' );
00056 return false;
00057 }
00058 $this->mTargetTitle = $title;
00059
00060 $wgOut->setPageTitle( wfMsg( 'recentchangeslinked-title', $title->getPrefixedText() ) );
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071 $dbr = wfGetDB( DB_SLAVE, 'recentchangeslinked' );
00072 $id = $title->getArticleId();
00073 $ns = $title->getNamespace();
00074 $dbkey = $title->getDBkey();
00075
00076 $tables = array( 'recentchanges' );
00077 $select = array( $dbr->tableName( 'recentchanges' ) . '.*' );
00078 $join_conds = array();
00079 $query_options = array();
00080
00081
00082 if( $uid = $wgUser->getId() ) {
00083 $tables[] = 'watchlist';
00084 $select[] = 'wl_user';
00085 $join_conds['watchlist'] = array( 'LEFT JOIN', "wl_user={$uid} AND wl_title=rc_title AND wl_namespace=rc_namespace" );
00086 }
00087
00088 ChangeTags::modifyDisplayQuery( $tables, $select, $conds, $join_conds,
00089 $query_options, $opts['tagfilter'] );
00090
00091
00092
00093
00094 if( $ns == NS_CATEGORY && !$showlinkedto ) {
00095
00096
00097 $link_tables = array( 'categorylinks' );
00098 $showlinkedto = true;
00099 } else {
00100
00101 $link_tables = array( 'pagelinks', 'templatelinks' );
00102
00103 if( $ns == NS_FILE || !$showlinkedto ) $link_tables[] = 'imagelinks';
00104 }
00105
00106 if( $id == 0 && !$showlinkedto )
00107 return false;
00108
00109
00110 $prefix = array( 'pagelinks' => 'pl', 'templatelinks' => 'tl', 'categorylinks' => 'cl', 'imagelinks' => 'il' );
00111
00112 $subsql = array();
00113
00114 foreach( $link_tables as $link_table ) {
00115 $pfx = $prefix[$link_table];
00116
00117
00118 if( $link_table == 'imagelinks' ) $link_ns = NS_FILE;
00119 else if( $link_table == 'categorylinks' ) $link_ns = NS_CATEGORY;
00120 else $link_ns = 0;
00121
00122 if( $showlinkedto ) {
00123
00124 if( $link_ns ) {
00125 if( $ns != $link_ns ) continue;
00126 $subconds = array( "{$pfx}_to" => $dbkey );
00127 } else {
00128 $subconds = array( "{$pfx}_namespace" => $ns, "{$pfx}_title" => $dbkey );
00129 }
00130 $subjoin = "rc_cur_id = {$pfx}_from";
00131 } else {
00132
00133 $subconds = array( "{$pfx}_from" => $id );
00134 if( $link_table == 'imagelinks' || $link_table == 'categorylinks' ) {
00135 $subconds["rc_namespace"] = $link_ns;
00136 $subjoin = "rc_title = {$pfx}_to";
00137 } else {
00138 $subjoin = "rc_namespace = {$pfx}_namespace AND rc_title = {$pfx}_title";
00139 }
00140 }
00141
00142 $subsql[] = $dbr->selectSQLText(
00143 array_merge( $tables, array( $link_table ) ),
00144 $select,
00145 $conds + $subconds,
00146 __METHOD__,
00147 array( 'ORDER BY' => 'rc_timestamp DESC', 'LIMIT' => $limit ) + $query_options,
00148 $join_conds + array( $link_table => array( 'INNER JOIN', $subjoin ) )
00149 );
00150 }
00151
00152 if( count($subsql) == 0 )
00153 return false;
00154 if( count($subsql) == 1 )
00155 $sql = $subsql[0];
00156 else {
00157
00158 $sql = "(" . implode( ") UNION (", $subsql ) . ") ORDER BY rc_timestamp DESC LIMIT {$limit}";
00159 }
00160
00161 $res = $dbr->query( $sql, __METHOD__ );
00162
00163 if( $res->numRows() == 0 )
00164 $this->mResultEmpty = true;
00165
00166 return $res;
00167 }
00168
00169 function getExtraOptions( $opts ){
00170 $opts->consumeValues( array( 'showlinkedto', 'target' ) );
00171 $extraOpts = array();
00172 $extraOpts['namespace'] = $this->namespaceFilterForm( $opts );
00173 $extraOpts['target'] = array( wfMsg( 'recentchangeslinked-page' ),
00174 Xml::input( 'target', 40, str_replace('_',' ',$opts['target']) ) .
00175 Xml::check( 'showlinkedto', $opts['showlinkedto'], array('id' => 'showlinkedto') ) . ' ' .
00176 Xml::label( wfMsg("recentchangeslinked-to"), 'showlinkedto' ) );
00177 $tagFilter = ChangeTags::buildTagFilterSelector( $opts['tagfilter'] );
00178 if ($tagFilter)
00179 $extraOpts['tagfilter'] = $tagFilter;
00180 return $extraOpts;
00181 }
00182
00183 function setTopText( OutputPage $out, FormOptions $opts ) {
00184 global $wgUser;
00185 $skin = $wgUser->getSkin();
00186 if( isset( $this->mTargetTitle ) && is_object( $this->mTargetTitle ) )
00187 $out->setSubtitle( wfMsg( 'recentchangeslinked-backlink', $skin->link( $this->mTargetTitle,
00188 $this->mTargetTitle->getPrefixedText(), array(), array( 'redirect' => 'no' ) ) ) );
00189 }
00190
00191 function setBottomText( OutputPage $out, FormOptions $opts ){
00192 if( isset( $this->mTargetTitle ) && is_object( $this->mTargetTitle ) ){
00193 global $wgUser;
00194 $out->setFeedAppendQuery( "target=" . urlencode( $this->mTargetTitle->getPrefixedDBkey() ) );
00195 }
00196 if( isset( $this->mResultEmpty ) && $this->mResultEmpty ){
00197 $out->addWikiMsg( 'recentchangeslinked-noresult' );
00198 }
00199 }
00200 }