Make default params to CategoryViewer usable as defaults.
authorOri Livneh <ori@wikimedia.org>
Sat, 2 Mar 2013 00:34:09 +0000 (16:34 -0800)
committerGerrit Code Review <gerrit@wikimedia.org>
Wed, 6 Mar 2013 08:40:52 +0000 (08:40 +0000)
If the '$from' and '$to' parameters to the CategoryViewer constructor are left
off, they default to empty arrays. This makes later checks for $from['page'],
etc. issue an 'Undefined index' notice.

Using 'empty' would be more concise but could hide bugs.

Change-Id: I78793d13745d1fc1010b8e6861bdc3a89a39a87f

includes/CategoryViewer.php

index 7678ffe..878c371 100644 (file)
@@ -288,10 +288,10 @@ class CategoryViewer extends ContextSource {
                        # the collation in the database differs from the one
                        # set in $wgCategoryCollation, pagination might go totally haywire.
                        $extraConds = array( 'cl_type' => $type );
-                       if ( $this->from[$type] !== null ) {
+                       if ( isset( $this->from[$type] ) && $this->from[$type] !== null ) {
                                $extraConds[] = 'cl_sortkey >= '
                                        . $dbr->addQuotes( $this->collation->getSortKey( $this->from[$type] ) );
-                       } elseif ( $this->until[$type] !== null ) {
+                       } elseif ( isset( $this->until[$type] ) && $this->until[$type] !== null ) {
                                $extraConds[] = 'cl_sortkey < '
                                        . $dbr->addQuotes( $this->collation->getSortKey( $this->until[$type] ) );
                                $this->flip[$type] = true;
@@ -445,9 +445,9 @@ class CategoryViewer extends ContextSource {
         * @return String: HTML output, possibly empty if there are no other pages
         */
        private function getSectionPagingLinks( $type ) {
-               if ( $this->until[$type] !== null ) {
+               if ( isset( $this->until[$type] ) && $this->until[$type] !== null ) {
                        return $this->pagingLinks( $this->nextPage[$type], $this->until[$type], $type );
-               } elseif ( $this->nextPage[$type] !== null || $this->from[$type] !== null ) {
+               } elseif ( $this->nextPage[$type] !== null || ( isset( $this->from[$type] ) && $this->from[$type] !== null ) ) {
                        return $this->pagingLinks( $this->from[$type], $this->nextPage[$type], $type );
                } else {
                        return '';
@@ -677,7 +677,9 @@ class CategoryViewer extends ContextSource {
                }
 
                $fromOrUntil = false;
-               if ( $this->from[$pagingType] !== null || $this->until[$pagingType] !== null ) {
+               if ( ( isset( $this->from[$pagingType] ) && $this->from[$pagingType] !== null ) ||
+                       ( isset( $this->until[$pagingType] ) && $this->until[$pagingType] !== null )
+               ) {
                        $fromOrUntil = true;
                }