r45789 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r45788‎ | r45789 | r45790 >
Date:23:42, 15 January 2009
Author:werdna
Status:deferred (Comments)
Tags:
Comment:
Create tag tables, and show tags on Recent changes, related changes, new pages, watchlist and contributions.

Still to go:
History and logs, and some way of actually adding the tags.
Modified paths:
  • /branches/change-tagging/phase3/includes/ChangesList.php (modified) (history)
  • /branches/change-tagging/phase3/includes/specials/SpecialContributions.php (modified) (history)
  • /branches/change-tagging/phase3/includes/specials/SpecialNewpages.php (modified) (history)
  • /branches/change-tagging/phase3/includes/specials/SpecialRecentchanges.php (modified) (history)
  • /branches/change-tagging/phase3/includes/specials/SpecialRecentchangeslinked.php (modified) (history)
  • /branches/change-tagging/phase3/includes/specials/SpecialWatchlist.php (modified) (history)
  • /branches/change-tagging/phase3/maintenance/tables.sql (modified) (history)
  • /branches/change-tagging/phase3/maintenance/updaters.inc (modified) (history)

Diff [purge]

Index: branches/change-tagging/phase3/maintenance/updaters.inc
@@ -149,6 +149,8 @@
150150 array( 'add_field', 'site_stats', 'ss_active_users', 'patch-ss_active_users.sql' ),
151151 array( 'do_active_users_init' ),
152152 array( 'add_field', 'ipblocks', 'ipb_allow_usertalk', 'patch-ipb_allow_usertalk.sql' ),
 153+ array( 'add_table', 'change_tag', 'patch-change_tag.sql' ),
 154+ array( 'add_table', 'tag_summary', 'patch-change_tag.sql' ),
153155 ),
154156
155157 'sqlite' => array(
Index: branches/change-tagging/phase3/maintenance/tables.sql
@@ -1234,4 +1234,30 @@
12351235 ul_key varchar(255) NOT NULL primary key
12361236 ) /*$wgDBTableOptions*/;
12371237
 1238+--- A table to track tags for revisions, logs and recent changes.
 1239+CREATE TABLE /*_*/change_tag (
 1240+ ct_rc_id int NULL,
 1241+ ct_log_id int NULL,
 1242+ ct_rev_id int NULL,
 1243+ ct_tag varchar(255) NOT NULL,
 1244+ ct_params BLOB NULL,
 1245+
 1246+ UNIQUE KEY (ct_rc_id,ct_tag),
 1247+ UNIQUE KEY (ct_log_id,ct_tag),
 1248+ UNIQUE KEY (ct_rev_id,ct_tag),
 1249+ KEY (ct_tag,ct_rc_id,ct_rev_id,ct_log_id) -- Covering index, so we can pull all the info only out of the index.
 1250+) /*$wgDBTableOptions*/;
 1251+
 1252+-- Rollup table to pull a LIST of tags simply without ugly GROUP_CONCAT that only works on MySQL 4.1+
 1253+CREATE TABLE /*_*/tag_summary (
 1254+ ts_rc_id int NULL,
 1255+ ts_log_id int NULL,
 1256+ ts_rev_id int NULL,
 1257+ ts_tags BLOB NOT NULL,
 1258+
 1259+ UNIQUE KEY (ts_rc_id),
 1260+ UNIQUE KEY (ts_log_id),
 1261+ UNIQUE KEY (ts_rev_id),
 1262+) /*$wgDBTableOptions*/;
 1263+
12381264 -- vim: sw=2 sts=2 et
Index: branches/change-tagging/phase3/includes/ChangesList.php
@@ -338,6 +338,7 @@
339339 $this->insertDateHeader( $dateheader, $rc->mAttribs['rc_timestamp'] );
340340
341341 $s = '';
 342+ $classes = array();
342343 // Moved pages
343344 if( $rc->mAttribs['rc_type'] == RC_MOVE || $rc->mAttribs['rc_type'] == RC_MOVE_OVER_REDIRECT ) {
344345 $this->insertMove( $s, $rc );
@@ -383,11 +384,28 @@
384385 $s .= ' ' . wfMsg( 'number_of_watching_users_RCview',
385386 $wgContLang->formatNum($rc->numberofWatchingusers) );
386387 }
 388+ # Tags, if any.
 389+ if ($rc->mAttribs['ts_tags']) {
 390+ $tags = explode( ',', $rc->mAttribs['ts_tags'] );
 391+ $displayTags = array();
 392+ foreach( $tags as $tag ) {
 393+ if (!wfEmptyMsg( "recentchanges-tag-$tag" , wfMsg( "recentchanges-tag-$tag" ) ) ) {
 394+ $displayTags[] = wfMsgExt( "recentchanges-tag-$tag", 'parseinline' );
 395+ } else {
 396+ $displayTags[] = $tag;
 397+ }
 398+ }
 399+
 400+ $s .= ' (' . implode( ', ', $displayTags ) . ')';
 401+ $classes = array_merge( $classes, $tags );
 402+ }
387403
 404+ ## Classes
 405+ $classes = implode( ' ', $classes );
