Split off page history code to PageHistory.php out of Article.php and Skin.php.
authorBrion Vibber <brion@users.mediawiki.org>
Sun, 21 Dec 2003 12:01:29 +0000 (12:01 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Sun, 21 Dec 2003 12:01:29 +0000 (12:01 +0000)
No substantive changes yet.

includes/Article.php
includes/PageHistory.php [new file with mode: 0644]
includes/Skin.php
wiki.phtml

index 56ec140..470fffd 100644 (file)
@@ -597,79 +597,6 @@ class Article {
                $this->watch( false );
        }
 
-       # This shares a lot of issues (and code) with Recent Changes
-
-       function history()
-       {
-               global $wgUser, $wgOut, $wgLang, $offset, $limit;
-
-               # If page hasn't changed, client can cache this
-               
-               if( $wgOut->checkLastModified( $this->getTimestamp() ) ){
-                       # Client cache fresh and headers sent, nothing more to do.
-                       return;
-               }
-               $fname = "Article::history";
-               wfProfileIn( $fname );
-
-               $wgOut->setPageTitle( $this->mTitle->getPRefixedText() );
-               $wgOut->setSubtitle( wfMsg( "revhistory" ) );
-               $wgOut->setArticleFlag( false );
-               $wgOut->setRobotpolicy( "noindex,nofollow" );
-
-               if( $this->mTitle->getArticleID() == 0 ) {
-                       $wgOut->addHTML( wfMsg( "nohistory" ) );
-                       wfProfileOut( $fname );
-                       return;
-               }
-               
-               $offset = (int)$offset;
-               $limit = (int)$limit;
-               if( $limit == 0 ) $limit = 50;
-               $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 $offset, $limit";
-               $res = wfQuery( $sql, DB_READ, "Article::history" );
-
-               $revs = wfNumRows( $res );
-               if( $this->mTitle->getArticleID() == 0 ) {
-                       $wgOut->addHTML( wfMsg( "nohistory" ) );
-                       wfProfileOut( $fname );
-                       return;
-               }
-               
-               $sk = $wgUser->getSkin();
-               $numbar = wfViewPrevNext(
-                       $offset, $limit,
-                       $this->mTitle->getPrefixedText(),
-                       "action=history" );
-               $s = $numbar;
-               $s .= $sk->beginHistoryList();
-
-               if($offset == 0 )
-               $s .= $sk->historyLine( $this->getTimestamp(), $this->getUser(),
-                 $this->getUserText(), $namespace,
-                 $title, 0, $this->getComment(),
-                 ( $this->getMinorEdit() > 0 ) );
-
-               $revs = wfNumRows( $res );
-               while ( $line = wfFetchObject( $res ) ) {
-                       $s .= $sk->historyLine( $line->old_timestamp, $line->old_user,
-                         $line->old_user_text, $namespace,
-                         $title, $line->old_id,
-                         $line->old_comment, ( $line->old_minor_edit > 0 ) );
-               }
-               $s .= $sk->endHistoryList();
-               $s .= $numbar;
-               $wgOut->addHTML( $s );
-               wfProfileOut( $fname );
-       }
-
        function protect( $limit = "sysop" )
        {
                global $wgUser, $wgOut;
diff --git a/includes/PageHistory.php b/includes/PageHistory.php
new file mode 100644 (file)
index 0000000..d3fbff6
--- /dev/null
@@ -0,0 +1,163 @@
+<?php
+
+/* Page history
+   Split off from Article.php and Skin.php, 2003-12-22
+*/
+
+class PageHistory {
+       var $mArticle, $mTitle, $mSkin;
+       var $lastline, $lastdate;
+       
+       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, $offset, $limit;
+
+               # 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->setRobotpolicy( "noindex,nofollow" );
+
+               if( $this->mTitle->getArticleID() == 0 ) {
+                       $wgOut->addHTML( wfMsg( "nohistory" ) );
+                       wfProfileOut( $fname );
+                       return;
+               }
+               
+               $offset = (int)$offset;
+               $limit = (int)$limit;
+               if( $limit == 0 ) $limit = 50;
+               $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 $offset, $limit";
+               $res = wfQuery( $sql, DB_READ, $fname );
+
+               $revs = wfNumRows( $res );
+               if( $this->mTitle->getArticleID() == 0 ) {
+                       $wgOut->addHTML( wfMsg( "nohistory" ) );
+                       wfProfileOut( $fname );
+                       return;
+               }
+               
+               $this->mSkin = $wgUser->getSkin();
+               $numbar = wfViewPrevNext(
+                       $offset, $limit,
+                       $this->mTitle->getPrefixedText(),
+                       "action=history" );
+               $s = $numbar;
+               $s .= $this->beginHistoryList();
+
+               if($offset == 0 )
+               $s .= $this->historyLine( $this->mArticle->getTimestamp(), $this->mArticle->getUser(),
+                 $this->mArticle->getUserText(), $namespace,
+                 $title, 0, $this->mArticle->getComment(),
+                 ( $this->mArticle->getMinorEdit() > 0 ) );
+
+               $revs = wfNumRows( $res );
+               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 ) );
+               }
+               $s .= $this->endHistoryList();
+               $s .= $numbar;
+               $wgOut->addHTML( $s );
+               wfProfileOut( $fname );
+       }
+
+       function beginHistoryList()
+       {
+               $this->lastdate = $this->lastline = "";
+               $s = "\n<p>" . wfMsg( "histlegend" ) . "\n<ul>";
+               return $s;
+       }
+
+       function endHistoryList()
+       {
+               $last = wfMsg( "last" );
+
+               $s = preg_replace( "/!OLDID![0-9]+!/", $last, $this->lastline );
+               $s .= "</ul>\n";
+               return $s;
+       }
+
+       function historyLine( $ts, $u, $ut, $ns, $ttl, $oid, $c, $isminor )
+       {
+               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}" ), $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;
+               }
+               $s .= "({$curlink}) (!OLDID!{$oid}!) . .";
+
+               $M = wfMsg( "minoreditletter" );
+               if ( $isminor ) {
+                       $s .= " <strong>{$M}</strong>";
+               }
+               $s .= " {$link} . . {$ul}";
+
+               if ( "" != $c && "*" != $c ) {
+                       $s .= " <em>(" . wfEscapeHTML($c) . ")</em>";
+               }
+               $s .= "</li>\n";
+
+               $this->lastline = $s;
+               return $ret;
+       }
+
+}
+
+?>
index a26ebd7..16c400e 100644 (file)
@@ -1455,13 +1455,6 @@ class Skin {
                return "";
        }
 
