aboutsummaryrefslogtreecommitdiffstats
path: root/includes/PageHistory.php
blob: 34c6856dd0921e367ae45ce440dd98a580ebafa4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
<?php

/* Page history
   Split off from Article.php and Skin.php, 2003-12-22
*/

class PageHistory {
	var $mArticle, $mTitle, $mSkin;
	var $lastline, $lastdate;
	var $linesonpage;
	function PageHistory( $article ) {
		$this->mArticle =& $article;
		$this->mTitle =& $article->mTitle;
	}
	
	# This shares a lot of issues (and code) with Recent Changes

	function history()
	{
		global $wgUser, $wgOut, $wgLang;

		# If page hasn't changed, client can cache this
		
		if( $wgOut->checkLastModified( $this->mArticle->getTimestamp() ) ){
			# Client cache fresh and headers sent, nothing more to do.
			return;
		}
		$fname = "PageHistory::history";
		wfProfileIn( $fname );

		$wgOut->setPageTitle( $this->mTitle->getPRefixedText() );
		$wgOut->setSubtitle( wfMsg( "revhistory" ) );
		$wgOut->setArticleFlag( false );
		$wgOut->setArticleRelated( true );
		$wgOut->setRobotpolicy( "noindex,nofollow" );

		if( $this->mTitle->getArticleID() == 0 ) {
			$wgOut->addHTML( wfMsg( "nohistory" ) );
			wfProfileOut( $fname );
			return;
		}
		
		list( $limit, $offset ) = wfCheckLimits();
		
		/* We have to draw the latest revision from 'cur' */
		$rawlimit = $limit;
		$rawoffset = $offset - 1;
		if( 0 == $offset ) {
			$rawlimit--;
			$rawoffset = 0;
		}
		/* Check one extra row to see whether we need to show 'next' and diff links */
		$limitplus = $rawlimit + 1;
		
		$namespace = $this->mTitle->getNamespace();
		$title = $this->mTitle->getText();
		$sql = "SELECT old_id,old_user," .
		  "old_comment,old_user_text,old_timestamp,old_minor_edit ".
		  "FROM old USE INDEX (name_title_timestamp) " .
		  "WHERE old_namespace={$namespace} AND " .
		  "old_title='" . wfStrencode( $this->mTitle->getDBkey() ) . "' " .
		  "ORDER BY inverse_timestamp LIMIT $rawoffset, $limitplus";
		$res = wfQuery( $sql, DB_READ, $fname );

		$revs = wfNumRows( $res );
		
		if( $revs < $limitplus ) // the sql above tries to fetch one extra
			$this->linesonpage = $revs;
		else
			$this->linesonpage = $revs - 1;

		$atend = ($revs < $limitplus);
		
		$this->mSkin = $wgUser->getSkin();
		$numbar = wfViewPrevNext(
			$offset, $limit,
			$this->mTitle->getPrefixedText(),
			"action=history", $atend );
		$s = $numbar;
		$this->submitbuttonhtml = ( $this->linesonpage > 1) ? '<input class="historysubmit" 
		type="submit" accesskey="'.wfMsg('accesskey-compareselectedversions').
			'" title="'.wfMsg('tooltip-compareselectedversions').'" value="'.wfMsg('compareselectedversions')."\" />" :
			'';
		$s .= $this->beginHistoryList();
		$counter = 1;
		if( $offset == 0 ){
			$this->linesonpage++;
			$s .= $this->historyLine( 
				$this->mArticle->getTimestamp(), 
				$this->mArticle->getUser(),
				$this->mArticle->getUserText(), $namespace,
				$title, 0, $this->mArticle->getComment(),
				( $this->mArticle->getMinorEdit() > 0 ),
				$counter++
			);
		}
		while ( $line = wfFetchObject( $res ) ) {
			$s .= $this->historyLine( 
				$line->old_timestamp, $line->old_user,
				$line->old_user_text, $namespace,
				$title, $line->old_id,
				$line->old_comment, ( $line->old_minor_edit > 0 ),
				$counter++
			);
		}
		$s .= $this->endHistoryList( !$atend );
		$s .= $numbar;
		$wgOut->addHTML( $s );
		wfProfileOut( $fname );
	}

