PHPDocumentor [http://en.wikipedia.org/wiki/PhpDocumentor] documentation tweaking...
[lhc/web/wiklou.git] / includes / QueryPage.php
index 05de61e..d386d12 100644 (file)
@@ -1,52 +1,49 @@
 <?php
 /**
  * Contain a class for special pages
- * @package MediaWiki
  */
 
 /**
+ * List of query page classes and their associated special pages, 
+ * for periodic updates.
  *
- */
-require_once 'Feed.php';
-
-/**
- * List of query page classes and their associated special pages, for periodic update purposes
+ * DO NOT CHANGE THIS LIST without testing that 
+ * maintenance/updateSpecialPages.php still works.
  */
 global $wgQueryPages; // not redundant
 $wgQueryPages = array(
 //         QueryPage subclass           Special page name         Limit (false for none, none for the default)
 //----------------------------------------------------------------------------
-       array( 'AncientPagesPage',              'Ancientpages'                  ),
-       array( 'BrokenRedirectsPage',           'BrokenRedirects'               ),
-       array( 'CategoriesPage',                'Categories'                    ),
-       array( 'DeadendPagesPage',              'Deadendpages'                  ),
-       array( 'DisambiguationsPage',           'Disambiguations'               ),
-       array( 'DoubleRedirectsPage',           'DoubleRedirects'               ),
-       array( 'ListUsersPage',                 'Listusers'                     ),
-       array( 'LonelyPagesPage',               'Lonelypages'                   ),
-       array( 'LongPagesPage',                 'Longpages'                     ),
-       array( 'MostcategoriesPage',            'Mostcategories'                ),
-       array( 'MostimagesPage',                'Mostimages'                    ),
-       array( 'MostlinkedCategoriesPage',      'Mostlinkedcategories'          ),
-       array( 'MostlinkedPage',                'Mostlinked'                    ),
-       array( 'MostrevisionsPage',             'Mostrevisions'                 ),
-       array( 'NewPagesPage',                  'Newpages'                      ),
-       array( 'ShortPagesPage',                'Shortpages'                    ),
-       array( 'UncategorizedCategoriesPage',   'Uncategorizedcategories'       ),
-       array( 'UncategorizedPagesPage',        'Uncategorizedpages'            ),
-       array( 'UnusedCategoriesPage',          'Unusedcategories'              ),
-       array( 'UnusedimagesPage',              'Unusedimages'                  ),
-       array( 'WantedCategoriesPage',          'Wantedcategories'              ),
-       array( 'WantedPagesPage',               'Wantedpages'                   ),
+       array( 'AncientPagesPage',              'Ancientpages'                  ),
+       array( 'BrokenRedirectsPage',           'BrokenRedirects'               ),
+       array( 'DeadendPagesPage',              'Deadendpages'                  ),
+       array( 'DisambiguationsPage',           'Disambiguations'               ),
+       array( 'DoubleRedirectsPage',           'DoubleRedirects'               ),
+       array( 'ListredirectsPage',             'Listredirects' ),
+       array( 'LonelyPagesPage',               'Lonelypages'                   ),
+       array( 'LongPagesPage',                 'Longpages'                     ),
+       array( 'MostcategoriesPage',            'Mostcategories'                ),
+       array( 'MostimagesPage',                'Mostimages'                    ),
+       array( 'MostlinkedCategoriesPage',      'Mostlinkedcategories'          ),
+       array( 'MostlinkedPage',                'Mostlinked'                    ),
+       array( 'MostrevisionsPage',             'Mostrevisions'                 ),
+       array( 'NewPagesPage',                  'Newpages'                      ),
+       array( 'ShortPagesPage',                'Shortpages'                    ),
+       array( 'UncategorizedCategoriesPage',   'Uncategorizedcategories'       ),
+       array( 'UncategorizedPagesPage',        'Uncategorizedpages'            ),
+       array( 'UncategorizedImagesPage',       'Uncategorizedimages' ),
+       array( 'UnusedCategoriesPage',          'Unusedcategories'              ),
+       array( 'UnusedimagesPage',              'Unusedimages'                  ),
+       array( 'WantedCategoriesPage',          'Wantedcategories'              ),
+       array( 'WantedPagesPage',               'Wantedpages'                   ),
+       array( 'UnwatchedPagesPage',            'Unwatchedpages'                ),
+       array( 'UnusedtemplatesPage',           'Unusedtemplates' ),
 );
 wfRunHooks( 'wgQueryPages', array( &$wgQueryPages ) );
 
 global $wgDisableCounters;
 if ( !$wgDisableCounters )
        $wgQueryPages[] = array( 'PopularPagesPage',            'Popularpages'          );
-global $wgEnableUnwatchedpages;
-if ( $wgEnableUnwatchedpages )
-       $wgQueryPages[] = array( 'UnwatchedPagesPage',          'Unwatchedpages'        );
 
 
 /**
@@ -54,7 +51,6 @@ if ( $wgEnableUnwatchedpages )
  * we factor out some of the functionality into a superclass, and let
  * subclasses derive from it.
  *
- * @package MediaWiki
  */
 class QueryPage {
        /**
@@ -64,6 +60,14 @@ class QueryPage {
         */
        var $listoutput = false;
 
+       /**
+        * The offset and limit in use, as passed to the query() function
+        *
+        * @var integer
+        */
+       var $offset = 0;
+       var $limit = 0;
+
        /**
         * A mutator for $this->listoutput;
         *
@@ -82,6 +86,15 @@ class QueryPage {
                return '';
        }
 
+       /**
+        * Return title object representing this page
+        *
+        * @return Title
+        */
+       function getTitle() {
+               return SpecialPage::getTitleFor( $this->getName() );
+       }
+
        /**
         * Subclasses return an SQL query here.
         *
@@ -131,7 +144,7 @@ class QueryPage {
         */
        function isCached() {
                global $wgMiserMode;
-               
+
                return $this->isExpensive() && $wgMiserMode;
        }
 
@@ -184,8 +197,8 @@ class QueryPage {
         */
        function recache( $limit, $ignoreErrors = true ) {
                $fname = get_class($this) . '::recache';
-               $dbw =& wfGetDB( DB_MASTER );
-               $dbr =& wfGetDB( DB_SLAVE, array( $this->getName(), 'QueryPage::recache', 'vslow' ) );
+               $dbw = wfGetDB( DB_MASTER );
+               $dbr = wfGetDB( DB_SLAVE, array( $this->getName(), 'QueryPage::recache', 'vslow' ) );
                if ( !$dbw || !$dbr ) {
                        return false;
                }
@@ -244,6 +257,11 @@ class QueryPage {
                                $dbw->ignoreErrors( $ignoreW );
                                $dbr->ignoreErrors( $ignoreR );
                        }
+
+                       # Update the querycache_info record for the page
+                       $dbw->delete( 'querycache_info', array( 'qci_type' => $this->getName() ), $fname );
+                       $dbw->insert( 'querycache_info', array( 'qci_type' => $this->getName(), 'qci_timestamp' => $dbw->timestamp() ), $fname );
+
                }
                return $num;
        }
@@ -257,24 +275,53 @@ class QueryPage {
         * @param $shownavigation show navigation like "next 200"?
         */
        function doQuery( $offset, $limit, $shownavigation=true ) {
-               global $wgUser, $wgOut, $wgLang, $wgRequest, $wgContLang;
-               
+               global $wgUser, $wgOut, $wgLang, $wgContLang;
+
+               $this->offset = $offset;
+               $this->limit = $limit;
+
                $sname = $this->getName();
                $fname = get_class($this) . '::doQuery';
-               $sql = $this->getSQL();
-               $dbr =& wfGetDB( DB_SLAVE );
-               $dbw =& wfGetDB( DB_MASTER );
-               $querycache = $dbr->tableName( 'querycache' );
+               $dbr = wfGetDB( DB_SLAVE );
 
                $wgOut->setSyndicated( $this->isSyndicated() );
 
-               if ( $this->isCached() ) {
+               if ( !$this->isCached() ) {
+                       $sql = $this->getSQL();
+               } else {
+                       # Get the cached result
+                       $querycache = $dbr->tableName( 'querycache' );
                        $type = $dbr->strencode( $sname );
                        $sql =
                                "SELECT qc_type as type, qc_namespace as namespace,qc_title as title, qc_value as value
                                 FROM $querycache WHERE qc_type='$type'";
-                       if ( ! $this->listoutput )
-                               $wgOut->addWikiText( wfMsg( 'perfcached' ) );
+
+                       if( !$this->listoutput ) {
+
+                               # Fetch the timestamp of this update
+                               $tRes = $dbr->select( 'querycache_info', array( 'qci_timestamp' ), array( 'qci_type' => $type ), $fname );
+                               $tRow = $dbr->fetchObject( $tRes );
+                               
+                               if( $tRow ) {
+                                       $updated = $wgLang->timeAndDate( $tRow->qci_timestamp, true, true );
+                                       $cacheNotice = wfMsg( 'perfcachedts', $updated );
+                                       $wgOut->addMeta( 'Data-Cache-Time', $tRow->qci_timestamp );
+                                       $wgOut->addScript( '<script language="JavaScript">var dataCacheTime = \'' . $tRow->qci_timestamp . '\';</script>' );
+                               } else {
+                                       $cacheNotice = wfMsg( 'perfcached' );
+                               }
+       
+                               $wgOut->addWikiText( $cacheNotice );
+                               
+                               # If updates on this page have been disabled, let the user know
+                               # that the data set won't be refreshed for now
+                               global $wgDisableQueryPageUpdate;
+                               if( is_array( $wgDisableQueryPageUpdate ) && in_array( $this->getName(), $wgDisableQueryPageUpdate ) ) {
+                                       $wgOut->addWikiText( wfMsg( 'querypage-no-updates' ) );
+                               }
+                               
+                       }
+
                }
 
                $sql .= $this->getOrder();
@@ -288,6 +335,13 @@ class QueryPage {
 
                if($shownavigation) {
                        $wgOut->addHTML( $this->getPageHeader() );
+
+                       # if list is empty, show it
+                       if( $num == 0 ) {
+                               $wgOut->addHTML( '<p>' . wfMsgHTML('specialpage-empty') . '</p>' );
+                               return;
+                       }
+
                        $top = wfShowingResults( $offset, $num);
                        $wgOut->addHTML( "<p>{$top}\n" );
 
@@ -302,7 +356,7 @@ class QueryPage {
                if ( $num > 0 ) {
                        $s = array();
                        if ( ! $this->listoutput )
-                               $s[] = "<ol start='" . ( $offset + 1 ) . "' class='special'>";
+                               $s[] = $this->openList( $offset );
 
                        # Only read at most $num rows, because $res may contain the whole 1000
                        for ( $i = 0; $i < $num && $obj = $dbr->fetchObject( $res ); $i++ ) {
@@ -327,7 +381,7 @@ class QueryPage {
 
                        $dbr->freeResult( $res );
                        if ( ! $this->listoutput )
-                               $s[] = '</ol>';
+                               $s[] = $this->closeList();
                        $str = $this->listoutput ? $wgContLang->listToText( $s ) : implode( '', $s );
                        $wgOut->addHTML( $str );
                }
@@ -336,18 +390,27 @@ class QueryPage {
                }
                return $num;
        }
+       
+       function openList( $offset ) {
+               return "<ol start='" . ( $offset + 1 ) . "' class='special'>";
+       }
+       
+       function closeList() {
+               return '</ol>';
+       }
 
        /**
-        * Do any necessary preprocessing of the result object
+        * Do any necessary preprocessing of the result object.
+        * You should pass this by reference: &$db , &$res  [although probably no longer necessary in PHP5]
         */
        function preprocessResults( &$db, &$res ) {}
 
        /**
         * Similar to above, but packaging in a syndicated feed instead of a web page
         */
-       function doFeed( $class = '' ) {
+       function doFeed( $class = '', $limit = 50 ) {
                global $wgFeedClasses;
-               
+
                if( isset($wgFeedClasses[$class]) ) {
                        $feed = new $wgFeedClasses[$class](
                                $this->feedTitle(),
@@ -355,9 +418,9 @@ class QueryPage {
                                $this->feedUrl() );
                        $feed->outHeader();
 
-                       $dbr =& wfGetDB( DB_SLAVE );
+                       $dbr = wfGetDB( DB_SLAVE );
                        $sql = $this->getSQL() . $this->getOrder();
-                       $sql = $dbr->limitResult( $sql, 50, 0 );
+                       $sql = $dbr->limitResult( $sql, $limit, 0 );
                        $res = $dbr->query( $sql, 'QueryPage::doFeed' );
                        while( $obj = $dbr->fetchObject( $res ) ) {
                                $item = $this->feedResult( $obj );
@@ -410,10 +473,10 @@ class QueryPage {
        }
 
        function feedTitle() {
-               global $wgLanguageCode, $wgSitename;
+               global $wgContLanguageCode, $wgSitename;
                $page = SpecialPage::getPage( $this->getName() );
                $desc = $page->getDescription();
-               return "$wgSitename - $desc [$wgLanguageCode]";
+               return "$wgSitename - $desc [$wgContLanguageCode]";
        }
 
        function feedDesc() {
@@ -421,7 +484,7 @@ class QueryPage {
        }
 
        function feedUrl() {
-               $title = Title::MakeTitle( NS_SPECIAL, $this->getName() );
+               $title = SpecialPage::getTitleFor( $this->getName() );
                return $title->getFullURL();
        }
 }
@@ -431,7 +494,6 @@ class QueryPage {
  * titles that match some criteria. It formats each result item as a link to
  * that page.
  *
- * @package MediaWiki
  */
 class PageQueryPage extends QueryPage {