3 include_once ( "LogPage.php" ) ;
4 include_once ( "Feed.php" );
6 # This is a class for doing query pages; since they're almost all the same,
7 # we factor out some of the functionality into a superclass, and let
8 # subclasses derive from it.
11 # Subclasses return their name here. Make sure the name is also
12 # specified in Language.php, both in the $wgValidSpecialPagesEn
13 # variable, and as a language message param.
19 # Subclasses return a SQL query here.
21 function getSQL( $offset, $limit ) {
25 # Is this query expensive (for some definition of expensive)? Then we
26 # don't let it run in miser mode. $wgDisableQueryPages causes all query
27 # pages to be declared expensive. Some query pages are always expensive.
28 function isExpensive( ) {
29 global $wgDisableQueryPages;
30 return $wgDisableQueryPages;
33 # Formats the results of the query for display. The skin is the current
34 # skin; you can use it for making links. The result is a single row of
35 # result data. You should be able to grab SQL results off of it.
37 function formatResult( $skin, $result ) {
41 # This is the actual workhorse. It does everything needed to make a
42 # real, honest-to-gosh query page.
44 function doQuery( $offset, $limit ) {
45 global $wgUser, $wgOut, $wgLang, $wgMiserMode;
47 $sname = $this->getName();
48 $fname = get_class($this) . "::doQuery";
50 $wgOut->setSyndicated( true );
52 if ( $this->isExpensive( ) ) {
53 $vsp = $wgLang->getValidSpecialPages();
54 $logpage = new LogPage( "!" . $vsp[$sname] );
55 $logpage->mUpdateRecentChanges
= false;
58 $logpage->showAsDisabledPage();
63 $sql = $this->getSQL( $offset, $limit );
65 $res = wfQuery( $sql, DB_READ
, $fname );
67 $num = wfNumRows($res);
69 $sk = $wgUser->getSkin( );
71 $top = wfShowingResults( $offset, $num);
72 $wgOut->addHTML( "<p>{$top}\n" );
74 # often disable 'next' link when we reach the end
75 if($num < $limit) { $atend = true; } else { $atend = false; }
77 $sl = wfViewPrevNext( $offset, $limit , $wgLang->specialPage( $sname ), "" ,$atend );
78 $wgOut->addHTML( "<br />{$sl}</p>\n" );
80 $s = "<ol start='" . ( $offset +
1 ) . "'>";
81 while ( $obj = wfFetchObject( $res ) ) {
82 $format = $this->formatResult( $sk, $obj );
83 $s .= "<li>{$format}</li>\n";
87 $wgOut->addHTML( $s );
88 $wgOut->addHTML( "<p>{$sl}</p>\n" );
92 if ( $this->isExpensive() && $offset == 0 && $limit >= 50 ) {
93 $logpage->replaceContent( $s );
97 # Similar to above, but packaging in a syndicated feed instead of a web page
98 function doFeed( $class = "" ) {
99 global $wgFeedClasses;
100 global $wgOut, $wgLanguageCode, $wgLang;
101 if( isset($wgFeedClasses[$class]) ) {
102 $feed = new $wgFeedClasses[$class](
108 $sql = $this->getSQL( 0, 50 );
109 $res = wfQuery( $sql, DB_READ
, "QueryPage::doFeed" );
110 while( $obj = wfFetchObject( $res ) ) {
111 $item = $this->feedResult( $obj );
112 if( $item ) $feed->outItem( $item );
114 wfFreeResult( $res );
123 # Override for custom handling. If the titles/links are ok, just do feedItemDesc()
124 function feedResult( $row ) {
125 if( isset( $row->cur_title
) ) {
126 $title = Title
::MakeTitle( $row->cur_namespace
, $row->cur_title
);
127 } elseif( isset( $row->old_title
) ) {
128 $title = Title
::MakeTitle( $row->old_namespace
, $row->old_title
);
129 } elseif( isset( $row->rc_title
) ) {
130 $title = Title
::MakeTitle( $row->rc_namespace
, $row->rc_title
);
136 if( isset( $row->cur_timestamp
) ) {
137 $date = $row->cur_timestamp
;
138 } elseif( isset( $row->old_timestamp
) ) {
139 $date = $row->old_timestamp
;
140 } elseif( isset( $row->rc_cur_timestamp
) ) {
141 $date = $row->rc_cur_timestamp
;
145 if( isset( $row->cur_comment
) ) {
146 $comments = $row->cur_comment
;
147 } elseif( isset( $row->old_comment
) ) {
148 $comments = $row->old_comment
;
149 } elseif( isset( $row->rc_cur_comment
) ) {
150 $comments = $row->rc_cur_comment
;
155 $this->feedItemDesc( $row ),
156 $title->getFullURL(),
158 $this->feedItemAuthor( $row ),
165 function feedItemDesc( $row ) {
167 if( isset( $row->cur_comment
) ) {
168 $text = $row->cur_comment
;
169 } elseif( isset( $row->old_comment
) ) {
170 $text = $row->old_comment
;
171 } elseif( isset( $row->rc_comment
) ) {
172 $text = $row->rc_comment
;
174 $text = htmlspecialchars( $text );
176 if( isset( $row->cur_text
) ) {
177 $text = "<p>" . htmlspecialchars( wfMsg( "summary" ) ) . ": " . $text . "</p>\n<hr />\n<div>" .
178 nl2br( $row->cur_text
) . "</div>";;
183 function feedItemAuthor( $row ) {
185 $fields = array( "cur_user_text", "old_user_text", "rc_user_text" );
186 foreach( $fields as $field ) {
187 if( isset( $row->$field ) ) return $row->field;
190 new code follow, that's an ugly hack to fix things: */
191 if( isset( $row->cur_user_text
) ) return $row->cur_user_text
;
192 if( isset( $row->old_user_text
) ) return $row->old_user_text
;
193 if( isset( $row->rc_user_text
) ) return $row->rc_user_text
;
197 function feedTitle() {
198 global $wgLanguageCode, $wgSitename, $wgLang;
199 $pages = $wgLang->getValidSpecialPages();
200 $title = $pages[$this->getName()];
201 return "$wgSitename - $title [$wgLanguageCode]";
204 function feedDesc() {
205 return wfMsg( "fromwikipedia" );
210 $title = Title
::MakeTitle( NS_SPECIAL
, $this->getName() );
211 return $title->getFullURL();
215 # This is a subclass for very simple queries that are just looking for page
216 # titles that match some criteria. It formats each result item as a link to
219 class PageQueryPage
extends QueryPage
{
221 function formatResult( $skin, $result ) {
222 return $skin->makeKnownLink( $result->cur_title
, "" );