EBernhardson (WMF) has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/85787


Change subject: Add new recentchanges field rc_source to replace rc_type
......................................................................

Add new recentchanges field rc_source to replace rc_type

The existing field to differentiate between kinds of recentchanges rows is
the rc_type field. We want to allow extensions to insert their own custom
data into recentchanges, but we have learned via the NS_* series of constants
that requiring extensions to "register" a specific number is very error prone.

The solution, which this commit implements the first phase of, is to utilize
a new 16 byte string field rc_source.  Within that field change types will be
prefixed strings such as 'mw.edit' and 'mw.new'.

This commit adds the new field and begins populating it with data.  At some
point in the future the rc_type field will be dropped.

Change-Id: Iaddd6c446373a68d31586ed54346db7d04e13b2c
---
M includes/Defines.php
M includes/RecentChange.php
M includes/installer/MysqlUpdater.php
M includes/installer/PostgresUpdater.php
A maintenance/archives/patch-rc_source.sql
M maintenance/postgres/tables.sql
M maintenance/rebuildrecentchanges.php
M maintenance/tables.sql
8 files changed, 25 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/87/85787/1

diff --git a/includes/Defines.php b/includes/Defines.php
index 86c5520..02fd333 100644
--- a/includes/Defines.php
+++ b/includes/Defines.php
@@ -179,6 +179,14 @@
 /**@}*/
 
 /**@{
+ * RecentChange source identifiers
+ */
+define( 'RC_SRC_EDIT', 'mw.edit' );
+define( 'RC_SRC_NEW', 'mw.new' );
+define( 'RC_SRC_LOG', 'mw.log' );
+/**@}*/
+
+/**@{
  * Article edit flags
  */
 define( 'EDIT_NEW', 1 );
diff --git a/includes/RecentChange.php b/includes/RecentChange.php
index 980bd0a..055e6a8 100644
--- a/includes/RecentChange.php
+++ b/includes/RecentChange.php
@@ -30,6 +30,7 @@
  *  rc_namespace    namespace #
  *  rc_title        non-prefixed db key
  *  rc_type         is new entry, used to determine whether updating is 
necessary
+ *  rc_source       string representation of change source
  *  rc_minor        is minor
  *  rc_cur_id       page_id of associated page entry
  *  rc_user         user id who made the entry
@@ -159,6 +160,7 @@
                        'rc_this_oldid',
                        'rc_last_oldid',
                        'rc_type',
+                       'rc_source',
                        'rc_patrolled',
                        'rc_ip',
                        'rc_old_len',
@@ -489,6 +491,7 @@
                        'rc_namespace'  => $title->getNamespace(),
                        'rc_title'      => $title->getDBkey(),
                        'rc_type'       => RC_EDIT,
+                       'rc_source'     => RC_SRC_EDIT,
                        'rc_minor'      => $minor ? 1 : 0,
                        'rc_cur_id'     => $title->getArticleID(),
                        'rc_user'       => $user->getId(),
@@ -548,6 +551,7 @@
                        'rc_namespace'      => $title->getNamespace(),
                        'rc_title'          => $title->getDBkey(),
                        'rc_type'           => RC_NEW,
+                       'rc_source'         => RC_SRC_NEW,
                        'rc_minor'          => $minor ? 1 : 0,
                        'rc_cur_id'         => $title->getArticleID(),
                        'rc_user'           => $user->getId(),
@@ -657,6 +661,7 @@
                        'rc_namespace'  => $target->getNamespace(),
                        'rc_title'      => $target->getDBkey(),
                        'rc_type'       => RC_LOG,
+                       'rc_source'     => RC_SRC_LOG,
                        'rc_minor'      => 0,
                        'rc_cur_id'     => $target->getArticleID(),
                        'rc_user'       => $user->getId(),
@@ -716,6 +721,7 @@
                        'rc_comment' => $row->rev_comment,
                        'rc_minor' => $row->rev_minor_edit ? 1 : 0,
                        'rc_type' => $row->page_is_new ? RC_NEW : RC_EDIT,
+                       'rc_source' => $row->page_is_new ? RC_SRC_NEW : 
RC_SRC_EDIT,
                        'rc_cur_id' => $row->page_id,
                        'rc_this_oldid' => $row->rev_id,
                        'rc_last_oldid' => isset( $row->rc_last_oldid ) ? 
