X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fspecials%2FSpecialRecentchangeslinked.php;h=9010e1018ef60b973f8bfb6ff397f15bc752eaaa;hb=127befb1786c6a4279de2f27066a84b3560e9bbd;hp=2b00ef3f8f963c60bd5b0d3d83fb156e7390cece;hpb=c51e64755460f45877f189ff697806a1de1a7e23;p=lhc%2Fweb%2Fwiklou.git
diff --git a/includes/specials/SpecialRecentchangeslinked.php b/includes/specials/SpecialRecentchangeslinked.php
index 2b00ef3f8f..9010e1018e 100644
--- a/includes/specials/SpecialRecentchangeslinked.php
+++ b/includes/specials/SpecialRecentchangeslinked.php
@@ -1,19 +1,43 @@
add( 'target', '' );
$opts->add( 'showlinkedto', false );
+ $opts->add( 'tagfilter', '' );
return $opts;
}
@@ -21,25 +45,24 @@ class SpecialRecentchangeslinked extends SpecialRecentchanges {
$opts['target'] = $par;
}
- public function feedSetup(){
- global $wgRequest;
+ public function feedSetup() {
$opts = parent::feedSetup();
- $opts['target'] = $wgRequest->getVal( 'target' );
+ $opts['target'] = $this->getRequest()->getVal( 'target' );
return $opts;
}
public function getFeedObject( $feedFormat ){
$feed = new ChangesFeed( $feedFormat, false );
$feedObj = $feed->getFeedObject(
- wfMsgForContent( 'recentchangeslinked-title', $this->mTargetTitle->getPrefixedText() ),
- wfMsgForContent( 'recentchangeslinked' )
+ $this->msg( 'recentchangeslinked-title', $this->getTargetTitle()->getPrefixedText() )
+ ->inContentLanguage()->text(),
+ $this->msg( 'recentchangeslinked-feed' )->inContentLanguage()->text(),
+ $this->getTitle()->getFullUrl()
);
return array( $feed, $feedObj );
}
public function doMainQuery( $conds, $opts ) {
- global $wgUser, $wgOut;
-
$target = $opts['target'];
$showlinkedto = $opts['showlinkedto'];
$limit = $opts['limit'];
@@ -47,84 +70,206 @@ class SpecialRecentchangeslinked extends SpecialRecentchanges {
if ( $target === '' ) {
return false;
}
+ $outputPage = $this->getOutput();
$title = Title::newFromURL( $target );
if( !$title || $title->getInterwiki() != '' ){
- global $wgOut;
- $wgOut->wrapWikiMsg( '
$1
', 'allpagesbadtitle' );
+ $outputPage->wrapWikiMsg( "\n$1\n
", 'allpagesbadtitle' );
return false;
}
- $this->mTargetTitle = $title;
- $wgOut->setPageTitle( wfMsg( 'recentchangeslinked-title', $title->getPrefixedText() ) );
+ $outputPage->setPageTitle( $this->msg( 'recentchangeslinked-title', $title->getPrefixedText() ) );
+
+ /*
+ * Ordinary links are in the pagelinks table, while transclusions are
+ * in the templatelinks table, categorizations in categorylinks and
+ * image use in imagelinks. We need to somehow combine all these.
+ * Special:Whatlinkshere does this by firing multiple queries and
+ * merging the results, but the code we inherit from our parent class
+ * expects only one result set so we use UNION instead.
+ */
$dbr = wfGetDB( DB_SLAVE, 'recentchangeslinked' );
- $id = $title->getArticleId();
+ $id = $title->getArticleID();
+ $ns = $title->getNamespace();
+ $dbkey = $title->getDBkey();
$tables = array( 'recentchanges' );
$select = array( $dbr->tableName( 'recentchanges' ) . '.*' );
$join_conds = array();
+ $query_options = array();
+
+ // left join with watchlist table to highlight watched rows
+ $uid = $this->getUser()->getId();
+ if( $uid ) {
+ $tables[] = 'watchlist';
+ $select[] = 'wl_user';
+ $join_conds['watchlist'] = array( 'LEFT JOIN', "wl_user={$uid} AND wl_title=rc_title AND wl_namespace=rc_namespace" );
+ }
+ if ( $this->getUser()->isAllowed( 'rollback' ) ) {
+ $tables[] = 'page';
+ $join_conds['page'] = array('LEFT JOIN', 'rc_cur_id=page_id');
+ $select[] = 'page_latest';
+ }
+ if ( !$this->including() ) { // bug 23293
+ ChangeTags::modifyDisplayQuery( $tables, $select, $conds, $join_conds,
+ $query_options, $opts['tagfilter'] );
+ }
+
+ if ( !wfRunHooks( 'SpecialRecentChangesQuery', array( &$conds, &$tables, &$join_conds, $opts, &$query_options, &$select ) ) ) {
+ return false;
+ }
- if( $title->getNamespace() == NS_CATEGORY ) {
- $tables[] = 'categorylinks';
- $conds['cl_to'] = $title->getDBkey();
- $join_conds['categorylinks'] = array( 'LEFT JOIN', 'cl_from=rc_cur_id' );
+ if( $ns == NS_CATEGORY && !$showlinkedto ) {
+ // special handling for categories
+ // XXX: should try to make this less klugy
+ $link_tables = array( 'categorylinks' );
+ $showlinkedto = true;
} else {
+ // for now, always join on these tables; really should be configurable as in whatlinkshere
+ $link_tables = array( 'pagelinks', 'templatelinks' );
+ // imagelinks only contains links to pages in NS_FILE
+ if( $ns == NS_FILE || !$showlinkedto ) {
+ $link_tables[] = 'imagelinks';
+ }
+ }
+
+ if( $id == 0 && !$showlinkedto ) {
+ return false; // nonexistent pages can't link to any pages
+ }
+
+ // field name prefixes for all the various tables we might want to join with
+ $prefix = array( 'pagelinks' => 'pl', 'templatelinks' => 'tl', 'categorylinks' => 'cl', 'imagelinks' => 'il' );
+
+ $subsql = array(); // SELECT statements to combine with UNION
+
+ foreach( $link_tables as $link_table ) {
+ $pfx = $prefix[$link_table];
+
+ // imagelinks and categorylinks tables have no xx_namespace field, and have xx_to instead of xx_title
+ if( $link_table == 'imagelinks' ) {
+ $link_ns = NS_FILE;
+ } elseif( $link_table == 'categorylinks' ) {
+ $link_ns = NS_CATEGORY;
+ } else {
+ $link_ns = 0;
+ }
+
if( $showlinkedto ) {
- if( $title->getNamespace() == NS_TEMPLATE ){
- $tables[] = 'templatelinks';
- $conds['tl_namespace'] = $title->getNamespace();
- $conds['tl_title'] = $title->getDBkey();
- $join_conds['templatelinks'] = array( 'LEFT JOIN', 'tl_from=rc_cur_id' );
+ // find changes to pages linking to this page
+ if( $link_ns ) {
+ if( $ns != $link_ns ) {
+ continue;
+ } // should never happen, but check anyway
+ $subconds = array( "{$pfx}_to" => $dbkey );
+ } else {
+ $subconds = array( "{$pfx}_namespace" => $ns, "{$pfx}_title" => $dbkey );
+ }
+ $subjoin = "rc_cur_id = {$pfx}_from";
+ } else {
+ // find changes to pages linked from this page
+ $subconds = array( "{$pfx}_from" => $id );
+ if( $link_table == 'imagelinks' || $link_table == 'categorylinks' ) {
+ $subconds["rc_namespace"] = $link_ns;
+ $subjoin = "rc_title = {$pfx}_to";
} else {
- $tables[] = 'pagelinks';
- $conds['pl_namespace'] = $title->getNamespace();
- $conds['pl_title'] = $title->getDBkey();
- $join_conds['pagelinks'] = array( 'LEFT JOIN', 'pl_from=rc_cur_id' );
+ $subjoin = "rc_namespace = {$pfx}_namespace AND rc_title = {$pfx}_title";
}
+ }
+
+ if( $dbr->unionSupportsOrderAndLimit()) {
+ $order = array( 'ORDER BY' => 'rc_timestamp DESC' );
} else {
- $tables[] = 'pagelinks';
- $conds['pl_from'] = $id;
- $join_conds['pagelinks'] = array( 'LEFT JOIN', 'pl_namespace = rc_namespace AND pl_title = rc_title' );
+ $order = array();
}
+
+ $query = $dbr->selectSQLText(
+ array_merge( $tables, array( $link_table ) ),
+ $select,
+ $conds + $subconds,
+ __METHOD__,
+ $order + $query_options,
+ $join_conds + array( $link_table => array( 'INNER JOIN', $subjoin ) )
+ );
+
+ if( $dbr->unionSupportsOrderAndLimit())
+ $query = $dbr->limitResult( $query, $limit );
+
+ $subsql[] = $query;
}
- if( $uid = $wgUser->getId() ) {
- $tables[] = 'watchlist';
- $join_conds['watchlist'] = array( 'LEFT JOIN', "wl_user={$uid} AND wl_title=rc_title AND wl_namespace=rc_namespace" );
- $select[] = 'wl_user';
+ if( count($subsql) == 0 ) {
+ return false; // should never happen
+ }
+ if( count($subsql) == 1 && $dbr->unionSupportsOrderAndLimit() ) {
+ $sql = $subsql[0];
+ } else {
+ // need to resort and relimit after union
+ $sql = $dbr->unionQueries($subsql, false).' ORDER BY rc_timestamp DESC';
+ $sql = $dbr->limitResult($sql, $limit, false);
}
- $res = $dbr->select( $tables, $select, $conds, __METHOD__,
- array( 'ORDER BY' => 'rc_timestamp DESC', 'LIMIT' => $limit ), $join_conds );
+ $res = $dbr->query( $sql, __METHOD__ );
- if( $dbr->numRows( $res ) == 0 )
+ if( $res->numRows() == 0 ) {
$this->mResultEmpty = true;
+ }
return $res;
}
-
+
+ /**
+ * @param $opts FormOptions
+ * @return array
+ */
function getExtraOptions( $opts ){
- $opts->consumeValues( array( 'showlinkedto', 'target' ) );
+ $opts->consumeValues( array( 'showlinkedto', 'target', 'tagfilter' ) );
$extraOpts = array();
$extraOpts['namespace'] = $this->namespaceFilterForm( $opts );
- $extraOpts['target'] = array( wfMsg( 'recentchangeslinked-page' ),
- Xml::input( 'target', 40, $opts['target'] ) .
+ $extraOpts['target'] = array( $this->msg( 'recentchangeslinked-page' )->escaped(),
+ Xml::input( 'target', 40, str_replace('_',' ',$opts['target']) ) .
Xml::check( 'showlinkedto', $opts['showlinkedto'], array('id' => 'showlinkedto') ) . ' ' .
- Xml::label( wfMsg("recentchangeslinked-to"), 'showlinkedto' ) );
- $extraOpts['submit'] = Xml::submitbutton( wfMsg('allpagessubmit') );
+ Xml::label( $this->msg( 'recentchangeslinked-to' )->text(), 'showlinkedto' ) );
+ $tagFilter = ChangeTags::buildTagFilterSelector( $opts['tagfilter'] );
+ if ($tagFilter) {
+ $extraOpts['tagfilter'] = $tagFilter;
+ }
return $extraOpts;
}
-
- function setTopText( &$out, $opts ){}
-
- function setBottomText( &$out, $opts ){
- if( isset( $this->mTargetTitle ) && is_object( $this->mTargetTitle ) ){
- global $wgUser;
- $out->setFeedAppendQuery( "target=" . urlencode( $this->mTargetTitle->getPrefixedDBkey() ) );
- $out->addHTML("< ".$wgUser->getSkin()->makeLinkObj( $this->mTargetTitle, "", "redirect=no" )."
\n");
- }
- if( isset( $this->mResultEmpty ) && $this->mResultEmpty ){
- $out->addWikiMsg( 'recentchangeslinked-noresult' );
+
+ /**
+ * @return Title
+ */
+ function getTargetTitle() {
+ if ( $this->rclTargetTitle === null ) {
+ $opts = $this->getOptions();
+ if ( isset( $opts['target'] ) && $opts['target'] !== '' ) {
+ $this->rclTargetTitle = Title::newFromText( $opts['target'] );
+ } else {
+ $this->rclTargetTitle = false;
+ }
+ }
+ return $this->rclTargetTitle;
+ }
+
+ function setTopText( FormOptions $opts ) {
+ $target = $this->getTargetTitle();
+ if( $target ) {
+ $this->getOutput()->addBacklinkSubtitle( $target );
+ }
+ }
+
+ public function getFeedQuery() {
+ $target = $this->getTargetTitle();
+ if( $target ) {
+ return "target=" . urlencode( $target->getPrefixedDBkey() );
+ } else {
+ return false;
+ }
+ }
+
+ function setBottomText( FormOptions $opts ) {
+ if( isset( $this->mResultEmpty ) && $this->mResultEmpty ) {
+ $this->getOutput()->addWikiMsg( 'recentchangeslinked-noresult' );
}
}
}