Nighttime commit when I'm tired and want to get this thing checked in and go to bed...
[lhc/web/wiklou.git] / includes / PageHistory.php
index 9550da6..1c39955 100644 (file)
@@ -65,12 +65,11 @@ class PageHistory {
                 * Allow client caching.
                 */
 
-               if( $wgOut->checkLastModified( $this->mArticle->getTimestamp() ) )
+               if( $wgOut->checkLastModified( $this->mArticle->getTouched() ) )
                        /* Client cache fresh and headers sent, nothing more to do. */
                        return;
 
-               $fname = 'PageHistory::history';
-               wfProfileIn( $fname );
+               wfProfileIn( __METHOD__ );
 
                /*
                 * Setup page variables.
@@ -89,7 +88,7 @@ class PageHistory {
 
                $feedType = $wgRequest->getVal( 'feed' );
                if( $feedType ) {
-                       wfProfileOut( $fname );
+                       wfProfileOut( __METHOD__ );
                        return $this->feed( $feedType );
                }
 
@@ -98,7 +97,7 @@ class PageHistory {
                 */
                if( !$this->mTitle->exists() ) {
                        $wgOut->addWikiMsg( 'nohistory' );
-                       wfProfileOut( $fname );
+                       wfProfileOut( __METHOD__ );
                        return;
                }
 
@@ -126,7 +125,7 @@ class PageHistory {
                        $this->endHistoryList() .
                        $pager->getNavigationBar()
                );
-               wfProfileOut( $fname );
+               wfProfileOut( __METHOD__ );
        }
 
        /**
@@ -197,8 +196,8 @@ class PageHistory {
         *
         * @todo document some more, and maybe clean up the code (some params redundant?)
         *
-        * @param object $row The database row corresponding to the line (or is it the previous line?).
-        * @param object $next The database row corresponding to the next line (or is it this one?).
+        * @param Row $row The database row corresponding to the previous line.
+        * @param mixed $next The database row corresponding to the next line.
         * @param int $counter Apparently a counter of what row number we're at, counted from the top row = 1.
         * @param $notificationtimestamp
         * @param bool $latest Whether this row corresponds to the page's latest revision.
@@ -239,13 +238,13 @@ class PageHistory {
                }
                
                $s .= " $link";
-               $s .= ' '.$this->mSkin->revUserTools( $rev, true );
-               
+               $s .= " <span class='history-user'>" . $this->mSkin->revUserTools( $rev, true ) . "</span>";
+
                if( $row->rev_minor_edit ) {
-                       $s .= ' ' . wfElement( 'span', array( 'class' => 'minor' ), wfMsg( 'minoreditletter') );
+                       $s .= ' ' . Xml::element( 'span', array( 'class' => 'minor' ), wfMsg( 'minoreditletter') );
                }
 
-               if ( !is_null( $size = $rev->getSize() ) ) {
+               if ( !is_null( $size = $rev->getSize() ) && $rev->userCan( Revision::DELETED_TEXT ) ) {
                        if ( $size == 0 )
                                $stxt = wfMsgHtml( 'historyempty' );
                        else
@@ -253,19 +252,13 @@ class PageHistory {
                        $s .= " <span class=\"history-size\">$stxt</span>";
                }
 
-               #getComment is safe, but this is better formatted
-               if( $rev->isDeleted( Revision::DELETED_COMMENT ) ) {
-                       $s .= " <span class=\"history-deleted\"><span class=\"comment\">" .
-                       wfMsgHtml( 'rev-deleted-comment' ) . "</span></span>";
-               } else {
-                       $s .= $this->mSkin->revComment( $rev );
-               }
+               $s .= $this->mSkin->revComment( $rev, false, true );
                
                if ($notificationtimestamp && ($row->rev_timestamp >= $notificationtimestamp)) {
                        $s .= ' <span class="updatedmarker">' .  wfMsgHtml( 'updatedmarker' ) . '</span>';
                }
                #add blurb about text having been deleted
-               if( $row->rev_deleted & Revision::DELETED_TEXT ) {
+               if( $rev->isDeleted( Revision::DELETED_TEXT ) ) {
                        $s .= ' <tt>' . wfMsgHtml( 'deletedrev' ) . '</tt>';
                }
                
@@ -301,7 +294,11 @@ class PageHistory {
                return $s;
        }
        
-       /** @todo document */
+       /** 
+       * Create a link to view this revision of the page
+       * @param Revision $rev
+       * @returns string
+       */
        function revLink( $rev ) {
                global $wgLang;
                $date = $wgLang->timeanddate( wfTimestamp(TS_MW, $rev->getTimestamp()), true );
@@ -317,7 +314,12 @@ class PageHistory {
                return $link;
        }
 
-       /** @todo document */
+       /** 
+       * Create a diff-to-current link for this revision for this page
+       * @param Revision $rev
+       * @param Bool $latest, this is the latest revision of the page?
+       * @returns string
+       */
        function curLink( $rev, $latest ) {
                $cur = $this->message['cur'];
                if( $latest || !$rev->userCan( Revision::DELETED_TEXT ) ) {
@@ -330,25 +332,33 @@ class PageHistory {
                }
        }
 
-       /** @todo document */
-       function lastLink( $rev, $next, $counter ) {
+       /** 
+       * Create a diff-to-previous link for this revision for this page.
+       * @param Revision $prevRev, the previous revision
+       * @param mixed $next, the newer revision
+       * @param int $counter, what row on the history list this is
+       * @returns string
+       */
+       function lastLink( $prevRev, $next, $counter ) {
                $last = $this->message['last'];
-               if ( is_null( $next ) ) {
+               # $next may either be a Row, null, or "unkown"
+               $nextRev = is_object($next) ? new Revision( $next ) : $next;
+               if( is_null($next) ) {
                        # Probably no next row
                        return $last;
-               } elseif ( $next === 'unknown' ) {
+               } elseif( $next === 'unknown' ) {
                        # Next row probably exists but is unknown, use an oldid=prev link
                        return $this->mSkin->makeKnownLinkObj(
                                $this->mTitle,
                                $last,
-                               "diff=" . $rev->getId() . "&oldid=prev" );
-               } elseif( !$rev->userCan( Revision::DELETED_TEXT ) ) {
+                               "diff=" . $prevRev->getId() . "&oldid=prev" );
+               } elseif( !$prevRev->userCan(Revision::DELETED_TEXT) || !$nextRev->userCan(Revision::DELETED_TEXT) ) {
                        return $last;
                } else {
                        return $this->mSkin->makeKnownLinkObj(
                                $this->mTitle,
                                $last,
-                               "diff=" . $rev->getId() . "&oldid={$next->rev_id}"
+                               "diff=" . $prevRev->getId() . "&oldid={$next->rev_id}"
                                /*,
                                '',
                                '',
@@ -409,11 +419,11 @@ class PageHistory {
        function getLatestId() {
                if( is_null( $this->mLatestId ) ) {
                        $id = $this->mTitle->getArticleID();
-                       $db = wfGetDB(DB_SLAVE);
+                       $db = wfGetDB( DB_SLAVE );
                        $this->mLatestId = $db->selectField( 'page',
                                "page_latest",
                                array( 'page_id' => $id ),
-                               'PageHistory::getLatestID' );
+                               __METHOD__ );
                }
                return $this->mLatestId;
        }
@@ -424,8 +434,6 @@ class PageHistory {
         * used by the main UI but that's now handled by the pager.
         */
        function fetchRevisions($limit, $offset, $direction) {
-               $fname = 'PageHistory::fetchRevisions';
-
                $dbr = wfGetDB( DB_SLAVE );
 
                if ($direction == PageHistory::DIR_PREV)
@@ -444,7 +452,7 @@ class PageHistory {
                        'revision',
                        Revision::selectFields(),
                        array_merge(array("rev_page=$page_id"), $offsets),
-                       $fname,
+                       __METHOD__,
                        array('ORDER BY' => "rev_timestamp $dirs",
                                'USE INDEX' => 'page_timestamp', 'LIMIT' => $limit)
                        );
@@ -459,7 +467,6 @@ class PageHistory {
        /** @todo document */
        function getNotificationTimestamp() {
                global $wgUser, $wgShowUpdatedMarker;
-               $fname = 'PageHistory::getNotficationTimestamp';
 
                if ($this->mNotificationTimestamp !== NULL)
                        return $this->mNotificationTimestamp;
@@ -476,7 +483,7 @@ class PageHistory {
                                'wl_title' => $this->mTitle->getDBkey(),
                                'wl_user' => $wgUser->getID()
                        ),
-                       $fname);
+                       __METHOD__ );
                
                // Don't use the special value reserved for telling whether the field is filled
                if ( is_null( $this->mNotificationTimestamp ) ) {