$row->rc_last_oldid : 0,
diff --git a/includes/installer/MysqlUpdater.php 
b/includes/installer/MysqlUpdater.php
index 02faf7c..9220005 100644
--- a/includes/installer/MysqlUpdater.php
+++ b/includes/installer/MysqlUpdater.php
@@ -231,6 +231,7 @@
                        // 1.22
                        array( 'doIwlinksIndexNonUnique' ),
                        array( 'addIndex', 'iwlinks', 'iwl_prefix_from_title',  
'patch-iwlinks-from-title-index.sql' ),
+                       array( 'addField', 'recentchanges', 'rc_source', 
'patch-rc_source.sql' ),
                );
        }
 
diff --git a/includes/installer/PostgresUpdater.php 
b/includes/installer/PostgresUpdater.php
index 58a54c4..b86ffab 100644
--- a/includes/installer/PostgresUpdater.php
+++ b/includes/installer/PostgresUpdater.php
@@ -137,6 +137,7 @@
                        array( 'addPgField', 'recentchanges', 'rc_new_len',     
      'INTEGER' ),
                        array( 'addPgField', 'recentchanges', 'rc_old_len',     
      'INTEGER' ),
                        array( 'addPgField', 'recentchanges', 'rc_params',      
      'TEXT' ),
+                       array( 'addPgField', 'recentchanges', 'rc_source',      
      'TEXT' ),
                        array( 'addPgField', 'redirect',      'rd_interwiki',   
      'TEXT NULL' ),
                        array( 'addPgField', 'redirect',      'rd_fragment',    
      'TEXT NULL' ),
                        array( 'addPgField', 'revision',      'rev_deleted',    
      'SMALLINT NOT NULL DEFAULT 0' ),
diff --git a/maintenance/archives/patch-rc_source.sql 
b/maintenance/archives/patch-rc_source.sql
new file mode 100644
index 0000000..a9768dd
--- /dev/null
+++ b/maintenance/archives/patch-rc_source.sql
@@ -0,0 +1,4 @@
+-- first step of migrating recentchanges rc_type to rc_source
+ALTER TABLE /*$wgDBprefix*/recentchanges
+  ADD rc_source varchar(16) binary NULL default '';
+
diff --git a/maintenance/postgres/tables.sql b/maintenance/postgres/tables.sql
index 4d44705..5322254 100644
--- a/maintenance/postgres/tables.sql
+++ b/maintenance/postgres/tables.sql
@@ -405,6 +405,7 @@
   rc_this_oldid      INTEGER      NOT NULL,
   rc_last_oldid      INTEGER      NOT NULL,
   rc_type            SMALLINT     NOT NULL  DEFAULT 0,
+  rc_source          TEXT         NOT NULL,
   rc_patrolled       SMALLINT     NOT NULL  DEFAULT 0,
   rc_ip              CIDR,
   rc_old_len         INTEGER,
diff --git a/maintenance/rebuildrecentchanges.php 
b/maintenance/rebuildrecentchanges.php
index 1834825..cfddf88 100644
--- a/maintenance/rebuildrecentchanges.php
+++ b/maintenance/rebuildrecentchanges.php
@@ -83,6 +83,7 @@
                                'rc_this_oldid' => 'rev_id',
                                'rc_last_oldid' => 0, // is this ok?
                                'rc_type'       => $dbw->conditional( 
'page_is_new != 0', RC_NEW, RC_EDIT ),
+                               'rc_source'     => $dbw->conditional( 
'page_is_new != 0', RC_SRC_NEW, RC_SRC_EDIT ),
                                'rc_deleted'    => 'rev_deleted'
                        ), array(
                                'rev_timestamp > ' . $dbw->addQuotes( 
$dbw->timestamp( $cutoff ) ),
diff --git a/maintenance/tables.sql b/maintenance/tables.sql
index df1bc06..0a0eeda 100644
--- a/maintenance/tables.sql
+++ b/maintenance/tables.sql
@@ -1058,6 +1058,9 @@
   -- The type of change entry (RC_EDIT,RC_NEW,RC_LOG,RC_EXTERNAL)
   rc_type tinyint unsigned NOT NULL default 0,
 
+  -- The source of the change entry (replaces rc_type)
+  rc_source varchar(16) binary not null,
+
   -- If the Recent Changes Patrol option is enabled,
   -- users may mark edits as having been reviewed to
   -- remove a warning flag on the RC list.

-- 
To view, visit https://gerrit.wikimedia.org/r/85787
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Iaddd6c446373a68d31586ed54346db7d04e13b2c
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: EBernhardson (WMF) <ebernhard...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to