Handle multiple warnings correctly in ApiBase::setWarning(). Calling this function...
[lhc/web/wiklou.git] / includes / SpecialAllpages.php
index 8599cbf..7223e31 100644 (file)
@@ -1,6 +1,7 @@
 <?php
 /**
- * @addtogroup SpecialPage
+ * @file
+ * @ingroup SpecialPage
  */
 
 /**
@@ -35,14 +36,24 @@ function wfSpecialAllpages( $par=NULL, $specialPage ) {
 
 /**
  * Implements Special:Allpages
- * @addtogroup SpecialPage
+ * @ingroup SpecialPage
  */
 class SpecialAllpages {
-       var $maxPerPage=960;
-       var $topLevelMax=50;
-       var $name='Allpages';
-       # Determines, which message describes the input field 'nsfrom' (->SpecialPrefixindex.php)
-       var $nsfromMsg='allpagesfrom';
+       /**
+        * Maximum number of pages to show on single subpage.
+        */
+       protected $maxPerPage = 960;
+
+       /**
+        * Name of this special page. Used to make title objects that reference back
+        * to this page.
+        */
+       protected $name = 'Allpages';
+
+       /**
+        * Determines, which message describes the input field 'nsfrom'.
+        */
+       protected $nsfromMsg = 'allpagesfrom';
 
 /**
  * HTML for the top form
@@ -50,32 +61,34 @@ class SpecialAllpages {
  * @param string $from Article name we are starting listing at.
  */
 function namespaceForm ( $namespace = NS_MAIN, $from = '' ) {
-       global $wgScript, $wgContLang;
+       global $wgScript;
        $t = SpecialPage::getTitleFor( $this->name );
-       $align = $wgContLang->isRtl() ? 'left' : 'right';
 
        $out  = Xml::openElement( 'div', array( 'class' => 'namespaceoptions' ) );
        $out .= Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) );
        $out .= Xml::hidden( 'title', $t->getPrefixedText() );
+       $out .= Xml::openElement( 'fieldset' );
+       $out .= Xml::element( 'legend', null, wfMsg( 'allpages' ) );
        $out .= Xml::openElement( 'table', array( 'id' => 'nsselect', 'class' => 'allpages' ) );
        $out .= "<tr>
-                       <td align='$align'>" .
+                       <td class='mw-label'>" .
                                Xml::label( wfMsg( $this->nsfromMsg ), 'nsfrom' ) .
                        "</td>
-                       <td>" .
-                               Xml::input( 'from', 20, htmlspecialchars ( $from ), array( 'id' => 'nsfrom' ) ) .
+                       <td class='mw-input'>" .
+                               Xml::input( 'from', 20, $from, array( 'id' => 'nsfrom' ) ) .
                        "</td>
                </tr>
                <tr>
-                       <td align='$align'>" .
+                       <td class='mw-label'>" .
                                Xml::label( wfMsg( 'namespace' ), 'namespace' ) .
                        "</td>
-                       <td>" .
-                               Xml::namespaceSelector( $namespace, null ) .
+                       <td class='mw-input'>" .
+                               Xml::namespaceSelector( $namespace, null ) . ' ' .
                                Xml::submitButton( wfMsg( 'allpagessubmit' ) ) .
                        "</td>
                        </tr>";
        $out .= Xml::closeElement( 'table' );
+       $out .= Xml::closeElement( 'fieldset' );
        $out .= Xml::closeElement( 'form' );
        $out .= Xml::closeElement( 'div' );
        return $out;
