Revert "Deprecate no longer used Skin::getCommonStylePath."
[lhc/web/wiklou.git] / includes / specials / SpecialRecentchanges.php
index da7babe..bb384d4 100644 (file)
@@ -71,17 +71,13 @@ class SpecialRecentChanges extends IncludableSpecialPage {
         * @return FormOptions
         */
        public function setup( $parameters ) {
-               global $wgRequest;
-
                $opts = $this->getDefaultOptions();
 
-               $this->customFilters = array();
-               wfRunHooks( 'SpecialRecentChangesFilters', array( $this, &$this->customFilters ) );
-               foreach( $this->customFilters as $key => $params ) {
+               foreach( $this->getCustomFilters() as $key => $params ) {
                        $opts->add( $key, $params['default'] );
                }
 
-               $opts->fetchValuesFromRequest( $wgRequest );
+               $opts->fetchValuesFromRequest( $this->getRequest() );
 
                // Give precedence to subpage syntax
                if( $parameters !== null ) {
@@ -92,16 +88,29 @@ class SpecialRecentChanges extends IncludableSpecialPage {
                return $opts;
        }
 
+       /**
+        * Get custom show/hide filters
+        *
+        * @return Array Map of filter URL param names to properties (msg/default)
+        */
+       protected function getCustomFilters() {
+               if ( $this->customFilters === null ) {
+                       $this->customFilters = array();
+                       wfRunHooks( 'SpecialRecentChangesFilters', array( $this, &$this->customFilters ) );
+               }
+               return $this->customFilters;
+       }
+
        /**
         * Create a FormOptions object specific for feed requests and return it
         *
         * @return FormOptions
         */
        public function feedSetup() {
-               global $wgFeedLimit, $wgRequest;
+               global $wgFeedLimit;
                $opts = $this->getDefaultOptions();
                # Feed is cached on limit,hideminor,namespace; other params would randomly not work
-               $opts->fetchValuesFromRequest( $wgRequest, array( 'limit', 'hideminor', 'namespace' ) );
+               $opts->fetchValuesFromRequest( $this->getRequest(), array( 'limit', 'hideminor', 'namespace' ) );
                $opts->validateIntBounds( 'limit', 0, $wgFeedLimit );
                return $opts;
        }
@@ -111,9 +120,12 @@ class SpecialRecentChanges extends IncludableSpecialPage {
         */
        public function getOptions() {
                if ( $this->rcOptions === null ) {
-                       global $wgRequest;
-                       $feedFormat = $wgRequest->getVal( 'feed' );
-                       $this->rcOptions = $feedFormat ? $this->feedSetup() : $this->setup( $this->rcSubpage );
+                       if ( $this->including() ) {
+                               $isFeed = false;
+                       } else {
+                               $isFeed = (bool)$this->getRequest()->getVal( 'feed' );
+                       }
+                       $this->rcOptions = $isFeed ? $this->feedSetup() : $this->setup( $this->rcSubpage );
                }
                return $this->rcOptions;
        }
@@ -125,12 +137,11 @@ class SpecialRecentChanges extends IncludableSpecialPage {
         * @param $subpage String
         */
        public function execute( $subpage ) {
-               global $wgRequest, $wgOut;
                $this->rcSubpage = $subpage;
-               $feedFormat = $wgRequest->getVal( 'feed' );
+               $feedFormat = $this->including() ? null : $this->getRequest()->getVal( 'feed' );
 
                # 10 seconds server-side caching max
-               $wgOut->setSquidMaxage( 10 );
+               $this->getOutput()->setSquidMaxage( 10 );
                # Check if the client has a cached version
                $lastmod = $this->checkLastModified( $feedFormat );
                if( $lastmod === false ) {
@@ -179,8 +190,8 @@ class SpecialRecentChanges extends IncludableSpecialPage {
        public function getFeedObject( $feedFormat ){
                $changesFeed = new ChangesFeed( $feedFormat, 'rcfeed' );
                $formatter = $changesFeed->getFeedObject(
-                       wfMsgForContent( 'recentchanges' ),
-                       wfMsgForContent( 'recentchanges-feed-description' ),
+                       $this->msg( 'recentchanges' )->inContentLanguage()->text(),
+                       $this->msg( 'recentchanges-feed-description' )->inContentLanguage()->text(),
                        $this->getTitle()->getFullURL()
                );
                return array( $changesFeed, $formatter );
@@ -232,6 +243,9 @@ class SpecialRecentChanges extends IncludableSpecialPage {
                        if( preg_match( '/^days=(\d+)$/', $bit, $m ) ) {
                                $opts['days'] = $m[1];
                        }
+                       if( preg_match( '/^namespace=(\d+)$/', $bit, $m ) ) {
+                               $opts['namespace'] = $m[1];
+                       }
                }
        }
 
@@ -292,7 +306,6 @@ class SpecialRecentChanges extends IncludableSpecialPage {
 
                $conds[] = 'rc_timestamp >= ' . $dbr->addQuotes( $cutoff );
 
-
                $hidePatrol = $this->getUser()->useRCPatrol() && $opts['hidepatrolled'];
                $hideLoggedInUsers = $opts['hideliu'] && !$forcebot;
                $hideAnonymousUsers = $opts['hideanons'] && !$forcebot;
@@ -326,24 +339,25 @@ class SpecialRecentChanges extends IncludableSpecialPage {
 
                # Namespace filtering
                if( $opts['namespace'] !== '' ) {
-                       $namespaces[] = $opts['namespace'];
+                       $selectedNS = $dbr->addQuotes( $opts['namespace'] );
+                       $operator = $opts['invert'] ? '!='  : '=';
+                       $boolean  = $opts['invert'] ? 'AND' : 'OR';
 
-                       $inversionSuffix = $opts['invert'] ? '!' : '';
-                       
-                       if( $opts['associated'] ) {
-                               # namespace association (bug 2429)
-                               $namespaces[] = MWNamespace::getAssociated( $opts['namespace'] );
+                       # namespace association (bug 2429)
+                       if( !$opts['associated'] ) {
+                               $condition = "rc_namespace $operator $selectedNS";
+                       } else {
+                               # Also add the associated namespace
+                               $associatedNS = $dbr->addQuotes(
+                                       MWNamespace::getAssociated( $opts['namespace'] )
+                               );
+                               $condition = "(rc_namespace $operator $selectedNS "
+                                                  . $boolean
+                                                  . " rc_namespace $operator $associatedNS)";
                        }
 
-                       $condition = $dbr->makeList(
-                               array( 'rc_namespace' . $inversionSuffix
-                                       => $namespaces ),
-                               LIST_AND
-                       );
-
                        $conds[] = $condition;
                }
-
                return $conds;
        }
 
@@ -352,7 +366,7 @@ class SpecialRecentChanges extends IncludableSpecialPage {
         *
         * @param $conds Array
         * @param $opts FormOptions
-        * @return database result or false (for Recentchangeslinked only)
+        * @return bool|ResultWrapper result or false (for Recentchangeslinked only)
         */
        public function doMainQuery( $conds, $opts ) {
                $tables = array( 'recentchanges' );
@@ -450,14 +464,13 @@ class SpecialRecentChanges extends IncludableSpecialPage {
        }
 
        /**
-        * Send output to $wgOut, only called if not used feeds
+        * Send output to the OutputPage object, only called if not used feeds
         *
         * @param $rows Array of database rows
         * @param $opts FormOptions
         */
        public function webOutput( $rows, $opts ) {
-               global $wgOut, $wgRCShowWatchingUsers, $wgShowUpdatedMarker;
-               global $wgAllowCategorizedRecentChanges;
+               global $wgRCShowWatchingUsers, $wgShowUpdatedMarker, $wgAllowCategorizedRecentChanges;
 
                $limit = $opts['limit'];
 
@@ -467,7 +480,7 @@ class SpecialRecentChanges extends IncludableSpecialPage {
                }
 
                // And now for the content
-               $wgOut->setFeedAppendQuery( $this->getFeedQuery() );
+               $this->getOutput()->setFeedAppendQuery( $this->getFeedQuery() );
 
                if( $wgAllowCategorizedRecentChanges ) {
                        $this->filterByCategories( $rows, $opts );
@@ -479,7 +492,7 @@ class SpecialRecentChanges extends IncludableSpecialPage {
                $dbr = wfGetDB( DB_SLAVE );
 
                $counter = 1;
-               $list = ChangesList::newFromUser( $this->getUser() );
+               $list = ChangesList::newFromContext( $this->getContext() );
 
                $s = $list->beginRecentChangesList();
                foreach( $rows as $obj ) {
@@ -515,12 +528,13 @@ class SpecialRecentChanges extends IncludableSpecialPage {
                        --$limit;
                }
                $s .= $list->endRecentChangesList();
-               $wgOut->addHTML( $s );
+               $this->getOutput()->addHTML( $s );
        }
 
        /**
         * Get the query string to append to feed link URLs.
         * This is overridden by RCL to add the target parameter
+        * @return bool
         */
        public function getFeedQuery() {
                return false;
@@ -533,9 +547,9 @@ class SpecialRecentChanges extends IncludableSpecialPage {
         * @return String: XHTML
         */
        public function doHeader( $opts ) {
-               global $wgScript, $wgOut;
+               global $wgScript;
 
-               $this->setTopText( $wgOut, $opts );
+               $this->setTopText( $opts );
 
                $defaults = $opts->getAllValues();
                $nondefaults = $opts->getChangedValues();
@@ -551,17 +565,17 @@ class SpecialRecentChanges extends IncludableSpecialPage {
                $extraOpts = $this->getExtraOptions( $opts );
                $extraOptsCount = count( $extraOpts );
                $count = 0;
-               $submit = ' ' . Xml::submitbutton( wfMsg( 'allpagessubmit' ) );
+               $submit = ' ' . Xml::submitbutton( $this->msg( 'allpagessubmit' )->text() );
 
                $out = Xml::openElement( 'table', array( 'class' => 'mw-recentchanges-table' ) );
-               foreach( $extraOpts as $optionRow ) {
+               foreach( $extraOpts as $name => $optionRow ) {
                        # Add submit button to the last row only
                        ++$count;
-                       $addSubmit = $count === $extraOptsCount ? $submit : '';
+                       $addSubmit = ( $count === $extraOptsCount ) ? $submit : '';
 
                        $out .= Xml::openElement( 'tr' );
                        if( is_array( $optionRow ) ) {
-                               $out .= Xml::tags( 'td', array( 'class' => 'mw-label' ), $optionRow[0] );
+                               $out .= Xml::tags( 'td', array( 'class' => 'mw-label mw-' . $name . '-label' ), $optionRow[0] );
                                $out .= Xml::tags( 'td', array( 'class' => 'mw-input' ), $optionRow[1] . $addSubmit );
                        } else {
                                $out .= Xml::tags( 'td', array( 'class' => 'mw-input', 'colspan' => 2 ), $optionRow . $addSubmit );
@@ -581,11 +595,11 @@ class SpecialRecentChanges extends IncludableSpecialPage {
                $panel[] = $form;
                $panelString = implode( "\n", $panel );
 
-               $wgOut->addHTML(
-                       Xml::fieldset( wfMsg( 'recentchanges-legend' ), $panelString, array( 'class' => 'rcoptions' ) )
+               $this->getOutput()->addHTML(
+                       Xml::fieldset( $this->msg( 'recentchanges-legend' )->text(), $panelString, array( 'class' => 'rcoptions' ) )
                );
 
-               $this->setBottomText( $wgOut, $opts );
+               $this->setBottomText( $opts );
        }
 
        /**
@@ -615,21 +629,31 @@ class SpecialRecentChanges extends IncludableSpecialPage {
        /**
         * Send the text to be displayed above the options
         *
-        * @param $out OutputPage
         * @param $opts FormOptions
         */
-       function setTopText( OutputPage $out, FormOptions $opts ) {
-               $out->addWikiText( wfMsgForContentNoTrans( 'recentchangestext' ) );
+       function setTopText( FormOptions $opts ) {
+               global $wgContLang;
+
+               $message = $this->msg( 'recentchangestext' )->inContentLanguage();
+               if ( !$message->isDisabled() ) {
+                       $this->getOutput()->addWikiText(
+                               Html::rawElement( 'p',
+                                       array( 'lang' => $wgContLang->getCode(), 'dir' => $wgContLang->getDir() ),
+                                       "\n" . $message->plain() . "\n"
+                               ),
+                               /* $lineStart */ false,
+                               /* $interface */ false
+                       );
+               }
        }
 
        /**
         * Send the text to be displayed after the options, for use in
         * Recentchangeslinked
         *
-        * @param $out OutputPage
         * @param $opts FormOptions
         */
-       function setBottomText( OutputPage $out, FormOptions $opts ) {}
+       function setBottomText( FormOptions $opts ) {}
 
        /**
         * Creates the choose namespace selection
@@ -639,17 +663,20 @@ class SpecialRecentChanges extends IncludableSpecialPage {
         * @return String
         */
        protected function namespaceFilterForm( FormOptions $opts ) {
-               $nsSelect = Xml::namespaceSelector( $opts['namespace'], '' );
-               $nsLabel = Xml::label( wfMsg( 'namespace' ), 'namespace' );
+               $nsSelect = Html::namespaceSelector(
+                       array( 'selected' => $opts['namespace'], 'all' => '' ),
+                       array( 'name' => 'namespace', 'id' => 'namespace' )
+               );
+               $nsLabel = Xml::label( $this->msg( 'namespace' )->text(), 'namespace' );
                $invert = Xml::checkLabel(
-                       wfMsg( 'invert' ), 'invert', 'nsinvert',
+                       $this->msg( 'invert' )->text(), 'invert', 'nsinvert',
                        $opts['invert'],
-                       array( 'title' => wfMsg( 'tooltip-invert' ) )
+                       array( 'title' => $this->msg( 'tooltip-invert' )->text() )
                );
                $associated = Xml::checkLabel(
-                       wfMsg( 'namespace_association' ), 'associated', 'nsassociated',
+                       $this->msg( 'namespace_association' )->text(), 'associated', 'nsassociated',
                        $opts['associated'],
-                       array( 'title' => wfMsg( 'tooltip-namespace_association' ) )
+                       array( 'title' => $this->msg( 'tooltip-namespace_association' )->text() )
                );
                return array( $nsLabel, "$nsSelect $invert $associated" );
        }
@@ -661,10 +688,10 @@ class SpecialRecentChanges extends IncludableSpecialPage {
         * @return Array
         */
        protected function categoryFilterForm( FormOptions $opts ) {
-               list( $label, $input ) = Xml::inputLabelSep( wfMsg( 'rc_categories' ),
+               list( $label, $input ) = Xml::inputLabelSep( $this->msg( 'rc_categories' )->text(),
                        'categories', 'mw-categories', false, $opts['categories'] );
 
-               $input .= ' ' . Xml::checkLabel( wfMsg( 'rc_categories_any' ),
+               $input .= ' ' . Xml::checkLabel( $this->msg( 'rc_categories_any' )->text(),
                        'categories_any', 'mw-categories_any', $opts['categories_any'] );
 
                return array( $label, $input );
@@ -741,19 +768,15 @@ class SpecialRecentChanges extends IncludableSpecialPage {
         * @param $override Array: options to override
         * @param $options Array: current options
         * @param $active Boolean: whether to show the link in bold
+        * @return string
         */
        function makeOptionsLink( $title, $override, $options, $active = false ) {
                $params = $override + $options;
+               $text = htmlspecialchars( $title );
                if ( $active ) {
-                       return $this->getSkin()->link(
-                               $this->getTitle(),
-                               '<strong>' . htmlspecialchars( $title ) . '</strong>',
-                               array(), $params, array( 'known' ) );
-               } else {
-                       return $this->getSkin()->link(
-                               $this->getTitle(), htmlspecialchars( $title ), array(),
-                               $params, array( 'known' ) );
+                       $text = '<strong>' . $text . '</strong>';
                }
+               return Linker::linkKnown( $this->getTitle(), $text, array(), $params );
        }
 
        /**
@@ -761,23 +784,26 @@ class SpecialRecentChanges extends IncludableSpecialPage {
         *
         * @param $defaults Array
         * @param $nondefaults Array
+        * @return string
         */
        function optionsPanel( $defaults, $nondefaults ) {
-               global $wgLang, $wgRCLinkLimits, $wgRCLinkDays;
+               global $wgRCLinkLimits, $wgRCLinkDays;
 
                $options = $nondefaults + $defaults;
 
                $note = '';
-               if( !wfEmptyMsg( 'rclegend' ) ) {
-                       $note .= '<div class="mw-rclegend">' .
-                               wfMsgExt( 'rclegend', array( 'parseinline' ) ) . "</div>\n";
+               $msg = $this->msg( 'rclegend' );
+               if( !$msg->isDisabled() ) {
+                       $note .= '<div class="mw-rclegend">' . $msg->parse() . "</div>\n";
                }
+
+               $lang = $this->getLanguage();
+               $user = $this->getUser();
                if( $options['from'] ) {
-                       $note .= wfMsgExt( 'rcnotefrom', array( 'parseinline' ),
-                               $wgLang->formatNum( $options['limit'] ),
-                               $wgLang->timeanddate( $options['from'], true ),
-                               $wgLang->date( $options['from'], true ),
-                               $wgLang->time( $options['from'], true ) ) . '<br />';
+                       $note .= $this->msg( 'rcnotefrom' )->numParams( $options['limit'] )->params(
+                               $lang->userTimeAndDate( $options['from'], $user ),
+                               $lang->userDate( $options['from'], $user ),
+                               $lang->userTime( $options['from'], $user ) )->parse() . '<br />';
                }
 
                # Sort data for display and make sure it's unique after we've added user data.
@@ -790,34 +816,34 @@ class SpecialRecentChanges extends IncludableSpecialPage {
 
                // limit links
                foreach( $wgRCLinkLimits as $value ) {
-                       $cl[] = $this->makeOptionsLink( $wgLang->formatNum( $value ),
+                       $cl[] = $this->makeOptionsLink( $lang->formatNum( $value ),
                                array( 'limit' => $value ), $nondefaults, $value == $options['limit'] );
                }
-               $cl = $wgLang->pipeList( $cl );
+               $cl = $lang->pipeList( $cl );
 
                // day links, reset 'from' to none
                foreach( $wgRCLinkDays as $value ) {
-                       $dl[] = $this->makeOptionsLink( $wgLang->formatNum( $value ),
+                       $dl[] = $this->makeOptionsLink( $lang->formatNum( $value ),
                                array( 'days' => $value, 'from' => '' ), $nondefaults, $value == $options['days'] );
                }
-               $dl = $wgLang->pipeList( $dl );
+               $dl = $lang->pipeList( $dl );
 
 
                // show/hide links
-               $showhide = array( wfMsg( 'show' ), wfMsg( 'hide' ) );
+               $showhide = array( $this->msg( 'show' )->text(), $this->msg( 'hide' )->text() );
                $filters = array(
-                       'hideminor'     => 'rcshowhideminor',
-                       'hidebots'      => 'rcshowhidebots',
-                       'hideanons'     => 'rcshowhideanons',
-                       'hideliu'               => 'rcshowhideliu',
+                       'hideminor'     => 'rcshowhideminor',
+                       'hidebots'      => 'rcshowhidebots',
+                       'hideanons'     => 'rcshowhideanons',
+                       'hideliu'       => 'rcshowhideliu',
                        'hidepatrolled' => 'rcshowhidepatr',
-                       'hidemyself'    => 'rcshowhidemine'
+                       'hidemyself'    => 'rcshowhidemine'
                );
-               foreach ( $this->customFilters as $key => $params ) {
+               foreach ( $this->getCustomFilters() as $key => $params ) {
                        $filters[$key] = $params['msg'];
                }
                // Disable some if needed
-               if ( !$this->getUser()->useRCPatrol() ) {
+               if ( !$user->useRCPatrol() ) {
                        unset( $filters['hidepatrolled'] );
                }
 
@@ -825,19 +851,18 @@ class SpecialRecentChanges extends IncludableSpecialPage {
                foreach ( $filters as $key => $msg ) {
                        $link = $this->makeOptionsLink( $showhide[1 - $options[$key]],
                                array( $key => 1-$options[$key] ), $nondefaults );
-                       $links[] = wfMsgHtml( $msg, $link );
+                       $links[] = $this->msg( $msg )->rawParams( $link )->escaped();
                }
 
                // show from this onward link
                $timestamp = wfTimestampNow();
-               $now = $wgLang->timeanddate( $timestamp, true );
+               $now = $lang->userTimeAndDate( $timestamp, $user );
                $tl = $this->makeOptionsLink(
                        $now, array( 'from' => $timestamp ), $nondefaults
                );
 
-               $rclinks = wfMsgExt( 'rclinks', array( 'parseinline', 'replaceafter' ),
-                       $cl, $dl, $wgLang->pipeList( $links ) );
-               $rclistfrom = wfMsgExt( 'rclistfrom', array( 'parseinline', 'replaceafter' ), $tl );
+               $rclinks = $this->msg( 'rclinks' )->rawParams( $cl, $dl, $lang->pipeList( $links ) )->parse();
+               $rclistfrom = $this->msg( 'rclistfrom' )->rawParams( $tl )->parse();
                return "{$note}$rclinks<br />$rclistfrom";
        }
 
@@ -845,8 +870,7 @@ class SpecialRecentChanges extends IncludableSpecialPage {
         * add javascript specific to the [[Special:RecentChanges]] page
         */
        function addRecentChangesJS() {
-               global $wgOut;
-               $wgOut->addModules( array(
+               $this->getOutput()->addModules( array(
                        'mediawiki.special.recentchanges',
                ) );
        }