	function beginHistoryList()
	{
		global $wgTitle;
		$this->lastdate = $this->lastline = "";
		$s = "\n<p>" . wfMsg( "histlegend" ).'</p>'; 
		$s .="\n<form action=\"" . $wgTitle->escapeLocalURL( '-' ) . "\" method=\"get\">";
		$s .= "<input type=\"hidden\" name=\"title\" value=\"".wfEscapeHTML($wgTitle->getPrefixedDbKey())."\"/>\n";
		$s .= !empty($this->submitbuttonhtml) ? $this->submitbuttonhtml."\n":'';
		$s .= "" . "\n<ul id=\"pagehistory\" >";
		return $s;
	}

	function endHistoryList( $skip = false )
	{
		$last = wfMsg( "last" );

		$s = $skip ? "" : preg_replace( "/!OLDID![0-9]+!/", $last, $this->lastline );
		$s .= "</ul>";
		$s .= !empty($this->submitbuttonhtml) ? $this->submitbuttonhtml."\n":'';
		$s .= "</form>\n";
		return $s;
	}

	function historyLine( $ts, $u, $ut, $ns, $ttl, $oid, $c, $isminor, $counter = '' )
	{
		global $wgLang;

		$artname = Title::makeName( $ns, $ttl );
		$last = wfMsg( "last" );
		$cur = wfMsg( "cur" );
		$cr = wfMsg( "currentrev" );

		if ( $oid && $this->lastline ) {
			$ret = preg_replace( "/!OLDID!([0-9]+)!/", $this->mSkin->makeKnownLink(
			  $artname, $last, "diff=\\1&oldid={$oid}",'' ,'' ,' tabindex="'.$counter.'"' ), $this->lastline );
		} else {
			$ret = "";
		}
		$dt = $wgLang->timeanddate( $ts, true );

		if ( $oid ) {
			$q = "oldid={$oid}";
		} else {
			$q = "";
		}
		$link = $this->mSkin->makeKnownLink( $artname, $dt, $q );

		if ( 0 == $u ) {
			$ul = $this->mSkin->makeKnownLink( $wgLang->specialPage( "Contributions" ),
				$ut, "target=" . $ut );
		} else { 
			$ul = $this->mSkin->makeLink( $wgLang->getNsText(
				Namespace::getUser() ) . ":{$ut}", $ut );
		}

		$s = "<li>";
		if ( $oid ) {
			$curlink = $this->mSkin->makeKnownLink( $artname, $cur,
			  "diff=0&oldid={$oid}" );
		} else {
			$curlink = $cur;
		}
		$arbitrary = "";
		if( $this->linesonpage > 1) {
			# XXX: move title texts to javascript
			$checkmark = "";
			if ( !$oid ) {
				$arbitrary = '<input type="radio" style="visibility:hidden" name="oldid" value="'.$oid.'" title="'.wfMsg('selectolderversionfordiff').'" />';
				$checkmark = ' checked="checked"';
			} else {
				if( $counter == 2 ) $checkmark = ' checked="checked"';
				$arbitrary = '<input type="radio" name="oldid" value="'.$oid.'" title="'.wfMsg('selectolderversionfordiff').'"'.$checkmark.' />';
				$checkmark = '';
			}
			$arbitrary .= '<input type="radio" name="diff" value="'.$oid.'" title="'.wfMsg('selectnewerversionfordiff').'"'.$checkmark.' />';
		}
		$s .= "({$curlink}) (!OLDID!{$oid}!) $arbitrary {$link} <span class='user'>{$ul}</span>";
		$s .= $isminor ? ' <span class="minor">'.wfMsg( "minoreditletter" ).'</span>': '' ;
		

		if ( "" != $c && "*" != $c ) {

			$c = $this->mSkin->formatcomment($c);
			$s .= " <em>(" . $c . ")</em>";
		}
		$s .= "</li>\n";

		$this->lastline = $s;
		return $ret;
	}

}

?>