r45807 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r45806‎ | r45807 | r45808 >
Date:19:12, 16 January 2009
Author:werdna
Status:deferred
Tags:
Comment:
Add ChangeTags.php to repo.
Modified paths:
  • /branches/change-tagging/phase3/includes/ChangeTags.php (added) (history)

Diff [purge]

Index: branches/change-tagging/phase3/includes/ChangeTags.php
@@ -0,0 +1,65 @@
 2+<?php
 3+
 4+if (!defined( 'MEDIAWIKI' ))
 5+ die;
 6+
 7+class ChangeTags {
 8+ static function formatSummaryRow( $tags, $page, &$classes ) {
 9+ if (!$tags)
 10+ return '';
 11+
 12+ $tags = explode( ',', $tags );
 13+ $displayTags = array();
 14+ foreach( $tags as $tag ) {
 15+ if (!wfEmptyMsg( "$page-tag-$tag" , wfMsg( "$page-tag-$tag" ) ) ) {
 16+ $displayTags[] = wfMsgExt( "$page-tag-$tag", 'parseinline' );
 17+ } else {
 18+ $displayTags[] = $tag;
 19+ }
 20+ $classes[] = "mw-$page-tag-$tag";
 21+ }
 22+
 23+ return '(' . implode( ', ', $displayTags ) . ')';
 24+ }
 25+
 26+ ## Basic utility method to add tags to a particular change, given its rc_id, rev_id and/or log_id.
 27+ static function addTags( $tags, $rc_id=null, $rev_id=null, $log_id=null, $params = null ) {
 28+ if ( !is_array($tags) ) {
 29+ $tags = array( $tags );
 30+ }
 31+
 32+ if (!$rc_id && !$rev_id && !$log_id) {
 33+ throw new MWException( "At least one of: RCID, revision ID, and log ID MUST be specified when adding a tag to a change!" );
 34+ }
 35+
 36+ $tsConds = array_filter( array( 'ts_rc_id' => $rc_id, 'ts_rev_id' => $rev_id, 'ts_log_id' => $log_id ) );
 37+
 38+ ## Update the summary row.
 39+ $dbr = wfGetDB( DB_SLAVE );
 40+ $prevTags = $dbr->selectField( 'tag_summary', 'ts_tags', $tsConds, __METHOD__ );
 41+ $prevTags = $prevTags ? $prevTags : '';
 42+ $prevTags = array_filter( explode( ',', $prevTags ) );
 43+ $newTags = array_unique( array_merge( $prevTags, $tags ) );
 44+ sort($prevTags);
 45+ sort($newTags);
 46+
 47+ if ( $prevTags == $newTags ) {
 48+ // No change.
 49+ #print var_export( sort($prevTags), sort($newTags) );
 50+ return false;
 51+ }
 52+
 53+ $dbw = wfGetDB( DB_MASTER );
 54+ $dbw->replace( 'tag_summary', array( 'ts_rev_id', 'ts_rc_id', 'ts_log_id' ), array( array_merge( $tsConds, array( 'ts_tags' => implode( ',', $newTags ) ) ) ), __METHOD__ );
 55+
 56+ // Insert the tags rows.
 57+ $tagsRows = array();
 58+ foreach( $tags as $tag ) {
 59+ $tagsRows[] = array( 'ct_tag' => $tag, 'ct_rc_id' => $rc_id, 'ct_log_id' => $log_id, 'ct_rev_id' => $rev_id, 'ct_params' => $params );
 60+ }
 61+
 62+ $dbw->replace( 'change_tag', array( array( 'ct_tag', 'ct_rc_id', 'ct_rev_id', 'ct_log_id' ) ), $tagsRows, __METHOD__ );
 63+
 64+ return true;
 65+ }
 66+}
\ No newline at end of file

Status & tagging log