Extension:CodeBrowser

From MediaWiki.org
Jump to: navigation, search
MediaWiki extensions manual - list
Crystal Clear action run.png
CodeBrowser

Release status: beta

CodeBrowserScreenShot.png
Implementation Tag
Description Browse and display source code within page
Author(s) Dan Riedler (driedlertalk)
Latest version 0.1b (October 2011)
MediaWiki 1.17+
License public domain
Download Code
Parameters

$wg_codebrowser_config

Translate the CodeBrowser extension if possible

Check usage and version matrix; code metrics


Summary[edit | edit source]

This extension allows users to browse and display syntax-highlighted source code within a page. Currently the source code must be in a publicly accessible directory of the same server on which this extension is running.


Quick Example[edit | edit source]

On a mediawiki page, add the following tag:

<CodeBrowser startdir="path_relative_to_web_root"  />

where the attribute 'startdir' is a path to a source code directory relative to the web site root directory.

Live Demo[edit | edit source]

A live demo of this extension can be see here: CodeBrowser Demo

Installation[edit | edit source]

Pre-Install Requirements[edit | edit source]

This extension leverages two other extensions:

  1. Extension:Include
  2. SyntaxHighlight_GeSHi

These must be downloaded an installed first. Simply download each of these extension and upload them to your [mediawiki path]/extensions directory.

Install[edit | edit source]

  • Download the CodeBrowser extension from HERE
  • Extract and upload the entire CodeBrowser directory to your [mediawiki path]/extensions directory on your server (i.e. create a folder on your server: [mediawiki path]/extensions/CodeBrowser, and copy the files and folders in your downloaded CodeBrowser folder to your newly created folder on your server)
  • Add the following lines to your LocalSettings.php
require_once("$IP/extensions/SyntaxHighlight_GeSHi/SyntaxHighlight_GeSHi.php");
require_once("$IP/extensions/secure-include.php");                                                                                                                       
require_once("$IP/extensions/CodeBrowser/CodeBrowser.php");
$wg_codebrowser_config['basedir'] = "absolute_path_to_your_webroot";
  • Modify $wg_codebrowser_config['basedir'] to be the absolute path to your webroot (see [[[Extension:CodeBrowser#HowTo Find Absolute Webroot Path|HowTo Find Absolute Webroot Path]]] for more info).
  • In codebrowser.css, modify the paths:
background: #ffffff url(/w/extensions/CodeBrowser/images/captop.jpg) repeat-x;
background: #ffffff url(/w/extensions/CodeBrowser/images/tbar.gif) repeat-x;
background: #ffffff url(/w/extensions/CodeBrowser/images/tbov.gif) repeat-x;
background: #fff url(/w/extensions/CodeBrowser/images/bbar.gif) repeat-x;

to the actual paths on your server (basically change '/w/' to where ever you installed mediawiki on your server). NOTE: this is the same path as: $wgScriptPath in LocalSettings.php

  • The extension is now installed, see the next section [[[Extension:CodeBrowser#How to Use This Extension|How to Use This Extension]]]

How to Use This Extension[edit | edit source]

To use this extension, simply include the following tag in a mediawiki page:

<CodeBrowser startdir="path_relative_to_web_root"  />

and set 'startdir' to whichever directory that contains source code you want the user to browse.

Attributes[edit | edit source]

This extension has the following attributes:

startdir (required)[edit | edit source]

specifies the path to project relative to the domain root
Example Usage
Say you have a website: http://mywiki.com
Also say you have a project with source code at:
http://mywiki.com/projects/my_project/src
Then, to let users browse this code on your wiki, simply add the following to a wiki page:
<CodeBrowser startdir="projects/my_project/src"  />

refpage (optional)[edit | edit source]

places link to page on footer of table
Example Usage
Say you have a project page: http://mywiki.com/wiki/Projects:My_Project
You can add a reference link to this page at the bottom of the code browsing portal by adding the : following attribute:
<CodeBrowser startdir="projects/my_project/src" refpage="Projects:My_Project" />

Parameters[edit | edit source]

Various parameters can be adjusted from this extension by modifying the:

$wg_codebrowser_config[]

parameter in LocalSettings.php

basedir
this is the absolute path to your webroot
lang
the language (currently only english is supported)
open_in_new_window
when opening a source file, open in new window? true/false
time_format
the day/time format displayed for source files (see Date/Time Format for more info)
hidden_dirs
array containing directories to hide
supported_files
supported file types. The currently supported files are:
  • asp
  • aspx
  • bat
  • c
  • cpp
  • cs
  • h
  • htm
  • html
  • java
  • js
  • m
  • php
  • py
  • rtf
  • txt
  • xml
  • xsd

Frequently Asked Questions[edit | edit source]

HowTo Find Absolute Webroot Path[edit | edit source]

This is the absolute path to your when site's root directory. On a linux/apache server setup, it looks something like:

/home/your_user_name/public_html/

Note that the leading slash is required on a linux setup.