r37927 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r37926‎ | r37927 | r37928 >
Date:22:37, 22 July 2008
Author:vyznev
Status:old
Tags:
Comment:
Make Special:Recentchangeslinked display changes to transcluded pages (templatelinks table) and embedded images (imagelinks table). This should help a bit against the recent spate of template vandalism on enwiki.
Also make the "Show changes to pages linked" button work for categories.

Remaining issues / things to do:
- Test performance of the UNION query on a larger dataset than my test wiki.
- Add some checkboxes to allow filtering the results like on Special:Whatlinkshere.
- Try to think of some way to make the behavior for categories less klugy.
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/specials/SpecialRecentchangeslinked.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/specials/SpecialRecentchangeslinked.php
@@ -56,45 +56,94 @@
5757
5858 $wgOut->setPageTitle( wfMsg( 'recentchangeslinked-title', $title->getPrefixedText() ) );
5959
 60+ /*
 61+ * Ordinary links are in the pagelinks table, while transclusions are
 62+ * in the templatelinks table, categorizations in categorylinks and
 63+ * image use in imagelinks. We need to somehow combine all these.
 64+ * Special:Whatlinkshere does this by firing multiple queries and
 65+ * merging the results, but the code we inherit from our parent class
 66+ * expects only one result set so we use UNION instead.
 67+ */
 68+
6069 $dbr = wfGetDB( DB_SLAVE, 'recentchangeslinked' );
6170 $id = $title->getArticleId();
 71+ $ns = $title->getNamespace();
 72+ $dbkey = $title->getDBkey();
6273
6374 $tables = array( 'recentchanges' );
6475 $select = array( $dbr->tableName( 'recentchanges' ) . '.*' );
6576 $join_conds = array();
6677
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' );
 78+ // left join with watchlist table to highlight watched rows
 79+ if( $uid = $wgUser->getId() ) {
 80+ $tables[] = 'watchlist';
 81+ $select[] = 'wl_user';
 82+ $join_conds['watchlist'] = array( 'LEFT JOIN', "wl_user={$uid} AND wl_title=rc_title AND wl_namespace=rc_namespace" );
 83+ }
 84+
 85+ // XXX: parent class does this, should we too?
 86+ // wfRunHooks('SpecialRecentChangesQuery', array( &$conds, &$tables, &$join_conds, $opts ) );
 87+
 88+ if( $ns == NS_CATEGORY && !$showlinkedto ) {
 89+ // special handling for categories
 90+ // XXX: should try to make this less klugy
 91+ $link_tables = array( 'categorylinks' );
 92+ $showlinkedto = true;
7193 } else {
 94+ // for now, always join on these tables; really should be configurable as in whatlinkshere
 95+ $link_tables = array( 'pagelinks', 'templatelinks' );
 96+ // imagelinks only contains links to pages in NS_IMAGE
 97+ if( $ns == NS_IMAGE || !$showlinkedto ) $link_tables[] = 'imagelinks';
 98+ }
 99+
 100+ // field name prefixes for all the various tables we might want to join with
 101+ $prefix = array( 'pagelinks' => 'pl', 'templatelinks' => 'tl', 'categorylinks' => 'cl', 'imagelinks' => 'il' );
 102+
 103+ $subsql = array(); // SELECT statements to combine with UNION
 104+
 105+ foreach( $link_tables as $link_table ) {
 106+ $pfx = $prefix[$link_table];
 107+
 108+ // imagelinks and categorylinks tables have no xx_namespace field, and have xx_to instead of xx_title
 109+ if( $link_table == 'imagelinks' ) $link_ns = NS_IMAGE;
 110+ else if( $link_table == 'categorylinks' ) $link_ns = NS_CATEGORY;
 111+ else $link_ns = 0;
 112+
72113 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' );
 114+ // find changes to pages linking to this page
 115+ if( $link_ns ) {
 116+ if( $ns != $link_ns ) continue; // should never happen, but check anyway
 117+ $subconds = array( "{$pfx}_to" => $dbkey );
78118 } 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' );
 119+ $subconds = array( "{$pfx}_namespace" => $ns, "{$pfx}_title" => $dbkey );
83120 }
 121+ $subjoin = "rc_cur_id = {$pfx}_from";
84122 } 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' );
 123+ // find changes to pages linked from this page
 124+ $subconds = array( "{$pfx}_from" => $id );
 125+ if( $link_table == 'imagelinks' || $link_table == 'categorylinks' ) {
 126+ $subconds["rc_namespace"] = $link_ns;
 127+ $subjoin = "rc_title = {$pfx}_to";
 128+ } else {
 129+ $subjoin = "rc_namespace = {$pfx}_namespace AND rc_title = {$pfx}_title";
 130+ }
88131 }
 132+
 133+ $subsql[] = $dbr->selectSQLText( array_merge( $tables, array( $link_table ) ), $select, $conds + $subconds,
 134+ __METHOD__, array( 'ORDER BY' => 'rc_timestamp DESC', 'LIMIT' => $limit ),
 135+ $join_conds + array( $link_table => array( 'INNER JOIN', $subjoin ) ) );
89136 }
90137
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';
 138+ if( count($subsql) == 0 )
 139+ return false; // should never happen
 140+ if( count($subsql) == 1 )
 141+ $sql = $subsql[0];
 142+ else {
 143+ // need to resort and relimit after union
 144+ $sql = "(" . implode( ") UNION (", $subsql ) . ") ORDER BY rc_timestamp DESC LIMIT {$limit}";
95145 }
96146
97 - $res = $dbr->select( $tables, $select, $conds, __METHOD__,
98 - array( 'ORDER BY' => 'rc_timestamp DESC', 'LIMIT' => $limit ), $join_conds );
 147+ $res = $dbr->query( $sql, __METHOD__ );
99148
100149 if( $dbr->numRows( $res ) == 0 )
101150 $this->mResultEmpty = true;
Index: trunk/phase3/RELEASE-NOTES
@@ -191,7 +191,10 @@
192192 * (bug 9736) Redirects on Special:Fewestrevisions are now marked as such.
193193 * New date/time formats in Cs localization according to ČSN and PČP.
194194 * (bug 14883) Create hook AlternateSkinPreferences to alternate skin section in user preferences
195 -
 195+* Special:Recentchangeslinked now includes changes to transcluded pages and
 196+ displayed images; also, the "Show changes to pages linked" checkbox now works on
 197+ category pages too, showing all links that are not categorizations
 198+
196199 === Bug fixes in 1.13 ===
197200
198201 * (bug 10677) Add link to the file description page on the shared repository

Status & tagging log