r6791 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r6790‎ | r6791 | r6792 >
Date:10:07, 23 December 2004
Author:aoineko_jp
Status:old
Tags:
Comment:
stand alone version
Modified paths:
  • /trunk/extensions/wikiforum (added) (history)
  • /trunk/extensions/wikiforum/wikiforum.css (added) (history)
  • /trunk/extensions/wikiforum/wikiforum.php (added) (history)
  • /trunk/extensions/wikiforum/wikiforum.txt (added) (history)

Diff [purge]

Index: trunk/extensions/wikiforum/wikiforum.php
@@ -0,0 +1,332 @@
 2+<?php
 3+/* Wikiforum.php -- a basic forum extension for Mediawiki
 4+ * Copyright 2004 Guillaume Blanchard <aoineko@free.fr>
 5+ *
 6+ * This program is free software; you can redistribute it and/or modify
 7+ * it under the terms of the GNU General Public License as published by
 8+ * the Free Software Foundation; either version 2 of the License, or
 9+ * (at your option) any later version.
 10+ *
 11+ * This program is distributed in the hope that it will be useful,
 12+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
 13+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 14+ * GNU General Public License for more details.
 15+ *
 16+ * You should have received a copy of the GNU General Public License
 17+ * along with this program; if not, write to the Free Software
 18+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 19+ *
 20+ * @author Guillaume Blanchard <aoineko@free.fr>
 21+ * @package MediaWiki
 22+ * @subpackage Extensions
 23+ */
 24+
 25+/**
 26+ * This is not a valid entry point, perform no further processing unless MEDIAWIKI is defined
 27+ */
 28+if(defined('MEDIAWIKI'))
 29+{
 30+ $wgExtraNamespaces[NS_THREAD] = "Thread";
 31+
 32+ $wgExtensionFunctions[] = "wfForum";
 33+ $wgExtensionFunctions[] = "wfNewthread";
 34+
 35+ define('FORUM_VERSION', "1.0.1.0");
 36+ define('FORUM_MAX_THREAD', 50); // total number of last thread displayed on the forum page
 37+ define('FORUM_INCLUDED_NUM', 10); // number of thread directly included into the forum page
 38+ define('FORUM_SUM_LENGHT', 32); // maximum length of "last comment" field
 39+ define('FORUM_CSS', "$IP/extensions/wikiforum.css" ); // forum styles
 40+
 41+ /**
 42+ * New thread class
 43+ *
 44+ * @package MediaWiki
 45+ * @subpackage Extensions
 46+ */
 47+ class NewThread
 48+ {
 49+ function showForm()
 50+ {
 51+ global $wgOut, $wgUser, $wgRequest;
 52+
 53+ $wgOut->setPagetitle( wfMsg('ThreadNew') );
 54+ $wgOut->addLink(array(
 55+ "rel" => "stylesheet",
 56+ "type" => "text/css",
 57+ "media" => "screen,projection",
 58+ "href" => FORUM_CSS
 59+ ));
 60+
 61+ $titleObj = Title::makeTitle( NS_SPECIAL, "Newthread" );
 62+ $action = $titleObj->escapeLocalURL( "action=submit" );
 63+
 64+ $title = $wgRequest->getVal('threadTitle');
 65+ $desc = $wgRequest->getVal('threadDescription');
 66+
 67+ $rows = $wgUser->getOption( "rows" );
 68+ $cols = $wgUser->getOption( "cols" );
 69+ $wgOut->addHTML("<form id='newthread' method='post' action='{$action}'>\n".
 70+ wfMsg('ThreadTitle').": <input type='text' size='40' name='threadTitle' value='$title'/><br />\n".
 71+ "<textarea rows='$rows' cols='$cols' name='threadDescription'>$desc</textarea>\n".
 72+ "<input type='submit' value='".wfMsg('ThreadOpen')."'/>\n".
 73+ "</form>\n");
 74+ }
 75+
 76+ function doSubmit()
 77+ {
 78+ global $wgOut, $wgRequest, $wgParser, $wgUser;
 79+
 80+ $title = Title::makeTitle( NS_THREAD, ucfirst($wgRequest->getVal('threadTitle')) );
 81+
 82+ if($title->getArticleID() == 0) // article don't exist
 83+ {
 84+ $article = new Article( $title );
 85+ $article->insertNewArticle($wgRequest->getVal('threadDescription'), wfMsg('ThreadNew'), false, false);
 86+ }
 87+ else
 88+ {
 89+ $wgOut->addHTML("<div id=\"threadexist\">".wfMsg('ThreadExist')."</div>\n<br />\n");
 90+ $this->showForm();
 91+ }
 92+ }
 93+ }
 94+
 95+ /**
 96+ * Thread class
 97+ *
 98+ * @package MediaWiki
 99+ * @subpackage Extensions
 100+ */
 101+ class Thread
 102+ {
 103+ var $title;
 104+ var $comment;
 105+ var $user;
 106+ var $timestamp;
 107+ var $count;
 108+ }
 109+
 110+ /**
 111+ * Forum class
 112+ *
 113+ * @package MediaWiki
 114+ * @subpackage Extensions
 115+ */
 116+ class Forum
 117+ {
 118+ var $mMaxThread;
 119+ var $mMaxFullText;
 120+ var $mSumLength;
 121+
 122+ function Forum($thread=FORUM_MAX_THREAD, $included=FORUM_INCLUDED_NUM, $sum=FORUM_SUM_LENGHT)
 123+ {
 124+ $this->mMaxThread = $thread;
 125+ $this->mMaxFullText = $included;
 126+ $this->mSumLength = $sum;
 127+ }
 128+
 129+ function SetThreadNumber($thread=FORUM_MAX_THREAD)
 130+ {
 131+ $this->mMaxThread = $thread;
 132+ }
 133+
 134+ function SetIncludeNumber($included=FORUM_INCLUDED_NUM)
 135+ {
 136+ $this->mMaxFullText = $included;
 137+ }
 138+
 139+ function SetSummaryMaxLength($sum=FORUM_SUM_LENGHT)
 140+ {
 141+ $this->mSumLength = $sum;
 142+ }
 143+
 144+ function Generate()
 145+ {
 146+ global $wgLang, $wgServer;
 147+
 148+ $fname = 'Forum::generate';
 149+
 150+ // Get last X modified thread
 151+ wfDebug("FORUM - START GENERATE\n");
 152+ $dbr =& wfGetDB( DB_SLAVE );
 153+ $cur = $dbr->tableName( 'cur' );
 154+ $sql = "SELECT cur_title, cur_comment, cur_user_text, cur_timestamp, cur_counter FROM $cur".
 155+ " WHERE cur_namespace = ".NS_THREAD.
 156+ " AND cur_is_redirect = 0".
 157+ " ORDER BY cur_timestamp DESC".
 158+ " LIMIT $this->mMaxThread;";
 159+ $res = $dbr->query( $sql, $fname ) ;
 160+ $num = mysql_num_rows( $res );
 161+
 162+ // Generate forum's text
 163+ $text = "";
 164+ $text .= "__NOEDITSECTION____NOTOC__\n";
 165+ $text .= "<!-- This page was generated by forum.php -->\n";
 166+ $text .= "<div id=\"threadcreate\">[[Special:Newthread|".wfMsg('ThreadCreate')."]]</div>\n\n";
 167+
 168+ $text .= "> [{{SERVER}}{{localurl:Special:Allpages|from=&namespace=".NS_THREAD."}} ".wfMsg('ThreadAll')."]\n\n";
 169+
 170+ $tab = array();
 171+ $cnt = 0;
 172+ while( $x = mysql_fetch_array( $res ) )
 173+ {
 174+ $cnt++;
 175+ $tab[$num-$cnt] = new Thread;
 176+ $tab[$num-$cnt]->title = $x['cur_title'];
 177+ $tab[$num-$cnt]->comment = $x['cur_comment'];
 178+ $tab[$num-$cnt]->user = $x['cur_user_text'];
 179+ $tab[$num-$cnt]->timestamp = $x['cur_timestamp'];
 180+ $tab[$num-$cnt]->count = $x['cur_counter'];
 181+ if(strlen($tab[$num-$cnt]->comment) > $this->mSumLength)
 182+ $tab[$num-$cnt]->comment = substr($tab[$num-$cnt]->comment, 0, $this->mSumLength) . "...";
 183+ }
 184+ mysql_free_result( $res );
 185+
 186+ $summary = $num - $this->mMaxFullText;
 187+
 188+ if($summary > 0)
 189+ {
 190+ $text .= "<h1>$summary ".wfMsg('ThreadLastest')."</h1>\n";
 191+ $text .= "{| id=\"threadtable\" border=\"0\" cellspacing=\"0\" cellpadding=\"4px\" width=\"100%\"\n";
 192+ $text .= "|- id=\"threadtablehead\"\n";
 193+ $text .= "! ".wfMsg('ThreadName')." !! ".wfMsg('ThreadView')." !! ".wfMsg('ThreadUser')." !! ".wfMsg('ThreadComment')." !! ".wfMsg('ThreadTime')."\n";
 194+ }
 195+
 196+ for( $cnt=0; $cnt<$num; $cnt++ )
 197+ {
 198+ $t = $wgLang->getNsText( NS_THREAD );
 199+ if ( $t != '' )
 200+ $t .= ':' ;
 201+ $t .= $tab[$cnt]->title;
 202+
 203+ $title = Title::newFromText( $t );
 204+
 205+ if($cnt < $summary)
 206+ {
 207+ if($cnt & 1)
 208+ $text .= "|- class=\"threadrow\" id=\"threadrowodd\"\n";
 209+ else
 210+ $text .= "|- class=\"threadrow\" id=\"threadrowpeer\"\n";
 211+ $text .= "| [[$t|". $title->getText() ."]] ".
 212+ "|| ". $tab[$cnt]->count." ".
 213+ "|| [[". $wgLang->getNsText( NS_USER ) .":". $tab[$cnt]->user ."|" .$tab[$cnt]->user. "]] ".
 214+ "|| ". $tab[$cnt]->comment . " " .
 215+ "|| ". $wgLang->timeanddate($tab[$cnt]->timestamp) ."\n";
 216+ }
 217+ else
 218+ {
 219+ $text .= "<div id=\"threadcontent\">\n";
 220+ $text .= "<div id=\"threadedit\" style=\"float:right;\">[[$wgServer" . $title->getEditUrl() ." ".wfMsg('ThreadEdit')."]]</div>\n";
 221+ $text .= "==".$title->getText()."==\n";
 222+ $text .= "{{{$t}}}\n";
 223+ $text .= "</div>\n<br />\n";
 224+ }
 225+
 226+ if($cnt == $summary-1)
 227+ {
 228+ if($summary > 0)
 229+ $text .= "|}\n\n";
 230+ }
 231+ }
 232+
 233+ $text .= "<div id=\"threadcreate\">[[Special:Newthread|".wfMsg('ThreadCreate')."]]</div>";
 234+
 235+ wfDebug("FORUM - END GENERATE\n");
 236+
 237+ return $text;
 238+ }
 239+ }
 240+
 241+ $wgForum = new Forum();
 242+
 243+ /**
 244+ * Forum special page
 245+ *
 246+ * @package MediaWiki
 247+ * @subpackage Extensions
 248+ */
 249+ function wfForum()
 250+ {
 251+ global $IP;
 252+ require_once( "$IP/includes/SpecialPage.php" );
 253+
 254+ class SpecialForum extends SpecialPage
 255+ {
 256+ function SpecialForum()
 257+ {
 258+ SpecialPage::SpecialPage("Forum");
 259+ SpecialPage::setListed(true);
 260+ }
 261+
 262+ function execute()
 263+ {
 264+ global $wgOut, $wgForum;
 265+
 266+ $wgOut->setPagetitle('Forum');
 267+ $wgOut->addLink(array(
 268+ "rel" => "stylesheet",
 269+ "type" => "text/css",
 270+ "media" => "screen,projection",
 271+ "href" => FORUM_CSS
 272+ ));
 273+ $wgOut->addWikiText( $wgForum->Generate() );
 274+ }
 275+ }
 276+
 277+ global $wgMessageCache;
 278+ SpecialPage::addPage( new SpecialForum );
 279+ $wgMessageCache->addMessage( "ThreadName", "Name" );
 280+ $wgMessageCache->addMessage( "ThreadView", "View" );
 281+ $wgMessageCache->addMessage( "ThreadUser", "Last user" );
 282+ $wgMessageCache->addMessage( "ThreadComment", "Last comment" );
 283+ $wgMessageCache->addMessage( "ThreadTime", "Time" );
 284+ $wgMessageCache->addMessage( "ThreadEdit", "Edit" );
 285+ $wgMessageCache->addMessage( "ThreadCreate", "Create a new thread" );
 286+ $wgMessageCache->addMessage( "ThreadAll", "View all threads" );
 287+ $wgMessageCache->addMessage( "ThreadLastest", "lastest threads" );
 288+ }
 289+
 290+
 291+ /**
 292+ * New thread special page
 293+ *
 294+ * @package MediaWiki
 295+ * @subpackage Extensions
 296+ */
 297+ function wfNewthread()
 298+ {
 299+ global $IP;
 300+ require_once( "$IP/includes/SpecialPage.php" );
 301+
 302+ class SpecialNewthread extends SpecialPage
 303+ {
 304+ function SpecialNewthread()
 305+ {
 306+ SpecialPage::SpecialPage("Newthread");
 307+ SpecialPage::setListed(false);
 308+ }
 309+
 310+ function execute()
 311+ {
 312+ global $wgRequest, $action;
 313+
 314+ $nt = new NewThread();
 315+ if ( $action == "submit" && $wgRequest->wasPosted() )
 316+ $nt->doSubmit();
 317+ else
 318+ $nt->showForm();
 319+ }
 320+ }
 321+
 322+ global $wgMessageCache;
 323+ SpecialPage::addPage( new SpecialNewthread );
 324+ $wgMessageCache->addMessage( "ThreadNew", "New thread" );
 325+ $wgMessageCache->addMessage( "ThreadTitle", "Thread title" );
 326+ $wgMessageCache->addMessage( "ThreadOpen", "Open thread" );
 327+ $wgMessageCache->addMessage( "ThreadExist", "This thread already exist, please chose an other name!" );
 328+
 329+ }
 330+
 331+} // end if(defined('MEDIAWIKI'))
 332+
 333+?>
