(bug 29569) Avoid fatal errors in OutputPage when nonexistent module names are passed in
[lhc/web/wiklou.git] / includes / Pager.php
index b91b061..a03a1d1 100644 (file)
@@ -95,6 +95,9 @@ abstract class IndexPager extends ContextSource implements Pager {
 
        /** True if the current result set is the first one */
        public $mIsFirst;
+       public $mIsLast;
+
+       protected $mLastShown, $mFirstShown, $mPastTheEndIndex, $mDefaultQuery, $mNavigationBar;
 
        /**
         * Result object for the query. Warning: seek before use.
@@ -190,12 +193,16 @@ abstract class IndexPager extends ContextSource implements Pager {
 
        /**
         * Set the offset from an other source than the request
+        *
+        * @param $offset Int|String
         */
        function setOffset( $offset ) {
                $this->mOffset = $offset;
        }
        /**
         * Set the limit from an other source than the request
+        *
+        * @param $limit Int|String
         */
        function setLimit( $limit ) {
                $this->mLimit = $limit;
@@ -318,10 +325,16 @@ abstract class IndexPager extends ContextSource implements Pager {
         *
         * @return String
         */
-       function getBody() {
+       public function getBody() {
                if ( !$this->mQueryDone ) {
                        $this->doQuery();
                }
+
+               if ( $this->mResult->numRows() ) {
+                       # Do any special query batches before display
+                       $this->doBatchLookups();
+               }
+
                # Don't use any extra rows returned by the query
                $numRows = min( $this->mResult->numRows(), $this->mLimit );
 
@@ -377,13 +390,22 @@ abstract class IndexPager extends ContextSource implements Pager {
                );
        }
 
+       /**
+        * Called from getBody(), before getStartBody() is called and
+        * after doQuery() was called. This will be called only if there
+        * are rows in the result set.
+        *
+        * @return void
+        */
+       protected function doBatchLookups() {}
+
        /**
         * Hook into getBody(), allows text to be inserted at the start. This
         * will be called even if there are no rows in the result set.
         *
         * @return String
         */
-       function getStartBody() {
+       protected function getStartBody() {
                return '';
        }
 
@@ -392,7 +414,7 @@ abstract class IndexPager extends ContextSource implements Pager {
         *
         * @return String
         */
-       function getEndBody() {
+       protected function getEndBody() {
                return '';
        }
 
@@ -402,7 +424,7 @@ abstract class IndexPager extends ContextSource implements Pager {
         *
         * @return String
         */
-       function getEmptyBody() {
+       protected function getEmptyBody() {
                return '';
        }
 
@@ -497,6 +519,8 @@ abstract class IndexPager extends ContextSource implements Pager {
         * $linkTexts will be used. Both $linkTexts and $disabledTexts are arrays
         * of HTML.
         *
+        * @param $linkTexts Array
+        * @param $disabledTexts Array
         * @return Array
         */
        function getPagingLinks( $linkTexts, $disabledTexts = array() ) {
@@ -527,7 +551,7 @@ abstract class IndexPager extends ContextSource implements Pager {
                }
                foreach ( $this->mLimitsShown as $limit ) {
                        $links[] = $this->makeLink(
-                               $this->getLang()->formatNum( $limit ),
+                               $this->getLanguage()->formatNum( $limit ),
                                array( 'offset' => $offset, 'limit' => $limit ),
                                'num'
                        );
@@ -619,9 +643,12 @@ abstract class IndexPager extends ContextSource implements Pager {
  * @ingroup Pager
  */
 abstract class AlphabeticPager extends IndexPager {
+
        /**
         * Shamelessly stolen bits from ReverseChronologicalPager,
         * didn't want to do class magic as may be still revamped
+        *
+        * @return String HTML
         */
        function getNavigationBar() {
                if ( !$this->isNavigationBarShown() ) return '';
@@ -630,7 +657,7 @@ abstract class AlphabeticPager extends IndexPager {
                        return $this->mNavigationBar;
                }
 
-               $lang = $this->getLang();
+               $lang = $this->getLanguage();
 
                $opts = array( 'parsemag', 'escapenoentities' );
                $linkTexts = array(
@@ -723,7 +750,7 @@ abstract class ReverseChronologicalPager extends IndexPager {
                        return $this->mNavigationBar;
                }
 
-               $nicenumber = $this->getLang()->formatNum( $this->mLimit );
+               $nicenumber = $this->getLanguage()->formatNum( $this->mLimit );
                $linkTexts = array(
                        'prev' => wfMsgExt(
                                'pager-newer-n',
@@ -741,7 +768,7 @@ abstract class ReverseChronologicalPager extends IndexPager {
 
                $pagingLinks = $this->getPagingLinks( $linkTexts );
                $limitLinks = $this->getLimitLinks();
-               $limits = $this->getLang()->pipeList( $limitLinks );
+               $limits = $this->getLanguage()->pipeList( $limitLinks );
 
                $this->mNavigationBar = "({$pagingLinks['first']}" .
                        wfMsgExt( 'pipe-separator' , 'escapenoentities' ) .
@@ -884,9 +911,13 @@ abstract class TablePager extends IndexPager {
                return "<tr><td colspan=\"$colspan\">$msgEmpty</td></tr>\n";
        }
 
+       /**
+        * @param $row Array
+        * @return String HTML
+        */
        function formatRow( $row ) {
                $this->mCurrentRow = $row;      # In case formatValue etc need to know
-               $s = Xml::openElement( 'tr', $this->getRowAttrs($row) );
+               $s = Xml::openElement( 'tr', $this->getRowAttrs( $row ) );
                $fieldNames = $this->getFieldNames();
                foreach ( $fieldNames as $field => $name ) {
                        $value = isset( $row->$field ) ? $row->$field : null;
@@ -914,7 +945,7 @@ abstract class TablePager extends IndexPager {
         * Get attributes to be applied to the given row.
         *
         * @param $row Object: the database result row
-        * @return Associative array
+        * @return Array of <attr> => <value>
         */
        function getRowAttrs( $row ) {
                $class = $this->getRowClass( $row );
@@ -931,9 +962,9 @@ abstract class TablePager extends IndexPager {
         * take this as an excuse to hardcode styles; use classes and
         * CSS instead.  Row context is available in $this->mCurrentRow
         *
-        * @param $field The column
-        * @param $value The cell contents
-        * @return Associative array
+        * @param $field String The column
+        * @param $value String The cell contents
+        * @return Array of attr => value
         */
        function getCellAttrs( $field, $value ) {
                return array( 'class' => 'TablePager_col_' . $field );
@@ -957,6 +988,7 @@ abstract class TablePager extends IndexPager {
 
        /**
         * A navigation bar with images
+        * @return String HTML
         */
        function getNavigationBar() {
                global $wgStylePath;
@@ -984,7 +1016,7 @@ abstract class TablePager extends IndexPager {
                        'next' => 'arrow_disabled_right_25.png',
                        'last' => 'arrow_disabled_last_25.png',
                );
-               if( $this->getLang()->isRTL() ) {
+               if( $this->getLanguage()->isRTL() ) {
                        $keys = array_keys( $labels );
                        $images = array_combine( $keys, array_reverse( $images ) );
                        $disabledImages = array_combine( $keys, array_reverse( $disabledImages ) );
@@ -1028,7 +1060,7 @@ abstract class TablePager extends IndexPager {
                        # will be a string.
                        if( is_int( $value ) ){
                                $limit = $value;
-                               $text = $this->getLang()->formatNum( $limit );
+                               $text = $this->getLanguage()->formatNum( $limit );
                        } else {
                                $limit = $key;
                                $text = $value;
@@ -1044,6 +1076,7 @@ abstract class TablePager extends IndexPager {
         * Resubmits all defined elements of the query string, except for a
         * blacklist, passed in the $blacklist parameter.
         *
+        * @param $blacklist Array parameters from the request query which should not be resubmitted
         * @return String: HTML fragment
         */
        function getHiddenFields( $blacklist = array() ) {
@@ -1120,6 +1153,8 @@ abstract class TablePager extends IndexPager {
         * An array mapping database field names to a textual description of the
         * field name, for use in the table header. The description should be plain
         * text, it will be HTML-escaped later.
+        *
+        * @return Array
         */
        abstract function getFieldNames();
 }