Extension:ScuttleBookmarks
| This extension stores its source code on a wiki page. Please be aware that this code may be unreviewed or maliciously altered. They may contain security holes, outdated interfaces that are no longer compatible etc. Note: No localisation updates are provided for this extension by translatewiki.net. |
|
Scuttle Bookmarks Release status: stable |
|||
|---|---|---|---|
| Implementation | Tag | ||
| Description | Displays bookmarks from your Scuttle social bookmarking website in a blogroll type view on your Mediawiki website | ||
| Author(s) | Andreas Rindler (Lindeletalk) | ||
| Last version | 1.0 (and omCollabBookmarks 1.1) (2009-01-30) | ||
| MediaWiki | 1.10+ | ||
| Database changes | no | ||
| License | LGPL 2.1+ | ||
| Download | see here | ||
|
|||
|
|||
| Check usage and version matrix | |||
The ScuttleBookmarks extension allows users to display bookmarks from a Scuttle-based social bookmarking website (you have to install that site) in a simple text box within an article page on your MediaWiki website. Users configure query parameters that get passed to the extension. The extension creates client side Javascript-based http call to your Scuttle website and displays the results in the article.
Contents |
Usage [edit]
This extension would be used in a mashup between several wikis. For example, it can be put on a category page on one wiki to perform a query to a social bookmarking tool to display all bookmarks that have been tagged with the search term or where the search term matches the description of the bookmark. This allows users to quickly integrate social bookmarking capabilities with MediaWiki.
Here is an example how to use it within an article:
- displaytype (simple|blogroll) determines the display of the results list
- inputtype (searchterms|pagetitle|pagecategories) determines whether you will specify the search terms within the tags, whether to use the title of the page or to use the categories the article is assigned to
- searchtype (term|tag) determines whether the extension should use your search term across title, description and tags or only for tag.
- title (anystring) is displayed as the title above the results list
- <scuttlebookmarks>text</scuttlebookmarks> is the actual search term if you choose inputtype="searchterms"
Installation [edit]
Original [edit]
- Add the following to LocalSettings.php:
require_once('extensions/ScuttleBookmarks/ScuttleBookmarks.php');
- Create a folder ScuttleBookmarks in your MediaWiki extensions folder.
- Copy/paste the below PHP code into a text editor and save the file as ScuttleBookmarks.php in the ScuttleBookmarks folder.
- Copy/paste the CSS code into a text editor and save the file as ScuttleBookmarks.css in the same folder.
- Copy/paste the JavaScript code into a text editor and save the file as ScuttleBookmarks.js in the same folder.
Dependencies [edit]
The extension requires a new API file in your Scuttle installation. The newest version of Scuttle and the API file is available from: OM Bookmarks. Or if you want the API file only, download it here.
Current [edit]
The MIKE2.0 Team released the original extension under the new name omCollabBookmarks. It is available here: http://waterloo.openmethodology.org/trac/omcollab/browser/trunk/wiki/extensions/omCollabBookmarks
Code [edit]
- ScuttleBookmarks.php
<?php /** * mediawiki-scuttle bookmarks-extension : "Show Scuttle bookmarks on Your Site". * Copyright (C) 2007 Andreas Rindler * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * **/ /** * * @version 1.0 * @author Andreas Rindler * @copyright Andreas Rindler 2007 * **/ $wdVersion = '1.0'; $wgExtensionCredits['other'][] = array ( 'name' => "Scuttle Bookmarks", 'version' => $wdVersion, 'author' => 'Andreas Rindler <mediawiki at jenandi dot com>', 'url' => 'https://www.mediawiki.org/wiki/Extension:ScuttleBookmarks', 'description' => 'Allows to show Scuttle Bookmarks on your site' ); $wgExtensionFunctions[] = "wfScuttleBookmarksExtension"; function wfScuttleBookmarksExtension() { global $wgParser; $wgParser->setHook( "scuttlebookmarks", "showScuttleBookmarks" ); } # The callback function for converting the input text to HTML output function showScuttleBookmarks( $input, $argv, &$parser ) { global $wgScriptPath, $wgOut; //DEFAULTS $wgDisplayType = 'simple'; //use simple view $wgInputType = 'pagetitle'; //use page title as search term $wgSearchType = 'term'; //use search term to search Scuttle $wgSearchTerms = ''; $wgTitle = 'Bookmarks:'; //set title to Bookmarks //get user configuration if(array_key_exists('displaytype',$argv)){ $wgDisplayType = mysql_real_escape_string(trim($argv['displaytype'])); } if(array_key_exists('inputtype',$argv)){ $wgInputType = mysql_escape_string(trim($argv['inputtype'])); } if(array_key_exists('searchtype',$argv)){ $wgSearchType = mysql_escape_string(trim($argv['searchtype'])); } if(array_key_exists('title',$argv)){ $wgTitle = mysql_escape_string(trim($argv['title'])); } //CHECK FOR INPUTTYPE TO DETERMINE SEARCH TERMS if($wgInputType == 'pagecategories'){ //PERFORM SEARCH FOR PAGE CATEGORIES $wgPageTitle = $parser->getTitle(); $wgParentCats = $wgPageTitle->getParentCategories(); foreach( $wgParentCats as $key => $value ) { $wgSearchTerms .= str_replace("_"," ",str_replace("Category:","",$key)) . ';'; } } elseif($wgInputType == 'searchterms'){ //PERFORM SEARCH FOR INPUT TERMS SPECIFIED BY USER $wgSearchTerms = mysql_escape_string(trim($input)); } else { //must be 'pagetitle' default //PERFORM SEARCH FOR PAGE TITLE //TODO: might have to remove namespace $wgPageTitle = $parser->getTitle(); $wgSearchTerms = $wgPageTitle->getText(); } $output = ''; //Create link to stylesheet $output .= "<link rel=\"stylesheet\" type=\"text/css\" href=\"" . $wgScriptPath . "/extensions/ScuttleBookmarks/ScuttleBookmarks.css\"/>"; //Create div to display the results $output .= "<div id=\"scuttlebookmarks\"></div>"; //Create link to Javascript file that will handle request and response $output .= "\n<script type='text/javascript'>wgScuttleDisplayType='".$wgDisplayType."'; wgScuttleInputType='".$wgInputType."'; wgScuttleSearchType='".$wgSearchType."'; wgScuttleSearchTerms='".$wgSearchTerms."'; wgScuttleTitle='".$wgTitle."'; </script> <script src='" .$wgScriptPath. "/extensions/ScuttleBookmarks/ScuttleBookmarks.js' type='text/javascript'></script>"; //Inject into page return $output; }
- ScuttleBookmarks.css
/* ScuttleBookmarks Mediawiki Extension * * @author Andreas Rindler (mediawiki at jenandi dot com) * @licence GNU General Public Licence 2.0 or later * @description * */ /*Results DIV*/ #scuttlebookmarks { visibility: hidden; display: block; overflow: auto; } .sb_simplediv { max-height: 150px; margin-top : -1px; color: #c21731; background-color: #e9e9e9; font-size: x-small; } .sb_blogrolldiv { font-weight: normal; display: block; max-height: 300px; margin-top: 1.0em; margin-right: 0pt; margin-bottom: 1pt; margin-left: 0.1em; padding-top: 0pt; padding-right: 0em; padding-bottom: 1.5em; padding-left: 0.2em; border: 1px solid #c21731; } .sb_blogroll { display: block; border-bottom: 1px solid #aaaaaa; padding-top: 0.5em; } .sb_blogrolltitle { color: #2d5381; font-size: large; } .sb_description { } .sb_time { color: green; } .sb_to { color: black; } .sb_tags { color: green; }
- ScuttleBookmarks.js
/* ScuttleBookmarks Mediawiki Extension * * @author Andreas Rindler (mediawiki at jenandi dot com) * @licence GNU General Public Licence 2.0 or later * @description * */ //TURN DEBUG ON/OFF var debug = false; // Make the XMLHttpRequest object var http = createRequestObject(); if(wgScuttleSearchTerms.length>0){ sendRequest(wgScuttleSearchTerms); } // MAIN FUNCTION TO SEND REQUEST function sendRequest(q) { strQuery = new String(q); if (debug) {window.alert(strQuery);} //CONFIGURE ACCORDING TO YOUR WEB SERVER SETUP //IF DEPLOYED ON THE SAME SERVER under /bookmarks, THEN THE VARIABLE wgServer WILL PROVIDE THE CORRECT PATH //OTHERWISE SET THE VARIABLE MANUALLY HERE: //wgServer = "http://localhost"; if(wgScuttleSearchType == 'tag'){ http.open('get', wgServer +'/bookmarks/api/posts_public.php?tag='+strQuery); }else { //default to term search http.open('get', wgServer +'/bookmarks/api/posts_public.php?term='+strQuery); } http.onreadystatechange = handleResponse; http.send(null); } // WAIT FOR SERVER RESPONSE AND DISPLAY BOOKMARKS function handleResponse() { if(http.readyState == 4 && http.status == 200 && http.responseText){ var resultSet = http.responseText; if (debug) {window.alert(resultSet);} var resultDiv = document.getElementById("scuttlebookmarks"); resultDiv.innerHTML = ''; if (resultSet) { var xmlDoc = loadXML(resultSet); var allPosts = xmlDoc.getElementsByTagName("post"); if (allPosts.length > 0) { var result=document.createElement("span"); result.className = 'sb_title'; result.innerHTML = '<span id="sb_title">'+wgScuttleTitle+'</span> (Want to add a bookmark to this list? <a href=\"'+ wgServer +'/bookmarks/bookmarks.php/?action=add&tags='+ wgScuttleSearchTerms +'\" target=\"_blank\">Scuttle it!<img src=\"/bookmarks/icon.png\"></a>)<br>'; resultDiv.appendChild(result); resultDiv.style.visibility = 'visible'; for(var f=0; f<allPosts.length; ++f){ var result=document.createElement("span"); var sHref = allPosts[f].getAttribute("href"); var sTitle = allPosts[f].getAttribute("description"); var sDesc = allPosts[f].getAttribute("extended"); var sHash = allPosts[f].getAttribute("hash"); var sTags = allPosts[f].getAttribute("tag"); var sTime = allPosts[f].getAttribute("time"); var resultDiv = document.getElementById("scuttlebookmarks"); //check for display type if(wgScuttleDisplayType=='blogroll'){ resultDiv.className='sb_blogrolldiv'; result.className = 'sb_blogroll'; var sb_title = document.getElementById("sb_title"); sb_title.className = 'sb_blogrolltitle'; if(sDesc == null){ sDesc = ''; }else { sDesc = '<span class="sb_description">'+sDesc+'</span><br>'; } if(sTags == 'system:unfiled'){sTags = 'unfiled';} result.innerHTML = '<a href="'+sHref+'">'+sTitle+'</a><br>'+sDesc+'<span class="sb_time">'+sTime+'</span><span class="sb_to"> to </span><span class="sb_tags">'+sTags+'</span>'; resultDiv.appendChild(result); } else { //default to simple view resultDiv.className='sb_simplediv'; if(sDesc == null){sDesc = sTags.replace(/_/g," ");} if(sDesc == 'system:unfiled'){sDesc = sTitle;} result.innerHTML = '<a href="'+sHref+'" title="'+sDesc+'">'+sTitle.substr(0,22)+'...</a><br>'; resultDiv.appendChild(result); } } } } } } function loadXML(text){ var xmlDoc; // code for IE if (window.ActiveXObject) { xmlDoc=new ActiveXObject("Microsoft.XMLDOM"); xmlDoc.async="false"; xmlDoc.loadXML(text); } // code for Mozilla, Firefox, Opera, etc. else { var parser=new DOMParser(); xmlDoc=parser.parseFromString(text,"text/xml"); } return xmlDoc; } function createRequestObject() { var req; if(window.XMLHttpRequest){ // FIREFOX, SAFARI, OPERA req = new XMLHttpRequest(); } else if(window.ActiveXObject) { // IE 5+ req = new ActiveXObject("Microsoft.XMLHTTP"); } else { // IF ERROR alert('Problem creating the XMLHttpRequest object. Please contact your help desk.'); } return req; }
See also [edit]
- Extension:API Query Extension is another extension to create mashups based on Mediawiki
- Extension:OMBookmarks is another extension to create mashups based on Mediawiki