Fix typo in comment
[lhc/web/wiklou.git] / includes / specials / SpecialNewpages.php
index 123d539..3c31ca0 100644 (file)
@@ -34,6 +34,7 @@ class SpecialNewpages extends IncludableSpecialPage {
         * @var FormOptions
         */
        protected $opts;
+       protected $customFilters;
 
        // Some internal settings
        protected $showNavigation = false;
@@ -59,6 +60,12 @@ class SpecialNewpages extends IncludableSpecialPage {
                $opts->add( 'feed', '' );
                $opts->add( 'tagfilter', '' );
 
+               $this->customFilters = array();
+               wfRunHooks( 'SpecialNewPagesFilters', array( $this, &$this->customFilters ) );
+               foreach( $this->customFilters as $key => $params ) {
+                       $opts->add( $key, $params['default'] );
+               }
+
                // Set values
                $opts->fetchValuesFromRequest( $this->getRequest() );
                if ( $par ) $this->parseParams( $par );
@@ -71,7 +78,6 @@ class SpecialNewpages extends IncludableSpecialPage {
        }
 
        protected function parseParams( $par ) {
-               global $wgLang;
                $bits = preg_split( '/\s*,\s*/', trim( $par ) );
                foreach ( $bits as $bit ) {
                        if ( 'shownav' == $bit ) {
@@ -105,7 +111,7 @@ class SpecialNewpages extends IncludableSpecialPage {
                                $this->opts->setValue( 'username', $m[1] );
                        }
                        if ( preg_match( '/^namespace=(.*)$/', $bit, $m ) ) {
-                               $ns = $wgLang->getNsIndex( $m[1] );
+                               $ns = $this->getLanguage()->getNsIndex( $m[1] );
                                if( $ns !== false ) {
                                        $this->opts->setValue( 'namespace',  $ns );
                                }
@@ -132,11 +138,12 @@ class SpecialNewpages extends IncludableSpecialPage {
                        // Settings
                        $this->form();
 
-                       $this->setSyndicated();
                        $feedType = $this->opts->getValue( 'feed' );
                        if( $feedType ) {
                                return $this->feed( $feedType );
                        }
+
+                       $out->setFeedAppendQuery( wfArrayToCGI( $this->opts->getAllValues() ) );
                }
 
                $pager = new NewPagesPager( $this, $this->opts );
@@ -155,7 +162,7 @@ class SpecialNewpages extends IncludableSpecialPage {
        }
 
        protected function filterLinks() {
-               global $wgGroupPermissions, $wgLang;
+               global $wgGroupPermissions;
 
                // show/hide links
                $showhide = array( wfMsgHtml( 'show' ), wfMsgHtml( 'hide' ) );
@@ -167,13 +174,15 @@ class SpecialNewpages extends IncludableSpecialPage {
                        'hidebots' => 'rcshowhidebots',
                        'hideredirs' => 'whatlinkshere-hideredirs'
                );
+               foreach ( $this->customFilters as $key => $params ) {
+                       $filters[$key] = $params['msg'];
+               }
 
                // Disable some if needed
                # @todo FIXME: Throws E_NOTICEs if not set; and doesn't obey hooks etc.
                if ( $wgGroupPermissions['*']['createpage'] !== true ) {
                        unset( $filters['hideliu'] );
                }
-
                if ( !$this->getUser()->useNPPatrol() ) {
                        unset( $filters['hidepatrolled'] );
                }
@@ -185,13 +194,13 @@ class SpecialNewpages extends IncludableSpecialPage {
                $self = $this->getTitle();
                foreach ( $filters as $key => $msg ) {
                        $onoff = 1 - $this->opts->getValue( $key );
-                       $link = $this->getSkin()->link( $self, $showhide[$onoff], array(),
+                       $link = Linker::link( $self, $showhide[$onoff], array(),
                                        array( $key => $onoff ) + $changed
                        );
                        $links[$key] = wfMsgHtml( $msg, $link );
                }
 
-               return $wgLang->pipeList( $links );
+               return $this->getLanguage()->pipeList( $links );
        }
 
        protected function form() {
@@ -228,7 +237,16 @@ class SpecialNewpages extends IncludableSpecialPage {
                                        Xml::label( wfMsg( 'namespace' ), 'namespace' ) .
                                '</td>
                                <td class="mw-input">' .
-                                       Xml::namespaceSelector( $namespace, 'all' ) .
+                                       Html::namespaceSelector(
+                                               array(
+                                                       'selected' => $namespace,
+                                                       'all' => 'all',
+                                               ), array(
+                                                       'name'  => 'namespace',
+                                                       'id'    => 'namespace',
+                                                       'class' => 'namespaceselector',
+                                               )
+                                       ) .
                                '</td>
                        </tr>' . ( $tagFilter ? (
                        '<tr>
@@ -267,12 +285,6 @@ class SpecialNewpages extends IncludableSpecialPage {
                $this->getOutput()->addHTML( $form );
        }
 
-       protected function setSyndicated() {
-               $out = $this->getOutput();
-               $out->setSyndicated( true );
-               $out->setFeedAppendQuery( wfArrayToCGI( $this->opts->getAllValues() ) );
-       }
-
        /**
         * Format a row, providing the timestamp, links to the page/history, size, user links, and a comment
         *
@@ -280,8 +292,6 @@ class SpecialNewpages extends IncludableSpecialPage {
         * @return String
         */
        public function formatRow( $result ) {
-               global $wgLang, $wgContLang;
-
                # Revision deletion works on revisions, so we should cast one
                $row = array(
                                          'comment' => $result->rc_comment,
@@ -293,11 +303,19 @@ class SpecialNewpages extends IncludableSpecialPage {
 
                $classes = array();
 
-               $dm = $wgContLang->getDirMark();
+               $lang = $this->getLanguage();
+               $dm = $lang->getDirMark();
 
-               $title = Title::makeTitleSafe( $result->rc_namespace, $result->rc_title );
-               $time = Html::element( 'span', array( 'class' => 'mw-newpages-time' ),
-                       $wgLang->timeAndDate( $result->rc_timestamp, true )
+               $title = Title::newFromRow( $result );
+               $spanTime = Html::element( 'span', array( 'class' => 'mw-newpages-time' ),
+                       $lang->timeanddate( $result->rc_timestamp, true )
+               );
+               $time = Linker::linkKnown(
+                       $title,
+                       $spanTime,
+                       array(),
+                       array( 'oldid' => $result->rc_this_oldid ),
+                       array()
                );
 
                $query = array( 'redirect' => 'no' );
@@ -306,14 +324,14 @@ class SpecialNewpages extends IncludableSpecialPage {
                        $query['rcid'] = $result->rc_id;
                }
 
-               $plink = $this->getSkin()->linkKnown(
+               $plink = Linker::linkKnown(
                        $title,
                        null,
                        array( 'class' => 'mw-newpages-pagename' ),
                        $query,
                        array( 'known' ) // Set explicitly to avoid the default of 'known','noclasses'. This breaks the colouration for stubs
                );
-               $histLink = $this->getSkin()->linkKnown(
+               $histLink = Linker::linkKnown(
                        $title,
                        wfMsgHtml( 'hist' ),
                        array(),
@@ -321,13 +339,12 @@ class SpecialNewpages extends IncludableSpecialPage {
                );
                $hist = Html::rawElement( 'span', array( 'class' => 'mw-newpages-history' ), wfMsg( 'parentheses', $histLink ) );
 
-               $length = Html::rawElement( 'span', array( 'class' => 'mw-newpages-length' ),
-                               '[' . wfMsgExt( 'nbytes', array( 'parsemag', 'escape' ), $wgLang->formatNum( $result->length ) ) .
-                               ']'
+               $length = Html::element( 'span', array( 'class' => 'mw-newpages-length' ),
+                               '[' . $this->msg( 'nbytes' )->numParams( $result->length )->text() . ']'
                );
 
-               $ulink = $this->getSkin()->revUserTools( $rev );
-               $comment = $this->getSkin()->revComment( $rev );
+               $ulink = Linker::revUserTools( $rev );
+               $comment = Linker::revComment( $rev );
 
                if ( $this->patrollable( $result ) ) {
                        $classes[] = 'not-patrolled';
@@ -348,7 +365,14 @@ class SpecialNewpages extends IncludableSpecialPage {
 
                $css = count( $classes ) ? ' class="' . implode( ' ', $classes ) . '"' : '';
 
-               return "<li{$css}>{$time} {$dm}{$plink} {$hist} {$dm}{$length} {$dm}{$ulink} {$comment} {$tagDisplay}</li>\n";
+               # Display the old title if the namespace/title has been changed
+               $oldTitleText = '';
+               $oldTitle = Title::makeTitle( $result->rc_namespace, $result->rc_title );
+               if ( !$title->equals( $oldTitle ) ) {
+                       $oldTitleText = wfMessage( 'rc-old-title' )->params( $oldTitle->getPrefixedText() )->escaped(); 
+               }
+
+               return "<li{$css}>{$time} {$dm}{$plink} {$hist} {$dm}{$length} {$dm}{$ulink} {$comment} {$tagDisplay} {$oldTitleText}</li>\n";
        }
 
        /**
@@ -370,12 +394,12 @@ class SpecialNewpages extends IncludableSpecialPage {
                global $wgFeed, $wgFeedClasses, $wgFeedLimit;
 
                if ( !$wgFeed ) {
-                       $wgOut->addWikiMsg( 'feed-unavailable' );
+                       $this->getOutput()->addWikiMsg( 'feed-unavailable' );
                        return;
                }
 
                if( !isset( $wgFeedClasses[$type] ) ) {
-                       $this->getOut()->addWikiMsg( 'feed-invalid' );
+                       $this->getOutput()->addWikiMsg( 'feed-invalid' );
                        return;
                }
 
@@ -431,7 +455,7 @@ class SpecialNewpages extends IncludableSpecialPage {
                $revision = Revision::newFromId( $row->rev_id );
                if( $revision ) {
                        return '<p>' . htmlspecialchars( $revision->getUserText() ) . wfMsgForContent( 'colon-separator' ) .
-                               htmlspecialchars( FeedItem::stripComment( $revision->getComment() ) ) . 
+                               htmlspecialchars( FeedItem::stripComment( $revision->getComment() ) ) .
                                "</p>\n<hr />\n<div>" .
                                nl2br( htmlspecialchars( $revision->getText() ) ) . "</div>";
                }
@@ -444,30 +468,19 @@ class SpecialNewpages extends IncludableSpecialPage {
  */
 class NewPagesPager extends ReverseChronologicalPager {
        // Stored opts
-       protected $opts, $mForm;
+       protected $opts;
+
+       /**
+        * @var HtmlForm
+        */
+       protected $mForm;
 
        function __construct( $form, FormOptions $opts ) {
-               parent::__construct();
+               parent::__construct( $form->getContext() );
                $this->mForm = $form;
                $this->opts = $opts;
        }
 
-       function getTitle() {
-               static $title = null;
-               if ( $title === null ) {
-                       $title = $this->mForm->getTitle();
-               }
-               return $title;
-       }
-
-       function getUser() {
-               static $user = null;
-               if ( $user === null ) {
-                       $user = $this->mForm->getUser();
-               }
-               return $user;
-       }
-
        function getQueryInfo() {
                global $wgEnableNewpagesUserFilter, $wgGroupPermissions;
                $conds = array();
@@ -505,23 +518,26 @@ class NewPagesPager extends ReverseChronologicalPager {
                if ( $this->opts->getValue( 'hideredirs' ) ) {
                        $conds['page_is_redirect'] = 0;
                }
-  
+
                // Allow changes to the New Pages query
-               wfRunHooks( 'SpecialNewpagesConditions', array( &$this, $this->opts, &$conds ) );
+               $tables = array( 'recentchanges', 'page' );
+               $fields = array(
+                       'rc_namespace', 'rc_title', 'rc_cur_id', 'rc_user', 'rc_user_text',
+                       'rc_comment', 'rc_timestamp', 'rc_patrolled','rc_id', 'rc_deleted',
+                       'page_len AS length', 'page_latest AS rev_id', 'ts_tags', 'rc_this_oldid',
+                       'page_namespace', 'page_title'
+               );
+               $join_conds = array( 'page' => array( 'INNER JOIN', 'page_id=rc_cur_id' ) );
+
+               wfRunHooks( 'SpecialNewpagesConditions',
+                       array( &$this, $this->opts, &$conds, &$tables, &$fields, &$join_conds ) );
 
                $info = array(
-                       'tables' => array( 'recentchanges', 'page' ),
-                       'fields' => array(
-                               'rc_namespace', 'rc_title', 'rc_cur_id', 'rc_user',
-                               'rc_user_text', 'rc_comment', 'rc_timestamp', 'rc_patrolled',
-                               'rc_id', 'rc_deleted', 'page_len AS length', 'page_latest AS rev_id',
-                               'ts_tags'
-                       ),
-                       'conds' => $conds,
-                       'options' => array( 'USE INDEX' => array( 'recentchanges' => $rcIndexes ) ),
-                       'join_conds' => array(
-                               'page' => array( 'INNER JOIN', 'page_id=rc_cur_id' ),
-                       ),
+                       'tables'         => $tables,
+                       'fields'         => $fields,
+                       'conds'          => $conds,
+                       'options'        => array( 'USE INDEX' => array( 'recentchanges' => $rcIndexes ) ),
+                       'join_conds' => $join_conds
                );
 
                // Empty array for fields, it'll be set by us anyway.