Split off page history code to PageHistory.php out of Article.php and Skin.php.
[lhc/web/wiklou.git] / includes / PageHistory.php
1 <?php
2
3 /* Page history
4 Split off from Article.php and Skin.php, 2003-12-22
5 */
6
7 class PageHistory {
8 var $mArticle, $mTitle, $mSkin;
9 var $lastline, $lastdate;
10
11 function PageHistory( $article ) {
12 $this->mArticle =& $article;
13 $this->mTitle =& $article->mTitle;
14 }
15
16 # This shares a lot of issues (and code) with Recent Changes
17
18 function history()
19 {
20 global $wgUser, $wgOut, $wgLang, $offset, $limit;
21
22 # If page hasn't changed, client can cache this
23
24 if( $wgOut->checkLastModified( $this->mArticle->getTimestamp() ) ){
25 # Client cache fresh and headers sent, nothing more to do.
26 return;
27 }
28 $fname = "PageHistory::history";
29 wfProfileIn( $fname );
30
31 $wgOut->setPageTitle( $this->mTitle->getPRefixedText() );
32 $wgOut->setSubtitle( wfMsg( "revhistory" ) );
33 $wgOut->setArticleFlag( false );
34 $wgOut->setRobotpolicy( "noindex,nofollow" );
35
36 if( $this->mTitle->getArticleID() == 0 ) {
37 $wgOut->addHTML( wfMsg( "nohistory" ) );
38 wfProfileOut( $fname );
39 return;
40 }
41
42 $offset = (int)$offset;
43 $limit = (int)$limit;
44 if( $limit == 0 ) $limit = 50;
45 $namespace = $this->mTitle->getNamespace();
46 $title = $this->mTitle->getText();
47 $sql = "SELECT old_id,old_user," .
48 "old_comment,old_user_text,old_timestamp,old_minor_edit ".
49 "FROM old USE INDEX (name_title_timestamp) " .
50 "WHERE old_namespace={$namespace} AND " .
51 "old_title='" . wfStrencode( $this->mTitle->getDBkey() ) . "' " .
52 "ORDER BY inverse_timestamp LIMIT $offset, $limit";
53 $res = wfQuery( $sql, DB_READ, $fname );
54
55 $revs = wfNumRows( $res );
56 if( $this->mTitle->getArticleID() == 0 ) {
57 $wgOut->addHTML( wfMsg( "nohistory" ) );
58 wfProfileOut( $fname );
59 return;
60 }
61
62 $this->mSkin = $wgUser->getSkin();
63 $numbar = wfViewPrevNext(
64 $offset, $limit,
65 $this->mTitle->getPrefixedText(),
66 "action=history" );
67 $s = $numbar;
68 $s .= $this->beginHistoryList();
69
70 if($offset == 0 )
71 $s .= $this->historyLine( $this->mArticle->getTimestamp(), $this->mArticle->getUser(),
72 $this->mArticle->getUserText(), $namespace,
73 $title, 0, $this->mArticle->getComment(),
74 ( $this->mArticle->getMinorEdit() > 0 ) );
75
76 $revs = wfNumRows( $res );
77 while ( $line = wfFetchObject( $res ) ) {
78 $s .= $this->historyLine( $line->old_timestamp, $line->old_user,
79 $line->old_user_text, $namespace,
80 $title, $line->old_id,
81 $line->old_comment, ( $line->old_minor_edit > 0 ) );
82 }
83 $s .= $this->endHistoryList();
84 $s .= $numbar;
85 $wgOut->addHTML( $s );
86 wfProfileOut( $fname );
87 }
88
89 function beginHistoryList()
90 {
91 $this->lastdate = $this->lastline = "";
92 $s = "\n<p>" . wfMsg( "histlegend" ) . "\n<ul>";
93 return $s;
94 }
95
96 function endHistoryList()
97 {
98 $last = wfMsg( "last" );
99
100 $s = preg_replace( "/!OLDID![0-9]+!/", $last, $this->lastline );
101 $s .= "</ul>\n";
102 return $s;
103 }
104
105 function historyLine( $ts, $u, $ut, $ns, $ttl, $oid, $c, $isminor )
106 {
107 global $wgLang;
108
109 $artname = Title::makeName( $ns, $ttl );
110 $last = wfMsg( "last" );
111 $cur = wfMsg( "cur" );
112 $cr = wfMsg( "currentrev" );
113
114 if ( $oid && $this->lastline ) {
115 $ret = preg_replace( "/!OLDID!([0-9]+)!/", $this->mSkin->makeKnownLink(
116 $artname, $last, "diff=\\1&oldid={$oid}" ), $this->lastline );
117 } else {
118 $ret = "";
119 }
120 $dt = $wgLang->timeanddate( $ts, true );
121
122 if ( $oid ) {
123 $q = "oldid={$oid}";
124 } else {
125 $q = "";
126 }
127 $link = $this->mSkin->makeKnownLink( $artname, $dt, $q );
128
129 if ( 0 == $u ) {
130 $ul = $this->mSkin->makeKnownLink( $wgLang->specialPage( "Contributions" ),
131 $ut, "target=" . $ut );
132 } else {
133 $ul = $this->mSkin->makeLink( $wgLang->getNsText(
134 Namespace::getUser() ) . ":{$ut}", $ut );
135 }
136
137 $s = "<li>";
138 if ( $oid ) {
139 $curlink = $this->mSkin->makeKnownLink( $artname, $cur,
140 "diff=0&oldid={$oid}" );
141 } else {
142 $curlink = $cur;
143 }
144 $s .= "({$curlink}) (!OLDID!{$oid}!) . .";
145
146 $M = wfMsg( "minoreditletter" );
147 if ( $isminor ) {
148 $s .= " <strong>{$M}</strong>";
149 }
150 $s .= " {$link} . . {$ul}";
151
152 if ( "" != $c && "*" != $c ) {
153 $s .= " <em>(" . wfEscapeHTML($c) . ")</em>";
154 }
155 $s .= "</li>\n";
156
157 $this->lastline = $s;
158 return $ret;
159 }
160
161 }
162
163 ?>