Add tests for parser tag hooks.
[lhc/web/wiklou.git] / includes / HistoryPage.php
index 462d6a1..fed09ae 100644 (file)
@@ -19,7 +19,12 @@ class HistoryPage {
        const DIR_PREV = 0;
        const DIR_NEXT = 1;
 
-       var $article, $title, $skin;
+       /** Contains the Article object. Passed on construction. */
+       private $article;
+       /** The $article title object. Found on construction. */
+       private $title;
+       /** Shortcut to the user Skin object. */
+       private $skin;
 
        /**
         * Construct a new HistoryPage.
@@ -34,11 +39,13 @@ class HistoryPage {
                $this->preCacheMessages();
        }
 
-       function getArticle() {
+       /** Get the Article object we are working on. */
+       public function getArticle() {
                return $this->article;
        }
 
-       function getTitle() {
+       /** Get the Title object. */
+       public function getTitle() {
                return $this->title;
        }
 
@@ -46,7 +53,7 @@ class HistoryPage {
         * As we use the same small set of messages in various methods and that
         * they are called often, we call them once and save them in $this->message
         */
-       function preCacheMessages() {
+       private function preCacheMessages() {
                // Precache various messages
                if ( !isset( $this->message ) ) {
                        $msgs = array( 'cur', 'last', 'pipe-separator' );
@@ -63,7 +70,7 @@ class HistoryPage {
        function history() {
                global $wgOut, $wgRequest, $wgScript;
 
-               /*
+               /**
                 * Allow client caching.
                 */
                if ( $wgOut->checkLastModified( $this->article->getTouched() ) )
@@ -71,9 +78,7 @@ class HistoryPage {
 
                wfProfileIn( __METHOD__ );
 
-               /*
-                * Setup page variables.
-                */
+               // Setup page variables.
                $wgOut->setPageTitle( wfMsg( 'history-title', $this->title->getPrefixedText() ) );
                $wgOut->setPageTitleActionText( wfMsg( 'history_short' ) );
                $wgOut->setArticleFlag( false );
@@ -81,8 +86,9 @@ class HistoryPage {
                $wgOut->setRobotPolicy( 'noindex,nofollow' );
                $wgOut->setSyndicated( true );
                $wgOut->setFeedAppendQuery( 'action=history' );
-               $wgOut->addModules( array( 'mediawiki.legacy.history', 'mediawiki.views.history' ) );
+               $wgOut->addModules( array( 'mediawiki.legacy.history', 'mediawiki.action.history' ) );
 
+               // Creation of a subtitle link pointing to [[Special:Log]]
                $logPage = SpecialPage::getTitleFor( 'Log' );
                $logLink = $this->skin->link(
                        $logPage,
@@ -93,15 +99,14 @@ class HistoryPage {
                );
                $wgOut->setSubtitle( $logLink );
 
+               // Handle atom/RSS feeds.
                $feedType = $wgRequest->getVal( 'feed' );
                if ( $feedType ) {
                        wfProfileOut( __METHOD__ );
                        return $this->feed( $feedType );
                }
 
-               /*
-                * Fail if article doesn't exist.
-                */
+               // Fail nicely if article doesn't exist.
                if ( !$this->title->exists() ) {
                        $wgOut->addWikiMsg( 'nohistory' );
                        # show deletion/move log if there is an entry
@@ -123,10 +128,11 @@ class HistoryPage {
                /**
                 * Add date selector to quickly get to a certain time
                 */
-               $year = $wgRequest->getInt( 'year' );
-               $month = $wgRequest->getInt( 'month' );
-               $tagFilter = $wgRequest->getVal( 'tagfilter' );
+               $year        = $wgRequest->getInt( 'year' );
+               $month       = $wgRequest->getInt( 'month' );
+               $tagFilter   = $wgRequest->getVal( 'tagfilter' );
                $tagSelector = ChangeTags::buildTagFilterSelector( $tagFilter );
+
                /**
                 * Option to show only revisions that have been (partially) hidden via RevisionDelete
                 */
@@ -138,6 +144,7 @@ class HistoryPage {
                $checkDeleted = Xml::checkLabel( wfMsg( 'history-show-deleted' ),
                        'deleted', 'mw-show-deleted-only', $wgRequest->getBool( 'deleted' ) ) . "\n";
 
+               // Add the general form
                $action = htmlspecialchars( $wgScript );
                $wgOut->addHTML(
                        "<form action=\"$action\" method=\"get\" id=\"mw-history-searchform\">" .
@@ -157,15 +164,14 @@ class HistoryPage {
 
                wfRunHooks( 'PageHistoryBeforeList', array( &$this->article ) );
 
-               /**
-                * Do the list
-                */
+               // Create and output the list.
                $pager = new HistoryPager( $this, $year, $month, $tagFilter, $conds );
                $wgOut->addHTML(
                        $pager->getNavigationBar() .
                        $pager->getBody() .
                        $pager->getNavigationBar()
                );
+               $wgOut->preventClickjacking( $pager->getPreventClickjacking() );
 
                wfProfileOut( __METHOD__ );
        }
@@ -232,6 +238,7 @@ class HistoryPage {
                }
                $items = $this->fetchRevisions( $limit, 0, HistoryPage::DIR_NEXT );
 
+               // Generate feed elements enclosed between header and footer.
                $feed->outHeader();
                if ( $items ) {
                        foreach ( $items as $row ) {
@@ -303,11 +310,12 @@ class HistoryPage {
 class HistoryPager extends ReverseChronologicalPager {
        public $lastRow = false, $counter, $historyPage, $title, $buttons, $conds;
        protected $oldIdChecked;
+       protected $preventClickjacking = false;
 
        function __construct( $historyPage, $year = '', $month = '', $tagFilter = '', $conds = array() ) {
                parent::__construct();
                $this->historyPage = $historyPage;
-               $this->title = $this->historyPage->title;
+               $this->title = $this->historyPage->getTitle();
                $this->tagFilter = $tagFilter;
                $this->getDateCond( $year, $month );
                $this->conds = $conds;
@@ -331,7 +339,7 @@ class HistoryPager extends ReverseChronologicalPager {
                        'tables'  => array( 'revision' ),
                        'fields'  => Revision::selectFields(),
                        'conds'   => array_merge(
-                               array( 'rev_page' => $this->historyPage->title->getArticleID() ),
+                               array( 'rev_page' => $this->historyPage->getTitle()->getArticleID() ),
                                $this->conds ),
                        'options' => array( 'USE INDEX' => array( 'revision' => 'page_timestamp' ) ),
                        'join_conds' => array( 'tag_summary' => array( 'LEFT JOIN', 'ts_rev_id=rev_id' ) ),
@@ -393,6 +401,7 @@ class HistoryPager extends ReverseChronologicalPager {
                ) . "\n";
 
                if ( $wgUser->isAllowed( 'deleterevision' ) ) {
+                       $this->preventClickjacking();
                        $float = $wgContLang->alignEnd();
                        # Note bug #20966, <button> is non-standard in IE<8
                        $element = Html::element( 'button',
@@ -409,6 +418,7 @@ class HistoryPager extends ReverseChronologicalPager {
                        $this->buttons .= $element;
                }
                if ( $wgUser->isAllowed( 'revisionmove' ) ) {
+                       $this->preventClickjacking();
                        $float = $wgContLang->alignEnd();
                        # Note bug #20966, <button> is non-standard in IE<8
                        $element = Html::element( 'button',
@@ -510,6 +520,7 @@ class HistoryPager extends ReverseChronologicalPager {
                $del = '';
                // Show checkboxes for each revision
                if ( $wgUser->isAllowed( 'deleterevision' ) || $wgUser->isAllowed( 'revisionmove' ) ) {
+                       $this->preventClickjacking();
                        // If revision was hidden from sysops, disable the checkbox
                        // However, if the user has revisionmove rights, we cannot disable the checkbox
                        if ( !$rev->userCan( Revision::DELETED_RESTRICTED ) && !$wgUser->isAllowed( 'revisionmove' ) ) {
@@ -559,6 +570,7 @@ class HistoryPager extends ReverseChronologicalPager {
                # Rollback and undo links
                if ( !is_null( $next ) && is_object( $next ) ) {
                        if ( $latest && $this->title->userCan( 'rollback' ) && $this->title->userCan( 'edit' ) ) {
+                               $this->preventClickjacking();
                                $tools[] = '<span class="mw-rollback-link">' .
                                        $this->getSkin()->buildRollbackLink( $rev ) . '</span>';
                        }
@@ -748,6 +760,20 @@ class HistoryPager extends ReverseChronologicalPager {
                        return '';
                }
        }
+
+       /**
+        * This is called if a write operation is possible from the generated HTML
+        */
+       function preventClickjacking( $enable = true ) {
+               $this->preventClickjacking = $enable;
+       }
+
+       /**
+        * Get the "prevent clickjacking" flag
+        */
+       function getPreventClickjacking() {
+               return $this->preventClickjacking;
+       }
 }
 
 /**