Property changes on: trunk/extensions/wikiforum/wikiforum.php
___________________________________________________________________
Added: svn:keywords
1334 + Author Date Id Revision
Added: svn:eol-style
2335 + native
Index: trunk/extensions/wikiforum/wikiforum.css
@@ -0,0 +1,41 @@
 2+form#newthread {}
 3+
 4+div#threadcreate
 5+{
 6+ border:1px solid #aaaaaa;
 7+ background-color:#f9f9f9;
 8+ padding:0.5em;
 9+ clear:both;
 10+ font-size:120%;
 11+ text-align:center;
 12+}
 13+
 14+div#threadexist { color:red; }
 15+
 16+table#threadtable { border:1px solid #aaaaaa; }
 17+
 18+th#threadtablehead
 19+{
 20+ background:#D0D0D0;
 21+ font-weight:bold;
 22+ padding:0.5em;
 23+}
 24+
 25+td.threadrow {}
 26+td.threadrow#threadrowodd { background:#F0F0F0; }
 27+td.threadrow#threadrowpeer { background:#FFFFFF; }
 28+
 29+div#threadcontent
 30+{
 31+ border:1px solid #aaaaaa;
 32+ background-color:white;
 33+ padding:1em;
 34+ clear:both;
 35+}
 36+
 37+div#threadedit
 38+{
 39+ margin-left:0.5em;
 40+ margin-bottom:0.5em;
 41+ float:right;
 42+}
