Example #1
0
	/**
	 * What to do if the category table conflicts with the number of results
	 * returned?  This function says what. Each type is considered independently
	 * of the other types.
	 *
	 * @param int $rescnt The number of items returned by our database query.
	 * @param int $dbcnt The number of items according to the category table.
	 * @param string $type 'subcat', 'article', or 'file'
	 * @return string: A message giving the number of items, to output to HTML.
	 */
	private function getCountMessage( $rescnt, $dbcnt, $type ) {
		// There are three cases:
		//   1) The category table figure seems sane.  It might be wrong, but
		//      we can't do anything about it if we don't recalculate it on ev-
		//      ery category view.
		//   2) The category table figure isn't sane, like it's smaller than the
		//      number of actual results, *but* the number of results is less
		//      than $this->limit and there's no offset.  In this case we still
		//      know the right figure.
		//   3) We have no idea.

		// Check if there's a "from" or "until" for anything

		// This is a little ugly, but we seem to use different names
		// for the paging types then for the messages.
		if ( $type === 'article' ) {
			$pagingType = 'page';
		} else {
			$pagingType = $type;
		}

		$fromOrUntil = false;
		if ( ( isset( $this->from[$pagingType] ) && $this->from[$pagingType] !== null ) ||
			( isset( $this->until[$pagingType] ) && $this->until[$pagingType] !== null )
		) {
			$fromOrUntil = true;
		}

		if ( $dbcnt == $rescnt ||
			( ( $rescnt == $this->limit || $fromOrUntil ) && $dbcnt > $rescnt )
		) {
			// Case 1: seems sane.
			$totalcnt = $dbcnt;
		} elseif ( $rescnt < $this->limit && !$fromOrUntil ) {
			// Case 2: not sane, but salvageable.  Use the number of results.
			// Since there are fewer than 200, we can also take this opportunity
			// to refresh the incorrect category table entry -- which should be
			// quick due to the small number of entries.
			$totalcnt = $rescnt;
			$this->cat->refreshCounts();
		} else {
			// Case 3: hopeless.  Don't give a total count at all.
			// Messages: category-subcat-count-limited, category-article-count-limited,
			// category-file-count-limited
			return $this->msg( "category-$type-count-limited" )->numParams( $rescnt )->parseAsBlock();
		}
		// Messages: category-subcat-count, category-article-count, category-file-count
		return $this->msg( "category-$type-count" )->numParams( $rescnt, $totalcnt )->parseAsBlock();
	}
Example #2
0
 /**
  * What to do if the category table conflicts with the number of results
  * returned?  This function says what. Each type is considered independently
  * of the other types.
  *
  * Note for grepping: uses the messages category-article-count,
  * category-article-count-limited, category-subcat-count,
  * category-subcat-count-limited, category-file-count,
  * category-file-count-limited.
  *
  * @param $rescnt Int: The number of items returned by our database query.
  * @param $dbcnt Int: The number of items according to the category table.
  * @param $type String: 'subcat', 'article', or 'file'
  * @return String: A message giving the number of items, to output to HTML.
  */
 private function getCountMessage($rescnt, $dbcnt, $type)
 {
     global $wgLang;
     # There are three cases:
     #   1) The category table figure seems sane.  It might be wrong, but
     #      we can't do anything about it if we don't recalculate it on ev-
     #      ery category view.
     #   2) The category table figure isn't sane, like it's smaller than the
     #      number of actual results, *but* the number of results is less
     #      than $this->limit and there's no offset.  In this case we still
     #      know the right figure.
     #   3) We have no idea.
     # Check if there's a "from" or "until" for anything
     // This is a little ugly, but we seem to use different names
     // for the paging types then for the messages.
     if ($type === 'article') {
         $pagingType = 'page';
     } else {
         $pagingType = $type;
     }
     $fromOrUntil = false;
     if ($this->from[$pagingType] !== null || $this->until[$pagingType] !== null) {
         $fromOrUntil = true;
     }
     if ($dbcnt == $rescnt || ($rescnt == $this->limit || $fromOrUntil) && $dbcnt > $rescnt) {
         # Case 1: seems sane.
         $totalcnt = $dbcnt;
     } elseif ($rescnt < $this->limit && !$fromOrUntil) {
         # Case 2: not sane, but salvageable.  Use the number of results.
         # Since there are fewer than 200, we can also take this opportunity
         # to refresh the incorrect category table entry -- which should be
         # quick due to the small number of entries.
         $totalcnt = $rescnt;
         $this->cat->refreshCounts();
     } else {
         # Case 3: hopeless.  Don't give a total count at all.
         return wfMsgExt("category-{$type}-count-limited", 'parse', $wgLang->formatNum($rescnt));
     }
     return wfMsgExt("category-{$type}-count", 'parse', $wgLang->formatNum($rescnt), $wgLang->formatNum($totalcnt));
 }