API: Requesting a token you aren't allowed to request no longer dies with an error...
[lhc/web/wiklou.git] / includes / SpecialNewpages.php
index dcda205..a9f58b2 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /**
- *
- * @addtogroup SpecialPage
+ * @file
+ * @ingroup SpecialPage
  */
 
 
@@ -15,7 +15,7 @@ function wfSpecialNewPages( $par, $sp ) {
 
 /**
  * implements Special:Newpages
- * @addtogroup SpecialPage
+ * @ingroup SpecialPage
  */
 class NewPagesForm {
 
@@ -30,11 +30,12 @@ class NewPagesForm {
 
                // Options
                $opts = new FormOptions();
+               $this->opts = $opts; // bind
                $opts->add( 'hideliu', false );
                $opts->add( 'hidepatrolled', false );
                $opts->add( 'hidebots', false );
                $opts->add( 'limit', 50 );
-               $opts->add( 'offset', 0 );
+               $opts->add( 'offset', '' );
                $opts->add( 'namespace', '0' );
                $opts->add( 'username', '' );
                $opts->add( 'feed', '' );
@@ -50,12 +51,12 @@ class NewPagesForm {
                }
 
                // Store some objects
-               $this->opts = $opts;
                $this->skin = $wgUser->getSkin();
                $this->title = SpecialPage::getTitleFor( 'NewPages' );
        }
 
        protected function parseParams( $par ) {
+               global $wgLang;
                $bits = preg_split( '/\s*,\s*/', trim( $par ) );
                foreach ( $bits as $bit ) {
                        if ( 'shownav' == $bit )
@@ -72,7 +73,8 @@ class NewPagesForm {
                        $m = array();
                        if ( preg_match( '/^limit=(\d+)$/', $bit, $m ) )
                                $this->opts->setValue( 'limit', intval($m[1]) );
-                       if ( preg_match( '/^offset=(\d+)$/', $bit, $m ) )
+                       // PG offsets not just digits!
+                       if ( preg_match( '/^offset=([^=]+)$/', $bit, $m ) )
                                $this->opts->setValue( 'offset',  intval($m[1]) );
                        if ( preg_match( '/^namespace=(.*)$/', $bit, $m ) ) {
                                $ns = $wgLang->getNsIndex( $m[1] );
@@ -96,10 +98,10 @@ class NewPagesForm {
                $this->showNavigation = !$including; // Maybe changed in setup
                $this->setup( $par );
 
-               // Settings
-               $this->form();
+               if( !$including ) {
+                       // Settings
+                       $this->form();
 
-               if( !$including ){
                        $this->setSyndicated();
                        $feedType = $this->opts->getValue( 'feed' );
                        if( $feedType ) {
@@ -135,10 +137,10 @@ class NewPagesForm {
 
                // Disable some if needed
                if ( $wgGroupPermissions['*']['createpage'] !== true )
-                       unset($hidelinks['hideliu']);
+                       unset($filters['hideliu']);
 
-               if ( $wgUser->useNPPatrol() )
-                       unset($hidelinks['hidepatrolled']);
+               if ( !$wgUser->useNPPatrol() )
+                       unset($filters['hidepatrolled']);
 
                $links = array();
                $changed = $this->opts->getChangedValues();
@@ -244,9 +246,9 @@ class NewPagesForm {
                $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 ) ? 'not-patrolled' : '';
+               $css = $this->patrollable( $result ) ? " class='not-patrolled'" : '';
 
-               return "<li class='$css'>{$time} {$dm}{$plink} ({$hist}) {$dm}[{$length}] {$dm}{$ulink} {$comment}</li>\n";
+               return "<li{$css}>{$time} {$dm}{$plink} ({$hist}) {$dm}[{$length}] {$dm}{$ulink} {$comment}</li>\n";
        }
 
        /**
@@ -287,6 +289,12 @@ class NewPagesForm {
                        $this->title->getFullUrl() );
 
                $pager = new NewPagesPager( $this, $this->opts );
+               $limit = $this->opts->getValue( 'limit' );
+               global $wgFeedLimit;
+               if( $limit > $wgFeedLimit ) {
+                       $limit = $wgFeedLimit;
+               }
+               $pager->mLimit = $limit;
 
                $feed->outHeader();
                if( $pager->getNumRows() > 0 ) {
@@ -346,7 +354,7 @@ class NewPagesForm {
 }
 
 /**
- * @addtogroup Pager
+ * @ingroup SpecialPage Pager
  */
 class NewPagesPager extends ReverseChronologicalPager {
        // Stored opts
@@ -386,12 +394,13 @@ class NewPagesPager extends ReverseChronologicalPager {
                }
                $conds[] = 'page_id = rc_cur_id';
                $conds['page_is_redirect'] = 0;
-
-               # If anons cannot make new pages, don't query for it!
-               if( $wgGroupPermissions['*']['createpage'] && $this->opts->getValue( 'hideliu' ) ) {
-                       $conds['rc_user'] = 0;
-               } elseif ( $user ) {
+               # $wgEnableNewpagesUserFilter - temp WMF hack
+               if( $wgEnableNewpagesUserFilter && $user ) {
                        $conds['rc_user_text'] = $user->getText();
+                       $rcIndexes = 'rc_user_text';
+               # If anons cannot make new pages, don't "exclude logged in users"!
+               } elseif( $wgGroupPermissions['*']['createpage'] && $this->opts->getValue( 'hideliu' ) ) {
+                       $conds['rc_user'] = 0;
                }
                # If this user cannot see patrolled edits or they are off, don't do dumb queries!
                if( $this->opts->getValue( 'hidepatrolled' ) && $wgUser->useNPPatrol() ) {
@@ -400,11 +409,6 @@ class NewPagesPager extends ReverseChronologicalPager {
                if( $this->opts->getValue( 'hidebots' ) ) {
                        $conds['rc_bot'] = 0;
                }
-               # $wgEnableNewpagesUserFilter - temp WMF hack
-               if( $wgEnableNewpagesUserFilter && $user ) {
-                       $conds['rc_user_text'] = $user->getText();
-                       $rcIndexes = 'rc_user_text';
-               }
 
                return array(
                        'tables' => array( 'recentchanges', 'page' ),