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.
104 lines
2.6 KiB
PHP
104 lines
2.6 KiB
PHP
<?
|
|
|
|
include_once ( "LogPage.php" ) ;
|
|
|
|
# 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.
|
|
|
|
class QueryPage {
|
|
|
|
# Subclasses return their name here. Make sure the name is also
|
|
# specified in Language.php, both in the $wgValidSpecialPagesEn
|
|
# variable, and as a language message param.
|
|
|
|
function getName() {
|
|
return "";
|
|
}
|
|
|
|
# Subclasses return a SQL query here.
|
|
|
|
function getSQL( $offset, $limit ) {
|
|
return "";
|
|
}
|
|
|
|
# Is this query expensive (for some definition of expensive)? Then we
|
|
# don't let it run in miser mode. The default is 0. Expensive
|
|
# subqueries should override this.
|
|
|
|
function isExpensive( ) {
|
|
return 0;
|
|
}
|
|
|
|
# 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.
|
|
|
|
function formatResult( $skin, $result ) {
|
|
return "";
|
|
}
|
|
|
|
# This is the actual workhorse. It does everything needed to make a
|
|
# real, honest-to-gosh query page.
|
|
|
|
function doQuery( $offset, $limit ) {
|
|
|
|
global $wgUser, $wgOut, $wgLang, $wgMiserMode;
|
|
|
|
$sname = $this->getName();
|
|
$fname = get_class($this) . "::doQuery";
|
|
|
|
if ( $this->isExpensive( ) ) {
|
|
|
|
$vsp = $wgLang->getValidSpecialPages();
|
|
$logpage = new LogPage( $vsp[$sname] );
|
|
$logpage->mUpdateRecentChanges = false;
|
|
|
|
if ( $wgMiserMode ) {
|
|
$logpage->showAsDisabledPage();
|
|
return;
|
|
}
|
|
}
|
|
|
|
$sql = $this->getSQL( $offset, $limit );
|
|
|
|
$res = wfQuery( $sql, DB_READ, $fname );
|
|
|
|
$sk = $wgUser->getSkin( );
|
|
|
|
$top = wfShowingResults( $offset, $limit );
|
|
$wgOut->addHTML( "<p>{$top}\n" );
|
|
|
|
$sl = wfViewPrevNext( $offset, $limit, $wgLang->specialPage( $sname ) );
|
|
$wgOut->addHTML( "<br>{$sl}\n" );
|
|
|
|
$s = "<ol start=" . ( $offset + 1 ) . ">";
|
|
while ( $obj = wfFetchObject( $res ) ) {
|
|
$format = $this->formatResult( $sk, $obj );
|
|
$s .= "<li>{$format}</li>\n";
|
|
}
|
|
wfFreeResult( $res );
|
|
$s .= "</ol>";
|
|
$wgOut->addHTML( $s );
|
|
$wgOut->addHTML( "<p>{$sl}\n" );
|
|
|
|
# Saving cache
|
|
|
|
if ( $this->isExpensive() && $offset == 0 && $limit >= 50 ) {
|
|
$logpage->replaceContent( $s );
|
|
}
|
|
}
|
|
}
|
|
|
|
# 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.
|
|
|
|
class PageQueryPage extends QueryPage {
|
|
|
|
function formatResult( $skin, $result ) {
|
|
return $skin->makeKnownLink( $result->cur_title, "" );
|
|
}
|
|
}
|
|
|
|
?>
|