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)
Last version 0.1b (October 2011)
MediaWiki 1.17+
License public domain
Download Code
Parameters

$wg_codebrowser_config

Check usage (experimental)


Contents

[edit] Summary

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.


[edit] Quick Example

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.

[edit] Live Demo

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

[edit] Installation

[edit] Pre-Install Requirements

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.

[edit] Install

  • 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]]]

[edit] How to Use This Extension

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.

[edit] Attributes

This extension has the following attributes:

[edit] startdir (required)

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"  />

[edit] refpage (optional)

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" />

[edit] Parameters

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

[edit] Frequently Asked Questions

[edit] HowTo Find Absolute Webroot Path

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.

Personal tools
Namespaces

Variants
Actions
Navigation
Support
Download
Development
Communication
Print/export
Toolbox