/**
*
*/
-require_once ( 'Feed.php' );
+require_once 'Feed.php';
/**
* List of query page classes and their associated special pages, for periodic update purposes
*/
+global $wgQueryPages; // not redundant
$wgQueryPages = array(
-// QueryPage subclass Special page name
-//------------------------------------------------------------
- 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' ),
+// 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( 'UnwatchedPagesPage', 'Unwatchedpages' ),
);
-
+wfRunHooks( 'wgQueryPages', array( &$wgQueryPages ) );
+
global $wgDisableCounters;
-if( !$wgDisableCounters ) {
- $wgQueryPages[] = array( 'PopularPagesPage', 'Popularpages' );
-}
+if ( !$wgDisableCounters )
+ $wgQueryPages[] = array( 'PopularPagesPage', 'Popularpages' );
+
/**
* This is a class for doing query pages; since they're almost all the same,
* @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
return $wgDisableQueryPages;
}
+ /**
+ * Whether or not the output of the page in question is retrived from
+ * the database cache.
+ *
+ * @return bool
+ */
+ function isCached() {
+ global $wgMiserMode;
+
+ return $this->isExpensive() && $wgMiserMode;
+ }
+
/**
* Sometime we dont want to build rss / atom feeds.
*/
/**
* Clear the cache and save new results
*/
- function recache( $ignoreErrors = true ) {
+ 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->delete( 'querycache', array( 'qc_type' => $this->getName() ), $fname );
# Do query
$sql = $this->getSQL() . $this->getOrder();
- $sql = $dbr->limitResult($sql, 1000,0);
+ if ($limit !== false)
+ $sql = $dbr->limitResult($sql, $limit, 0);
$res = $dbr->query($sql, $fname);
$num = false;
if ( $res ) {
* @param $shownavigation show navigation like "next 200"?
*/
function doQuery( $offset, $limit, $shownavigation=true ) {
- global $wgUser, $wgOut, $wgLang, $wgRequest, $wgContLang;
- global $wgMiserMode;
+ 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() );
- if ( $this->isExpensive() ) {
- // Disabled recache parameter due to retry problems -- TS
- if( $wgMiserMode ) {
- $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->isCached() ) {
+ $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' ) );
- }
}
$sql .= $this->getOrder();
$res = $dbr->query( $sql );
$num = $dbr->numRows($res);
+ $this->preprocessResults( $dbr, $res );
+
$sk = $wgUser->getSkin( );
if($shownavigation) {
$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 ),
$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++ ) {
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";
}
}
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" );
return $num;
}
+ /**
+ * Do any necessary preprocessing of the result object.
+ * You should pass this by reference: &$db , &$res
+ */
+ function preprocessResults( $db, $res ) {}
+
/**
* Similar to above, but packaging in a syndicated feed instead of a web page
*/
function doFeed( $class = '' ) {
global $wgFeedClasses;
- global $wgOut, $wgLanguageCode, $wgLang;
+
if( isset($wgFeedClasses[$class]) ) {
$feed = new $wgFeedClasses[$class](
$this->feedTitle(),
$feed->outHeader();
$dbr =& wfGetDB( DB_SLAVE );
- $sql = $this->getSQL() . $this->getOrder()
+ $sql = $this->getSQL() . $this->getOrder();
$sql = $dbr->limitResult( $sql, 50, 0 );
$res = $dbr->query( $sql, 'QueryPage::doFeed' );
while( $obj = $dbr->fetchObject( $res ) ) {
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;
- } else {
- $date = '';
- }
-
+ $date = isset( $row->timestamp ) ? $row->timestamp : '';
$comments = '';
if( $title ) {
$talkpage = $title->getTalkPage();
}
function feedItemDesc( $row ) {
- return isset( $row->comment )
- ? htmlspecialchars( $row->comment )
- : '';
+ return isset( $row->comment ) ? htmlspecialchars( $row->comment ) : '';
}
function feedItemAuthor( $row ) {
- if( isset( $row->user_text ) ) {
- return $row->user_text;
- } else {
- return '';
- }
+ return isset( $row->user_text ) ? $row->user_text : '';
}
function feedTitle() {
- global $wgLanguageCode, $wgSitename, $wgLang;
+ global $wgLanguageCode, $wgSitename;
$page = SpecialPage::getPage( $this->getName() );
$desc = $page->getDescription();
return "$wgSitename - $desc [$wgLanguageCode]";
}
function feedUrl() {
- global $wgLang;
$title = Title::MakeTitle( NS_SPECIAL, $this->getName() );
return $title->getFullURL();
}
function formatResult( $skin, $result ) {
global $wgContLang;
$nt = Title::makeTitle( $result->namespace, $result->title );
- return $skin->makeKnownLinkObj( $nt, $wgContLang->convert( $nt->getPrefixedText() ) );
+ return $skin->makeKnownLinkObj( $nt, htmlspecialchars( $wgContLang->convert( $nt->getPrefixedText() ) ) );
}
}