From c34b7cd31075ef2df9713667c91c26bb7bd46a1a Mon Sep 17 00:00:00 2001 From: Guillaume Blanchard Date: Tue, 21 Dec 2004 16:11:34 +0000 Subject: [PATCH] first version (not usable) --- includes/SpecialForum.php | 151 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 151 insertions(+) create mode 100644 includes/SpecialForum.php diff --git a/includes/SpecialForum.php b/includes/SpecialForum.php new file mode 100644 index 0000000000..c2009deed0 --- /dev/null +++ b/includes/SpecialForum.php @@ -0,0 +1,151 @@ +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 .= "\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 .= "

[[$t|". $tab[$cnt]->title ."]]

\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; + } +} + +?> -- 2.20.1