* Avoid PHP warning messages when thumbnail not generated
[mediawiki.git] / includes / SpecialForum.php
blobc2009deed0f7cb45e93ed58ce69969a03bea0def
1 <?php
2 /**
4 * @package MediaWiki
5 * @subpackage SpecialPage
6 */
8 /**
9 * constructor
11 function wfSpecialForum()
13 $forum = new Forum( $isbn );
14 echo $forum->Generate();
17 class Thread
19 var $title;
20 var $comment;
21 var $user;
22 var $timestamp;
23 var $count;
26 class Forum
28 var $mMainPage;
29 var $mMaxThread;
30 var $mMaxFullText;
31 var $mSumLength;
33 function Forum()
35 $this->SetMainPage( "Forum" );
36 $this->mMaxThread = 50;
37 $this->mMaxFullText = 10;
38 $this->mSumLength = 30;
41 function SetMainPage( $mp )
43 global $wgLang;
44 $this->mMainPage = $wgLang->getNsText( NS_WIKIPEDIA ) . ":$mp";
47 function Generate()
49 global $wgLang, $wgServer;
51 $fname = 'Forum::generate';
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 );
65 // Generate forum's text
66 $text = "";
67 $text .= "<!-- This page was generated by forum.php -->\n";
68 $text .= "__NOEDITSECTION__\n";
70 $tab = array();
71 $cnt = 0;
72 while( $x = mysql_fetch_array( $res ) )
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) . "...";
84 mysql_free_result( $res );
86 $summary = $num - $this->mMaxFullText;
88 if($summary > 0)
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";
96 for( $cnt=0; $cnt<$num; $cnt++ )
98 $t = $wgLang->getNsText( NS_THREAD );
99 if ( $t != '' )
100 $t .= ':' ;
101 $t .= $tab[$cnt]->title;
103 $title = Title::newFromText( $t );
105 if($cnt < $summary)
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";
115 else
117 $text .= "<h1>[[$t|". $tab[$cnt]->title ."]]</h1>\n";
118 $text .= "{{{$t}}}\n\n";
119 $text .= "'''> [$wgServer" . $title->getEditUrl() ." Add a message]'''\n\n";
122 if($cnt == $summary-1)
124 if($summary > 0)
126 $text .= "|}\n\n";
131 $text .= "\n'''[[Create a new thread]]'''";
133 wfDebug( $text );
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");
145 wfDebug("FORUM - END GENERATE\n");
147 return $text;