From d169a9bc8a44752ed5b1ef1348f25ae2ab6bc24c Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Thu, 15 Jan 2009 17:53:19 +0000 Subject: [PATCH] (Bug 15936) New page's patrol button should always be visible --- includes/Article.php | 7 +++++++ includes/Revision.php | 22 ++++++++++++++++++++++ includes/Title.php | 22 ++++++++++++++++++++++ 3 files changed, 51 insertions(+) diff --git a/includes/Article.php b/includes/Article.php index a2db379629..8058eadc6e 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -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') ) { diff --git a/includes/Revision.php b/includes/Revision.php index 5fef68c296..458b312daa 100644 --- a/includes/Revision.php +++ b/includes/Revision.php @@ -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 diff --git a/includes/Title.php b/includes/Title.php index 7d470edebb..bac558f328 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -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 * -- 2.20.1