BUG#1402 Make link color of tab subject page link on talk page indicate whether artic...
[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 /**
18 *
19 * @package MediaWiki
20 * @subpackage SpecialPage
21 */
22 class Thread {
23 var $title;
24 var $comment;
25 var $user;
26 var $timestamp;
27 var $count;
28 }
29
30 /**
31 *
32 * @package MediaWiki
33 * @subpackage SpecialPage
34 */
35 class Forum {
36 var $mMainPage;
37 var $mMaxThread;
38 var $mMaxFullText;
39 var $mSumLength;
40
41 /** @todo document */
42 function Forum() {
43 $this->SetMainPage( "Forum" );
44 $this->mMaxThread = 50;
45 $this->mMaxFullText = 10;
46 $this->mSumLength = 30;
47 }
48
49 /** @todo document */
50 function SetMainPage( $mp ) {
51 global $wgLang;
52 $this->mMainPage = $wgLang->getNsText( NS_WIKIPEDIA ) . ":$mp";
53 }
54
55 function Generate() {
56 global $wgLang, $wgServer;
57
58 $fname = 'Forum::generate';
59
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 );
71
72 // Generate forum's text
73 $text = '';
74 $text .= "<!-- This page was generated by forum.php -->\n";
75 $text .= "__NOEDITSECTION__\n";
76
77 $tab = array();
78 $cnt = 0;
79
80 while( $x = mysql_fetch_array( $res ) ) {
81 $cnt++;
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) . "...";
90 }
91 }
92
93 // FIXME !! Use database abastraction layer
94 mysql_free_result( $res );
95
96 $summary = $num - $this->mMaxFullText;
97
98 if($summary > 0) {
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";
103 }
104
105 for( $cnt=0; $cnt<$num; $cnt++ ) {
106 $t = $wgLang->getNsText( NS_THREAD );
107 if ( $t != '' ) { $t .= ':' ; }
108 $t .= $tab[$cnt]->title;
109
110 $title = Title::newFromText( $t );
111
112 if($cnt < $summary) {
113 if($cnt & 1) {
114 $text .= "|- bgcolor=\"#F0F0F0\"\n";
115 } else {
116 $text .= "|- bgcolor=\"#FFFFFF\"\n";
117 }
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";
121 } else {
122 $text .= "<h1>[[$t|". $tab[$cnt]->title ."]]</h1>\n";
123 $text .= "{{{$t}}}\n\n";
124 $text .= "'''> [$wgServer" . $title->getEditUrl() ." Add a message]'''\n\n";
125 }
126
127 if($cnt == $summary-1) {
128 if($summary > 0) {
129 $text .= "|}\n\n";
130 }
131 }
132 }
133
134 $text .= "\n'''[[Create a new thread]]'''";
135
136 wfDebug( $text );
137 /*
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);
143 if($ok)
144 wfDebug("FORUM - UPDATE SUCCED\n");
145 else
146 wfDebug("FORUM - UPDATE FAILED\n");
147 */
148 wfDebug("FORUM - END GENERATE\n");
149
150 return $text;
151 }
152 }
153 ?>