* using htmlspecialchars() for safe XHTML output
[lhc/web/wiklou.git] / includes / QueryPage.php
index 8c6e110..4616d59 100644 (file)
@@ -20,7 +20,7 @@ $wgQueryPages = array(
     array( 'DeadendPagesPage',          'Deadendpages'      ),
     array( 'DisambiguationsPage',       'Disambiguations'   ),
     array( 'DoubleRedirectsPage',       'DoubleRedirects'   ),
-    array( 'ListUsersPage',             'Listusers'         ), 
+    array( 'ListUsersPage',             'Listusers'         ),
     array( 'LonelyPagesPage',           'Lonelypages'       ),
     array( 'LongPagesPage',             'Longpages'         ),
     array( 'NewPagesPage',              'Newpages'          ),
@@ -29,6 +29,7 @@ $wgQueryPages = array(
     array( 'UncategorizedPagesPage',    'Uncategorizedpages'),
     array( 'UnusedimagesPage',          'Unusedimages'      ),
     array( 'WantedPagesPage',           'Wantedpages'       ),
+    array( 'MostlinkedPage',           'Mostlinked'        ),
 );
     
 global $wgDisableCounters;
@@ -118,7 +119,7 @@ class QueryPage {
        function getPageHeader( ) {
                return '';
        }
-       
+
        /**
         * If using extra form wheely-dealies, return a set of parameters here
         * as an associative array. They will be encoded and added to the paging
@@ -128,7 +129,7 @@ class QueryPage {
        function linkParameters() {
                return array();
        }
-       
+
        /**
         * Some special pages (for example SpecialListusers) might not return the
         * current object formatted, but return the previous one instead.
@@ -151,7 +152,7 @@ class QueryPage {
                }
 
                $querycache = $dbr->tableName( 'querycache' );
-               
+
                if ( $ignoreErrors ) {
                        $ignoreW = $dbw->ignoreErrors( true );
                        $ignoreR = $dbr->ignoreErrors( true );
@@ -160,7 +161,9 @@ class QueryPage {
                # Clear out any old cached data
                $dbw->delete( 'querycache', array( 'qc_type' => $this->getName() ), $fname );
                # Do query
-               $res = $dbr->query( $this->getSQL() . $this->getOrder() . $dbr->limitResult( 1000,0 ), $fname );
+               $sql = $this->getSQL() . $this->getOrder();
+               $sql = $dbr->limitResult($sql, 1000,0);
+               $res = $dbr->query($sql, $fname);
                $num = false;
                if ( $res ) {
                        $num = $dbr->numRows( $res );
@@ -236,21 +239,24 @@ class QueryPage {
                                $wgOut->addWikiText( wfMsg( 'perfcached' ) );
                        }
                }
-               
-               $res = $dbr->query( $sql . $this->getOrder() .
-                                   $dbr->limitResult( $limit,$offset ), $fname );
+
+               $sql .= $this->getOrder();
+               $sql = $dbr->limitResult($sql, $limit, $offset);
+               $res = $dbr->query( $sql );
                $num = $dbr->numRows($res);
-               
+
+               $this->preprocessResults( $dbr, $res );
+
                $sk = $wgUser->getSkin( );
 
                if($shownavigation) {
                        $wgOut->addHTML( $this->getPageHeader() );
                        $top = wfShowingResults( $offset, $num);
                        $wgOut->addHTML( "<p>{$top}\n" );
-       
+
                        # often disable 'next' link when we reach the end
                        if($num < $limit) { $atend = true; } else { $atend = false; }
-                       
+
                        $sl = wfViewPrevNext( $offset, $limit ,
                                $wgContLang->specialPage( $sname ),
                                wfArrayToCGI( $this->linkParameters() ), $atend );
@@ -279,7 +285,7 @@ class QueryPage {
                                        $s .= "<li{$attr}>{$format}</li>\n";
                                }
                        }
-                       
+
                        $dbr->freeResult( $res );
                        $s .= '</ol>';
                        $wgOut->addHTML( $s );
@@ -290,6 +296,11 @@ class QueryPage {
                return $num;
        }
 
+       /**
+        * Do any necessary preprocessing of the result object
+        */
+       function preprocessResults( &$db, &$res ) {}
+
        /**
         * Similar to above, but packaging in a syndicated feed instead of a web page
         */
@@ -304,7 +315,8 @@ class QueryPage {
                        $feed->outHeader();
 
                        $dbr =& wfGetDB( DB_SLAVE );
-                       $sql = $this->getSQL() . $this->getOrder().$dbr->limitResult( 50, 0 );
+                       $sql = $this->getSQL() . $this->getOrder();
+                       $sql = $dbr->limitResult( $sql, 50, 0 );
                        $res = $dbr->query( $sql, 'QueryPage::doFeed' );
                        while( $obj = $dbr->fetchObject( $res ) ) {
                                $item = $this->feedResult( $obj );
@@ -327,7 +339,7 @@ class QueryPage {
                if( !isset( $row->title ) ) {
                        return NULL;
                }
-               $title = Title::MakeTitle( IntVal( $row->namespace ), $row->title );
+               $title = Title::MakeTitle( intval( $row->namespace ), $row->title );
                if( $title ) {
                        if( isset( $row->timestamp ) ) {
                                $date = $row->timestamp;