(Bug 15936) New page's patrol button should always be visible
authorAaron Schulz <aaron@users.mediawiki.org>
Thu, 15 Jan 2009 17:53:19 +0000 (17:53 +0000)
committerAaron Schulz <aaron@users.mediawiki.org>
Thu, 15 Jan 2009 17:53:19 +0000 (17:53 +0000)
includes/Article.php
includes/Revision.php
includes/Title.php

index a2db379..8058ead 100644 (file)
@@ -967,6 +967,13 @@ class Article {
                        $wgOut->addWikiMsg('anontalkpagetext');
                }
 
+               # Only diffs and new page links from RC give rcid params, so if
+               # we are just viewing the page normally with no rcid, try to find it. 
+               # This is more convenient for users.
+               if( empty($rcid) && $this->mTitle->userCan('patrol') ) {
+                       $firstRev = $this->mTitle->getFirstRevision();
+                       $rcid = $firstRev->isUnpatrolled();
+               }
                # If we have been passed an &rcid= parameter, we want to give the user a
                # chance to mark this new article as patrolled.
                if( !empty($rcid) && $this->mTitle->exists() && $this->mTitle->userCan('patrol') ) {
index 5fef68c..458b312 100644 (file)
@@ -363,6 +363,7 @@ class Revision {
                } else {
                        throw new MWException( 'Revision constructor passed invalid row format.' );
                }
+               $this->mUnpatrolled = NULL;
        }
 
        /**#@+
@@ -536,6 +537,27 @@ class Revision {
        public function isMinor() {
                return (bool)$this->mMinorEdit;
        }
+       
+       /**
+        * @return int rcid of the unpatrolled row, zero if there isn't one
+        */
+       public function isUnpatrolled() {
+               if( $this->mUnpatrolled !== NULL ) {
+                       return $this->mUnpatrolled;
+               }
+               $dbr = wfGetDB( DB_SLAVE );
+               $this->mUnpatrolled = $dbr->selectField( 'recentchanges',
+                       'rc_id',
+                       array( // Add redundant user,timestamp condition so we can use the existing index
+                               'rc_user_text'  => $this->getRawUserText(),
+                               'rc_timestamp'  => $dbr->timestamp( $this->getTimestamp() ),
+                               'rc_this_oldid' => $this->getId(),
+                               'rc_patrolled'  => 0
+                       ),
+                       __METHOD__
+               );
+               return (int)$this->mUnpatrolled;
+       }
 
        /**
         * int $field one of DELETED_* bitfield constants
index 7d470ed..bac558f 100644 (file)
@@ -3033,6 +3033,28 @@ class Title {
                );
        }
        
+       /**
+        * Get the first revision of the page
+        *
+        * @param $flags \type{\int} GAID_FOR_UPDATE
+        * @return Revision (or NULL if page doesn't exist)
+        */
+       public function getFirstRevision( $flags=0 ) {
+               $db = ($flags & GAID_FOR_UPDATE) ? wfGetDB( DB_MASTER ) : wfGetDB( DB_SLAVE );
+               $pageId = $this->getArticleId($flags);
+               if( !$pageId ) return NULL;
+               $row = $db->selectRow( 'revision', '*',
+                       array( 'rev_page' => $pageId ),
+                       __METHOD__,
+                       array( 'ORDER BY' => 'rev_timestamp ASC', 'LIMIT' => 1 )
+               );
+               if( !$row ) {
+                       return NULL;
+               } else {
+                       return new Revision( $row );
+               }
+       }
+       
        /**
         * Check if this is a new page
         *