|
|
(70 intermediate revisions by 4 users not shown) |
Line 1: |
Line 1: |
− | I am involved on the development of a new extension, this one is very simple (like the others one) and its intended to HIGHLIGHT Syntax on code posted at the wiki. The extension will use enscript (available on all linuxes) and will put colour to the code , and them will put it under "pre" tags.
| |
| | | |
− | The CVS location of the code is :
| + | =Definition= |
− | http://www.wickle.com/horde/cvs/cvs.php/mediawikiextensions
| |
| | | |
− | == Requisites == | + | =Relevance= |
− | There r no good programs without little requirements ;)
| |
− | The only one is [http://www.gnu.org/software/enscript/enscript.html enscript]
| |
| | | |
− | I am using 1.6.1 but i tested sucesfully under last version 1.6.4
| |
− |
| |
− | == Download ==
| |
− | *Download the extension from my [http://www.wickle.com/cvs/mediawikiextensions CVS] at wickle
| |
− | *Alternate Download at SF.net : [http://cvs.sourceforge.net/viewcvs.py/mwextensions/mediawikiextensions/ SF.net CVS]
| |
| | | |
− | == Install instructions ==
| |
− | you must copy SyntaxHighlight.php to $mediawiki/extensions directory and add this line to LocalSettings.php:
| |
− | include("extensions/SyntaxHighlight.php");
| |
| | | |
− | Also you must set $wgSyntaxSettings->dotCommand = "/usr/bin/enscript";
| + | =Explanation= |
− | to accomplish your installation of SyntaxHighlight.
| |
| | | |
| | | |
− | == Using it == | + | ==Benefits of Object Oriented Programming== |
| | | |
− | To use , the only thing you must do are put the code between <pre><code> and </code></pre> tags. And inside this tags you must put one tag indicating the
| + | Object Oriented Programming was made for humans by humans to help deal with the complex, irrational, rigid system that is the computer. Object Oriented languages don't benefit the machine very much but they do benefit the humans that need to program the machine. |
− | language used (for example <perl/>,<sh/>,<java/>)
| |
| | | |
− | == Samples ==
| + | *Ease of maintenance : |
| + | **no more file new project most code need to be maintained for long period of time. This gets even more difficult with many authors. It's very rare to hit file-> new project in the real world |
| + | *Extend-ability |
| + | **Flexible modular clean code lasts much longer. We will make a new project every week but solutions and projects are often used in a modular fashion. Groups of '''loosely coupled objects''' are one of the goals in object oriented programming |
| + | *Re-usability |
| + | **Once a problem has been solved with OOP the solution can often be reused over and over again. One of you goals is to keep code DRY |
| + | ***'''D'''on't (or at least try not to) |
| + | ***'''R'''epeat |
| + | ***'''Y'''ourself |
| + | **of course this concept can be stifling to beginning programmers so we will also try to adhere to the [https://people.apache.org/~fhanik/kiss.html K.I.S.S principal] |
| | | |
| + | =Resources= |
| + | == See also == |
| | | |
− | === Perl ===
| + | * [[Object Oriented Programming I | 2014 OOP I Class Site]] |
− | <code>
| |
− | <perl/>
| |
− | #!/usr/local/bin/perl5.8.2
| |
− | #envia un correo a account_for_backups@gmail.com como usuario wickle con el backup de las
| |
− | #ultimas base de datos de wickle y con el label Backup
| |
− | #Usa Mail::Webmail::Gmail en #http://search.cpan.org/dist/Mail-Webmail-Gmail/lib/Mail/Webmail/Gmail.pm
| |
− | #Syntax ./send_gmail.pl file_to_backup.tar.gz
| |
| | | |
− | use Mail::Webmail::Gmail;
| + | ==Notes== |
| | | |
− | my $backup_label="Backups";
| |
− | my $file_to_backup=$ARGV[0];
| |
− | my $mail_to_backup="account_for_backups@gmail.com";
| |
− | my $now = localtime time;
| |
− | print "It is now $now.\nfile to backup: $file_to_backup\n";
| |
− | my ( $gmail ) = Mail::Webmail::Gmail->new(
| |
− | username => 'mygmailaccount', password => 'mypassword', );
| |
− | my $msgid = $gmail->send_message( to => 'account_for_backups@gmail.com', subject => 'Backup bases de datos '. $now, msgbody => 'Backup del dia '.$now. ' realizado', file0 => [$file_to_backup] );
| |
− | print "Msgid: $msgid\n";
| |
− | if ( $msgid ) {
| |
− | if ( $gmail->error() ) {
| |
− | print $gmail->error_msg();
| |
− | } else {
| |
− | ### Add this label to our new message ###
| |
− | $gmail->edit_labels( label => $backup_label, action => 'add', 'msgid' => $msgid );
| |
− | if ( $gmail->error() ) {
| |
− | print $gmail->error_msg();
| |
− | } else {
| |
− | print "Added label: $backup_label to message $msgid\n";
| |
− | }
| |
− | }
| |
− | }
| |
− | </code>
| |
| | | |
| + | ==External Links== |
| | | |
− | === bash ===
| + | [http://www.archive.org/details/arsdigitac04 Object-Oriented Program Design and Software Engineering] |
− | <code>
| + | http://www.codeproject.com/cpp/oopuml.asp OOP and UML |
− | <sh/>
| |
− | #!/bin/bash
| |
− | #Getting some variables
| |
− | FULLPATH=`dirname $1`;
| |
− | BASE=`basename $1`;
| |
− | # Needs an argument
| |
− | if [ $# -eq 0 ] ; then
| |
− | # no argument given, print usage
| |
− | echo "start control version on configuration file";
| |
− | echo "use: $0 file";
| |
− | else
| |
− | # check if RCS directory exist or create it
| |
− | if [ -d $FULLPATH/RCS ] ; then
| |
− | echo "revisions directory existent ...";
| |
− | else
| |
− | mkdir $FULLPATH/RCS
| |
− | fi
| |
| | | |
− | # Things to do when a RCS file exist
| + | [[Category:Programming Language Concepts]] |
− | if [ -e $FULLPATH/RCS/$BASE,v ] ; then
| + | [[Category:Object Oriented Programming]] |
− | echo "File exist. Checking for differences ..."
| + | [[Category:C Sharp]] |
− | # Check if there is any differences
| |
− | if ! rcsdiff $1; then
| |
− | echo "==================================="
| |
− | echo "WARNING: changes have been made to $1 and are not in the repository. Carefully look at the diff above, comment them below for committing or CTRL+C to abort."
| |
− | # Lock file
| |
− | /usr/bin/rcs -l $1
| |
− | if ! /usr/bin/ci -u $1; then
| |
− | echo "Error when commiting. Aborting"
| |
− | exit
| |
− | fi
| |
− | fi
| |
− | echo "==================================="
| |
− | echo "Getting lastest revision and locking it ..."
| |
− | /usr/bin/co -l $1
| |
− | fi
| |
− | | |
− | echo "Launching editor ..."
| |
− | vim $1
| |
− | # changes made, commit them to the repository unlocked
| |
− | /usr/bin/ci -u $1
| |
− | exit
| |
− | fi
| |
− | </code>
| |
− | | |
− | | |
− | === Java ===
| |
− | | |
− | <code>
| |
− | <java/>
| |
− | /*
| |
− | * Algernon - a rule-based inference engine in Java.
| |
− | * http://algernon-j.sourceforge.net/
| |
− | *
| |
− | * This example shows how to open a Protege knowledge base
| |
− | * in Java and use Algernon to query the KB.
| |
− | *
| |
− | * To run it, be sure to change the path in NEWSPAPER_PROJECT
| |
− | * to match the correct project on your system.
| |
− | *
| |
− | * Micheal Hewett
| |
− | * 05 May 2004
| |
− | * hewett@cs.stanford.edu
| |
− | */
| |
− | | |
− | package org.algernon.test;
| |
− | | |
− | import java.util.*;
| |
− | | |
− | import org.algernon.Algernon;
| |
− | import org.algernon.util.ErrorSet;
| |
− | import org.algernon.datatype.Result;
| |
− | import org.algernon.datatype.BindingList;
| |
− | import org.algernon.kb.okbc.protege.AlgernonProtegeKB;
| |
− | import org.algernon.kb.AlgernonKB;
| |
− | | |
− | | |
− | // date created: Wed Aug 14 11:02:44 2002
| |
− | /**
| |
− | * Opens the Protege newspaper KB and makes some simple queries on it.
| |
− | *
| |
− | * Example:
| |
− | *
| |
− | | |
− | * java -classpath algernon.jar:protege.jar org.algernon.test.SimpleAlgernonExample
| |
− | *
| |
− | | |
− | | |
− | * @see org.algernon.Algernon
| |
− | * @author Micheal S. Hewett hewett@smi.stanford.edu
| |
− | *
| |
− | */
| |
− | public class SimpleAlgernonExample extends Object
| |
− | {
| |
− | public static String NEWSPAPER_PROJECT = "/Applications/Protege_2.0/examples/newspaper/newspaper.pprj";
| |
− | | |
− | protected Algernon f_algy = null; // Algernon instance
| |
− | protected AlgernonKB f_kb = null;
| |
− | protected String f_projectFile = "";
| |
− | | |
− | | |
− | | |
− | // date created: Wed Aug 14 11:02:44 2002
| |
− | // created by: Micheal S. Hewett hewett@smi.stanford.edu
| |
− | public SimpleAlgernonExample()
| |
− | {
| |
− | f_projectFile = NEWSPAPER_PROJECT;
| |
− | }
| |
− | | |
− | public SimpleAlgernonExample(String project)
| |
− | {
| |
− | f_projectFile = project;
| |
− | }
| |
− | | |
− | | |
− | /**
| |
− | * Opens the KB and initializes Algernon.
| |
− | */
| |
− | public void init()
| |
− | {
| |
− | try {
| |
− | f_algy = new Algernon();
| |
− | f_kb = new AlgernonProtegeKB(f_algy, f_projectFile);
| |
− | f_algy.addKB(f_kb);
| |
− | }
| |
− | catch (Exception e) {
| |
− | System.err.println(e + "\nUnable to open the '" + f_projectFile + "' KB.");
| |
− | stop();
| |
− | }
| |
− | | |
− | }
| |
− | | |
− | | |
− | /**
| |
− | * Halts the program nicely.
| |
− | */
| |
− | public void stop()
| |
− | {
| |
− | if (f_kb != null)
| |
− | f_kb.close();
| |
− | }
| |
− | | |
− | public static void main(String[] args)
| |
− | {
| |
− | SimpleAlgernonExample example = new SimpleAlgernonExample(NEWSPAPER_PROJECT);
| |
− | example.init();
| |
− | example.start();
| |
− | }
| |
− | | |
− | public void start()
| |
− | {
| |
− | | |
− | try {
| |
− | // Example that retrieves all bindings of the variable ?X.
| |
− | // Note that the variable names are case-sensitive:
| |
− | | |
− | ErrorSet errors = new ErrorSet();
| |
− | String query = "((:instance Author ?a)(name ?a ?name))";
| |
− | | |
− | Result result = (Result)f_algy.ask(query, errors);
| |
− | | |
− | if (result == null)
| |
− | {
| |
− | System.err.println("Errors during ask of '" + query + "'");
| |
− | System.err.println(errors.toString());
| |
− | }
| |
− | else
| |
− | {
| |
− | // One way to access the results is to iterate on the results
| |
− | // using result.iterator(). Each element of the iterator
| |
− | // is of type BindingList.
| |
− | for (Iterator iterator = result.iterator();
| |
− | iterator.hasNext();)
| |
− | {
| |
− | // Result contains some BindingList objects.
| |
− | BindingList bl = (BindingList) iterator.next();
| |
− | | |
− | // The bound object will either be a Java Object (Integer, Float, etc.)
| |
− | // or a KB object (typically a Protege Instance).
| |
− | // If you want Algernon objects, use algy.getAlgernonBinding().
| |
− | Object author = f_algy.getBinding("?a", bl);
| |
− | Object name = f_algy.getBinding("?name", bl);
| |
− | | |
− | System.out.println("Author: " + author + ", name: " + name);
| |
− | | |
− | // If for some reason you don't know the names of the variables
| |
− | // in the Binding Lists, you can iterate on the BindingList to
| |
− | // retrieve variable names and values. See the JavaDoc documentation
| |
− | // for the BindingList api.
| |
− | }
| |
− | | |
− | // A simpler way to show the results is to let Algernon print the results:
| |
− | System.out.println(f_algy.printResultToString("ask", result));
| |
− | | |
− | }
| |
− | } catch (Exception e) {
| |
− | System.err.println("Error running Algernon: " + e);
| |
− | e.printStackTrace();
| |
− | } finally {
| |
− | stop();
| |
− | }
| |
− | }
| |
− | | |
− | }
| |
− | </code>
| |
− | | |
− | | |
− | | |
− | [[Category:PHP]] | |
− | [[Category:Mediawiki Extensions]] | |
Object Oriented Programming was made for humans by humans to help deal with the complex, irrational, rigid system that is the computer. Object Oriented languages don't benefit the machine very much but they do benefit the humans that need to program the machine.