]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blobdiff - includes/specials/SpecialNewpages.php
MediaWiki 1.17.0
[autoinstallsdev/mediawiki.git] / includes / specials / SpecialNewpages.php
index 08e776d898044657b4ab7acf38bca29762cec926..3235436a591e5dd169191e22df348817e46eafd4 100644 (file)
@@ -1,10 +1,32 @@
 <?php
+/**
+ * Implements Special:Newpages
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ * @ingroup SpecialPage
+ */
 
 /**
- * implements Special:Newpages
+ * A special page that list newly created pages
+ *
  * @ingroup SpecialPage
  */
-class SpecialNewpages extends SpecialPage {
+class SpecialNewpages extends IncludableSpecialPage {
 
        // Stored objects
        protected $opts, $skin;
@@ -14,7 +36,6 @@ class SpecialNewpages extends SpecialPage {
 
        public function __construct() {
                parent::__construct( 'Newpages' );
-               $this->includable( true );      
        }
 
        protected function setup( $par ) {
@@ -24,7 +45,7 @@ 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' ) );
@@ -32,6 +53,7 @@ class SpecialNewpages extends SpecialPage {
                $opts->add( 'namespace', '0' );
                $opts->add( 'username', '' );
                $opts->add( 'feed', '' );
+               $opts->add( 'tagfilter', '' );
 
                // Set values
                $opts->fetchValuesFromRequest( $wgRequest );
@@ -84,11 +106,11 @@ class SpecialNewpages extends SpecialPage {
        /**
         * Show a form for filtering namespace and username
         *
-        * @param string $par
-        * @return string
+        * @param $par String
+        * @return String
         */
        public function execute( $par ) {
-               global $wgLang, $wgUser, $wgOut;
+               global $wgOut;
 
                $this->setHeaders();
                $this->outputHeader();
@@ -121,7 +143,7 @@ class SpecialNewpages extends SpecialPage {
        }
 
        protected function filterLinks() {
-               global $wgGroupPermissions, $wgUser;
+               global $wgGroupPermissions, $wgUser, $wgLang;
 
                // show/hide links
                $showhide = array( wfMsgHtml( 'show' ), wfMsgHtml( 'hide' ) );
@@ -135,6 +157,7 @@ class SpecialNewpages extends SpecialPage {
                );
 
                // Disable some if needed
+               # FIXME: throws E_NOTICEs if not set; and doesn't obey hooks etc
                if ( $wgGroupPermissions['*']['createpage'] !== true )
                        unset($filters['hideliu']);
 
@@ -154,7 +177,7 @@ class SpecialNewpages extends SpecialPage {
                        $links[$key] = wfMsgHtml( $msg, $link );
                }
 
-               return implode( ' | ', $links );
+               return $wgLang->pipeList( $links );
        }
 
        protected function form() {
@@ -164,6 +187,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 );
@@ -172,12 +196,16 @@ class SpecialNewpages extends SpecialPage {
                // Store query values in hidden fields so that form submission doesn't lose them
                $hidden = array();
                foreach ( $this->opts->getUnconsumedValues() as $key => $value ) {
-                       $hidden[] = Xml::hidden( $key, $value );
+                       $hidden[] = Html::hidden( $key, $value );
                }
                $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() ) .
+                       Html::hidden( 'title', $this->getTitle()->getPrefixedDBkey() ) .
                        Xml::fieldset( wfMsg( 'newpages' ) ) .
                        Xml::openElement( 'table', array( 'id' => 'mw-newpages-table' ) ) .
                        "<tr>
@@ -187,7 +215,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'>" .
@@ -218,44 +254,83 @@ class SpecialNewpages extends SpecialPage {
 
        protected function setSyndicated() {
                global $wgOut;
-               $queryParams = array(
-                       'namespace' => $this->opts->getValue( 'namespace' ),
-                       'username' => $this->opts->getValue( 'username' )
-               );
                $wgOut->setSyndicated( true );
-               $wgOut->setFeedAppendQuery( wfArrayToCGI( $queryParams ) );
+               $wgOut->setFeedAppendQuery( wfArrayToCGI( $this->opts->getAllValues() ) );
        }
 
        /**
         * Format a row, providing the timestamp, links to the page/history, size, user links, and a comment
         *
-        * @param $skin Skin to use
         * @param $result Result row
-        * @return string
+        * @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' );
-               $length = wfMsgExt( 'nbytes', array( 'parsemag', 'escape' ),
-                       $wgLang->formatNum( $result->length ) );
+               $time = Html::element( 'span', array( 'class' => 'mw-newpages-time' ),
+                       $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( 'class' => 'mw-newpages-pagename' ),
+                       $query,
+                       array( 'known' ) // Set explicitly to avoid the default of 'known','noclasses'. This breaks the colouration for stubs
+               );
+               $histLink = $this->skin->linkKnown(
+                       $title,
+                       wfMsgHtml( 'hist' ),
+                       array(),
+                       array( 'action' => 'history' )
+               );
+               $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 ) ) .
+                               ']'
+               );
                $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';
+               }
+
+               # Add a class for zero byte pages
+               if ( $result->length == 0 ) {
+                       $classes[] = 'mw-newpages-zero-byte-page';
+               }
 
-               return "<li{$css}>{$time} {$dm}{$plink} ({$hist}) {$dm}[{$length}] {$dm}{$ulink} {$comment}</li>\n";
+               # Tags, if any. check for including due to bug 23293
+               if ( !$this->including() ) {
+                       list( $tagDisplay, $newClasses ) = ChangeTags::formatSummaryRow( $result->ts_tags, 'newpages' );
+                       $classes = array_merge( $classes, $newClasses );
+               } else {
+                       $tagDisplay = '';
+               }
+
+               $css = count($classes) ? ' class="'.implode( " ", $classes).'"' : '';
+
+               return "<li{$css}>{$time} {$dm}{$plink} {$hist} {$dm}{$length} {$dm}{$ulink} {$comment} {$tagDisplay}</li>\n";
        }
 
        /**
         * Should a specific result row provide "patrollable" links?
         *
         * @param $result Result row
-        * @return bool
+        * @return Boolean
         */
        protected function patrollable( $result ) {
                global $wgUser;
@@ -264,19 +339,18 @@ class SpecialNewpages extends SpecialPage {
 
        /**
         * Output a subscription feed listing recent edits to this page.
-        * @param string $type
+        *
+        * @param $type String
         */
        protected function feed( $type ) {
-               global $wgFeed, $wgFeedClasses, $wgFeedLimit;
+               global $wgFeed, $wgFeedClasses, $wgFeedLimit, $wgOut;
 
                if ( !$wgFeed ) {
-                       global $wgOut;
                        $wgOut->addWikiMsg( 'feed-unavailable' );
                        return;
                }
 
                if( !isset( $wgFeedClasses[$type] ) ) {
-                       global $wgOut;
                        $wgOut->addWikiMsg( 'feed-invalid' );
                        return;
                }
@@ -292,7 +366,7 @@ class SpecialNewpages extends SpecialPage {
 
                $feed->outHeader();
                if( $pager->getNumRows() > 0 ) {
-                       while( $row = $pager->mResult->fetchObject() ) {
+                       foreach ( $pager->mResult as $row ) {
                                $feed->outItem( $this->feedItem( $row ) );
                        }
                }
@@ -300,10 +374,10 @@ class SpecialNewpages extends SpecialPage {
        }
 
        protected function feedTitle() {
-               global $wgContLanguageCode, $wgSitename;
+               global $wgLanguageCode, $wgSitename;
                $page = SpecialPage::getPage( 'Newpages' );
                $desc = $page->getDescription();
-               return "$wgSitename - $desc [$wgContLanguageCode]";
+               return "$wgSitename - $desc [$wgLanguageCode]";
        }
 
        protected function feedItem( $row ) {
@@ -320,7 +394,7 @@ class SpecialNewpages extends SpecialPage {
                                $this->feedItemAuthor( $row ),
                                $comments);
                } else {
-                       return NULL;
+                       return null;
                }
        }
 
@@ -331,7 +405,7 @@ class SpecialNewpages extends SpecialPage {
        protected function feedItemDesc( $row ) {
                $revision = Revision::newFromId( $row->rev_id );
                if( $revision ) {
-                       return '<p>' . htmlspecialchars( $revision->getUserText() ) . ': ' .
+                       return '<p>' . htmlspecialchars( $revision->getUserText() ) . wfMsgForContent( 'colon-separator' ) .
                                htmlspecialchars( FeedItem::stripComment( $revision->getComment() ) ) . 
                                "</p>\n<hr />\n<div>" .
                                nl2br( htmlspecialchars( $revision->getText() ) ) . "</div>";
@@ -377,7 +451,6 @@ class NewPagesPager extends ReverseChronologicalPager {
                } else {
                        $rcIndexes = array( 'rc_timestamp' );
                }
-               $conds[] = 'page_id = rc_cur_id';
 
                # $wgEnableNewpagesUserFilter - temp WMF hack
                if( $wgEnableNewpagesUserFilter && $user ) {
@@ -398,14 +471,33 @@ 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));
 
-               return array(
+               $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() {
@@ -419,7 +511,7 @@ class NewPagesPager extends ReverseChronologicalPager {
        function getStartBody() {
                # Do a batch existence check on pages
                $linkBatch = new LinkBatch();
-               while( $row = $this->mResult->fetchObject() ) {
+               foreach ( $this->mResult as $row ) {
                        $linkBatch->add( NS_USER, $row->rc_user_text );
                        $linkBatch->add( NS_USER_TALK, $row->rc_user_text );
                        $linkBatch->add( $row->rc_namespace, $row->rc_title );