-       function beginHistoryList()
-       {
-               $this->lastdate = $this->lastline = "";
-               $s = "\n<p>" . wfMsg( "histlegend" ) . "\n<ul>";
-               return $s;
-       }
-
        function beginImageHistoryList()
        {
                $s = "\n<h2>" . wfMsg( "imghistory" ) . "</h2>\n" .
@@ -1476,69 +1469,12 @@ class Skin {
                return $s;
        }
 
-       function endHistoryList()
-       {
-               $last = wfMsg( "last" );
-
-               $s = preg_replace( "/!OLDID![0-9]+!/", $last, $this->lastline );
-               $s .= "</ul>\n";
-               return $s;
-       }
-
        function endImageHistoryList()
        {
                $s = "</ul>\n";
                return $s;
        }
 
-       function historyLine( $ts, $u, $ut, $ns, $ttl, $oid, $c, $isminor )
-       {
-               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->makeKnownLink(
-                         $artname, $last, "diff=\\1&oldid={$oid}" ), $this->lastline );
-               } else {
-                       $ret = "";
-               }
-               $dt = $wgLang->timeanddate( $ts, true );
-
-               if ( $oid ) { $q = "oldid={$oid}"; }
-               else { $q = ""; }
-               $link = $this->makeKnownLink( $artname, $dt, $q );
-
-               if ( 0 == $u ) {
-                       $ul = $this->makeKnownLink( $wgLang->specialPage( "Contributions" ),
-                       $ut, "target=" . $ut );
-               } else { 
-                       $ul = $this->makeLink( $wgLang->getNsText(
-                               Namespace::getUser() ) . ":{$ut}", $ut ); }
-
-               $s = "<li>";
-               if ( $oid ) {
-                       $curlink = $this->makeKnownLink( $artname, $cur,
-                         "diff=0&oldid={$oid}" );
-               } else {
-                       $curlink = $cur;
-               }
-               $s .= "({$curlink}) (!OLDID!{$oid}!) . .";
-
-               $M = wfMsg( "minoreditletter" );
-               if ( $isminor ) { $s .= " <strong>{$M}</strong>"; }
-               $s .= " {$link} . . {$ul}";
-
-               if ( "" != $c && "*" != $c ) { $s .= " <em>(" . wfEscapeHTML($c) . ")</em>"; }
-               $s .= "</li>\n";
-
-               $this->lastline = $s;
-               return $ret;
-       }
-
        function recentChangesBlockLine ( $y ) {
                global $wgUploadPath ;
 
index 5141de3..962a97e 100644 (file)
@@ -74,7 +74,6 @@ if ( Namespace::getSpecial() == $wgTitle->getNamespace() ) {
                case "view":
                case "watch":
                case "unwatch":
-               case "history":
                case "delete":
                case "revert":
                case "rollback":
@@ -91,6 +90,11 @@ if ( Namespace::getSpecial() == $wgTitle->getNamespace() ) {
                        $editor = new EditPage( $wgArticle );
                        $editor->$action();
                        break;
+               case "history":
+                       include_once( "PageHistory.php" );
+                       $history = new PageHistory( $wgArticle );
+                       $history->history();
+                       break;
                default:
                        $wgOut->errorpage( "nosuchaction", "nosuchactiontext" );
        }