Make default params to CategoryViewer usable as defaults.

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
This commit is contained in:
Ori Livneh 2013-03-01 16:34:09 -08:00 committed by Gerrit Code Review
parent 90797afe53
commit 538014185a

View 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;
}