Fix 2714 : backlink from special:whatlinkshere was hard set as 'existing'
[lhc/web/wiklou.git] / includes / QueryPage.php
index 3b34359..9488751 100644 (file)
@@ -16,28 +16,38 @@ 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( 'DeadendPagesPage',          'Deadendpages'      ),
-    array( 'DisambiguationsPage',       'Disambiguations'   ),
-    array( 'DoubleRedirectsPage',       'DoubleRedirects'   ),
-    array( 'ListUsersPage',             'Listusers'         ),
-    array( 'LonelyPagesPage',           'Lonelypages'       ),
-    array( 'LongPagesPage',             'Longpages'         ),
-    array( 'NewPagesPage',              'Newpages'          ),
-    array( 'ShortPagesPage',            'Shortpages'        ),
-    array( 'UncategorizedCategoriesPage','Uncategorizedcategories'),
-    array( 'UncategorizedPagesPage',    'Uncategorizedpages'),
-    array( 'UnusedimagesPage',          'Unusedimages'      ),
-    array( 'WantedPagesPage',           'Wantedpages'       ),
-    array( 'MostlinkedPage',           'Mostlinked'        ),
+       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'                   ),
 );
 wfRunHooks( 'wgQueryPages', array( &$wgQueryPages ) );
 
 global $wgDisableCounters;
-if( !$wgDisableCounters ) {
-       $wgQueryPages[] = array( 'PopularPagesPage',          'Popularpages'      );
-}
+if ( !$wgDisableCounters )
+       $wgQueryPages[] = array( 'PopularPagesPage',            'Popularpages'          );
+global $wgEnableUnwatchedpages;
+if ( $wgEnableUnwatchedpages )
+       $wgQueryPages[] = array( 'UnwatchedPagesPage',          'Unwatchedpages'        );
+
 
 /**
  * This is a class for doing query pages; since they're almost all the same,
@@ -47,6 +57,21 @@ if( !$wgDisableCounters ) {
  * @package MediaWiki
  */
 class QueryPage {
+       /**
+        * Whether or not we want plain listoutput rather than an ordered list
+        *
+        * @var bool
+        */
+       var $listoutput = false;
+
+       /**
+        * A mutator for $this->listoutput;
+        *
+        * @param bool $bool
+        */
+       function setListoutput( $bool ) {
+               $this->listoutput = $bool;
+       }
 
        /**
         * Subclasses return their name here. Make sure the name is also
@@ -232,13 +257,12 @@ class QueryPage {
         * @param $shownavigation show navigation like "next 200"?
         */
        function doQuery( $offset, $limit, $shownavigation=true ) {
-               global $wgUser, $wgOut, $wgLang, $wgRequest, $wgContLang;
+               global $wgUser, $wgOut, $wgContLang;
                
                $sname = $this->getName();
                $fname = get_class($this) . '::doQuery';
                $sql = $this->getSQL();
                $dbr =& wfGetDB( DB_SLAVE );
-               $dbw =& wfGetDB( DB_MASTER );
                $querycache = $dbr->tableName( 'querycache' );
 
                $wgOut->setSyndicated( $this->isSyndicated() );
@@ -248,7 +272,8 @@ class QueryPage {
                        $sql =
                                "SELECT qc_type as type, qc_namespace as namespace,qc_title as title, qc_value as value
                                 FROM $querycache WHERE qc_type='$type'";
-                       $wgOut->addWikiText( wfMsg( 'perfcached' ) );
+                       if ( ! $this->listoutput )
+                               $wgOut->addWikiText( wfMsg( 'perfcached' ) );
                }
 
                $sql .= $this->getOrder();
@@ -266,7 +291,7 @@ class QueryPage {
                        $wgOut->addHTML( "<p>{$top}\n" );
 
                        # often disable 'next' link when we reach the end
-                       if($num < $limit) { $atend = true; } else { $atend = false; }
+                       $atend = $num < $limit;
 
                        $sl = wfViewPrevNext( $offset, $limit ,
                                $wgContLang->specialPage( $sname ),
@@ -274,7 +299,9 @@ class QueryPage {
                        $wgOut->addHTML( "<br />{$sl}</p>\n" );
                }
                if ( $num > 0 ) {
-                       $s = "<ol start='" . ( $offset + 1 ) . "' class='special'>";
+                       $s = array();
+                       if ( ! $this->listoutput )
+                               $s[] = "<ol start='" . ( $offset + 1 ) . "' class='special'>";
 
                        # Only read at most $num rows, because $res may contain the whole 1000
                        for ( $i = 0; $i < $num && $obj = $dbr->fetchObject( $res ); $i++ ) {
@@ -282,7 +309,7 @@ class QueryPage {
                                if ( $format ) {
                                        $attr = ( isset ( $obj->usepatrol ) && $obj->usepatrol &&
                                                                                $obj->patrolled == 0 ) ? ' class="not-patrolled"' : '';
-                                       $s .= "<li{$attr}>{$format}</li>\n";
+                                       $s[] = $this->listoutput ? $format : "<li{$attr}>{$format}</li>\n";
                                }
                        }
 
@@ -293,13 +320,15 @@ class QueryPage {
                                if( $format ) {
                                        $attr = ( isset ( $obj->usepatrol ) && $obj->usepatrol &&
                                                                                $obj->patrolled == 0 ) ? ' class="not-patrolled"' : '';
-                                       $s .= "<li{$attr}>{$format}</li>\n";
+                                       $s[] = "<li{$attr}>{$format}</li>\n";
                                }
                        }
 
                        $dbr->freeResult( $res );
-                       $s .= '</ol>';
-                       $wgOut->addHTML( $s );
+                       if ( ! $this->listoutput )
+                               $s[] = '</ol>';
+                       $str = $this->listoutput ? $wgContLang->listToText( $s ) : implode( '', $s );
+                       $wgOut->addHTML( $str );
                }
                if($shownavigation) {
                        $wgOut->addHTML( "<p>{$sl}</p>\n" );
@@ -308,9 +337,10 @@ class QueryPage {
        }
 
        /**
-        * Do any necessary preprocessing of the result object
+        * Do any necessary preprocessing of the result object.
+        * You should pass this by reference: &$db , &$res
         */
-       function preprocessResults( &$db, &$res ) {}
+       function preprocessResults( $db, $res ) {}
 
        /**
         * Similar to above, but packaging in a syndicated feed instead of a web page