first version (not usable)
[lhc/web/wiklou.git] / includes / SpecialForum.php
1 <?php
2 /**
3 *
4 * @package MediaWiki
5 * @subpackage SpecialPage
6 */
7
8 /**
9 * constructor
10 */
11 function wfSpecialForum()
12 {
13 $forum = new Forum( $isbn );
14 echo $forum->Generate();
15 }
16
17 class Thread
18 {
19 var $title;
20 var $comment;
21 var $user;
22 var $timestamp;
23 var $count;
24 }
25
26 class Forum
27 {
28 var $mMainPage;
29 var $mMaxThread;
30 var $mMaxFullText;
31 var $mSumLength;
32
33 function Forum()
34 {
35 $this->SetMainPage( "Forum" );
36 $this->mMaxThread = 50;
37 $this->mMaxFullText = 10;
38 $this->mSumLength = 30;
39 }
40
41 function SetMainPage( $mp )
42 {
43 global $wgLang;
44 $this->mMainPage = $wgLang->getNsText( NS_WIKIPEDIA ) . ":$mp";
45 }
46
47 function Generate()
48 {
49 global $wgLang, $wgServer;
50
51 $fname = 'Forum::generate';
52
53 // Get last X modified thread
54 wfDebug("FORUM - START GENERATE\n");
55 $dbr =& wfGetDB( DB_SLAVE );
56 $cur = $dbr->tableName( 'cur' );
57 $sql = "SELECT cur_title, cur_comment, cur_user_text, cur_timestamp, cur_counter FROM $cur".
58 "WHERE cur_namespace = ".NS_THREAD.
59 "AND cur_is_redirect = 0".
60 "ORDER BY cur_timestamp DESC".
61 "LIMIT $this->mMaxThread";
62 $res = $dbr->query( $sql, $fname ) ;
63 $num = mysql_num_rows( $res );
64
65 // Generate forum's text
66 $text = "";
67 $text .= "<!-- This page was generated by forum.php -->\n";
68 $text .= "__NOEDITSECTION__\n";
69
70 $tab = array();
71 $cnt = 0;
72 while( $x = mysql_fetch_array( $res ) )
73 {
74 $cnt++;
75 $tab[$num-$cnt] = new Thread;
76 $tab[$num-$cnt]->title = $x['cur_title'];
77 $tab[$num-$cnt]->comment = $x['cur_comment'];
78 $tab[$num-$cnt]->user = $x['cur_user_text'];
79 $tab[$num-$cnt]->timestamp = $x['cur_timestamp'];
80 $tab[$num-$cnt]->count = $x['cur_counter'];
81 if(strlen($tab[$num-$cnt]->comment) > $this->mSumLength)
82 $tab[$num-$cnt]->comment = substr($tab[$num-$cnt]->comment, 0, $this->mSumLength) . "...";
83 }
84 mysql_free_result( $res );
85
86 $summary = $num - $this->mMaxFullText;
87
88 if($summary > 0)
89 {
90 //$text .= "==Last thread==\n";
91 $text .= "{| border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\"100%\" style=\"border:1px solid black;\"\n";
92 $text .= "|- bgcolor=\"#D0D0D0\"\n";
93 $text .= "! Thread !! Cnt !! Last user !! Last comment !! Time\n";
94 }
95
96 for( $cnt=0; $cnt<$num; $cnt++ )
97 {
98 $t = $wgLang->getNsText( NS_THREAD );
99 if ( $t != '' )
100 $t .= ':' ;
101 $t .= $tab[$cnt]->title;
102
103 $title = Title::newFromText( $t );
104
105 if($cnt < $summary)
106 {
107 if($cnt & 1)
108 $text .= "|- bgcolor=\"#F0F0F0\"\n";
109 else
110 $text .= "|- bgcolor=\"#FFFFFF\"\n";
111 $text .= "| [[$t|". $tab[$cnt]->title ."]] || ". $tab[$cnt]->count ." || [[".
112 $wgLang->getNsText( NS_USER ) .":". $tab[$cnt]->user ."|" .$tab[$cnt]->user. "]] || ". $tab[$cnt]->comment ." || ".
113 $wgLang->timeanddate($tab[$cnt]->timestamp) ."\n";
114 }
115 else
116 {
117 $text .= "<h1>[[$t|". $tab[$cnt]->title ."]]</h1>\n";
118 $text .= "{{{$t}}}\n\n";
119 $text .= "'''> [$wgServer" . $title->getEditUrl() ." Add a message]'''\n\n";
120 }
121
122 if($cnt == $summary-1)
123 {
124 if($summary > 0)
125 {
126 $text .= "|}\n\n";
127 }
128 }
129 }
130
131 $text .= "\n'''[[Create a new thread]]'''";
132
133 wfDebug( $text );
134 /*
135 // Generate forum's main page
136 wfDebug("FORUM - CREATE PAGE <$this->mMainPage>\n");
137 $title = Title::newFromText( $this->mMainPage );
138 $article = new Article( $title );
139 $ok = $article->updateArticle($text, "Upade forum", true, false);
140 if($ok)
141 wfDebug("FORUM - UPDATE SUCCED\n");
142 else
143 wfDebug("FORUM - UPDATE FAILED\n");
144 */
145 wfDebug("FORUM - END GENERATE\n");
146
147 return $text;
148 }
149 }
150
151 ?>