2004-02-18 02:15:00 +00:00
|
|
|
<?php
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
|
|
|
|
* Contain a class for special pages
|
2004-09-03 23:00:01 +00:00
|
|
|
* @package MediaWiki
|
2004-09-02 23:28:24 +00:00
|
|
|
*/
|
I was adding a special page (dead-end pages), and I realized that almost all
the special query pages were pretty much identical. I copy-and-pasted one to
make the one I was working on, and I realized that that was Wrong.
So, I took the common elements and made them into a class, QueryPage.php.
Then, I derived each of the existing special pages from QueryPage, and
overrode places where they differed. This is a Recipe pattern, btw, for
those of you following along at home.
Anyways, the upshot is that the query pages are a lot shorter, with just the
essentials that make them different from other query pages, and there's one
place to make big UI changes for all queries.
2003-12-01 16:04:35 +00:00
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
*/
|
2004-08-15 19:12:17 +00:00
|
|
|
require_once ( 'Feed.php' );
|
I was adding a special page (dead-end pages), and I realized that almost all
the special query pages were pretty much identical. I copy-and-pasted one to
make the one I was working on, and I realized that that was Wrong.
So, I took the common elements and made them into a class, QueryPage.php.
Then, I derived each of the existing special pages from QueryPage, and
overrode places where they differed. This is a Recipe pattern, btw, for
those of you following along at home.
Anyways, the upshot is that the query pages are a lot shorter, with just the
essentials that make them different from other query pages, and there's one
place to make big UI changes for all queries.
2003-12-01 16:04:35 +00:00
|
|
|
|
2005-04-24 04:16:50 +00:00
|
|
|
/**
|
|
|
|
|
* List of query page classes and their associated special pages, for periodic update purposes
|
|
|
|
|
*/
|
|
|
|
|
$wgQueryPages = array(
|
|
|
|
|
// QueryPage subclass Special page name
|
|
|
|
|
//------------------------------------------------------------
|
|
|
|
|
array( 'AncientPagesPage', 'Ancientpages' ),
|
|
|
|
|
array( 'BrokenRedirectsPage', 'BrokenRedirects' ),
|
|
|
|
|
array( 'DeadendPagesPage', 'Deadendpages' ),
|
|
|
|
|
array( 'DisambiguationsPage', 'Disambiguations' ),
|
|
|
|
|
array( 'DoubleRedirectsPage', 'DoubleRedirects' ),
|
2005-08-02 13:35:19 +00:00
|
|
|
array( 'ListUsersPage', 'Listusers' ),
|
2005-04-24 04:16:50 +00:00
|
|
|
array( 'LonelyPagesPage', 'Lonelypages' ),
|
|
|
|
|
array( 'LongPagesPage', 'Longpages' ),
|
|
|
|
|
array( 'NewPagesPage', 'Newpages' ),
|
|
|
|
|
array( 'ShortPagesPage', 'Shortpages' ),
|
|
|
|
|
array( 'UncategorizedCategoriesPage','Uncategorizedcategories'),
|
|
|
|
|
array( 'UncategorizedPagesPage', 'Uncategorizedpages'),
|
|
|
|
|
array( 'UnusedimagesPage', 'Unusedimages' ),
|
|
|
|
|
array( 'WantedPagesPage', 'Wantedpages' ),
|
2005-08-15 02:57:19 +00:00
|
|
|
array( 'MostlinkedPage', 'Mostlinked' ),
|
2005-04-24 04:16:50 +00:00
|
|
|
);
|
|
|
|
|
|
2005-07-15 23:56:58 +00:00
|
|
|
global $wgDisableCounters;
|
|
|
|
|
if( !$wgDisableCounters ) {
|
|
|
|
|
$wgQueryPages[] = array( 'PopularPagesPage', 'Popularpages' );
|
|
|
|
|
}
|
2005-04-24 04:16:50 +00:00
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
|
|
|
|
* This is a class for doing query pages; since they're almost all the same,
|
|
|
|
|
* we factor out some of the functionality into a superclass, and let
|
|
|
|
|
* subclasses derive from it.
|
|
|
|
|
*
|
2004-09-03 23:00:01 +00:00
|
|
|
* @package MediaWiki
|
2004-09-02 23:28:24 +00:00
|
|
|
*/
|
I was adding a special page (dead-end pages), and I realized that almost all
the special query pages were pretty much identical. I copy-and-pasted one to
make the one I was working on, and I realized that that was Wrong.
So, I took the common elements and made them into a class, QueryPage.php.
Then, I derived each of the existing special pages from QueryPage, and
overrode places where they differed. This is a Recipe pattern, btw, for
those of you following along at home.
Anyways, the upshot is that the query pages are a lot shorter, with just the
essentials that make them different from other query pages, and there's one
place to make big UI changes for all queries.
2003-12-01 16:04:35 +00:00
|
|
|
class QueryPage {
|
2004-09-03 21:22:20 +00:00
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
|
|
|
|
* Subclasses return their name here. Make sure the name is also
|
|
|
|
|
* specified in SpecialPage.php and in Language.php as a language message
|
|
|
|
|
* param.
|
|
|
|
|
*/
|
2004-01-25 02:27:49 +00:00
|
|
|
function getName() {
|
2004-08-15 19:12:17 +00:00
|
|
|
return '';
|
I was adding a special page (dead-end pages), and I realized that almost all
the special query pages were pretty much identical. I copy-and-pasted one to
make the one I was working on, and I realized that that was Wrong.
So, I took the common elements and made them into a class, QueryPage.php.
Then, I derived each of the existing special pages from QueryPage, and
overrode places where they differed. This is a Recipe pattern, btw, for
those of you following along at home.
Anyways, the upshot is that the query pages are a lot shorter, with just the
essentials that make them different from other query pages, and there's one
place to make big UI changes for all queries.
2003-12-01 16:04:35 +00:00
|
|
|
}
|
|
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
|
|
|
|
* Subclasses return an SQL query here.
|
2004-09-03 21:22:20 +00:00
|
|
|
*
|
2004-09-02 23:28:24 +00:00
|
|
|
* Note that the query itself should return the following four columns:
|
|
|
|
|
* 'type' (your special page's name), 'namespace', 'title', and 'value'
|
|
|
|
|
* *in that order*. 'value' is used for sorting.
|
|
|
|
|
*
|
|
|
|
|
* These may be stored in the querycache table for expensive queries,
|
|
|
|
|
* and that cached data will be returned sometimes, so the presence of
|
|
|
|
|
* extra fields can't be relied upon. The cached 'value' column will be
|
|
|
|
|
* an integer; non-numeric values are useful only for sorting the initial
|
|
|
|
|
* query.
|
|
|
|
|
*
|
|
|
|
|
* Don't include an ORDER or LIMIT clause, this will be added.
|
|
|
|
|
*/
|
2004-05-09 01:30:34 +00:00
|
|
|
function getSQL() {
|
|
|
|
|
return "SELECT 'sample' as type, 0 as namespace, 'Sample result' as title, 42 as value";
|
|
|
|
|
}
|
2004-08-09 05:38:11 +00:00
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
|
|
|
|
* Override to sort by increasing values
|
|
|
|
|
*/
|
2004-05-09 01:30:34 +00:00
|
|
|
function sortDescending() {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
I was adding a special page (dead-end pages), and I realized that almost all
the special query pages were pretty much identical. I copy-and-pasted one to
make the one I was working on, and I realized that that was Wrong.
So, I took the common elements and made them into a class, QueryPage.php.
Then, I derived each of the existing special pages from QueryPage, and
overrode places where they differed. This is a Recipe pattern, btw, for
those of you following along at home.
Anyways, the upshot is that the query pages are a lot shorter, with just the
essentials that make them different from other query pages, and there's one
place to make big UI changes for all queries.
2003-12-01 16:04:35 +00:00
|
|
|
|
2004-08-10 13:55:29 +00:00
|
|
|
function getOrder() {
|
2004-08-15 19:12:17 +00:00
|
|
|
return ' ORDER BY value ' .
|
|
|
|
|
($this->sortDescending() ? 'DESC' : '');
|
2004-08-10 13:55:29 +00:00
|
|
|
}
|
|
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
|
|
|
|
* Is this query expensive (for some definition of expensive)? Then we
|
|
|
|
|
* don't let it run in miser mode. $wgDisableQueryPages causes all query
|
|
|
|
|
* pages to be declared expensive. Some query pages are always expensive.
|
|
|
|
|
*/
|
2004-01-25 02:27:49 +00:00
|
|
|
function isExpensive( ) {
|
|
|
|
|
global $wgDisableQueryPages;
|
|
|
|
|
return $wgDisableQueryPages;
|
|
|
|
|
}
|
I was adding a special page (dead-end pages), and I realized that almost all
the special query pages were pretty much identical. I copy-and-pasted one to
make the one I was working on, and I realized that that was Wrong.
So, I took the common elements and made them into a class, QueryPage.php.
Then, I derived each of the existing special pages from QueryPage, and
overrode places where they differed. This is a Recipe pattern, btw, for
those of you following along at home.
Anyways, the upshot is that the query pages are a lot shorter, with just the
essentials that make them different from other query pages, and there's one
place to make big UI changes for all queries.
2003-12-01 16:04:35 +00:00
|
|
|
|
2004-11-13 20:33:37 +00:00
|
|
|
/**
|
|
|
|
|
* Sometime we dont want to build rss / atom feeds.
|
|
|
|
|
*/
|
|
|
|
|
function isSyndicated() {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
|
|
|
|
* Formats the results of the query for display. The skin is the current
|
|
|
|
|
* skin; you can use it for making links. The result is a single row of
|
|
|
|
|
* result data. You should be able to grab SQL results off of it.
|
2005-02-01 01:42:22 +00:00
|
|
|
* If the function return "false", the line output will be skipped.
|
2004-09-02 23:28:24 +00:00
|
|
|
*/
|
2004-01-25 02:27:49 +00:00
|
|
|
function formatResult( $skin, $result ) {
|
2004-08-15 19:12:17 +00:00
|
|
|
return '';
|
I was adding a special page (dead-end pages), and I realized that almost all
the special query pages were pretty much identical. I copy-and-pasted one to
make the one I was working on, and I realized that that was Wrong.
So, I took the common elements and made them into a class, QueryPage.php.
Then, I derived each of the existing special pages from QueryPage, and
overrode places where they differed. This is a Recipe pattern, btw, for
those of you following along at home.
Anyways, the upshot is that the query pages are a lot shorter, with just the
essentials that make them different from other query pages, and there's one
place to make big UI changes for all queries.
2003-12-01 16:04:35 +00:00
|
|
|
}
|
2004-09-03 21:22:20 +00:00
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
|
|
|
|
* The content returned by this function will be output before any result
|
2005-06-30 07:37:04 +00:00
|
|
|
*/
|
2004-08-15 19:22:40 +00:00
|
|
|
function getPageHeader( ) {
|
|
|
|
|
return '';
|
|
|
|
|
}
|
2005-08-02 13:35:19 +00:00
|
|
|
|
2005-06-30 07:37:04 +00:00
|
|
|
/**
|
|
|
|
|
* 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
|
|
|
|
|
* links (prev/next/lengths).
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
function linkParameters() {
|
|
|
|
|
return array();
|
|
|
|
|
}
|
2005-08-02 13:35:19 +00:00
|
|
|
|
2005-02-01 02:02:14 +00:00
|
|
|
/**
|
|
|
|
|
* Some special pages (for example SpecialListusers) might not return the
|
|
|
|
|
* current object formatted, but return the previous one instead.
|
|
|
|
|
* Setting this to return true, will call one more time wfFormatResult to
|
|
|
|
|
* be sure that the very last result is formatted and shown.
|
|
|
|
|
*/
|
|
|
|
|
function tryLastResult( ) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2004-08-09 05:38:11 +00:00
|
|
|
|
2005-04-24 08:31:12 +00:00
|
|
|
/**
|
|
|
|
|
* Clear the cache and save new results
|
|
|
|
|
*/
|
|
|
|
|
function recache( $ignoreErrors = true ) {
|
|
|
|
|
$fname = get_class($this) . '::recache';
|
|
|
|
|
$dbw =& wfGetDB( DB_MASTER );
|
|
|
|
|
$dbr =& wfGetDB( DB_SLAVE, array( $this->getName(), 'QueryPage::recache', 'vslow' ) );
|
|
|
|
|
if ( !$dbw || !$dbr ) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$querycache = $dbr->tableName( 'querycache' );
|
2005-08-02 13:35:19 +00:00
|
|
|
|
2005-04-24 08:31:12 +00:00
|
|
|
if ( $ignoreErrors ) {
|
|
|
|
|
$ignoreW = $dbw->ignoreErrors( true );
|
|
|
|
|
$ignoreR = $dbr->ignoreErrors( true );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Clear out any old cached data
|
|
|
|
|
$dbw->delete( 'querycache', array( 'qc_type' => $this->getName() ), $fname );
|
|
|
|
|
# Do query
|
2005-08-09 10:30:20 +00:00
|
|
|
$sql = $this->getSQL() . $this->getOrder();
|
|
|
|
|
$sql = $dbr->limitResult($sql, 1000,0);
|
|
|
|
|
$res = $dbr->query($sql, $fname);
|
2005-04-24 08:31:12 +00:00
|
|
|
$num = false;
|
|
|
|
|
if ( $res ) {
|
|
|
|
|
$num = $dbr->numRows( $res );
|
|
|
|
|
# Fetch results
|
|
|
|
|
$insertSql = "INSERT INTO $querycache (qc_type,qc_namespace,qc_title,qc_value) VALUES ";
|
|
|
|
|
$first = true;
|
|
|
|
|
while ( $res && $row = $dbr->fetchObject( $res ) ) {
|
|
|
|
|
if ( $first ) {
|
|
|
|
|
$first = false;
|
|
|
|
|
} else {
|
|
|
|
|
$insertSql .= ',';
|
|
|
|
|
}
|
|
|
|
|
if ( isset( $row->value ) ) {
|
|
|
|
|
$value = $row->value;
|
|
|
|
|
} else {
|
|
|
|
|
$value = '';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$insertSql .= '(' .
|
|
|
|
|
$dbw->addQuotes( $row->type ) . ',' .
|
|
|
|
|
$dbw->addQuotes( $row->namespace ) . ',' .
|
|
|
|
|
$dbw->addQuotes( $row->title ) . ',' .
|
|
|
|
|
$dbw->addQuotes( $value ) . ')';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Save results into the querycache table on the master
|
|
|
|
|
if ( !$first ) {
|
|
|
|
|
if ( !$dbw->query( $insertSql, $fname ) ) {
|
|
|
|
|
// Set result to false to indicate error
|
|
|
|
|
$dbr->freeResult( $res );
|
|
|
|
|
$res = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if ( $res ) {
|
|
|
|
|
$dbr->freeResult( $res );
|
|
|
|
|
}
|
|
|
|
|
if ( $ignoreErrors ) {
|
|
|
|
|
$dbw->ignoreErrors( $ignoreW );
|
|
|
|
|
$dbr->ignoreErrors( $ignoreR );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return $num;
|
|
|
|
|
}
|
|
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
|
|
|
|
* This is the actual workhorse. It does everything needed to make a
|
|
|
|
|
* real, honest-to-gosh query page.
|
|
|
|
|
*
|
|
|
|
|
* @param $offset database query offset
|
|
|
|
|
* @param $limit database query limit
|
2005-05-28 17:17:27 +00:00
|
|
|
* @param $shownavigation show navigation like "next 200"?
|
2004-09-02 23:28:24 +00:00
|
|
|
*/
|
2005-05-28 17:17:27 +00:00
|
|
|
function doQuery( $offset, $limit, $shownavigation=true ) {
|
2004-12-11 19:23:03 +00:00
|
|
|
global $wgUser, $wgOut, $wgLang, $wgRequest, $wgContLang;
|
2004-05-09 01:30:34 +00:00
|
|
|
global $wgMiserMode;
|
2004-01-25 02:27:49 +00:00
|
|
|
|
|
|
|
|
$sname = $this->getName();
|
2004-08-15 19:12:17 +00:00
|
|
|
$fname = get_class($this) . '::doQuery';
|
2004-07-10 03:09:26 +00:00
|
|
|
$sql = $this->getSQL();
|
2004-07-18 08:48:43 +00:00
|
|
|
$dbr =& wfGetDB( DB_SLAVE );
|
|
|
|
|
$dbw =& wfGetDB( DB_MASTER );
|
2004-07-10 03:09:26 +00:00
|
|
|
$querycache = $dbr->tableName( 'querycache' );
|
2004-01-25 02:27:49 +00:00
|
|
|
|
2004-11-13 20:33:37 +00:00
|
|
|
$wgOut->setSyndicated( $this->isSyndicated() );
|
2004-08-09 05:38:11 +00:00
|
|
|
|
2004-05-09 01:30:34 +00:00
|
|
|
if ( $this->isExpensive() ) {
|
2005-04-24 04:16:50 +00:00
|
|
|
// Disabled recache parameter due to retry problems -- TS
|
2005-04-24 08:31:12 +00:00
|
|
|
if( $wgMiserMode ) {
|
2004-07-31 22:10:29 +00:00
|
|
|
$type = $dbr->strencode( $sname );
|
2004-05-09 01:30:34 +00:00
|
|
|
$sql =
|
|
|
|
|
"SELECT qc_type as type, qc_namespace as namespace,qc_title as title, qc_value as value
|
2004-07-10 03:09:26 +00:00
|
|
|
FROM $querycache WHERE qc_type='$type'";
|
2004-08-22 17:24:50 +00:00
|
|
|
$wgOut->addWikiText( wfMsg( 'perfcached' ) );
|
2004-01-25 02:27:49 +00:00
|
|
|
}
|
|
|
|
|
}
|
2005-08-02 13:35:19 +00:00
|
|
|
|
2005-08-09 10:30:20 +00:00
|
|
|
$sql .= $this->getOrder();
|
|
|
|
|
$sql = $dbr->limitResult($sql, $limit, $offset);
|
2005-08-02 13:35:19 +00:00
|
|
|
$res = $dbr->query( $sql );
|
2005-06-23 18:25:00 +00:00
|
|
|
$num = $dbr->numRows($res);
|
2005-08-02 13:35:19 +00:00
|
|
|
|
2005-09-11 12:33:59 +00:00
|
|
|
$this->preprocessResults( $dbr, $res );
|
|
|
|
|
|
2004-01-25 02:27:49 +00:00
|
|
|
$sk = $wgUser->getSkin( );
|
2004-09-03 21:22:20 +00:00
|
|
|
|
2005-05-28 17:17:27 +00:00
|
|
|
if($shownavigation) {
|
|
|
|
|
$wgOut->addHTML( $this->getPageHeader() );
|
|
|
|
|
$top = wfShowingResults( $offset, $num);
|
|
|
|
|
$wgOut->addHTML( "<p>{$top}\n" );
|
2005-08-02 13:35:19 +00:00
|
|
|
|
2005-05-28 17:17:27 +00:00
|
|
|
# often disable 'next' link when we reach the end
|
|
|
|
|
if($num < $limit) { $atend = true; } else { $atend = false; }
|
2005-08-02 13:35:19 +00:00
|
|
|
|
2005-06-30 07:37:04 +00:00
|
|
|
$sl = wfViewPrevNext( $offset, $limit ,
|
|
|
|
|
$wgContLang->specialPage( $sname ),
|
|
|
|
|
wfArrayToCGI( $this->linkParameters() ), $atend );
|
2005-05-28 17:17:27 +00:00
|
|
|
$wgOut->addHTML( "<br />{$sl}</p>\n" );
|
|
|
|
|
}
|
2005-01-16 02:57:30 +00:00
|
|
|
if ( $num > 0 ) {
|
|
|
|
|
$s = "<ol start='" . ( $offset + 1 ) . "' class='special'>";
|
2005-02-01 02:02:14 +00:00
|
|
|
|
2005-01-16 02:57:30 +00:00
|
|
|
# Only read at most $num rows, because $res may contain the whole 1000
|
|
|
|
|
for ( $i = 0; $i < $num && $obj = $dbr->fetchObject( $res ); $i++ ) {
|
|
|
|
|
$format = $this->formatResult( $sk, $obj );
|
2005-02-01 01:41:30 +00:00
|
|
|
if ( $format ) {
|
|
|
|
|
$attr = ( isset ( $obj->usepatrol ) && $obj->usepatrol &&
|
|
|
|
|
$obj->patrolled == 0 ) ? ' class="not-patrolled"' : '';
|
|
|
|
|
$s .= "<li{$attr}>{$format}</li>\n";
|
|
|
|
|
}
|
2005-01-16 02:57:30 +00:00
|
|
|
}
|
2005-02-01 02:02:14 +00:00
|
|
|
|
|
|
|
|
if($this->tryLastResult()) {
|
|
|
|
|
// flush the very last result
|
|
|
|
|
$obj = null;
|
|
|
|
|
$format = $this->formatResult( $sk, $obj );
|
|
|
|
|
if( $format ) {
|
2005-02-06 14:26:52 +00:00
|
|
|
$attr = ( isset ( $obj->usepatrol ) && $obj->usepatrol &&
|
|
|
|
|
$obj->patrolled == 0 ) ? ' class="not-patrolled"' : '';
|
2005-02-01 02:02:14 +00:00
|
|
|
$s .= "<li{$attr}>{$format}</li>\n";
|
|
|
|
|
}
|
|
|
|
|
}
|
2005-08-02 13:35:19 +00:00
|
|
|
|
2005-01-16 02:57:30 +00:00
|
|
|
$dbr->freeResult( $res );
|
|
|
|
|
$s .= '</ol>';
|
2005-01-22 02:37:18 +00:00
|
|
|
$wgOut->addHTML( $s );
|
2004-01-25 02:27:49 +00:00
|
|
|
}
|
2005-05-28 17:17:27 +00:00
|
|
|
if($shownavigation) {
|
|
|
|
|
$wgOut->addHTML( "<p>{$sl}</p>\n" );
|
|
|
|
|
}
|
2005-04-24 04:16:50 +00:00
|
|
|
return $num;
|
I was adding a special page (dead-end pages), and I realized that almost all
the special query pages were pretty much identical. I copy-and-pasted one to
make the one I was working on, and I realized that that was Wrong.
So, I took the common elements and made them into a class, QueryPage.php.
Then, I derived each of the existing special pages from QueryPage, and
overrode places where they differed. This is a Recipe pattern, btw, for
those of you following along at home.
Anyways, the upshot is that the query pages are a lot shorter, with just the
essentials that make them different from other query pages, and there's one
place to make big UI changes for all queries.
2003-12-01 16:04:35 +00:00
|
|
|
}
|
2004-08-09 05:38:11 +00:00
|
|
|
|
2005-09-11 12:33:59 +00:00
|
|
|
/**
|
|
|
|
|
* Do any necessary preprocessing of the result object
|
|
|
|
|
*/
|
|
|
|
|
function preprocessResults( &$db, &$res ) {}
|
|
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
|
|
|
|
* Similar to above, but packaging in a syndicated feed instead of a web page
|
|
|
|
|
*/
|
2004-08-15 19:12:17 +00:00
|
|
|
function doFeed( $class = '' ) {
|
2004-03-05 10:16:46 +00:00
|
|
|
global $wgFeedClasses;
|
2005-09-13 17:32:55 +00:00
|
|
|
|
2004-04-28 04:37:31 +00:00
|
|
|
if( isset($wgFeedClasses[$class]) ) {
|
|
|
|
|
$feed = new $wgFeedClasses[$class](
|
2004-03-05 10:16:46 +00:00
|
|
|
$this->feedTitle(),
|
|
|
|
|
$this->feedDesc(),
|
|
|
|
|
$this->feedUrl() );
|
|
|
|
|
$feed->outHeader();
|
2004-08-09 05:38:11 +00:00
|
|
|
|
2004-07-18 08:48:43 +00:00
|
|
|
$dbr =& wfGetDB( DB_SLAVE );
|
2005-08-09 10:32:59 +00:00
|
|
|
$sql = $this->getSQL() . $this->getOrder();
|
2005-08-09 10:30:20 +00:00
|
|
|
$sql = $dbr->limitResult( $sql, 50, 0 );
|
2004-08-15 19:12:17 +00:00
|
|
|
$res = $dbr->query( $sql, 'QueryPage::doFeed' );
|
2004-07-10 03:09:26 +00:00
|
|
|
while( $obj = $dbr->fetchObject( $res ) ) {
|
2004-03-05 10:16:46 +00:00
|
|
|
$item = $this->feedResult( $obj );
|
|
|
|
|
if( $item ) $feed->outItem( $item );
|
|
|
|
|
}
|
2004-07-10 03:09:26 +00:00
|
|
|
$dbr->freeResult( $res );
|
2004-03-05 10:16:46 +00:00
|
|
|
|
|
|
|
|
$feed->outFooter();
|
|
|
|
|
return true;
|
|
|
|
|
} else {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
|
|
|
|
* Override for custom handling. If the titles/links are ok, just do
|
|
|
|
|
* feedItemDesc()
|
|
|
|
|
*/
|
2004-03-05 11:21:43 +00:00
|
|
|
function feedResult( $row ) {
|
2004-05-09 01:30:34 +00:00
|
|
|
if( !isset( $row->title ) ) {
|
2004-03-05 10:16:46 +00:00
|
|
|
return NULL;
|
|
|
|
|
}
|
2005-08-16 23:36:16 +00:00
|
|
|
$title = Title::MakeTitle( intval( $row->namespace ), $row->title );
|
2004-03-05 10:16:46 +00:00
|
|
|
if( $title ) {
|
2005-09-13 17:32:55 +00:00
|
|
|
$date = isset( $row->timestamp ) ? $row->timestamp : '';
|
2004-08-15 19:12:17 +00:00
|
|
|
$comments = '';
|
2004-04-29 01:14:32 +00:00
|
|
|
if( $title ) {
|
|
|
|
|
$talkpage = $title->getTalkPage();
|
|
|
|
|
$comments = $talkpage->getFullURL();
|
2004-04-28 04:37:31 +00:00
|
|
|
}
|
2004-08-09 05:38:11 +00:00
|
|
|
|
2004-03-05 10:16:46 +00:00
|
|
|
return new FeedItem(
|
2005-03-18 06:49:14 +00:00
|
|
|
$title->getPrefixedText(),
|
2004-03-05 11:21:43 +00:00
|
|
|
$this->feedItemDesc( $row ),
|
2004-03-07 07:26:56 +00:00
|
|
|
$title->getFullURL(),
|
2004-03-19 05:31:18 +00:00
|
|
|
$date,
|
2004-04-28 04:37:31 +00:00
|
|
|
$this->feedItemAuthor( $row ),
|
|
|
|
|
$comments);
|
2004-03-05 10:16:46 +00:00
|
|
|
} else {
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
2004-08-09 05:38:11 +00:00
|
|
|
|
2004-03-05 10:16:46 +00:00
|
|
|
function feedItemDesc( $row ) {
|
2005-09-13 17:32:55 +00:00
|
|
|
return isset( $row->comment ) ? htmlspecialchars( $row->comment ) : '';
|
2004-03-19 05:31:18 +00:00
|
|
|
}
|
2004-08-09 05:38:11 +00:00
|
|
|
|
2004-03-19 05:31:18 +00:00
|
|
|
function feedItemAuthor( $row ) {
|
2005-09-13 17:32:55 +00:00
|
|
|
return isset( $row->user_text ) ? $row->user_text : '';
|
2004-03-05 10:16:46 +00:00
|
|
|
}
|
2004-08-09 05:38:11 +00:00
|
|
|
|
2004-03-05 10:16:46 +00:00
|
|
|
function feedTitle() {
|
2005-09-13 17:32:55 +00:00
|
|
|
global $wgLanguageCode, $wgSitename;
|
2004-05-20 14:13:03 +00:00
|
|
|
$page = SpecialPage::getPage( $this->getName() );
|
|
|
|
|
$desc = $page->getDescription();
|
|
|
|
|
return "$wgSitename - $desc [$wgLanguageCode]";
|
2004-03-05 10:16:46 +00:00
|
|
|
}
|
2004-08-09 05:38:11 +00:00
|
|
|
|
2004-03-05 10:16:46 +00:00
|
|
|
function feedDesc() {
|
2004-09-03 21:29:06 +00:00
|
|
|
return wfMsg( 'tagline' );
|
2004-03-05 10:16:46 +00:00
|
|
|
}
|
2004-08-09 05:38:11 +00:00
|
|
|
|
2004-03-05 10:16:46 +00:00
|
|
|
function feedUrl() {
|
2004-03-08 09:09:35 +00:00
|
|
|
$title = Title::MakeTitle( NS_SPECIAL, $this->getName() );
|
|
|
|
|
return $title->getFullURL();
|
2004-03-05 10:16:46 +00:00
|
|
|
}
|
I was adding a special page (dead-end pages), and I realized that almost all
the special query pages were pretty much identical. I copy-and-pasted one to
make the one I was working on, and I realized that that was Wrong.
So, I took the common elements and made them into a class, QueryPage.php.
Then, I derived each of the existing special pages from QueryPage, and
overrode places where they differed. This is a Recipe pattern, btw, for
those of you following along at home.
Anyways, the upshot is that the query pages are a lot shorter, with just the
essentials that make them different from other query pages, and there's one
place to make big UI changes for all queries.
2003-12-01 16:04:35 +00:00
|
|
|
}
|
|
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
|
|
|
|
* This is a subclass for very simple queries that are just looking for page
|
|
|
|
|
* titles that match some criteria. It formats each result item as a link to
|
|
|
|
|
* that page.
|
2004-09-03 23:00:01 +00:00
|
|
|
*
|
|
|
|
|
* @package MediaWiki
|
2004-09-02 23:28:24 +00:00
|
|
|
*/
|
I was adding a special page (dead-end pages), and I realized that almost all
the special query pages were pretty much identical. I copy-and-pasted one to
make the one I was working on, and I realized that that was Wrong.
So, I took the common elements and made them into a class, QueryPage.php.
Then, I derived each of the existing special pages from QueryPage, and
overrode places where they differed. This is a Recipe pattern, btw, for
those of you following along at home.
Anyways, the upshot is that the query pages are a lot shorter, with just the
essentials that make them different from other query pages, and there's one
place to make big UI changes for all queries.
2003-12-01 16:04:35 +00:00
|
|
|
class PageQueryPage extends QueryPage {
|
|
|
|
|
|
2004-01-25 02:27:49 +00:00
|
|
|
function formatResult( $skin, $result ) {
|
2004-10-21 03:36:19 +00:00
|
|
|
global $wgContLang;
|
2004-05-09 01:30:34 +00:00
|
|
|
$nt = Title::makeTitle( $result->namespace, $result->title );
|
2005-09-13 17:32:55 +00:00
|
|
|
return $skin->makeKnownLinkObj( $nt, htmlspecialchars( $wgContLang->convert( $nt->getPrefixedText() ) ) );
|
2004-01-25 02:27:49 +00:00
|
|
|
}
|
I was adding a special page (dead-end pages), and I realized that almost all
the special query pages were pretty much identical. I copy-and-pasted one to
make the one I was working on, and I realized that that was Wrong.
So, I took the common elements and made them into a class, QueryPage.php.
Then, I derived each of the existing special pages from QueryPage, and
overrode places where they differed. This is a Recipe pattern, btw, for
those of you following along at home.
Anyways, the upshot is that the query pages are a lot shorter, with just the
essentials that make them different from other query pages, and there's one
place to make big UI changes for all queries.
2003-12-01 16:04:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
?>
|