Merge "Implement static public Parser::getExternalLinkRel"
[lhc/web/wiklou.git] / includes / RecentChange.php
index 3cf6c72..87fa428 100644 (file)
@@ -55,6 +55,7 @@
  *  lang            the interwiki prefix, automatically set in save()
  *  oldSize         text size before the change
  *  newSize         text size after the change
+ *  pageStatus      status of the page: created, deleted, moved, restored, changed
  *
  * temporary:       not stored in the database
  *      notificationtimestamp
@@ -125,7 +126,7 @@ class RecentChange {
         */
        public static function newFromConds( $conds, $fname = __METHOD__ ) {
                $dbr = wfGetDB( DB_SLAVE );
-               $row = $dbr->selectRow( 'recentchanges', '*', $conds, $fname );
+               $row = $dbr->selectRow( 'recentchanges', self::selectFields(), $conds, $fname );
                if ( $row !== false ) {
                        return self::newFromRow( $row );
                } else {
@@ -133,6 +134,40 @@ class RecentChange {
                }
        }
 
+       /**
+        * Return the list of recentchanges fields that should be selected to create
+        * a new recentchanges object.
+        * @return array
+        */
+       public static function selectFields() {
+               return array(
+                       'rc_id',
+                       'rc_timestamp',
+                       'rc_cur_time',
+                       'rc_user',
+                       'rc_user_text',
+                       'rc_namespace',
+                       'rc_title',
+                       'rc_comment',
+                       'rc_minor',
+                       'rc_bot',
+                       'rc_new',
+                       'rc_cur_id',
+                       'rc_this_oldid',
+                       'rc_last_oldid',
+                       'rc_type',
+                       'rc_patrolled',
+                       'rc_ip',
+                       'rc_old_len',
+                       'rc_new_len',
+                       'rc_deleted',
+                       'rc_logid',
+                       'rc_log_type',
+                       'rc_log_action',
+                       'rc_params',
+               );
+       }
+
        # Accessors
 
        /**
@@ -239,7 +274,8 @@ class RecentChange {
                                        $this->mAttribs['rc_timestamp'],
                                        $this->mAttribs['rc_comment'],
                                        $this->mAttribs['rc_minor'],
-                                       $this->mAttribs['rc_last_oldid'] );
+                                       $this->mAttribs['rc_last_oldid'],
+                                       $this->mExtra['pageStatus'] );
                        }
                }
        }
@@ -427,6 +463,7 @@ class RecentChange {
                        'lastTimestamp' => $lastTimestamp,
                        'oldSize'       => $oldSize,
                        'newSize'       => $newSize,
+                       'pageStatus'   => 'changed'
                );
                $rc->save();
                return $rc;
@@ -484,7 +521,8 @@ class RecentChange {
                        'prefixedDBkey' => $title->getPrefixedDBkey(),
                        'lastTimestamp' => 0,
                        'oldSize' => 0,
-                       'newSize' => $size
+                       'newSize' => $size,
+                       'pageStatus' => 'created'
                );
                $rc->save();
                return $rc;
@@ -538,6 +576,27 @@ class RecentChange {
                $type, $action, $target, $logComment, $params, $newId = 0, $actionCommentIRC = '' ) {
                global $wgRequest;
 
+               ## Get pageStatus for email notification
+               switch ( $type . '-' . $action ) {
+                       case 'delete-delete':
+                               $pageStatus = 'deleted';
+                               break;
+                       case 'move-move':
+                       case 'move-move_redir':
+                               $pageStatus = 'moved';
+                               break;
+                       case 'delete-restore':
+                               $pageStatus = 'restored';
+                               break;
+                       case 'upload-upload':
+                               $pageStatus = 'created';
+                               break;
+                       case 'upload-overwrite':
+                       default:
+                               $pageStatus = 'changed';
+                               break;
+               }
+
                $rc = new RecentChange;
                $rc->mTitle = $target;
                $rc->mPerformer = $user;
@@ -571,6 +630,7 @@ class RecentChange {
                        'prefixedDBkey' => $title->getPrefixedDBkey(),
                        'lastTimestamp' => 0,
                        'actionComment' => $actionComment, // the comment appended to the action, passed from LogPage
+                       'pageStatus'    => $pageStatus,
                        'actionCommentIRC' => $actionCommentIRC
                );
                return $rc;