doc fix
[lhc/web/wiklou.git] / includes / PageHistory.php
index 4ad2fe2..0dbf356 100644 (file)
@@ -6,9 +6,6 @@
  * @package MediaWiki
  */
 
-define('DIR_PREV', 0);
-define('DIR_NEXT', 1);
-
 /**
  * This class handles printing the history page for an article.  In order to
  * be efficient, it uses timestamps rather than offsets for paging, to avoid
@@ -21,6 +18,9 @@ define('DIR_NEXT', 1);
  */
 
 class PageHistory {
+       const DIR_PREV = 0;
+       const DIR_NEXT = 1;
+       
        var $mArticle, $mTitle, $mSkin;
        var $lastdate;
        var $linesonpage;
@@ -71,6 +71,13 @@ class PageHistory {
                $wgOut->setArticleFlag( false );
                $wgOut->setArticleRelated( true );
                $wgOut->setRobotpolicy( 'noindex,nofollow' );
+               $wgOut->setSyndicated( true );
+
+               $feedType = $wgRequest->getVal( 'feed' );
+               if( $feedType ) {
+                       wfProfileOut( $fname );
+                       return $this->feed( $feedType );
+               }
 
                /*
                 * Fail if article doesn't exist.
@@ -99,6 +106,7 @@ class PageHistory {
                 * "go=last" means to jump to the last history page.
                 */
                if (($gowhere = $wgRequest->getText("go")) !== NULL) {
+                       $gourl = null;
                        switch ($gowhere) {
                        case "first":
                                if (($lastid = $this->getLastOffsetForPaging($this->mTitle->getArticleID(), $limit)) === NULL)
@@ -106,8 +114,6 @@ class PageHistory {
                                $gourl = $wgTitle->getLocalURL("action=history&limit={$limit}&offset=".
                                                wfTimestamp(TS_MW, $lastid));
                                break;
-                       default:
-                               $gourl = NULL;
                        }
 
                        if (!is_null($gourl)) {
@@ -139,7 +145,7 @@ class PageHistory {
                        $this->linesonpage = count($revisions) - 1;
 
                /* Un-reverse revisions */
-               if ($direction == DIR_PREV)
+               if ($direction == PageHistory::DIR_PREV)
                        $revisions = array_reverse($revisions);
 
                /*
@@ -174,7 +180,7 @@ class PageHistory {
        function beginHistoryList() {
                global $wgTitle;
                $this->lastdate = '';
-               $s = wfMsgWikiHtml( 'histlegend' );
+               $s = wfMsgExt( 'histlegend', array( 'parse') );
                $s .= '<form action="' . $wgTitle->escapeLocalURL( '-' ) . '" method="get">';
                $prefixedkey = htmlspecialchars($wgTitle->getPrefixedDbKey());
 
@@ -198,8 +204,6 @@ class PageHistory {
 
        /** @todo document */
        function endHistoryList() {
-               $last = wfMsg( 'last' );
-
                $s = '</ul>';
                $s .= $this->submitButton( array( 'id' => 'historysubmit' ) );
                $s .= '</form>';
@@ -213,9 +217,9 @@ class PageHistory {
                                array(
                                        'class'     => 'historysubmit',
                                        'type'      => 'submit',
-                                       'accesskey' => wfMsgHtml( 'accesskey-compareselectedversions' ),
-                                       'title'     => wfMsgHtml( 'tooltip-compareselectedversions' ),
-                                       'value'     => wfMsgHtml( 'compareselectedversions' ),
+                                       'accesskey' => wfMsg( 'accesskey-compareselectedversions' ),
+                                       'title'     => wfMsg( 'tooltip-compareselectedversions' ),
+                                       'value'     => wfMsg( 'compareselectedversions' ),
                                ) ) )
                        : '';
        }
@@ -224,6 +228,7 @@ class PageHistory {
        function historyLine( $row, $next, $counter = '', $notificationtimestamp = false, $latest = false, $firstInList = false ) {
                global $wgUser;
                $rev = new Revision( $row );
+               $rev->setTitle( $this->mTitle );
 
                $s = '<li>';
                $curlink = $this->curLink( $rev, $latest );
@@ -251,14 +256,14 @@ class PageHistory {
                $s .= " $link <span class='history-user'>$user</span>";
 
                if( $row->rev_minor_edit ) {
-                       $s .= ' ' . wfElement( 'span', array( 'class' => 'minor' ), wfMsgHtml( 'minoreditletter') );
+                       $s .= ' ' . wfElement( 'span', array( 'class' => 'minor' ), wfMsg( 'minoreditletter') );
                }
 
                $s .= $this->mSkin->revComment( $rev );
                if ($notificationtimestamp && ($row->rev_timestamp >= $notificationtimestamp)) {
                        $s .= ' <span class="updatedmarker">' .  wfMsgHtml( 'updatedmarker' ) . '</span>';
                }
-               if( $row->rev_deleted & MW_REV_DELETED_TEXT ) {
+               if( $row->rev_deleted & Revision::MW_REV_DELETED_TEXT ) {
                        $s .= ' ' . wfMsgHtml( 'deletedrev' );
                }
                $s .= "</li>\n";
@@ -270,13 +275,13 @@ class PageHistory {
        function revLink( $rev ) {
                global $wgLang;
                $date = $wgLang->timeanddate( wfTimestamp(TS_MW, $rev->getTimestamp()), true );
-               if( $rev->userCan( MW_REV_DELETED_TEXT ) ) {
+               if( $rev->userCan( Revision::MW_REV_DELETED_TEXT ) ) {
                        $link = $this->mSkin->makeKnownLinkObj(
                                $this->mTitle, $date, "oldid=" . $rev->getId() );
                } else {
                        $link = $date;
                }
-               if( $rev->isDeleted( MW_REV_DELETED_TEXT ) ) {
+               if( $rev->isDeleted( Revision::MW_REV_DELETED_TEXT ) ) {
                        return '<span class="history-deleted">' . $link . '</span>';
                }
                return $link;
@@ -284,8 +289,8 @@ class PageHistory {
 
        /** @todo document */
        function curLink( $rev, $latest ) {
-               $cur = wfMsgHtml( 'cur' );
-               if( $latest || !$rev->userCan( MW_REV_DELETED_TEXT ) ) {
+               $cur = wfMsgExt( 'cur', array( 'escape') );
+               if( $latest || !$rev->userCan( Revision::MW_REV_DELETED_TEXT ) ) {
                        return $cur;
                } else {
                        return $this->mSkin->makeKnownLinkObj(
@@ -297,7 +302,7 @@ class PageHistory {
 
        /** @todo document */
        function lastLink( $rev, $next, $counter ) {
-               $last = htmlspecialchars( wfMsg( 'last' ) );
+               $last = wfMsgExt( 'last', array( 'escape' ) );
                if( is_null( $next ) ) {
                        if( $rev->getTimestamp() == $this->getEarliestOffset() ) {
                                return $last;
@@ -308,7 +313,7 @@ class PageHistory {
                                        $last,
                                        "diff=" . $rev->getId() . "&oldid=prev" );
                        }
-               } elseif( !$rev->userCan( MW_REV_DELETED_TEXT ) ) {
+               } elseif( !$rev->userCan( Revision::MW_REV_DELETED_TEXT ) ) {
                        return $last;
                } else {
                        return $this->mSkin->makeKnownLinkObj(
@@ -332,7 +337,7 @@ class PageHistory {
 #                              'title' => wfMsgHtml( 'selectolderversionfordiff' )
                        );
 
-                       if( !$rev->userCan( MW_REV_DELETED_TEXT ) ) {
+                       if( !$rev->userCan( Revision::MW_REV_DELETED_TEXT ) ) {
                                $radio['disabled'] = 'disabled';
                        }
 
@@ -427,9 +432,9 @@ class PageHistory {
        function getDirection() {
                global $wgRequest;
                if ($wgRequest->getText("dir") == "prev")
-                       return DIR_PREV;
+                       return PageHistory::DIR_PREV;
                else
-                       return DIR_NEXT;
+                       return PageHistory::DIR_NEXT;
        }
 
        /** @todo document */
@@ -438,9 +443,9 @@ class PageHistory {
 
                $dbr =& wfGetDB( DB_SLAVE );
 
-               if ($direction == DIR_PREV)
+               if ($direction == PageHistory::DIR_PREV)
                        list($dirs, $oper) = array("ASC", ">=");
-               else /* $direction == DIR_NEXT */
+               else /* $direction == PageHistory::DIR_NEXT */
                        list($dirs, $oper) = array("DESC", "<=");
 
                if ($offset)
@@ -488,6 +493,11 @@ class PageHistory {
                                'wl_user' => $wgUser->getID()
                        ),
                        $fname);
+               
+               // Don't use the special value reserved for telling whether the field is filled
+               if ( is_null( $this->mNotificationTimestamp ) ) {
+                       $this->mNotificationTimestamp = false;
+               }
 
                return $this->mNotificationTimestamp;
        }
@@ -505,7 +515,7 @@ class PageHistory {
                 * When we're displaying previous revisions, we need to reverse
                 * the array, because it's queried in reverse order.
                 */
-               if ($direction == DIR_PREV)
+               if ($direction == PageHistory::DIR_PREV)
                        $revisions = array_reverse($revisions);
 
                /*
@@ -518,6 +528,9 @@ class PageHistory {
                if( count( $revisions ) ) {
                        $latestShown = wfTimestamp(TS_MW, $revisions[0]->rev_timestamp);
                        $earliestShown = wfTimestamp(TS_MW, $revisions[count($revisions) - 1]->rev_timestamp);
+               } else {
+                       $latestShown = null;
+                       $earliestShown = null;
                }
 
                /* Don't announce the limit everywhere if it's the default */
@@ -564,6 +577,92 @@ class PageHistory {
                                $this->mTitle, $text,
                                wfArrayToCGI( $query, array( 'action' => 'history' )));
        }
+       
+       
+       /**
+        * Output a subscription feed listing recent edits to this page.
+        * @param string $type
+        */
+       function feed( $type ) {
+               require_once 'SpecialRecentchanges.php';
+               
+               global $wgFeedClasses;
+               if( !isset( $wgFeedClasses[$type] ) ) {
+                       global $wgOut;
+                       $wgOut->addWikiText( wfMsg( 'feed-invalid' ) );
+                       return;
+               }
+               
+               $feed = new $wgFeedClasses[$type](
+                       $this->mTitle->getPrefixedText() . ' - ' .
+                               wfMsgForContent( 'history-feed-title' ),
+                       wfMsgForContent( 'history-feed-description' ),
+                       $this->mTitle->getFullUrl( 'action=history' ) );
+
+               $items = $this->fetchRevisions(10, 0, PageHistory::DIR_NEXT);
+               $feed->outHeader();
+               if( $items ) {
+                       foreach( $items as $row ) {
+                               $feed->outItem( $this->feedItem( $row ) );
+                       }
+               } else {
+                       $feed->outItem( $this->feedEmpty() );
+               }
+               $feed->outFooter();
+       }
+       
+       function feedEmpty() {
+               global $wgOut;
+               return new FeedItem(
+                       wfMsgForContent( 'nohistory' ),
+                       $wgOut->parse( wfMsgForContent( 'history-feed-empty' ) ),
+                       $this->mTitle->getFullUrl(),
+                       wfTimestamp( TS_MW ),
+                       '',
+                       $this->mTitle->getTalkPage()->getFullUrl() );
+       }
+       
+       /**
+        * Generate a FeedItem object from a given revision table row
+        * Borrows Recent Changes' feed generation functions for formatting;
+        * includes a diff to the previous revision (if any).
+        *
+        * @param $row
+        * @return FeedItem
+        */
+       function feedItem( $row ) {
+               $rev = new Revision( $row );
+               $rev->setTitle( $this->mTitle );
+               $text = rcFormatDiffRow( $this->mTitle,
+                       $this->mTitle->getPreviousRevisionID( $rev->getId() ),
+                       $rev->getId(),
+                       $rev->getTimestamp(),
+                       $rev->getComment() );
+               
+               if( $rev->getComment() == '' ) {
+                       global $wgContLang;
+                       $title = wfMsgForContent( 'history-feed-item-nocomment',
+                               $rev->getUserText(),
+                               $wgContLang->timeanddate( $rev->getTimestamp() ) );
+               } else {
+                       $title = $rev->getUserText() . ": " . $this->stripComment( $rev->getComment() );
+               }
+
+               return new FeedItem(
+                       $title,
+                       $text,
+                       $this->mTitle->getFullUrl( 'diff=' . $rev->getId() . '&oldid=prev' ),
+                       $rev->getTimestamp(),
+                       $rev->getUserText(),
+                       $this->mTitle->getTalkPage()->getFullUrl() );
+       }
+       
+       /**
+        * Quickie hack... strip out wikilinks to more legible form from the comment.
+        */
+       function stripComment( $text ) {
+               return preg_replace( '/\[\[([^]]*\|)?([^]]+)\]\]/', '\2', $text );
+       }
 
 
 }