Main Page | Namespace List | Class Hierarchy | Class List | File List | Class Members | File Members | Related Pages

PageHistory.php

Go to the documentation of this file.
00001 <?php 00002 00003 /* Page history 00004 Split off from Article.php and Skin.php, 2003-12-22 00005 */ 00006 00007 class PageHistory { 00008 var $mArticle, $mTitle, $mSkin; 00009 var $lastline, $lastdate; 00010 var $linesonpage; 00011 function PageHistory( $article ) { 00012 $this->mArticle =& $article; 00013 $this->mTitle =& $article->mTitle; 00014 } 00015 00016 # This shares a lot of issues (and code) with Recent Changes 00017 00018 function history() 00019 { 00020 global $wgUser, $wgOut, $wgLang, $wgIsMySQL, $wgIsPg; 00021 00022 # If page hasn't changed, client can cache this 00023 00024 if( $wgOut->checkLastModified( $this->mArticle->getTimestamp() ) ){ 00025 # Client cache fresh and headers sent, nothing more to do. 00026 return; 00027 } 00028 $fname = "PageHistory::history"; 00029 wfProfileIn( $fname ); 00030 00031 $wgOut->setPageTitle( $this->mTitle->getPRefixedText() ); 00032 $wgOut->setSubtitle( wfMsg( "revhistory" ) ); 00033 $wgOut->setArticleFlag( false ); 00034 $wgOut->setArticleRelated( true ); 00035 $wgOut->setRobotpolicy( "noindex,nofollow" ); 00036 00037 if( $this->mTitle->getArticleID() == 0 ) { 00038 $wgOut->addHTML( wfMsg( "nohistory" ) ); 00039 wfProfileOut( $fname ); 00040 return; 00041 } 00042 00043 list( $limit, $offset ) = wfCheckLimits(); 00044 00045 /* We have to draw the latest revision from 'cur' */ 00046 $rawlimit = $limit; 00047 $rawoffset = $offset - 1; 00048 if( 0 == $offset ) { 00049 $rawlimit--; 00050 $rawoffset = 0; 00051 } 00052 /* Check one extra row to see whether we need to show 'next' and diff links */ 00053 $limitplus = $rawlimit + 1; 00054 00055 $namespace = $this->mTitle->getNamespace(); 00056 $title = $this->mTitle->getText(); 00057 $use_index=$wgIsMySQL?"USE INDEX (name_title_timestamp)":""; 00058 $oldtable=$wgIsPg?'"old"':'old'; 00059 $sql = "SELECT old_id,old_user," . 00060 "old_comment,old_user_text,old_timestamp,old_minor_edit ". 00061 "FROM $oldtable $use_index " . 00062 "WHERE old_namespace={$namespace} AND " . 00063 "old_title='" . wfStrencode( $this->mTitle->getDBkey() ) . "' " . 00064 "ORDER BY inverse_timestamp".wfLimitResult($limitplus,$rawoffset); 00065 $res = wfQuery( $sql, DB_READ, $fname ); 00066 00067 $revs = wfNumRows( $res ); 00068 00069 if( $revs < $limitplus ) // the sql above tries to fetch one extra 00070 $this->linesonpage = $revs; 00071 else 00072 $this->linesonpage = $revs - 1; 00073 00074 $atend = ($revs < $limitplus); 00075 00076 $this->mSkin = $wgUser->getSkin(); 00077 $numbar = wfViewPrevNext( 00078 $offset, $limit, 00079 $this->mTitle->getPrefixedText(), 00080 "action=history", $atend ); 00081 $s = $numbar; 00082 if($this->linesonpage > 0) { 00083 $submitpart1 = '<input class="historysubmit" type="submit" accesskey="'.wfMsg('accesskey-compareselectedversions'). 00084 '" title="'.wfMsg('tooltip-compareselectedversions').'" value="'.wfMsg('compareselectedversions').'"'; 00085 $this->submitbuttonhtml1 = $submitpart1 . ' />'; 00086 $this->submitbuttonhtml2 = $submitpart1 . ' id="historysubmit" />'; 00087 } 00088 $s .= $this->beginHistoryList(); 00089 $counter = 1; 00090 if( $offset == 0 ){ 00091 $this->linesonpage++; 00092 $s .= $this->historyLine( 00093 $this->mArticle->getTimestamp(), 00094 $this->mArticle->getUser(), 00095 $this->mArticle->getUserText(), $namespace, 00096 $title, 0, $this->mArticle->getComment(), 00097 ( $this->mArticle->getMinorEdit() > 0 ), 00098 $counter++ 00099 ); 00100 } 00101 while ( $line = wfFetchObject( $res ) ) { 00102 $s .= $this->historyLine( 00103 $line->old_timestamp, $line->old_user, 00104 $line->old_user_text, $namespace, 00105 $title, $line->old_id, 00106 $line->old_comment, ( $line->old_minor_edit > 0 ), 00107 $counter++ 00108 ); 00109 } 00110 $s .= $this->endHistoryList( !$atend ); 00111 $s .= $numbar; 00112 $wgOut->addHTML( $s ); 00113 wfProfileOut( $fname ); 00114 } 00115 00116 function beginHistoryList() 00117 { 00118 global $wgTitle; 00119 $this->lastdate = $this->lastline = ""; 00120 $s = "\n<p>" . wfMsg( "histlegend" ).'</p>'; 00121 $s .="\n<form action=\"" . $wgTitle->escapeLocalURL( '-' ) . "\" method=\"get\">"; 00122 $s .= "<input type=\"hidden\" name=\"title\" value=\"".wfEscapeHTML($wgTitle->getPrefixedDbKey())."\"/>\n"; 00123 $s .= !empty($this->submitbuttonhtml1) ? $this->submitbuttonhtml1."\n":''; 00124 $s .= "" . "\n<ul id=\"pagehistory\" >"; 00125 return $s; 00126 } 00127 00128 function endHistoryList( $skip = false ) 00129 { 00130 $last = wfMsg( "last" ); 00131 00132 $s = $skip ? "" : preg_replace( "/!OLDID![0-9]+!/", $last, $this->lastline ); 00133 $s .= "</ul>"; 00134 $s .= !empty($this->submitbuttonhtml2) ? $this->submitbuttonhtml2."\n":''; 00135 $s .= "</form>\n"; 00136 return $s; 00137 } 00138 00139 function historyLine( $ts, $u, $ut, $ns, $ttl, $oid, $c, $isminor, $counter = '' ) 00140 { 00141 global $wgLang; 00142 00143 $artname = Title::makeName( $ns, $ttl ); 00144 $last = wfMsg( "last" ); 00145 $cur = wfMsg( "cur" ); 00146 $cr = wfMsg( "currentrev" ); 00147 00148 if ( $oid && $this->lastline ) { 00149 $ret = preg_replace( "/!OLDID!([0-9]+)!/", $this->mSkin->makeKnownLink( 00150 $artname, $last, "diff=\\1&oldid={$oid}",'' ,'' ,' tabindex="'.$counter.'"' ), $this->lastline ); 00151 } else { 00152 $ret = ""; 00153 } 00154 $dt = $wgLang->timeanddate( $ts, true ); 00155 00156 if ( $oid ) { 00157 $q = "oldid={$oid}"; 00158 } else { 00159 $q = ""; 00160 } 00161 $link = $this->mSkin->makeKnownLink( $artname, $dt, $q ); 00162 00163 if ( 0 == $u ) { 00164 $ul = $this->mSkin->makeKnownLink( $wgLang->specialPage( "Contributions" ), 00165 $ut, "target=" . $ut ); 00166 } else { 00167 $ul = $this->mSkin->makeLink( $wgLang->getNsText( 00168 Namespace::getUser() ) . ":{$ut}", $ut ); 00169 } 00170 00171 $s = "<li>"; 00172 if ( $oid ) { 00173 $curlink = $this->mSkin->makeKnownLink( $artname, $cur, 00174 "diff=0&oldid={$oid}" ); 00175 } else { 00176 $curlink = $cur; 00177 } 00178 $arbitrary = ""; 00179 if( $this->linesonpage > 1) { 00180 # XXX: move title texts to javascript 00181 $checkmark = ""; 00182 if ( !$oid ) { 00183 $arbitrary = '<input type="radio" style="visibility:hidden" name="oldid" value="'.$oid.'" title="'.wfMsg('selectolderversionfordiff').'" />'; 00184 $checkmark = ' checked="checked"'; 00185 } else { 00186 if( $counter == 2 ) $checkmark = ' checked="checked"'; 00187 $arbitrary = '<input type="radio" name="oldid" value="'.$oid.'" title="'.wfMsg('selectolderversionfordiff').'"'.$checkmark.' />'; 00188 $checkmark = ''; 00189 } 00190 $arbitrary .= '<input type="radio" name="diff" value="'.$oid.'" title="'.wfMsg('selectnewerversionfordiff').'"'.$checkmark.' />'; 00191 } 00192 $s .= "({$curlink}) (!OLDID!{$oid}!) $arbitrary {$link} <span class='user'>{$ul}</span>"; 00193 $s .= $isminor ? ' <span class="minor">'.wfMsg( "minoreditletter" ).'</span>': '' ; 00194 00195 00196 if ( "" != $c && "*" != $c ) { 00197 00198 $c = $this->mSkin->formatcomment($c); 00199 $s .= " <em>(" . $c . ")</em>"; 00200 } 00201 $s .= "</li>\n"; 00202 00203 $this->lastline = $s; 00204 return $ret; 00205 } 00206 00207 } 00208 00209 ?>

Generated on Tue Jun 29 23:40:06 2004 for Mediawiki by doxygen 1.3.7