388406 wfRunHooks( 'OldChangesListRecentChangesLine', array(&$this, &$s, $rc) );
389407
390408 wfProfileOut( __METHOD__ );
391 - return "$dateheader<li>$s</li>\n";
 409+ return "$dateheader<li class=\"$classes\">$s</li>\n";
392410 }
393411 }
394412
Index: branches/change-tagging/phase3/includes/specials/SpecialRecentchangeslinked.php
@@ -82,6 +82,11 @@
8383 $join_conds['watchlist'] = array( 'LEFT JOIN', "wl_user={$uid} AND wl_title=rc_title AND wl_namespace=rc_namespace" );
8484 }
8585
 86+ // JOIN on tag_summary
 87+ $tables[] = 'tag_summary';
 88+ $select[] = 'ts_tags';
 89+ $join_conds['tag_summary'] = array( 'LEFT JOIN', 'ts_rc_id=rc_id' );
 90+
8691 // XXX: parent class does this, should we too?
8792 // wfRunHooks('SpecialRecentChangesQuery', array( &$conds, &$tables, &$join_conds, $opts ) );
8893
Index: branches/change-tagging/phase3/includes/specials/SpecialNewpages.php
@@ -235,6 +235,9 @@
236236 */
237237 public function formatRow( $result ) {
238238 global $wgLang, $wgContLang, $wgUser;
 239+
 240+ $classes = array();
 241+
239242 $dm = $wgContLang->getDirMark();
240243
241244 $title = Title::makeTitleSafe( $result->rc_namespace, $result->rc_title );
@@ -247,9 +250,30 @@
248251 $ulink = $this->skin->userLink( $result->rc_user, $result->rc_user_text ) . ' ' .
249252 $this->skin->userToolLinks( $result->rc_user, $result->rc_user_text );
250253 $comment = $this->skin->commentBlock( $result->rc_comment );
251 - $css = $this->patrollable( $result ) ? " class='not-patrolled'" : '';
 254+
 255+ if ( $this->patrollable( $result ) )
 256+ $classes[] = 'not-patrolled';
252257
253 - return "<li{$css}>{$time} {$dm}{$plink} ({$hist}) {$dm}[{$length}] {$dm}{$ulink} {$comment}</li>\n";
 258+ # Tags, if any.
 259+ $tagDisplay = '';
 260+ if ($result->ts_tags) {
 261+ $tags = explode( ',', $result->ts_tags );
 262+ $displayTags = array();
 263+ foreach( $tags as $tag ) {
 264+ if (!wfEmptyMsg( "recentchanges-tag-$tag" , wfMsg( "recentchanges-tag-$tag" ) ) ) {
 265+ $displayTags[] = wfMsgExt( "recentchanges-tag-$tag", 'parseinline' );
 266+ } else {
 267+ $displayTags[] = $tag;
 268+ }
 269+ }
 270+
 271+ $tagDisplay = ' (' . implode( ', ', $displayTags ) . ')';
 272+ $classes = array_merge( $classes, $tags );
 273+ }
 274+
 275+ $css = count($classes) ? ' class="'.implode( " ", $classes).'"' : '';
 276+
 277+ return "<li{$css}>{$time} {$dm}{$plink} ({$hist}) {$dm}[{$length}] {$dm}{$ulink} {$comment} {$tagDisplay}</li>\n";
254278 }
255279
256280 /**
@@ -378,7 +402,6 @@
379403 } else {
380404 $rcIndexes = array( 'rc_timestamp' );
381405 }
382 - $conds[] = 'page_id = rc_cur_id';
383406
384407 # $wgEnableNewpagesUserFilter - temp WMF hack
385408 if( $wgEnableNewpagesUserFilter && $user ) {
@@ -401,11 +424,15 @@
402425 }
403426
404427 return array(
405 - 'tables' => array( 'recentchanges', 'page' ),
 428+ 'tables' => array( 'recentchanges', 'page', 'tag_summary' ),
406429 'fields' => 'rc_namespace,rc_title, rc_cur_id, rc_user,rc_user_text,rc_comment,
407 - rc_timestamp,rc_patrolled,rc_id,page_len as length, page_latest as rev_id',
 430+ rc_timestamp,rc_patrolled,rc_id,page_len as length, page_latest as rev_id, ts_tags',
408431 'conds' => $conds,
409 - 'options' => array( 'USE INDEX' => array('recentchanges' => $rcIndexes) )
 432+ 'options' => array( 'USE INDEX' => array('recentchanges' => $rcIndexes) ),
 433+ 'join_conds' => array(
 434+ 'tag_summary' => array('LEFT JOIN', 'ts_rc_id=rc_id'),
 435+ 'page' => array('INNER JOIN', 'page_id=rc_cur_id'),
 436+ ),
410437 );
411438 }
412439
Index: branches/change-tagging/phase3/includes/specials/SpecialRecentchanges.php
@@ -274,13 +274,19 @@
275275 $namespace = $opts['namespace'];
276276 $invert = $opts['invert'];
277277
 278+ $join_conds = array();
 279+
278280 // JOIN on watchlist for users
279281 if( $uid ) {
280282 $tables[] = 'watchlist';
281 - $join_conds = array( 'watchlist' => array('LEFT JOIN',
282 - "wl_user={$uid} AND wl_title=rc_title AND wl_namespace=rc_namespace") );
 283+ $join_conds['watchlist'] = array('LEFT JOIN',
 284+ "wl_user={$uid} AND wl_title=rc_title AND wl_namespace=rc_namespace");
283285 }
284286
 287+ // JOIN on tag_summary
 288+ $tables[] = 'tag_summary';
 289+ $join_conds['tag_summary'] = array( 'LEFT JOIN', 'ts_rc_id=rc_id' );
 290+
285291 wfRunHooks('SpecialRecentChangesQuery', array( &$conds, &$tables, &$join_conds, $opts ) );
286292
287293 // Is there either one namespace selected or excluded?
Index: branches/change-tagging/phase3/includes/specials/SpecialContributions.php
@@ -392,13 +392,18 @@
393393
394394 function getQueryInfo() {
395395 list( $tables, $index, $userCond, $join_cond ) = $this->getUserCond();
396 - $conds = array_merge( array('page_id=rev_page'), $userCond, $this->getNamespaceCond() );
 396+
 397+ $tables[] = 'tag_summary';
 398+ $join_cond['tag_summary'] = array('LEFT JOIN','ts_rev_id=rev_id');
 399+ $join_cond['page'] = array( 'INNER JOIN', 'page_id=rev_page' );
 400+
 401+ $conds = array_merge( $userCond, $this->getNamespaceCond() );
397402 $queryInfo = array(
398403 'tables' => $tables,
399404 'fields' => array(
400405 'page_namespace', 'page_title', 'page_is_new', 'page_latest', 'rev_id', 'rev_page',
401406 'rev_text_id', 'rev_timestamp', 'rev_comment', 'rev_minor_edit', 'rev_user',
402 - 'rev_user_text', 'rev_parent_id', 'rev_deleted'
 407+ 'rev_user_text', 'rev_parent_id', 'rev_deleted', 'ts_tags',
403408 ),
404409 'conds' => $conds,
405410 'options' => array( 'USE INDEX' => array('revision' => $index) ),
@@ -464,6 +469,7 @@
465470
466471 $sk = $this->getSkin();
467472 $rev = new Revision( $row );
 473+ $classes = array();
468474
469475 $page = Title::makeTitle( $row->page_namespace, $row->page_title );
470476 $link = $sk->makeKnownLinkObj( $page );
@@ -520,10 +526,28 @@
521527 if( $rev->isDeleted( Revision::DELETED_TEXT ) ) {
522528 $ret .= ' ' . wfMsgHtml( 'deletedrev' );
523529 }
 530+
 531+ # Tags, if any.
 532+ if ($row->ts_tags) {
 533+ $tags = explode( ',', $row->ts_tags );
 534+ $displayTags = array();
 535+ foreach( $tags as $tag ) {
 536+ if (!wfEmptyMsg( "recentchanges-tag-$tag" , wfMsg( "recentchanges-tag-$tag" ) ) ) {
 537+ $displayTags[] = wfMsgExt( "recentchanges-tag-$tag", 'parseinline' );
 538+ } else {
 539+ $displayTags[] = $tag;
 540+ }
 541+ }
 542+
 543+ $ret .= ' (' . implode( ', ', $displayTags ) . ')';
 544+ $classes = array_merge( $classes, $tags );
 545+ }
 546+
524547 // Let extensions add data
525548 wfRunHooks( 'ContributionsLineEnding', array( &$this, &$ret, $row ) );
526 -
527 - $ret = "<li>$ret</li>\n";
 549+
 550+ $classes = implode( ' ', $classes );
 551+ $ret = "<li class=\"$classes\">$ret</li>\n";
528552 wfProfileOut( __METHOD__ );
529553 return $ret;
530554 }
Index: branches/change-tagging/phase3/includes/specials/SpecialWatchlist.php
@@ -189,12 +189,13 @@
190190 }
191191 $form .= '<hr />';
192192
193 - $tables = array( 'recentchanges', 'watchlist', 'page' );
194 - $fields = array( "{$recentchanges}.*" );
 193+ $tables = array( 'recentchanges', 'watchlist', 'page', 'tag_summary' );
 194+ $fields = array( "{$recentchanges}.*", 'ts_tags' );
195195 $conds = array();
196196 $join_conds = array(
197197 'watchlist' => array('INNER JOIN',"wl_user='{$uid}' AND wl_namespace=rc_namespace AND wl_title=rc_title"),
198 - 'page' => array('LEFT JOIN','rc_cur_id=page_id')
 198+ 'page' => array('LEFT JOIN','rc_cur_id=page_id'),
 199+ 'tag_summary' => array('LEFT JOIN', 'ts_rc_id=rc_id'),
199200 );
200201 $options = array( 'ORDER BY' => 'rc_timestamp DESC' );
201202 if( $wgShowUpdatedMarker ) {

Comments

#Comment by Catrope (talk | contribs)   07:48, 16 January 2009

It seems you forgot to svn add patch-change_tag.sql

Status & tagging log