Extension:PhpBB ShowTopic

From MediaWiki.org
Jump to navigation Jump to search
MediaWiki extensions manual
OOjs UI icon advanced.svg
phpBB_ShowTopic
Release status: experimental
Implementation Tag
Description Show phpBB topic inside Mediawiki's Pages
Author(s) runey71 (Runey71talk)
Latest version 0.1
License No license specified
Download Extension:PhpBB_ShowTopic#Code
Thos Version is Tested on phpBB 3.x
0.1 - Initial Release
Example see Wiki
require_once("$IP/extensions/phpBB_ShowTopic/phpBB_ShowTopic.php");
Translate the PhpBB ShowTopic extension if it is available at translatewiki.net
Check usage and version matrix.

What can this extension do?[edit]

This extension can show a pbpBB topic and a specified number of posts within MediaWiki.

Usage[edit]

<phpbb_topic>forumId|topicId|postLimit|bgColour</phpbb_topic>

  • forumId = Unique ID of the forum containing the topic you wish to display
  • topicId = Unique ID of the topic you wish to display
  • postLimit = Maximum number of posts to display from the selected topic
  • bgColour = Background colour ie: FEFAF3

Download instructions[edit]

Please cut and paste the code found below and place it in $IP/extensions/phpBB_ShowTopic/phpBB_ShowTopic.php. Note: $IP stands for the root directory of your MediaWiki installation, the same directory that holds LocalSettings.php.

Installation[edit]

To install this extension, add the following to LocalSettings.php:

require_once("$IP/extensions/phpBB_ShowTopic/phpBB_ShowTopic.php");

Configuration parameters[edit]

Inside PHPBB_ShowForum.php you have to change this parameter in according with your forum configuration:

  $phpbbDBSERVER= MySQL Host
  $phpbbDBUSER= MySQL User
  $phpbbDBUSERPW= MySQL Password
  $phpbbDBNAME= MySQL Database Name
  $phpbbDBPrefix="phpbb_" PHPbb's Table prefix (Usually no changes needed)

  $phpbb_home = "http://www.yoursite.com/forum/" Full Address of your forum

Code[edit]

<?php
/*
 * Installation:
 *      require_once("extensions/phpBB_ShowTopic/phpBB_ShowTopic.php"); in LocalSettings.php
 *      update  $phpbbDBSERVER,  $phpbbDBUSER,  $phpbbDBUSERPW,  $phpbbDBNAME, $phpbbDBPrefix, $phpbb_home
 * Usage:
 *      <phpbb_topic>forumID|topicID|postLimit|bgColour</phpbb_topic>
 *
 * @version 0.1 runey71
 *
 * 0.1 - Initial Release
 *
 * http://www.mediawiki.org/wiki/Extension:phpBB_ShowTopic
 */
 
if( !defined( 'MEDIAWIKI' ) ) {
        echo( "This is an extension to the MediaWiki package and cannot be run standalone.\n" );
        die( -1 );
}
 
// Extension credits that will show up on Special:Version
$wgExtensionCredits['parserhook']['phpBB_ShowTopic'] = array(
        'name'         => 'phpBB Show Topic',
        'version'      => '0.1',
        'author'       => 'runey71, [http://www.mediawiki.org/wiki/User:Runey71]',
        'description'  => 'Link to Show phpBB Topic in MediaWiki',
        'url'          => ''
);
 
 
$wgExtensionFunctions[] = "wfPHPBBExtension";
 
function wfPHPBBExtension() {
        global $wgParser;
        $wgParser->setHook( "phpbb_topic", "showTopic" );
}
 
function showTopic( $input, $argv, &$parser) {
 
   $phpbbDBSERVER="Database Address";
   $phpbbDBUSER="Username";
   $phpbbDBUSERPW="Password";
   $phpbbDBNAME="Database Name";
   $phpbbDBPrefix="phpbb_";
 
   $phpbb_home = "http://www.example.com/forum/";
 
    # --------------------------------------------
 
        //Disabling Cache
    $parser->disableCache();
 
        //Split input in 2 Parameters
        list($forumID, $topicID, $postLimit, $bgColour) = split('[|.-]', $input);
 
 
    $link = mysql_connect($phpbbDBSERVER,$phpbbDBUSER ,$phpbbDBUSERPW);
    if ( !$link ) { return "<hr><b>Error while connecting to host \"$phpbbDBSERVER\" !</b><hr>"; }
 
    $db_selected = mysql_select_db($phpbbDBNAME, $link);
    if (!$db_selected) {return "<hr><b>Error while selecting database \"$phpbbDBNAME\" !</b><hr>"; }
						
        $sql = "SELECT p.forum_id, p.topic_id, p.post_id, p.post_text
				FROM ". $phpbbDBPrefix ."topics AS t, 
                ". $phpbbDBPrefix ."posts AS p 
				WHERE p.forum_id = $forumID
				AND p.topic_id = $topicID
				ORDER BY p.post_id ASC 
				LIMIT 0, $postLimit"; 

    $qryres = mysql_query($sql);
    if (!$qryres) { return "<hr><b>Error while MySQL Query :". mysql_error() ;}
 
        $out = "<table width=\"100%\"  border=\"0\" cellspacing=\"0\" cellpadding=\"1\">";
        $row_count = 0;
        //Cycle inside recordset and populate page
                while ($row = mysql_fetch_row($qryres))
                {
                        $out = $out . " <tr style=\"background-color: #$bgColour\"><td width=\"80%\">".$row[3]."</td></tr>";
 
                }  //End While
 
                $out = $out . "</table>";
 
    mysql_free_result($qryres);
 
        return $out;
}
 
?>

To Do[edit]

  • Add BBCode Parser
  • Improve layout
  • What to do with URLs in topic posts that link back to other topic posts. Leave as is or turn into MediaWiki links?
  • Check code and update to suit MediaWiki 1.15 or later (if not already)

See also[edit]