* ( bug 18264 ) upload-by-url form was still disabled in non-js2 form output
[lhc/web/wiklou.git] / includes / specials / SpecialNewpages.php
index 3783cde..cf1e1af 100644 (file)
@@ -24,13 +24,15 @@ class SpecialNewpages extends SpecialPage {
                $opts = new FormOptions();
                $this->opts = $opts; // bind
                $opts->add( 'hideliu', false );
-               $opts->add( 'hidepatrolled', false );
+               $opts->add( 'hidepatrolled', $wgUser->getBoolOption( 'newpageshidepatrolled' ) );
                $opts->add( 'hidebots', false );
+               $opts->add( 'hideredirs', true );
                $opts->add( 'limit', (int)$wgUser->getOption( 'rclimit' ) );
                $opts->add( 'offset', '' );
                $opts->add( 'namespace', '0' );
                $opts->add( 'username', '' );
                $opts->add( 'feed', '' );
+               $opts->add( 'tagfilter', '' );
 
                // Set values
                $opts->fetchValuesFromRequest( $wgRequest );
@@ -58,6 +60,8 @@ class SpecialNewpages extends SpecialPage {
                                $this->opts->setValue( 'hidepatrolled', true );
                        if ( 'hidebots' == $bit )
                                $this->opts->setValue( 'hidebots', true );
+                       if ( 'showredirs' == $bit )
+                               $this->opts->setValue( 'hideredirs', false );
                        if ( is_numeric( $bit ) )
                                $this->opts->setValue( 'limit', intval( $bit ) );
 
@@ -67,6 +71,8 @@ class SpecialNewpages extends SpecialPage {
                        // PG offsets not just digits!
                        if ( preg_match( '/^offset=([^=]+)$/', $bit, $m ) )
                                $this->opts->setValue( 'offset',  intval($m[1]) );
+                       if ( preg_match( '/^username=(.*)$/', $bit, $m ) )
+                               $this->opts->setValue( 'username', $m[1] );
                        if ( preg_match( '/^namespace=(.*)$/', $bit, $m ) ) {
                                $ns = $wgLang->getNsIndex( $m[1] );
                                if( $ns !== false ) {
@@ -83,7 +89,7 @@ class SpecialNewpages extends SpecialPage {
         * @return string
         */
        public function execute( $par ) {
-               global $wgLang, $wgUser, $wgOut;
+               global $wgLang, $wgOut;
 
                $this->setHeaders();
                $this->outputHeader();
@@ -116,7 +122,7 @@ class SpecialNewpages extends SpecialPage {
        }
 
        protected function filterLinks() {
-               global $wgGroupPermissions, $wgUser;
+               global $wgGroupPermissions, $wgUser, $wgLang;
 
                // show/hide links
                $showhide = array( wfMsgHtml( 'show' ), wfMsgHtml( 'hide' ) );
@@ -125,7 +131,8 @@ class SpecialNewpages extends SpecialPage {
                $filters = array(
                        'hideliu' => 'rcshowhideliu',
                        'hidepatrolled' => 'rcshowhidepatr',
-                       'hidebots' => 'rcshowhidebots'
+                       'hidebots' => 'rcshowhidebots',
+                       'hideredirs' => 'whatlinkshere-hideredirs'
                );
 
                // Disable some if needed
@@ -142,13 +149,13 @@ class SpecialNewpages extends SpecialPage {
                $self = $this->getTitle();
                foreach ( $filters as $key => $msg ) {
                        $onoff = 1 - $this->opts->getValue($key);
-                       $link = $this->skin->makeKnownLinkObj( $self, $showhide[$onoff],
-                               wfArrayToCGI( array( $key => $onoff ), $changed )
+                       $link = $this->skin->link( $self, $showhide[$onoff], array(),
+                                array( $key => $onoff ) + $changed
                        );
                        $links[$key] = wfMsgHtml( $msg, $link );
                }
 
-               return implode( ' | ', $links );
+               return $wgLang->pipeList( $links );
        }
 
        protected function form() {
@@ -158,6 +165,7 @@ class SpecialNewpages extends SpecialPage {
                $this->opts->consumeValue( 'offset' ); // don't carry offset, DWIW
                $namespace = $this->opts->consumeValue( 'namespace' );
                $username = $this->opts->consumeValue( 'username' );
+               $tagFilterVal = $this->opts->consumeValue( 'tagfilter' );
 
                // Check username input validity
                $ut = Title::makeTitleSafe( NS_USER, $username );
@@ -170,6 +178,10 @@ class SpecialNewpages extends SpecialPage {
                }
                $hidden = implode( "\n", $hidden );
 
+               $tagFilter = ChangeTags::buildTagFilterSelector( $tagFilterVal );
+               if ($tagFilter)
+                       list( $tagFilterLabel, $tagFilterSelector ) = $tagFilter;
+
                $form = Xml::openElement( 'form', array( 'action' => $wgScript ) ) .
                        Xml::hidden( 'title', $this->getTitle()->getPrefixedDBkey() ) .
                        Xml::fieldset( wfMsg( 'newpages' ) ) .
@@ -181,7 +193,15 @@ class SpecialNewpages extends SpecialPage {
                                <td class='mw-input'>" .
                                        Xml::namespaceSelector( $namespace, 'all' ) .
                                "</td>
-                       </tr>" .
+                       </tr>" . ( $tagFilter ? (
+                       "<tr>
+                               <td class='mw-label'>" .
+                                       $tagFilterLabel .
+                               "</td>
+                               <td class='mw-input'>" .
+                                       $tagFilterSelector .
+                               "</td>
+                       </tr>" ) : '' ) .
                        ($wgEnableNewpagesUserFilter ?
                        "<tr>
                                <td class='mw-label'>" .
@@ -228,21 +248,48 @@ class SpecialNewpages extends SpecialPage {
         * @return string
         */
        public function formatRow( $result ) {
-               global $wgLang, $wgContLang, $wgUser;
+               global $wgLang, $wgContLang;
+
+               $classes = array();
+               
                $dm = $wgContLang->getDirMark();
 
                $title = Title::makeTitleSafe( $result->rc_namespace, $result->rc_title );
-               $time = $wgLang->timeAndDate( $result->rc_timestamp, true );
-               $plink = $this->skin->makeKnownLinkObj( $title, '', $this->patrollable( $result ) ? 'rcid=' . $result->rc_id : '' );
-               $hist = $this->skin->makeKnownLinkObj( $title, wfMsgHtml( 'hist' ), 'action=history' );
+               $time = htmlspecialchars( $wgLang->timeAndDate( $result->rc_timestamp, true ) );
+
+               $query = array( 'redirect' => 'no' );
+
+               if( $this->patrollable( $result ) )
+                       $query['rcid'] = $result->rc_id;
+
+               $plink = $this->skin->linkKnown(
+                       $title,
+                       null,
+                       array(),
+                       $query
+               );
+               $hist = $this->skin->linkKnown(
+                       $title,
+                       wfMsgHtml( 'hist' ),
+                       array(),
+                       array( 'action' => 'history' )
+               );
                $length = wfMsgExt( 'nbytes', array( 'parsemag', 'escape' ),
                        $wgLang->formatNum( $result->length ) );
                $ulink = $this->skin->userLink( $result->rc_user, $result->rc_user_text ) . ' ' .
                        $this->skin->userToolLinks( $result->rc_user, $result->rc_user_text );
                $comment = $this->skin->commentBlock( $result->rc_comment );
-               $css = $this->patrollable( $result ) ? " class='not-patrolled'" : '';
+               
+               if ( $this->patrollable( $result ) )
+                       $classes[] = 'not-patrolled';
 
-               return "<li{$css}>{$time} {$dm}{$plink} ({$hist}) {$dm}[{$length}] {$dm}{$ulink} {$comment}</li>\n";
+               # Tags, if any.
+               list( $tagDisplay, $newClasses ) = ChangeTags::formatSummaryRow( $result->ts_tags, 'newpages' );
+               $classes = array_merge( $classes, $newClasses );
+
+               $css = count($classes) ? ' class="'.implode( " ", $classes).'"' : '';
+
+               return "<li{$css}>{$time} {$dm}{$plink} ({$hist}) {$dm}[{$length}] {$dm}{$ulink} {$comment} {$tagDisplay}</li>\n";
        }
 
        /**
@@ -277,7 +324,7 @@ class SpecialNewpages extends SpecialPage {
 
                $feed = new $wgFeedClasses[$type](
                        $this->feedTitle(),
-                       wfMsg( 'tagline' ),
+                       wfMsgExt( 'tagline', 'parsemag' ),
                        $this->getTitle()->getFullUrl() );
 
                $pager = new NewPagesPager( $this, $this->opts );
@@ -318,13 +365,6 @@ class SpecialNewpages extends SpecialPage {
                }
        }
 
-       /**
-        * Quickie hack... strip out wikilinks to more legible form from the comment.
-        */
-       protected function stripComment( $text ) {
-               return preg_replace( '/\[\[([^]]*\|)?([^]]+)\]\]/', '\2', $text );
-       }
-
        protected function feedItemAuthor( $row ) {
                return isset( $row->rc_user_text ) ? $row->rc_user_text : '';
        }
@@ -332,8 +372,8 @@ class SpecialNewpages extends SpecialPage {
        protected function feedItemDesc( $row ) {
                $revision = Revision::newFromId( $row->rev_id );
                if( $revision ) {
-                       return '<p>' . htmlspecialchars( $revision->getUserText() ) . ': ' .
-                               htmlspecialchars( $revision->getComment() ) . 
+                       return '<p>' . htmlspecialchars( $revision->getUserText() ) . wfMsgForContent( 'colon-separator' ) .
+                               htmlspecialchars( FeedItem::stripComment( $revision->getComment() ) ) . 
                                "</p>\n<hr />\n<div>" .
                                nl2br( htmlspecialchars( $revision->getText() ) ) . "</div>";
                }
@@ -348,8 +388,6 @@ class NewPagesPager extends ReverseChronologicalPager {
        // Stored opts
        protected $opts, $mForm;
 
-       private $hideliu, $hidepatrolled, $hidebots, $namespace, $user, $spTitle;
-
        function __construct( $form, FormOptions $opts ) {
                parent::__construct();
                $this->mForm = $form;
@@ -380,8 +418,7 @@ class NewPagesPager extends ReverseChronologicalPager {
                } else {
                        $rcIndexes = array( 'rc_timestamp' );
                }
-               $conds[] = 'page_id = rc_cur_id';
-               $conds['page_is_redirect'] = 0;
+
                # $wgEnableNewpagesUserFilter - temp WMF hack
                if( $wgEnableNewpagesUserFilter && $user ) {
                        $conds['rc_user_text'] = $user->getText();
@@ -398,13 +435,33 @@ class NewPagesPager extends ReverseChronologicalPager {
                        $conds['rc_bot'] = 0;
                }
 
-               return array(
+               if ( $this->opts->getValue( 'hideredirs' ) ) {
+                       $conds['page_is_redirect'] = 0;
+               }
+
+               $info = array(
                        'tables' => array( 'recentchanges', 'page' ),
                        'fields' => 'rc_namespace,rc_title, rc_cur_id, rc_user,rc_user_text,rc_comment,
-                               rc_timestamp,rc_patrolled,rc_id,page_len as length, page_latest as rev_id',
+                               rc_timestamp,rc_patrolled,rc_id,page_len as length, page_latest as rev_id, ts_tags',
                        'conds' => $conds,
-                       'options' => array( 'USE INDEX' => array('recentchanges' => $rcIndexes) )
+                       'options' => array( 'USE INDEX' => array('recentchanges' => $rcIndexes) ),
+                       'join_conds' => array(
+                               'page' => array('INNER JOIN', 'page_id=rc_cur_id'),
+                       ),
                );
+
+               ## Empty array for fields, it'll be set by us anyway.
+               $fields = array();
+
+               ## Modify query for tags
+               ChangeTags::modifyDisplayQuery( $info['tables'],
+                                                                               $fields,
+                                                                               $info['conds'],
+                                                                               $info['join_conds'],
+                                                                               $info['options'],
+                                                                               $this->opts['tagfilter'] );
+
+               return $info;
        }
 
        function getIndexField() {