2004-02-18 02:15:00 +00:00
|
|
|
<?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
|
|
|
|
2004-05-07 13:43:10 +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
|
|
|
|
|
|
|
|
# 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 {
|
2004-01-25 02:27:49 +00:00
|
|
|
# Subclasses return their name here. Make sure the name is also
|
2004-05-20 14:13:03 +00:00
|
|
|
# specified in SpecialPage.php and in Language.php as a language message param.
|
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-01-25 02:27:49 +00:00
|
|
|
function getName() {
|
|
|
|
|
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-05-09 01:30:34 +00:00
|
|
|
# Subclasses return an SQL query here.
|
|
|
|
|
#
|
2004-08-11 00:07:12 +00:00
|
|
|
# Note that the query itself should return the following four columns:
|
|
|
|
|
# 'type' (your special page's name), 'namespace', 'title', and 'value'
|
2004-08-11 00:10:48 +00:00
|
|
|
# *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.
|
2004-05-09 01:30:34 +00:00
|
|
|
#
|
|
|
|
|
# Don't include an ORDER or LIMIT clause, this will be added.
|
|
|
|
|
|
|
|
|
|
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-05-09 01:30:34 +00:00
|
|
|
# Override to sort by increasing values
|
|
|
|
|
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-05-09 01:30:34 +00:00
|
|
|
# Don't override this unless you're darn sure.
|
|
|
|
|
function getOrderLimit( $offset, $limit ) {
|
|
|
|
|
return " ORDER BY value " .
|
|
|
|
|
($this->sortDescending() ? "DESC" : "")
|
2004-06-11 16:37:15 +00:00
|
|
|
. wfLimitResult($limit,$offset);
|
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
|
|
|
|
2004-08-10 13:55:29 +00:00
|
|
|
function getOrder() {
|
|
|
|
|
return " ORDER BY value " .
|
|
|
|
|
($this->sortDescending() ? "DESC" : "");
|
|
|
|
|
}
|
|
|
|
|
|
2004-01-25 02:27:49 +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.
|
|
|
|
|
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-01-25 02:27:49 +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.
|
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-01-25 02:27:49 +00:00
|
|
|
function formatResult( $skin, $result ) {
|
|
|
|
|
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-08-09 05:38:11 +00:00
|
|
|
|
2004-01-25 02:27:49 +00:00
|
|
|
# This is the actual workhorse. It does everything needed to make a
|
|
|
|
|
# real, honest-to-gosh query page.
|
2004-08-09 05:38:11 +00:00
|
|
|
|
2004-01-25 02:27:49 +00:00
|
|
|
function doQuery( $offset, $limit ) {
|
2004-05-09 01:30:34 +00:00
|
|
|
global $wgUser, $wgOut, $wgLang, $wgRequest;
|
|
|
|
|
global $wgMiserMode;
|
2004-01-25 02:27:49 +00:00
|
|
|
|
|
|
|
|
$sname = $this->getName();
|
|
|
|
|
$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-03-19 05:31:18 +00:00
|
|
|
$wgOut->setSyndicated( true );
|
2004-07-10 03:09:26 +00:00
|
|
|
$res = false;
|
2004-08-09 05:38:11 +00:00
|
|
|
|
2004-05-09 01:30:34 +00:00
|
|
|
if ( $this->isExpensive() ) {
|
|
|
|
|
$recache = $wgRequest->getBool( "recache" );
|
|
|
|
|
if( $recache ) {
|
|
|
|
|
# Clear out any old cached data
|
2004-07-10 03:09:26 +00:00
|
|
|
$dbw->delete( 'querycache', array( 'qc_type' => $sname ), $fname );
|
2004-08-09 05:38:11 +00:00
|
|
|
|
2004-07-10 03:09:26 +00:00
|
|
|
# Do query on the (possibly out of date) slave server
|
2004-05-09 01:30:34 +00:00
|
|
|
$maxstored = 1000;
|
2004-08-10 13:55:29 +00:00
|
|
|
$res = $dbr->query( $sql . $this->getOrder() . $dbr->limitResult( $maxstored,0 ), $fname );
|
2004-08-09 05:38:11 +00:00
|
|
|
|
2004-07-10 03:09:26 +00:00
|
|
|
# Fetch results
|
|
|
|
|
$insertSql = "INSERT INTO $querycache (qc_type,qc_namespace,qc_title,qc_value) VALUES ";
|
|
|
|
|
$first = true;
|
|
|
|
|
while ( $row = $dbr->fetchObject( $res ) ) {
|
|
|
|
|
if ( $first ) {
|
|
|
|
|
$first = false;
|
|
|
|
|
} else {
|
|
|
|
|
$insertSql .= ",";
|
2004-08-09 05:38:11 +00:00
|
|
|
}
|
2004-07-10 03:09:26 +00:00
|
|
|
$insertSql .= "(" .
|
|
|
|
|
$dbw->addQuotes( $row->type ) . "," .
|
|
|
|
|
$dbw->addQuotes( $row->namespace ) . "," .
|
|
|
|
|
$dbw->addQuotes( $row->title ) . "," .
|
2004-07-14 18:37:11 +00:00
|
|
|
$dbw->addQuotes( $row->value ) . ")";
|
2004-07-10 03:09:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Save results into the querycache table on the master
|
|
|
|
|
$dbw->query( $insertSql, $fname );
|
|
|
|
|
|
|
|
|
|
# Set result pointer to allow reading for display
|
|
|
|
|
$numRows = $dbr->numRows( $res );
|
|
|
|
|
if ( $numRows <= $offset ) {
|
|
|
|
|
$num = 0;
|
|
|
|
|
} else {
|
|
|
|
|
$dbr->dataSeek( $res, $offset );
|
|
|
|
|
$num = max( $limit, $numRows - $offset );
|
|
|
|
|
}
|
2004-05-09 01:30:34 +00:00
|
|
|
}
|
|
|
|
|
if( $wgMiserMode || $recache ) {
|
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-05-09 01:30:34 +00:00
|
|
|
}
|
|
|
|
|
if( $wgMiserMode ) {
|
|
|
|
|
$wgOut->addWikiText( wfMsg( "perfcached" ) );
|
2004-01-25 02:27:49 +00:00
|
|
|
}
|
|
|
|
|
}
|
2004-07-10 03:09:26 +00:00
|
|
|
if ( $res === false ) {
|
2004-08-10 13:55:29 +00:00
|
|
|
$res = $dbr->query( $sql . $this->getOrder() .
|
|
|
|
|
$dbr->limitResult( $limit,$offset ), $fname );
|
2004-07-10 03:09:26 +00:00
|
|
|
$num = $dbr->numRows($res);
|
|
|
|
|
}
|
2004-08-09 05:38:11 +00:00
|
|
|
|
|
|
|
|
|
2004-01-25 02:27:49 +00:00
|
|
|
$sk = $wgUser->getSkin( );
|
|
|
|
|
|
2004-04-09 14:53:41 +00:00
|
|
|
$top = wfShowingResults( $offset, $num);
|
2004-01-25 02:27:49 +00:00
|
|
|
$wgOut->addHTML( "<p>{$top}\n" );
|
|
|
|
|
|
2004-04-27 04:25:06 +00:00
|
|
|
# often disable 'next' link when we reach the end
|
|
|
|
|
if($num < $limit) { $atend = true; } else { $atend = false; }
|
2004-08-09 05:38:11 +00:00
|
|
|
|
2004-04-27 04:25:06 +00:00
|
|
|
$sl = wfViewPrevNext( $offset, $limit , $wgLang->specialPage( $sname ), "" ,$atend );
|
2004-04-09 08:27:00 +00:00
|
|
|
$wgOut->addHTML( "<br />{$sl}</p>\n" );
|
2004-01-25 02:27:49 +00:00
|
|
|
|
2004-08-09 05:38:11 +00:00
|
|
|
$s = "<ol start='" . ( $offset + 1 ) . "' class='special'>";
|
2004-07-10 03:09:26 +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++ ) {
|
2004-01-25 02:27:49 +00:00
|
|
|
$format = $this->formatResult( $sk, $obj );
|
2004-08-15 09:54:28 +00:00
|
|
|
$attr = ( isset ( $obj->usepatrol ) && $obj->usepatrol &&
|
2004-08-10 23:06:38 +00:00
|
|
|
$obj->patrolled == 0 ) ? ' class="not_patrolled"' : '';
|
2004-08-09 05:38:11 +00:00
|
|
|
$s .= "<li{$attr}>{$format}</li>\n";
|
2004-01-25 02:27:49 +00:00
|
|
|
}
|
2004-07-10 03:09:26 +00:00
|
|
|
$dbr->freeResult( $res );
|
2004-01-25 02:27:49 +00:00
|
|
|
$s .= "</ol>";
|
|
|
|
|
$wgOut->addHTML( $s );
|
2004-04-09 08:27:00 +00:00
|
|
|
$wgOut->addHTML( "<p>{$sl}</p>\n" );
|
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
|
|
|
|
2004-03-05 10:16:46 +00:00
|
|
|
# Similar to above, but packaging in a syndicated feed instead of a web page
|
|
|
|
|
function doFeed( $class = "" ) {
|
|
|
|
|
global $wgFeedClasses;
|
|
|
|
|
global $wgOut, $wgLanguageCode, $wgLang;
|
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 );
|
2004-08-10 13:55:29 +00:00
|
|
|
$sql = $this->getSQL() . $this->getOrder().$dbr->limitResult( 50, 0 );
|
2004-07-10 03:09:26 +00:00
|
|
|
$res = $dbr->query( $sql, "QueryPage::doFeed" );
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# 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;
|
|
|
|
|
}
|
2004-05-09 01:30:34 +00:00
|
|
|
$title = Title::MakeTitle( IntVal( $row->namespace ), $row->title );
|
2004-03-05 10:16:46 +00:00
|
|
|
if( $title ) {
|
2004-05-09 01:30:34 +00:00
|
|
|
if( isset( $row->timestamp ) ) {
|
|
|
|
|
$date = $row->timestamp;
|
|
|
|
|
} else {
|
|
|
|
|
$date = "";
|
2004-03-05 11:21:43 +00:00
|
|
|
}
|
2004-08-09 05:38:11 +00:00
|
|
|
|
2004-04-28 04:37:31 +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(
|
|
|
|
|
$title->getText(),
|
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 ) {
|
2004-03-19 05:31:18 +00:00
|
|
|
$text = "";
|
2004-05-09 01:30:34 +00:00
|
|
|
if( isset( $row->comment ) ) {
|
|
|
|
|
$text = htmlspecialchars( $row->comment );
|
|
|
|
|
} else {
|
|
|
|
|
$text = "";
|
2004-03-19 05:31:18 +00:00
|
|
|
}
|
2004-08-09 05:38:11 +00:00
|
|
|
|
2004-05-09 01:30:34 +00:00
|
|
|
if( isset( $row->text ) ) {
|
2004-03-19 05:31:18 +00:00
|
|
|
$text = "<p>" . htmlspecialchars( wfMsg( "summary" ) ) . ": " . $text . "</p>\n<hr />\n<div>" .
|
2004-05-09 01:30:34 +00:00
|
|
|
nl2br( htmlspecialchars( $row->text ) ) . "</div>";;
|
2004-03-19 05:31:18 +00:00
|
|
|
}
|
|
|
|
|
return $text;
|
|
|
|
|
}
|
2004-08-09 05:38:11 +00:00
|
|
|
|
2004-03-19 05:31:18 +00:00
|
|
|
function feedItemAuthor( $row ) {
|
2004-05-09 01:30:34 +00:00
|
|
|
if( isset( $row->user_text ) ) {
|
|
|
|
|
return $row->user_text;
|
|
|
|
|
} else {
|
|
|
|
|
return "";
|
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() {
|
|
|
|
|
global $wgLanguageCode, $wgSitename, $wgLang;
|
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() {
|
|
|
|
|
return wfMsg( "fromwikipedia" );
|
|
|
|
|
}
|
2004-08-09 05:38:11 +00:00
|
|
|
|
2004-03-05 10:16:46 +00:00
|
|
|
function feedUrl() {
|
|
|
|
|
global $wgLang;
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# 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 {
|
|
|
|
|
|
2004-01-25 02:27:49 +00:00
|
|
|
function formatResult( $skin, $result ) {
|
2004-05-09 01:30:34 +00:00
|
|
|
$nt = Title::makeTitle( $result->namespace, $result->title );
|
|
|
|
|
return $skin->makeKnownLinkObj( $nt, "" );
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
?>
|