@@ -86,7 +99,6 @@ function namespaceForm ( $namespace = NS_MAIN, $from = '' ) {
  */
 function showToplevel ( $namespace = NS_MAIN, $including = false ) {
        global $wgOut, $wgContLang;
-       $fname = "indexShowToplevel";
        $align = $wgContLang->isRtl() ? 'left' : 'right';
 
        # TODO: Either make this *much* faster or cache the title index points
@@ -101,7 +113,11 @@ function showToplevel ( $namespace = NS_MAIN, $including = false ) {
        $lines = $wgMemc->get( $key );
 
        if( !is_array( $lines ) ) {
-               $firstTitle = $dbr->selectField( 'page', 'page_title', $where, $fname, array( 'LIMIT' => 1 ) );
+               $options = array( 'LIMIT' => 1 );
+               if ( ! $dbr->implicitOrderby() ) {
+                       $options['ORDER BY'] = 'page_title';
+               }
+               $firstTitle = $dbr->selectField( 'page', 'page_title', $where, __METHOD__, $options );
                $lastTitle = $firstTitle;
 
                # This array is going to hold the page_titles in order.
@@ -117,8 +133,8 @@ function showToplevel ( $namespace = NS_MAIN, $including = false ) {
                        $res = $dbr->select(
                                'page', /* FROM */
                                'page_title', /* WHAT */
-                               $where + array( $chunk),
-                               $fname,
+                               $where + array($chunk),
+                               __METHOD__,
                                array ('LIMIT' => 2, 'OFFSET' => $this->maxPerPage - 1, 'ORDER BY' => 'page_title') );
 
                        if ( $s = $dbr->fetchObject( $res ) ) {
@@ -129,7 +145,7 @@ function showToplevel ( $namespace = NS_MAIN, $including = false ) {
                                        array(
                                                'page_namespace' => $namespace,
                                                $chunk
-                                       ), $fname );
+                                       ), __METHOD__ );
                                array_push( $lines, $endTitle );
                                $done = true;
                        }
@@ -161,7 +177,7 @@ function showToplevel ( $namespace = NS_MAIN, $including = false ) {
                $out .= $this->showline ( $inpoint, $outpoint, $namespace, false );
        }
        $out .= '</table>';
-       $nsForm = $this->namespaceForm ( $namespace, '', false );
+       $nsForm = $this->namespaceForm( $namespace, '', false );
 
        # Is there more?
        if ( $including ) {
@@ -210,7 +226,6 @@ function showline( $inpoint, $outpoint, $namespace = NS_MAIN ) {
 function showChunk( $namespace = NS_MAIN, $from, $including = false ) {
        global $wgOut, $wgUser, $wgContLang;
 
-       $fname = 'indexShowChunk';
        $sk = $wgUser->getSkin();
 
        $fromList = $this->getNamespaceKeyAndText($namespace, $from);
@@ -235,7 +250,7 @@ function showChunk( $namespace = NS_MAIN, $from, $including = false ) {
                                'page_namespace' => $namespace,
                                'page_title >= ' . $dbr->addQuotes( $fromKey )
                        ),
-                       $fname,
+                       __METHOD__,
                        array(
                                'ORDER BY'  => 'page_title',
                                'LIMIT'     => $this->maxPerPage + 1,
@@ -243,30 +258,34 @@ function showChunk( $namespace = NS_MAIN, $from, $including = false ) {
                        )
                );
 
-               $out = '<table style="background: inherit;" border="0" width="100%">';
-
-               while( ($n < $this->maxPerPage) && ($s = $dbr->fetchObject( $res )) ) {
-                       $t = Title::makeTitle( $s->page_namespace, $s->page_title );
-                       if( $t ) {
-                               $link = ($s->page_is_redirect ? '<div class="allpagesredirect">' : '' ) .
-                                       $sk->makeKnownLinkObj( $t, htmlspecialchars( $t->getText() ), false, false ) .
-                                       ($s->page_is_redirect ? '</div>' : '' );
-                       } else {
-                               $link = '[[' . htmlspecialchars( $s->page_title ) . ']]';
-                       }
-                       if( $n % 3 == 0 ) {
-                               $out .= '<tr>';
+               if( $res->numRows() > 0 ) {
+                       $out = '<table style="background: inherit;" border="0" width="100%">';
+       
+                       while( ($n < $this->maxPerPage) && ($s = $dbr->fetchObject( $res )) ) {
+                               $t = Title::makeTitle( $s->page_namespace, $s->page_title );
+                               if( $t ) {
+                                       $link = ($s->page_is_redirect ? '<div class="allpagesredirect">' : '' ) .
+                                               $sk->makeKnownLinkObj( $t, htmlspecialchars( $t->getText() ), false, false ) .
+                                               ($s->page_is_redirect ? '</div>' : '' );
+                               } else {
+                                       $link = '[[' . htmlspecialchars( $s->page_title ) . ']]';
+                               }
+                               if( $n % 3 == 0 ) {
+                                       $out .= '<tr>';
+                               }
+                               $out .= "<td width=\"33%\">$link</td>";
+                               $n++;
+                               if( $n % 3 == 0 ) {
+                                       $out .= '</tr>';
+                               }
                        }
-                       $out .= "<td>$link</td>";
-                       $n++;
-                       if( $n % 3 == 0 ) {
+                       if( ($n % 3) != 0 ) {
                                $out .= '</tr>';
                        }
+                       $out .= '</table>';
+               } else {
+                       $out = '';
                }
-               if( ($n % 3) != 0 ) {
-                       $out .= '</tr>';
-               }
-               $out .= '</table>';
        }
 
        if ( $including ) {
@@ -282,7 +301,7 @@ function showChunk( $namespace = NS_MAIN, $from, $including = false ) {
                                'page',
                                'page_title',
                                array( 'page_namespace' => $namespace, 'page_title < '.$dbr->addQuotes($from) ),
-                               $fname,
+                               __METHOD__,
                                array( 'ORDER BY' => 'page_title DESC', 'LIMIT' => $this->maxPerPage, 'OFFSET' => ($this->maxPerPage - 1 ) )
                        );
 
@@ -293,8 +312,11 @@ function showChunk( $namespace = NS_MAIN, $from, $including = false ) {
                        } else {
                                # The previous chunk is not complete, need to link to the very first title
                                # available in the database
-                               $reallyFirstPage_title = $dbr->selectField( 'page', 'page_title', array( 'page_namespace' => $namespace ), $fname, array( 'LIMIT' => 1) );
-
+                               $options = array( 'LIMIT' => 1 );
+                               if ( ! $dbr->implicitOrderby() ) {
+                                       $options['ORDER BY'] = 'page_title';
+                               }
+                               $reallyFirstPage_title = $dbr->selectField( 'page', 'page_title', array( 'page_namespace' => $namespace ), __METHOD__, $options );
                                # Show the previous link if it s not the current requested chunk
                                if( $from != $reallyFirstPage_title ) {
                                        $prevTitle =  Title::makeTitle( $namespace, $reallyFirstPage_title );
@@ -304,7 +326,7 @@ function showChunk( $namespace = NS_MAIN, $from, $including = false ) {
                        }
                }
 
-               $nsForm = $this->namespaceForm ( $namespace, $from );
+               $nsForm = $this->namespaceForm( $namespace, $from );
                $out2 = '<table style="background: inherit;" width="100%" cellpadding="0" cellspacing="0" border="0">';
                $out2 .= '<tr valign="top"><td>' . $nsForm;
                $out2 .= '</td><td align="' . $align . '" style="font-size: smaller; margin-bottom: 1em;">' .
@@ -315,16 +337,20 @@ function showChunk( $namespace = NS_MAIN, $from, $including = false ) {
 
                # Do we put a previous link ?
                if( isset( $prevTitle ) &&  $pt = $prevTitle->getText() ) {
-                       $q = 'from=' . $prevTitle->getPartialUrl() . ( $namespace ? '&namespace=' . $namespace : '' );
-                       $prevLink = $sk->makeKnownLinkObj( $self, wfMsgHTML( 'prevpage', $pt ), $q );
+                       $q = 'from=' . $prevTitle->getPartialUrl()
+                               . ( $namespace ? '&namespace=' . $namespace : '' );
+                       $prevLink = $sk->makeKnownLinkObj( $self,
+                               wfMsgHTML( 'prevpage', htmlspecialchars( $pt ) ), $q );
                        $out2 .= ' | ' . $prevLink;
                }
 
                if( $n == $this->maxPerPage && $s = $dbr->fetchObject($res) ) {
                        # $s is the first link of the next chunk
                        $t = Title::MakeTitle($namespace, $s->page_title);
-                       $q = 'from=' . $t->getPartialUrl() . ( $namespace ? '&namespace=' . $namespace : '' );
-                       $nextLink = $sk->makeKnownLinkObj( $self, wfMsgHtml( 'nextpage', $t->getText() ), $q );
+                       $q = 'from=' . $t->getPartialUrl()
+                               . ( $namespace ? '&namespace=' . $namespace : '' );
+                       $nextLink = $sk->makeKnownLinkObj( $self,
+                               wfMsgHtml( 'nextpage', htmlspecialchars( $t->getText() ) ), $q );
                        $out2 .= ' | ' . $nextLink;
                }
                $out2 .= "</td></tr></table><hr />";
@@ -345,9 +371,9 @@ function showChunk( $namespace = NS_MAIN, $from, $including = false ) {
                $wgOut->addHTML( '</p>' );
 
        }
-       
+
 }
-       
+
 /**
  * @param int $ns the namespace of the article
  * @param string $text the name of the article
@@ -376,5 +402,3 @@ function getNamespaceKeyAndText ($ns, $text) {
        }
 }
 }
-
-?>