Follow-up on r56284: LogEventsList::showLogExtract gets associative array for additio...
[lhc/web/wiklou.git] / includes / HistoryPage.php
index 2420d6e..81ab58b 100644 (file)
@@ -29,8 +29,8 @@ class HistoryPage {
         */
        function __construct( $article ) {
                global $wgUser;
-               $this->article =& $article;
-               $this->title =& $article->getTitle();
+               $this->article = $article;
+               $this->title = $article->getTitle();
                $this->skin = $wgUser->getSkin();
                $this->preCacheMessages();
        }
@@ -105,6 +105,13 @@ class HistoryPage {
                 */
                if( !$this->title->exists() ) {
                        $wgOut->addWikiMsg( 'nohistory' );
+                       # show deletion/move log if there is an entry
+                       LogEventsList::showLogExtract( $wgOut, array( 'delete', 'move' ), $this->title->getPrefixedText(), '',
+                               array(  'lim' => 10,
+                                       'conds' => array( "log_action != 'revision'" ),
+                                       'showIfEmpty' => false,
+                                       'msgKey' => array( 'moveddeleted-notice' ) ) 
+                       );
                        wfProfileOut( __METHOD__ );
                        return;
                }
@@ -215,8 +222,9 @@ class HistoryPage {
                        $wgOut->parse( wfMsgForContent( 'history-feed-empty' ) ),
                        $this->title->getFullUrl(),
                        wfTimestamp( TS_MW ),
-                               '',
-                       $this->title->getTalkPage()->getFullUrl() );
+                       '',
+                       $this->title->getTalkPage()->getFullUrl()
+               );
        }
 
        /**
@@ -230,12 +238,13 @@ class HistoryPage {
        function feedItem( $row ) {
                $rev = new Revision( $row );
                $rev->setTitle( $this->title );
-               $text = FeedUtils::formatDiffRow( $this->title,
-               $this->title->getPreviousRevisionID( $rev->getId() ),
-               $rev->getId(),
-               $rev->getTimestamp(),
-               $rev->getComment() );
-
+               $text = FeedUtils::formatDiffRow(
+                       $this->title,
+                       $this->title->getPreviousRevisionID( $rev->getId() ),
+                       $rev->getId(),
+                       $rev->getTimestamp(),
+                       $rev->getComment()
+               );
                if( $rev->getComment() == '' ) {
                        global $wgContLang;
                        $title = wfMsgForContent( 'history-feed-item-nocomment',
@@ -244,14 +253,14 @@ class HistoryPage {
                } else {
                        $title = $rev->getUserText() . wfMsgForContent( 'colon-separator' ) . FeedItem::stripComment( $rev->getComment() );
                }
-
                return new FeedItem(
                        $title,
                        $text,
                        $this->title->getFullUrl( 'diff=' . $rev->getId() . '&oldid=prev' ),
                        $rev->getTimestamp(),
                        $rev->getUserText(),
-                       $this->title->getTalkPage()->getFullUrl() );
+                       $this->title->getTalkPage()->getFullUrl()
+               );
        }
 }
 
@@ -260,7 +269,7 @@ class HistoryPage {
  * @ingroup Pager
  */
 class HistoryPager extends ReverseChronologicalPager {
-       public $lastRow = false, $counter, $historyPage, $title;
+       public $lastRow = false, $counter, $historyPage, $title, $buttons;
        protected $oldIdChecked;
 
        function __construct( $historyPage, $year='', $month='', $tagFilter = '' ) {
@@ -270,6 +279,11 @@ class HistoryPager extends ReverseChronologicalPager {
                $this->tagFilter = $tagFilter;
                $this->getDateCond( $year, $month );
        }
+       
+       // For hook compatibility...
+       function getArticle() {
+               return $this->historyPage->getArticle();
+       }
 
        function getQueryInfo() {
                $queryInfo = array(
@@ -295,7 +309,7 @@ class HistoryPager extends ReverseChronologicalPager {
 
        function formatRow( $row ) {
                if( $this->lastRow ) {
-                       $latest = $this->counter == 1 && $this->mIsFirst;
+                       $latest = ($this->counter == 1 && $this->mIsFirst);
                        $firstInList = $this->counter == 1;
                        $s = $this->historyLine( $this->lastRow, $row, $this->counter++,
                                $this->title->getNotificationTimestamp(), $latest, $firstInList );
@@ -312,63 +326,62 @@ class HistoryPager extends ReverseChronologicalPager {
         * @return string HTML output
         */
        function getStartBody() {
-               global $wgScript, $wgEnableHtmlDiff, $wgUser;
+               global $wgScript, $wgEnableHtmlDiff, $wgUser, $wgOut;
                $this->lastRow = false;
                $this->counter = 1;
                $this->oldIdChecked = 0;
 
-               $s = wfMsgExt( 'histlegend', array( 'parse') );
-               if( $this->getNumRows() > 1 && $wgUser->isAllowed('deleterevision') ) {
-                       $revdel = SpecialPage::getTitleFor( 'Revisiondelete' );
-                       $s .= Xml::openElement( 'form',
+               $wgOut->wrapWikiMsg( "<div class='mw-history-legend'>\n$1</div>", 'histlegend' );
+               $s = Xml::openElement( 'form', array( 'action' => $wgScript,
+                       'id' => 'mw-history-compare' ) ) . "\n";
+               $s .= Xml::hidden( 'title', $this->title->getPrefixedDbKey() ) . "\n";
+
+               $this->buttons = '<div>';
+               if( $wgUser->isAllowed('deleterevision') ) {
+                       $this->buttons .= Xml::element( 'button', 
                                array(
-                                       'action' => $revdel->getLocalURL( array( 
-                                               'type' => 'revision',
-                                               'target' => $this->title->getPrefixedDbKey()
-                                       ) ),
-                                       'method' => 'post', 
-                                       'id' => 'mw-history-revdeleteform',
-                                       'style'  => 'visibility:hidden;float:right;'
-                               )
-                       );
-                       $s .= Xml::hidden( 'ids', '', array('id'=>'revdel-oldid') );
-                       $s .= Xml::submitButton( wfMsg( 'showhideselectedversions' ) );
-                       $s .= Xml::closeElement( 'form' );
+                                       'type' => 'submit',
+                                       'name' => 'action',
+                                       'value' => 'revisiondelete',
+                                       'style' => 'float: right',
+                               ),
+                               wfMsg( 'showhideselectedversions' )
+                       ) . "\n";
                }
-               $s .= Xml::openElement( 'form', array( 'action' => $wgScript,
-                       'id' => 'mw-history-compare' ) );
-               $s .= Xml::hidden( 'title', $this->title->getPrefixedDbKey() );
                if( $wgEnableHtmlDiff ) {
-                       $s .= $this->submitButton( wfMsg( 'visualcomparison'),
+                       $this->buttons .= Xml::element( 'button',
                                array(
-                                       'name' => 'htmldiff',
+                                       'type'      => 'submit',
+                                       'name'      => 'htmldiff',
+                                       'value'     => '1',
                                        'class'     => 'historysubmit',
                                        'accesskey' => wfMsg( 'accesskey-visualcomparison' ),
                                        'title'     => wfMsg( 'tooltip-compareselectedversions' ),
-                               )
-                       );
-                       $s .= $this->submitButton( wfMsg( 'wikicodecomparison'),
+                               ),
+                               wfMsg( 'visualcomparison')
+                       ) . "\n";
+                       $this->buttons .= $this->submitButton( wfMsg( 'wikicodecomparison'),
                                array(
                                        'class'     => 'historysubmit',
                                        'accesskey' => wfMsg( 'accesskey-compareselectedversions' ),
                                        'title'     => wfMsg( 'tooltip-compareselectedversions' ),
                                )
-                       );
+                       ) . "\n";
                } else {
-                       $s .= $this->submitButton( wfMsg( 'compareselectedversions'),
+                       $this->buttons .= $this->submitButton( wfMsg( 'compareselectedversions'),
                                array(
                                        'class'     => 'historysubmit',
                                        'accesskey' => wfMsg( 'accesskey-compareselectedversions' ),
                                        'title'     => wfMsg( 'tooltip-compareselectedversions' ),
                                )
-                       );
+                       ) . "\n";
                }
-               $s .= '<ul id="pagehistory">' . "\n";
+               $this->buttons .= '</div>';
+               $s .= $this->buttons . '<ul id="pagehistory">' . "\n";
                return $s;
        }
 
        function getEndBody() {
-
                if( $this->lastRow ) {
                        $latest = $this->counter == 1 && $this->mIsFirst;
                        $firstInList = $this->counter == 1;
@@ -388,34 +401,8 @@ class HistoryPager extends ReverseChronologicalPager {
                } else {
                        $s = '';
                }
-
-               global $wgEnableHtmlDiff;
-               $s .= '</ul>';
-               if( $wgEnableHtmlDiff ) {
-                       $s .= $this->submitButton( wfMsg( 'visualcomparison'),
-                               array(
-                                       'name' => 'htmldiff',
-                                       'class'     => 'historysubmit',
-                                       'accesskey' => wfMsg( 'accesskey-visualcomparison' ),
-                                       'title'     => wfMsg( 'tooltip-compareselectedversions' ),
-                               )
-                       );
-                       $s .= $this->submitButton( wfMsg( 'wikicodecomparison'),
-                               array(
-                                       'class'     => 'historysubmit',
-                                       'accesskey' => wfMsg( 'accesskey-compareselectedversions' ),
-                                       'title'     => wfMsg( 'tooltip-compareselectedversions' ),
-                               )
-                       );
-               } else {
-                       $s .= $this->submitButton( wfMsg( 'compareselectedversions'),
-                               array(
-                                       'class'     => 'historysubmit',
-                                       'accesskey' => wfMsg( 'accesskey-compareselectedversions' ),
-                                       'title'     => wfMsg( 'tooltip-compareselectedversions' ),
-                               )
-                       );
-               }
+               $s .= "</ul>\n";
+               $s .= $this->buttons;
                $s .= '</form>';
                return $s;
        }
@@ -464,28 +451,13 @@ class HistoryPager extends ReverseChronologicalPager {
                $s = "($curlink) ($lastlink) $diffButtons";
 
                if( $wgUser->isAllowed( 'deleterevision' ) ) {
-                       // Hide JS by default for non-JS browsing
-                       $hidden = array( 'style' => 'display:none' );
                        // If revision was hidden from sysops
                        if( !$rev->userCan( Revision::DELETED_RESTRICTED ) ) {
-                               $del = Xml::check( 'deleterevisions', false,
-                                       $hidden + array('disabled' => 'disabled') );
-                               $del .= Xml::tags( 'span', array( 'class'=>'mw-revdelundel-link' ),
-                                       '(' . $this->historyPage->message['rev-delundel'] . ')' );
+                               $del = Xml::check( 'deleterevisions', false, array('disabled' => 'disabled') );
                        // Otherwise, show the link...
                        } else {
                                $id = $rev->getId();
-                               $jsCall = "updateShowHideForm($id,this.checked)";
-                               $del = Xml::check( 'showhiderevisions', false,
-                                       $hidden + array(
-                                               'onchange' => $jsCall,
-                                               'id' => "mw-revdel-$id" ) );
-                               $query = array(
-                                       'type' => 'revision',
-                                       'target' => $this->title->getPrefixedDbkey(),
-                                       'ids' => $rev->getId() );
-                               $del .= $this->getSkin()->revDeleteLink( $query,
-                                       $rev->isDeleted( Revision::DELETED_RESTRICTED ) );
+                               $del = Xml::check( 'showhiderevisions', false, array( 'name' => "ids[$id]" ) );
                        }
                        $s .= " $del ";
                }
@@ -509,6 +481,7 @@ class HistoryPager extends ReverseChronologicalPager {
 
                $tools = array();
 
+               # Rollback and undo links
                if( !is_null( $next ) && is_object( $next ) ) {
                        if( $latest && $this->title->userCan( 'rollback' ) && $this->title->userCan( 'edit' ) ) {
                                $tools[] = '<span class="mw-rollback-link">'.