5 * @subpackage SpecialPage
11 function wfSpecialForum()
13 $forum = new Forum( $isbn );
14 echo $forum->Generate();
20 * @subpackage SpecialPage
33 * @subpackage SpecialPage
43 $this->SetMainPage( "Forum" );
44 $this->mMaxThread
= 50;
45 $this->mMaxFullText
= 10;
46 $this->mSumLength
= 30;
50 function SetMainPage( $mp ) {
52 $this->mMainPage
= $wgLang->getNsText( NS_WIKIPEDIA
) . ":$mp";
56 global $wgLang, $wgServer;
58 $fname = 'Forum::generate';
60 // Get last X modified thread
61 wfDebug("FORUM - START GENERATE\n");
62 $dbr =& wfGetDB( DB_SLAVE
);
63 $cur = $dbr->tableName( 'cur' );
64 $sql = "SELECT cur_title, cur_comment, cur_user_text, cur_timestamp, cur_counter FROM $cur".
65 "WHERE cur_namespace = ".NS_THREAD
.
66 "AND cur_is_redirect = 0".
67 "ORDER BY cur_timestamp DESC".
68 "LIMIT $this->mMaxThread";
69 $res = $dbr->query( $sql, $fname ) ;
70 $num = mysql_num_rows( $res );
72 // Generate forum's text
74 $text .= "<!-- This page was generated by forum.php -->\n";
75 $text .= "__NOEDITSECTION__\n";
80 while( $x = mysql_fetch_array( $res ) ) {
82 $tab[$num-$cnt] = new Thread
;
83 $tab[$num-$cnt]->title
= $x['cur_title'];
84 $tab[$num-$cnt]->comment
= $x['cur_comment'];
85 $tab[$num-$cnt]->user
= $x['cur_user_text'];
86 $tab[$num-$cnt]->timestamp
= $x['cur_timestamp'];
87 $tab[$num-$cnt]->count
= $x['cur_counter'];
88 if(strlen($tab[$num-$cnt]->comment
) > $this->mSumLength
) {
89 $tab[$num-$cnt]->comment
= substr($tab[$num-$cnt]->comment
, 0, $this->mSumLength
) . "...";
93 // FIXME !! Use database abastraction layer
94 mysql_free_result( $res );
96 $summary = $num - $this->mMaxFullText
;
99 //$text .= "==Last thread==\n";
100 $text .= "{| border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\"100%\" style=\"border:1px solid black;\"\n";
101 $text .= "|- bgcolor=\"#D0D0D0\"\n";
102 $text .= "! Thread !! Cnt !! Last user !! Last comment !! Time\n";
105 for( $cnt=0; $cnt<$num; $cnt++
) {
106 $t = $wgLang->getNsText( NS_THREAD
);
107 if ( $t != '' ) { $t .= ':' ; }
108 $t .= $tab[$cnt]->title
;
110 $title = Title
::newFromText( $t );
112 if($cnt < $summary) {
114 $text .= "|- bgcolor=\"#F0F0F0\"\n";
116 $text .= "|- bgcolor=\"#FFFFFF\"\n";
118 $text .= "| [[$t|". $tab[$cnt]->title
."]] || ". $tab[$cnt]->count
." || [[".
119 $wgLang->getNsText( NS_USER
) .":". $tab[$cnt]->user
."|" .$tab[$cnt]->user
. "]] || ". $tab[$cnt]->comment
." || ".
120 $wgLang->timeanddate($tab[$cnt]->timestamp
) ."\n";
122 $text .= "<h1>[[$t|". $tab[$cnt]->title
."]]</h1>\n";
123 $text .= "{{{$t}}}\n\n";
124 $text .= "'''> [$wgServer" . $title->getEditUrl() ." Add a message]'''\n\n";
127 if($cnt == $summary-1) {
134 $text .= "\n'''[[Create a new thread]]'''";
138 // Generate forum's main page
139 wfDebug("FORUM - CREATE PAGE <$this->mMainPage>\n");
140 $title = Title::newFromText( $this->mMainPage );
141 $article = new Article( $title );
142 $ok = $article->updateArticle($text, "Upade forum", true, false);
144 wfDebug("FORUM - UPDATE SUCCED\n");
146 wfDebug("FORUM - UPDATE FAILED\n");
148 wfDebug("FORUM - END GENERATE\n");