--- /dev/null
+<?php
+/**
+ *
+ * @package MediaWiki
+ * @subpackage SpecialPage
+ */
+
+/**
+ * constructor
+ */
+function wfSpecialForum()
+{
+ $forum = new Forum( $isbn );
+ echo $forum->Generate();
+}
+
+class Thread
+{
+ var $title;
+ var $comment;
+ var $user;
+ var $timestamp;
+ var $count;
+}
+
+class Forum
+{
+ var $mMainPage;
+ var $mMaxThread;
+ var $mMaxFullText;
+ var $mSumLength;
+
+ function Forum()
+ {
+ $this->SetMainPage( "Forum" );
+ $this->mMaxThread = 50;
+ $this->mMaxFullText = 10;
+ $this->mSumLength = 30;
+ }
+
+ function SetMainPage( $mp )
+ {
+ global $wgLang;
+ $this->mMainPage = $wgLang->getNsText( NS_WIKIPEDIA ) . ":$mp";
+ }
+
+ function Generate()
+ {
+ global $wgLang, $wgServer;
+
+ $fname = 'Forum::generate';
+
+ // Get last X modified thread
+ wfDebug("FORUM - START GENERATE\n");
+ $dbr =& wfGetDB( DB_SLAVE );
+ $cur = $dbr->tableName( 'cur' );
+ $sql = "SELECT cur_title, cur_comment, cur_user_text, cur_timestamp, cur_counter FROM $cur".
+ "WHERE cur_namespace = ".NS_THREAD.
+ "AND cur_is_redirect = 0".
+ "ORDER BY cur_timestamp DESC".
+ "LIMIT $this->mMaxThread";
+ $res = $dbr->query( $sql, $fname ) ;
+ $num = mysql_num_rows( $res );
+
+ // Generate forum's text
+ $text = "";
+ $text .= "<!-- This page was generated by forum.php -->\n";
+ $text .= "__NOEDITSECTION__\n";
+
+ $tab = array();
+ $cnt = 0;
+ while( $x = mysql_fetch_array( $res ) )
+ {
+ $cnt++;
+ $tab[$num-$cnt] = new Thread;
+ $tab[$num-$cnt]->title = $x['cur_title'];
+ $tab[$num-$cnt]->comment = $x['cur_comment'];
+ $tab[$num-$cnt]->user = $x['cur_user_text'];
+ $tab[$num-$cnt]->timestamp = $x['cur_timestamp'];
+ $tab[$num-$cnt]->count = $x['cur_counter'];
+ if(strlen($tab[$num-$cnt]->comment) > $this->mSumLength)
+ $tab[$num-$cnt]->comment = substr($tab[$num-$cnt]->comment, 0, $this->mSumLength) . "...";
+ }
+ mysql_free_result( $res );
+
+ $summary = $num - $this->mMaxFullText;
+
+ if($summary > 0)
+ {
+ //$text .= "==Last thread==\n";
+ $text .= "{| border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\"100%\" style=\"border:1px solid black;\"\n";
+ $text .= "|- bgcolor=\"#D0D0D0\"\n";
+ $text .= "! Thread !! Cnt !! Last user !! Last comment !! Time\n";
+ }
+
+ for( $cnt=0; $cnt<$num; $cnt++ )
+ {
+ $t = $wgLang->getNsText( NS_THREAD );
+ if ( $t != '' )
+ $t .= ':' ;
+ $t .= $tab[$cnt]->title;
+
+ $title = Title::newFromText( $t );
+
+ if($cnt < $summary)
+ {
+ if($cnt & 1)
+ $text .= "|- bgcolor=\"#F0F0F0\"\n";
+ else
+ $text .= "|- bgcolor=\"#FFFFFF\"\n";
+ $text .= "| [[$t|". $tab[$cnt]->title ."]] || ". $tab[$cnt]->count ." || [[".
+ $wgLang->getNsText( NS_USER ) .":". $tab[$cnt]->user ."|" .$tab[$cnt]->user. "]] || ". $tab[$cnt]->comment ." || ".
+ $wgLang->timeanddate($tab[$cnt]->timestamp) ."\n";
+ }
+ else
+ {
+ $text .= "<h1>[[$t|". $tab[$cnt]->title ."]]</h1>\n";
+ $text .= "{{{$t}}}\n\n";
+ $text .= "'''> [$wgServer" . $title->getEditUrl() ." Add a message]'''\n\n";
+ }
+
+ if($cnt == $summary-1)
+ {
+ if($summary > 0)
+ {
+ $text .= "|}\n\n";
+ }
+ }
+ }
+
+ $text .= "\n'''[[Create a new thread]]'''";
+
+ wfDebug( $text );
+/*
+ // Generate forum's main page
+ wfDebug("FORUM - CREATE PAGE <$this->mMainPage>\n");
+ $title = Title::newFromText( $this->mMainPage );
+ $article = new Article( $title );
+ $ok = $article->updateArticle($text, "Upade forum", true, false);
+ if($ok)
+ wfDebug("FORUM - UPDATE SUCCED\n");
+ else
+ wfDebug("FORUM - UPDATE FAILED\n");
+*/
+ wfDebug("FORUM - END GENERATE\n");
+
+ return $text;
+ }
+}
+
+?>