Merge "Bump grunt to 1.0.1, remove grunt-cli"
[lhc/web/wiklou.git] / includes / actions / HistoryAction.php
index 43260d0..5ec10e6 100644 (file)
@@ -61,8 +61,8 @@ class HistoryAction extends FormlessAction {
                return Linker::linkKnown(
                        SpecialPage::getTitleFor( 'Log' ),
                        $this->msg( 'viewpagelogs' )->escaped(),
-                       array(),
-                       array( 'page' => $this->getTitle()->getPrefixedText() )
+                       [],
+                       [ 'page' => $this->getTitle()->getPrefixedText() ]
                );
        }
 
@@ -80,7 +80,7 @@ class HistoryAction extends FormlessAction {
        private function preCacheMessages() {
                // Precache various messages
                if ( !isset( $this->message ) ) {
-                       $msgs = array( 'cur', 'last', 'pipe-separator' );
+                       $msgs = [ 'cur', 'last', 'pipe-separator' ];
                        foreach ( $msgs as $msg ) {
                                $this->message[$msg] = $this->msg( $msg )->escaped();
                        }
@@ -109,7 +109,7 @@ class HistoryAction extends FormlessAction {
                if ( $useFileCache && HTMLFileCache::useFileCache( $this->getContext() ) ) {
                        $cache = new HTMLFileCache( $this->getTitle(), 'history' );
                        if ( !$cache->isCacheGood( /* Assume up to date */ ) ) {
-                               ob_start( array( &$cache, 'saveToFileCache' ) );
+                               ob_start( [ &$cache, 'saveToFileCache' ] );
                        }
                }
 
@@ -118,10 +118,10 @@ class HistoryAction extends FormlessAction {
                $out->addModules( 'mediawiki.action.history' );
                if ( $config->get( 'UseMediaWikiUIEverywhere' ) ) {
                        $out = $this->getOutput();
-                       $out->addModuleStyles( array(
+                       $out->addModuleStyles( [
                                'mediawiki.ui.input',
                                'mediawiki.ui.checkbox',
-                       ) );
+                       ] );
                }
 
                // Handle atom/RSS feeds.
@@ -140,14 +140,14 @@ class HistoryAction extends FormlessAction {
                        # show deletion/move log if there is an entry
                        LogEventsList::showLogExtract(
                                $out,
-                               array( 'delete', 'move' ),
+                               [ 'delete', 'move' ],
                                $this->getTitle(),
                                '',
-                               array( 'lim' => 10,
-                                       'conds' => array( "log_action != 'revision'" ),
+                               [ 'lim' => 10,
+                                       'conds' => [ "log_action != 'revision'" ],
                                        'showIfEmpty' => false,
-                                       'msgKey' => array( 'moveddeleted-notice' )
-                               )
+                                       'msgKey' => [ 'moveddeleted-notice' ]
+                               ]
                        );
 
                        return;
@@ -165,9 +165,9 @@ class HistoryAction extends FormlessAction {
                 * Option to show only revisions that have been (partially) hidden via RevisionDelete
                 */
                if ( $request->getBool( 'deleted' ) ) {
-                       $conds = array( 'rev_deleted != 0' );
+                       $conds = [ 'rev_deleted != 0' ];
                } else {
-                       $conds = array();
+                       $conds = [];
                }
                if ( $this->getUser()->isAllowed( 'deletedhistory' ) ) {
                        $checkDeleted = Xml::checkLabel( $this->msg( 'history-show-deleted' )->text(),
@@ -183,7 +183,7 @@ class HistoryAction extends FormlessAction {
                        Xml::fieldset(
                                $this->msg( 'history-fieldset-title' )->text(),
                                false,
-                               array( 'id' => 'mw-history-search' )
+                               [ 'id' => 'mw-history-search' ]
                        ) .
                        Html::hidden( 'title', $this->getTitle()->getPrefixedDBkey() ) . "\n" .
                        Html::hidden( 'action', 'history' ) . "\n" .
@@ -195,13 +195,13 @@ class HistoryAction extends FormlessAction {
                        $checkDeleted .
                        Html::submitButton(
                                $this->msg( 'historyaction-submit' )->text(),
-                               array(),
-                               array( 'mw-ui-progressive' )
+                               [],
+                               [ 'mw-ui-progressive' ]
                        ) . "\n" .
                        '</fieldset></form>'
                );
 
-               Hooks::run( 'PageHistoryBeforeList', array( &$this->page, $this->getContext() ) );
+               Hooks::run( 'PageHistoryBeforeList', [ &$this->page, $this->getContext() ] );
 
                // Create and output the list.
                $pager = new HistoryPager( $this, $year, $month, $tagFilter, $conds );
@@ -227,31 +227,31 @@ class HistoryAction extends FormlessAction {
        function fetchRevisions( $limit, $offset, $direction ) {
                // Fail if article doesn't exist.
                if ( !$this->getTitle()->exists() ) {
-                       return new FakeResultWrapper( array() );
+                       return new FakeResultWrapper( [] );
                }
 
                $dbr = wfGetDB( DB_SLAVE );
 
                if ( $direction === self::DIR_PREV ) {
-                       list( $dirs, $oper ) = array( "ASC", ">=" );
+                       list( $dirs, $oper ) = [ "ASC", ">=" ];
                } else { /* $direction === self::DIR_NEXT */
-                       list( $dirs, $oper ) = array( "DESC", "<=" );
+                       list( $dirs, $oper ) = [ "DESC", "<=" ];
                }
 
                if ( $offset ) {
-                       $offsets = array( "rev_timestamp $oper " . $dbr->addQuotes( $dbr->timestamp( $offset ) ) );
+                       $offsets = [ "rev_timestamp $oper " . $dbr->addQuotes( $dbr->timestamp( $offset ) ) ];
                } else {
-                       $offsets = array();
+                       $offsets = [];
                }
 
                $page_id = $this->page->getId();
 
                return $dbr->select( 'revision',
                        Revision::selectFields(),
-                       array_merge( array( 'rev_page' => $page_id ), $offsets ),
+                       array_merge( [ 'rev_page' => $page_id ], $offsets ),
                        __METHOD__,
-                       array( 'ORDER BY' => "rev_timestamp $dirs",
-                               'USE INDEX' => 'page_timestamp', 'LIMIT' => $limit )
+                       [ 'ORDER BY' => "rev_timestamp $dirs",
+                               'USE INDEX' => 'page_timestamp', 'LIMIT' => $limit ]
                );
        }
 
@@ -380,7 +380,7 @@ class HistoryPager extends ReverseChronologicalPager {
         * @param string $tagFilter
         * @param array $conds
         */
-       function __construct( $historyPage, $year = '', $month = '', $tagFilter = '', $conds = array() ) {
+       function __construct( $historyPage, $year = '', $month = '', $tagFilter = '', $conds = [] ) {
                parent::__construct( $historyPage->getContext() );
                $this->historyPage = $historyPage;
                $this->tagFilter = $tagFilter;
@@ -403,15 +403,15 @@ class HistoryPager extends ReverseChronologicalPager {
        }
 
        function getQueryInfo() {
-               $queryInfo = array(
-                       'tables' => array( 'revision', 'user' ),
+               $queryInfo = [
+                       'tables' => [ 'revision', 'user' ],
                        'fields' => array_merge( Revision::selectFields(), Revision::selectUserFields() ),
                        'conds' => array_merge(
-                               array( 'rev_page' => $this->getWikiPage()->getId() ),
+                               [ 'rev_page' => $this->getWikiPage()->getId() ],
                                $this->conds ),
-                       'options' => array( 'USE INDEX' => array( 'revision' => 'page_timestamp' ) ),
-                       'join_conds' => array( 'user' => Revision::userJoinCond() ),
-               );
+                       'options' => [ 'USE INDEX' => [ 'revision' => 'page_timestamp' ] ],
+                       'join_conds' => [ 'user' => Revision::userJoinCond() ],
+               ];
                ChangeTags::modifyDisplayQuery(
                        $queryInfo['tables'],
                        $queryInfo['fields'],
@@ -420,7 +420,7 @@ class HistoryPager extends ReverseChronologicalPager {
                        $queryInfo['options'],
                        $this->tagFilter
                );
-               Hooks::run( 'PageHistoryPager::getQueryInfo', array( &$this, &$queryInfo ) );
+               Hooks::run( 'PageHistoryPager::getQueryInfo', [ &$this, &$queryInfo ] );
 
                return $queryInfo;
        }
@@ -454,14 +454,14 @@ class HistoryPager extends ReverseChronologicalPager {
        }
 
        function doBatchLookups() {
-               if ( !Hooks::run( 'PageHistoryPager::doBatchLookups', array( $this, $this->mResult ) ) ) {
+               if ( !Hooks::run( 'PageHistoryPager::doBatchLookups', [ $this, $this->mResult ] ) ) {
                        return;
                }
 
                # Do a link batch query
                $this->mResult->seek( 0 );
                $batch = new LinkBatch();
-               $revIds = array();
+               $revIds = [];
                foreach ( $this->mResult as $row ) {
                        if ( $row->rev_parent_id ) {
                                $revIds[] = $row->rev_parent_id;
@@ -490,8 +490,8 @@ class HistoryPager extends ReverseChronologicalPager {
                $this->oldIdChecked = 0;
 
                $this->getOutput()->wrapWikiMsg( "<div class='mw-history-legend'>\n$1\n</div>", 'histlegend' );
-               $s = Html::openElement( 'form', array( 'action' => wfScript(),
-                       'id' => 'mw-history-compare' ) ) . "\n";
+               $s = Html::openElement( 'form', [ 'action' => wfScript(),
+                       'id' => 'mw-history-compare' ] ) . "\n";
                $s .= Html::hidden( 'title', $this->getTitle()->getPrefixedDBkey() ) . "\n";
                $s .= Html::hidden( 'action', 'historysubmit' ) . "\n";
                $s .= Html::hidden( 'type', 'revision' ) . "\n";
@@ -499,7 +499,7 @@ class HistoryPager extends ReverseChronologicalPager {
                // Button container stored in $this->buttons for re-use in getEndBody()
                $this->buttons = '<div>';
                $className = 'historysubmit mw-history-compareselectedversions-button';
-               $attrs = array( 'class' => $className )
+               $attrs = [ 'class' => $className ]
                        + Linker::tooltipAndAccesskeyAttribs( 'compareselectedversions' );
                $this->buttons .= $this->submitButton( $this->msg( 'compareselectedversions' )->text(),
                        $attrs
@@ -514,9 +514,14 @@ class HistoryPager extends ReverseChronologicalPager {
                        $actionButtons .= $this->getRevisionButton( 'editchangetags', 'history-edit-tags' );
                }
                if ( $actionButtons ) {
-                       $this->buttons .= Xml::tags( 'div', array( 'class' =>
-                               'mw-history-revisionactions' ), $actionButtons );
+                       $this->buttons .= Xml::tags( 'div', [ 'class' =>
+                               'mw-history-revisionactions' ], $actionButtons );
+               }
+
+               if ( $user->isAllowed( 'deleterevision' ) || $this->showTagEditUI ) {
+                       $this->buttons .= ( new ListToggle( $this->getOutput() ) )->getHTML();
                }
+
                $this->buttons .= '</div>';
 
                $s .= $this->buttons;
@@ -530,12 +535,12 @@ class HistoryPager extends ReverseChronologicalPager {
                # Note bug #20966, <button> is non-standard in IE<8
                $element = Html::element(
                        'button',
-                       array(
+                       [
                                'type' => 'submit',
                                'name' => $name,
                                'value' => '1',
                                'class' => "historysubmit mw-history-$name-button",
-                       ),
+                       ],
                        $this->msg( $msg )->text()
                ) . "\n";
                return $element;
@@ -584,7 +589,7 @@ class HistoryPager extends ReverseChronologicalPager {
         * @param array $attributes Attributes
         * @return string HTML output for the submit button
         */
-       function submitButton( $message, $attributes = array() ) {
+       function submitButton( $message, $attributes = [] ) {
                # Disable submit button if history has 1 revision only
                if ( $this->getNumRows() > 1 ) {
                        return Html::submitButton( $message, $attributes );
@@ -624,7 +629,7 @@ class HistoryPager extends ReverseChronologicalPager {
                $curLastlinks = $curlink . $this->historyPage->message['pipe-separator'] . $lastlink;
                $histLinks = Html::rawElement(
                        'span',
-                       array( 'class' => 'mw-history-histlinks' ),
+                       [ 'class' => 'mw-history-histlinks' ],
                        $this->msg( 'parentheses' )->rawParams( $curLastlinks )->escaped()
                );
 
@@ -632,7 +637,7 @@ class HistoryPager extends ReverseChronologicalPager {
                $s = $histLinks . $diffButtons;
 
                $link = $this->revLink( $rev );
-               $classes = array();
+               $classes = [];
 
                $del = '';
                $user = $this->getUser();
@@ -644,11 +649,11 @@ class HistoryPager extends ReverseChronologicalPager {
                        // If revision was hidden from sysops and we don't need the checkbox
                        // for anything else, disable it
                        if ( !$this->showTagEditUI && !$rev->userCan( Revision::DELETED_RESTRICTED, $user ) ) {
-                               $del = Xml::check( 'deleterevisions', false, array( 'disabled' => 'disabled' ) );
+                               $del = Xml::check( 'deleterevisions', false, [ 'disabled' => 'disabled' ] );
                        // Otherwise, enable the checkbox...
                        } else {
                                $del = Xml::check( 'showhiderevisions', false,
-                                       array( 'name' => 'ids[' . $rev->getId() . ']' ) );
+                                       [ 'name' => 'ids[' . $rev->getId() . ']' ] );
                        }
                // User can only view deleted revisions...
                } elseif ( $rev->getVisibility() && $user->isAllowed( 'deletedhistory' ) ) {
@@ -657,8 +662,8 @@ class HistoryPager extends ReverseChronologicalPager {
                                $del = Linker::revDeleteLinkDisabled( false );
                        // Otherwise, show the link...
                        } else {
-                               $query = array( 'type' => 'revision',
-                                       'target' => $this->getTitle()->getPrefixedDBkey(), 'ids' => $rev->getId() );
+                               $query = [ 'type' => 'revision',
+                                       'target' => $this->getTitle()->getPrefixedDBkey(), 'ids' => $rev->getId() ];
                                $del .= Linker::revDeleteLink( $query,
                                        $rev->isDeleted( Revision::DELETED_RESTRICTED ), false );
                        }
@@ -677,7 +682,7 @@ class HistoryPager extends ReverseChronologicalPager {
                $s .= $dirmark;
 
                if ( $rev->isMinor() ) {
-                       $s .= ' ' . ChangesList::flag( 'minor' );
+                       $s .= ' ' . ChangesList::flag( 'minor', $this->getContext() );
                }
 
                # Sometimes rev_len isn't populated
@@ -699,7 +704,7 @@ class HistoryPager extends ReverseChronologicalPager {
                        $classes[] = 'mw-history-line-updated';
                }
 
-               $tools = array();
+               $tools = [];
 
                # Rollback and undo links
                if ( $prevRev && $this->getTitle()->quickUserCan( 'edit', $user ) ) {
@@ -708,7 +713,7 @@ class HistoryPager extends ReverseChronologicalPager {
                                $rollbackLink = Linker::generateRollback(
                                        $rev,
                                        $this->getContext(),
-                                       array( 'verify', 'noBrackets' )
+                                       [ 'verify', 'noBrackets' ]
                                );
                                if ( $rollbackLink ) {
                                        $this->preventClickjacking();
@@ -721,30 +726,34 @@ class HistoryPager extends ReverseChronologicalPager {
                        ) {
                                # Create undo tooltip for the first (=latest) line only
                                $undoTooltip = $latest
-                                       ? array( 'title' => $this->msg( 'tooltip-undo' )->text() )
-                                       : array();
+                                       ? [ 'title' => $this->msg( 'tooltip-undo' )->text() ]
+                                       : [];
                                $undolink = Linker::linkKnown(
                                        $this->getTitle(),
                                        $this->msg( 'editundo' )->escaped(),
                                        $undoTooltip,
-                                       array(
+                                       [
                                                'action' => 'edit',
                                                'undoafter' => $prevRev->getId(),
                                                'undo' => $rev->getId()
-                                       )
+                                       ]
                                );
                                $tools[] = "<span class=\"mw-history-undo\">{$undolink}</span>";
                        }
                }
                // Allow extension to add their own links here
-               Hooks::run( 'HistoryRevisionTools', array( $rev, &$tools, $prevRev, $user ) );
+               Hooks::run( 'HistoryRevisionTools', [ $rev, &$tools, $prevRev, $user ] );
 
                if ( $tools ) {
                        $s2 .= ' ' . $this->msg( 'parentheses' )->rawParams( $lang->pipeList( $tools ) )->escaped();
                }
 
                # Tags
-               list( $tagSummary, $newClasses ) = ChangeTags::formatSummaryRow( $row->ts_tags, 'history' );
+               list( $tagSummary, $newClasses ) = ChangeTags::formatSummaryRow(
+                       $row->ts_tags,
+                       'history',
+                       $this->getContext()
+               );
                $classes = array_merge( $classes, $newClasses );
                if ( $tagSummary !== '' ) {
                        $s2 .= " $tagSummary";
@@ -755,9 +764,9 @@ class HistoryPager extends ReverseChronologicalPager {
                        $s .= ' <span class="mw-changeslist-separator">. .</span> ' . $s2;
                }
 
-               Hooks::run( 'PageHistoryLineEnding', array( $this, &$row, &$s, &$classes ) );
+               Hooks::run( 'PageHistoryLineEnding', [ $this, &$row, &$s, &$classes ] );
 
-               $attribs = array();
+               $attribs = [];
                if ( $classes ) {
                        $attribs['class'] = implode( ' ', $classes );
                }
@@ -778,8 +787,8 @@ class HistoryPager extends ReverseChronologicalPager {
                        $link = Linker::linkKnown(
                                $this->getTitle(),
                                $date,
-                               array( 'class' => 'mw-changeslist-date' ),
-                               array( 'oldid' => $rev->getId() )
+                               [ 'class' => 'mw-changeslist-date' ],
+                               [ 'oldid' => $rev->getId() ]
                        );
                } else {
                        $link = $date;
@@ -806,11 +815,11 @@ class HistoryPager extends ReverseChronologicalPager {
                        return Linker::linkKnown(
                                $this->getTitle(),
                                $cur,
-                               array(),
-                               array(
+                               [],
+                               [
                                        'diff' => $this->getWikiPage()->getLatest(),
                                        'oldid' => $rev->getId()
-                               )
+                               ]
                        );
                }
        }
@@ -837,11 +846,11 @@ class HistoryPager extends ReverseChronologicalPager {
                        return Linker::linkKnown(
                                $this->getTitle(),
                                $last,
-                               array(),
-                               array(
+                               [],
+                               [
                                        'diff' => $prevRev->getId(),
                                        'oldid' => 'prev'
-                               )
+                               ]
                        );
                }
 
@@ -856,11 +865,11 @@ class HistoryPager extends ReverseChronologicalPager {
                return Linker::linkKnown(
                        $this->getTitle(),
                        $last,
-                       array(),
-                       array(
+                       [],
+                       [
                                'diff' => $prevRev->getId(),
                                'oldid' => $next->rev_id
-                       )
+                       ]
                );
        }
 
@@ -875,37 +884,37 @@ class HistoryPager extends ReverseChronologicalPager {
        function diffButtons( $rev, $firstInList ) {
                if ( $this->getNumRows() > 1 ) {
                        $id = $rev->getId();
-                       $radio = array( 'type' => 'radio', 'value' => $id );
+                       $radio = [ 'type' => 'radio', 'value' => $id ];
                        /** @todo Move title texts to javascript */
                        if ( $firstInList ) {
                                $first = Xml::element( 'input',
-                                       array_merge( $radio, array(
+                                       array_merge( $radio, [
                                                'style' => 'visibility:hidden',
                                                'name' => 'oldid',
-                                               'id' => 'mw-oldid-null' ) )
+                                               'id' => 'mw-oldid-null' ] )
                                );
-                               $checkmark = array( 'checked' => 'checked' );
+                               $checkmark = [ 'checked' => 'checked' ];
                        } else {
                                # Check visibility of old revisions
                                if ( !$rev->userCan( Revision::DELETED_TEXT, $this->getUser() ) ) {
                                        $radio['disabled'] = 'disabled';
-                                       $checkmark = array(); // We will check the next possible one
+                                       $checkmark = []; // We will check the next possible one
                                } elseif ( !$this->oldIdChecked ) {
-                                       $checkmark = array( 'checked' => 'checked' );
+                                       $checkmark = [ 'checked' => 'checked' ];
                                        $this->oldIdChecked = $id;
                                } else {
-                                       $checkmark = array();
+                                       $checkmark = [];
                                }
                                $first = Xml::element( 'input',
-                                       array_merge( $radio, $checkmark, array(
+                                       array_merge( $radio, $checkmark, [
                                                'name' => 'oldid',
-                                               'id' => "mw-oldid-$id" ) ) );
-                               $checkmark = array();
+                                               'id' => "mw-oldid-$id" ] ) );
+                               $checkmark = [];
                        }
                        $second = Xml::element( 'input',
-                               array_merge( $radio, $checkmark, array(
+                               array_merge( $radio, $checkmark, [
                                        'name' => 'diff',
-                                       'id' => "mw-diff-$id" ) ) );
+                                       'id' => "mw-diff-$id" ] ) );
 
                        return $first . $second;
                } else {