Extension:OMBookmarks
From MediaWiki.org
|
Release status: stable |
|||
|---|---|---|---|
| Implementation | Tag | ||
| Description | Displays bookmarks from MIKE2.0 Openmethodology Bookmarks in a blogroll type view on your Mediawiki website. | ||
| Author(s) | Andreas Rindler (LindeleTalk) | ||
| Last Version | 1.0 (26/11/2007) | ||
| MediaWiki | 1.11, 1.10 | ||
| License | LGPL 2.1 or higher | ||
| Download | no link | ||
|
|||
|
check usage (experimental) |
|||
Contents |
[edit] What can this extension do?
This extension allows users to display bookmarks from MIKE2.0 Openmethodology Bookmarks (OM Bookmarks) in a simple text box within an article page. Users configure query parameters that get passed to the extension. The extension creates a server side http call to OM Bookmarks and displays the results in the article.
[edit] Usage
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 OM Bookmarks 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:
<ombookmarks displaytype="blogroll" inputtype="searchterms" searchtype="term" title="Links to articles and assets on OM Bookmarks:">Master Data Management</ombookmarks>
[edit] Installation
- Add the following to LocalSettings.php:
require_once('extensions/ombookmarks/ombookmarks.php');
- Create a folder ombookmarks in your MediaWiki extensions folder.
- Copy/paste the below PHP code into a text editor and save the file as ombookmarks.php in the ombookmarks folder.
- Copy/paste the CSS code into a text editor and save the file as ombookmarks.css in the same folder.
[edit] Code
<?php /** * Openmethodology Bookmarks Extension : "Show MIKE2.0 Openmethodology 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, <mediawiki at jenandi dot com> * @copyright Andreas Rindler 2007 **/ $wdVersion = '1.0'; $wgExtensionCredits['other'][] = array ( 'name' => "OM Bookmarks", 'version' => $wdVersion, 'author' => 'Andreas Rindler <mediawiki at jenandi dot com>', 'url' => 'http://www.mediawiki.org/wiki/Extension:OMBookmarks', 'description' => 'Show MIKE2.0 Openmethodology Bookmarks On Your Site' ); $wgExtensionFunctions[] = "wfOMBookmarksExtension"; function wfOMBookmarksExtension() { global $wgParser; $wgParser->setHook( "ombookmarks", "showombookmarks" ); } # The callback function for converting the input text to HTML output function showombookmarks( $input, $argv, &$parser ) { global $wgScriptPath; //DEFAULTS $wgomDisplayType = 'blogroll'; //use blogroll view (blogroll|simple) $wgomInputType = 'pagetitle'; //use page title as search term $wgomSearchType = 'term'; //use search term to search Openmethodology Bookmarks $wgomSearchTerms = ''; $wgomTitle = 'OM Bookmarks:'; //set title to Bookmarks //get user configuration if(array_key_exists('displaytype',$argv)){ $wgomDisplayType = mysql_real_escape_string(trim($argv['displaytype'])); } if(array_key_exists('inputtype',$argv)){ $wgomInputType = mysql_escape_string(trim($argv['inputtype'])); } if(array_key_exists('searchtype',$argv)){ $wgomSearchType = mysql_escape_string(trim($argv['searchtype'])); } if(array_key_exists('title',$argv)){ $wgomTitle = mysql_escape_string(trim($argv['title'])); } //CHECK FOR INPUTTYPE TO DETERMINE SEARCH TERMS if($wgomInputType == 'pagecategories'){ //PERFORM SEARCH FOR PAGE CATEGORIES $wgPageTitle = $parser->getTitle(); $wgParentCats = $wgPageTitle->getParentCategories(); foreach( $wgParentCats as $key => $value ) { $wgomSearchTerms .= str_replace("_"," ",str_replace("Category:","",$key)) . ';'; } } elseif($wgomInputType == 'searchterms'){ //PERFORM SEARCH FOR INPUT TERMS SPECIFIED BY USER $wgomSearchTerms = mysql_escape_string(trim($input)); $wgomSearchTerms = str_replace(" ","%20",$wgomSearchTerms); } else { //must be 'pagetitle' default //PERFORM SEARCH FOR PAGE TITLE //TODO: might have to remove namespace $wgPageTitle = $parser->getTitle(); $wgomSearchTerms = $wgPageTitle->getText(); } $output = ''; //Create link to stylesheet $output .= "<link rel=\"stylesheet\" type=\"text/css\" href=\"" . $wgScriptPath . "/extensions/ombookmarks/ombookmarks.css\"/>"; //query OM Bookmarks API if($wgomSearchType == 'tag'){ $wgResponse = request_page('http://mike2.openmethodology.org/bookmarks/api/posts_public.php?tag='.$wgomSearchTerms); }else { //default to term search $wgResponse = request_page('http://mike2.openmethodology.org/bookmarks/api/posts_public.php?term='.$wgomSearchTerms); } //Create div to display the results if($wgomDisplayType=='blogroll'){ $classtype = 'om_blogrolldiv'; }else { $classtype = 'om_simplediv'; } $output .= "<div class=\"".$classtype."\" style=\"visibility: visible;\" id=\"ombookmarks\"><span class=\"om_title\"><span class=\"om_blogrolltitle\">". $wgomTitle ."</span> (Want to add a bookmark to this list? <a href=\"http://mike2.openmethodology.org/bookmarks/bookmarks.php/?action=add&tags=". $wgomSearchTerms ."\" target=\"_blank\">Scuttle it!<img src=\"http://mike2.openmethodology.org/bookmarks/icon.png\"></a>)</span><br>"; if($wgResponse['errno'] == 0){ $doc = new DOMDocument(); $doc->loadXML($wgResponse['content']); $allPosts = $doc->getElementsByTagName("post"); foreach($allPosts as $post){ $sHref = $post->getAttribute("href"); $sTitle = $post->getAttribute("description"); $sDesc = $post->getAttribute("extended"); $sHash = $post->getAttribute("hash"); $sTags = $post->getAttribute("tag"); $sTime = $post->getAttribute("time"); //check for display type if($wgomDisplayType=='blogroll'){ $output .= '<span class="om_blogroll">'; if($sDesc == null){ $sDesc = ''; }else { $sDesc = '<span class="om_description">'.$sDesc.'</span><br>'; } if($sTags == 'system:unfiled'){$sTags = 'unfiled';} $output .= '<a href="'.$sHref.'">'.$sTitle.'</a><br>'.$sDesc.'<span class="om_time">'.$sTime.'</span><span class="om_to"> to </span><span class="om_tags">'.$sTags.'</span>'; // resultDiv.appendChild(result); $output .= '</span>'; } else { //default to simple view if($sDesc == null){$sDesc = str_replace('_',' ', $sTags);} if($sDesc == 'system:unfiled'){$sDesc = $sTitle;} $output .= '<span><a href="'.$sHref.'" title="'.$sDesc.'">'.sTitle.'...</a></span><br>'; } } }//end if content > 0 else { $output .= "Error message: ".$wgResponse['errno']; } $output .= "</div>"; // } //Inject into page return $output; } /** * Get a web file (HTML, XHTML, XML, image, etc.) from a URL. Return an * array containing the HTTP server response header fields and content. */ function request_page( $url ){ //set up options for the http call $options = array( CURLOPT_RETURNTRANSFER => true, // return web page CURLOPT_HEADER => false, // don't return headers CURLOPT_FOLLOWLOCATION => true, // follow redirects CURLOPT_ENCODING => "", // handle all encodings CURLOPT_USERAGENT => "OMBookmarksExtension", // who am i CURLOPT_AUTOREFERER => true, // set referer on redirect CURLOPT_CONNECTTIMEOUT => 120, // timeout on connect CURLOPT_TIMEOUT => 120, // timeout on response CURLOPT_MAXREDIRS => 10, // stop after 10 redirects ); //initiate and send post $ch = curl_init( $url ); curl_setopt_array( $ch, $options ); $content = curl_exec( $ch ); $err = curl_errno( $ch ); $errmsg = curl_error( $ch ); $header = curl_getinfo( $ch ); curl_close( $ch ); //prepare content $header['errno'] = $err; $header['errmsg'] = $errmsg; $header['content'] = $content; return $header; } ?>
/* OMBookmarks Mediawiki Extension * * @author Andreas Rindler (mediawiki at jenandi dot com) * @licence GNU General Public Licence 2.0 or later * @description * */ /*Results DIV*/ #ombookmarks { display: block; overflow: auto; } .om_simplediv { max-height: 150px; margin-top : -1px; color: #c21731; background-color: #e9e9e9; font-size: x-small; } .om_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; } .om_blogroll { display: block; border-bottom: 1px solid #aaaaaa; padding-top: 0.5em; } .om_blogrolltitle { color: #2d5381; font-size: large; } .om_description { } .om_time { color: green; } .om_to { color: black; } .om_tags { color: green; }
[edit] See also
- Extension:API_Query_Extension is another extension to create mashups based on Mediawiki
- Extension:ScuttleBookmarks is another extension to create mashups based on Mediawiki