\ No newline at end of file
Property changes on: trunk/extensions/wikiforum/wikiforum.css
___________________________________________________________________
Added: svn:keywords
143 + Author Date Id Revision
Added: svn:eol-style
244 + native
Index: trunk/extensions/wikiforum/wikiforum.txt
@@ -0,0 +1,29 @@
 2+Wikiforum.php -- a forum-like extension for Mediawiki
 3+Copyright 2004 Guillaume Blanchard <aoineko@free.fr>
 4+
 5+==============================================================================
 6+This program is free software; you can redistribute it and/or modify
 7+it under the terms of the GNU General Public License as published by
 8+the Free Software Foundation; either version 2 of the License, or
 9+(at your option) any later version.
 10+
 11+This program is distributed in the hope that it will be useful,
 12+but WITHOUT ANY WARRANTY; without even the implied warranty of
 13+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 14+GNU General Public License for more details.
 15+
 16+You should have received a copy of the GNU General Public License
 17+along with this program; if not, write to the Free Software
 18+Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 19+==============================================================================
 20+
 21+To install this extension, just add the below to your LocalSettings.php:
 22+
 23+ define('NS_THREAD', 110); // thread namespace (can be any thing greater than 100)
 24+ require_once( "extensions/wikiforum.php" );
 25+
 26+You can also configurate the forum with the fellowing functions:
 27+
 28+ $wgForum->SetThreadNumber(10); // set the total number of threads
 29+ $wgForum->SetIncludeNumber(3); // set the total number of full included threads
 30+ $wgForum->SetSummaryMaxLength(10); // set the maximum length of summary into threads table
Property changes on: trunk/extensions/wikiforum/wikiforum.txt
___________________________________________________________________
Added: svn:keywords
131 + Author Date Id Revision
Added: svn:eol-style
232 + native

Status & tagging log