Meta:MediaWikiCodeExamples

From Juneday education
Jump to: navigation, search

Purpose

Here, the authors collect mediawiki syntax often used in this wiki.

Embedd a Vimeo video on a page

To embedd the video above (with vimeo id 170150317), use the following:

{{#ev:vimeo|170150317}}

Code smell warning image

This is code which you shouldn't write!

This is what the code smell warning thing looks like.

Here's some text and to the right of it we've got an info box.

Here's some text and to the right of it we've got an info box.

Here's some text and to the right of it we've got an info box.

Here's some text and to the right of it we've got an info box.

Here's some text and to the right of it we've got an info box.

Here's some text and to the right of it we've got an info box.

And here's the code to use if you want a code smell warning:

[[File:Code_smell.png|200px|thumb|right|This is code which you shouldn't write!|link=]]

Info box "SmallInfo" template

Information
This is an info box created with "our" SmallInfo template

Here's some text and to the right of it we've got an info box.

Here's some text and to the right of it we've got an info box.

Here's some text and to the right of it we've got an info box.

Here's some text and to the right of it we've got an info box.

Here's some text and to the right of it we've got an info box.

Here's some text and to the right of it we've got an info box.

The code:

{{SmallInfo|text=This is an info box created with "our" SmallInfo template|width=250}}

ReferenceLinks

See for instance

Code:

{{ReferenceLinks|See for instance |[[cd|read about cd,]]}}
{{ReferenceLinks||[[Chapter:Inheritance_-_Overriding_methods_in_Object_-_Exercises#Q8|  Overriding_methods_in_Object_-_Exercises#Q8]]}}

MariaDB difference warning!

Syntax difference ahead! Click on the image to see MariaDB version.

Here is a database section with SQLite specific syntax and to the right of it, we have a warning box which signals that there is a syntax difference ahead. The box is a link to a page explaning the difference (here, we've use a link to this very same page as an example - replace with the link to the page explaining how to do stuff in MariaDB).

Blah blah blah SQLite bla bla

Blah blah blah SQLite bla bla

Blah blah blah SQLite bla bla

Blah blah blah SQLite bla bla

Blah blah blah SQLite bla bla

Blah blah blah SQLite bla bla

Blah blah blah SQLite bla bla

Blah blah blah SQLite bla bla

Blah blah blah SQLite bla bla

Blah blah blah SQLite bla bla

Blah blah blah SQLite bla bla

Blah blah blah SQLite bla bla

Blah blah blah SQLite bla bla

Blah blah blah SQLite bla bla

Code:

[[File:SQL Syntax warning.png|200px|thumb|right|Syntax difference ahead! Click on the image to see MariaDB version.|link=Meta:MediaWikiCodeExamples]]

Note that the image is hardcoded and specifies the SQLite syntax warning image.

Include an image on a page

OrderSecurityException class diagram

This section has a UML class diagram as an illustration.

In order to make the rest of the page readable, we add some more text here.

Bla bla bladi-bla-bla bla bladi-bla-bla bla bladi-bla-bla bla bladi-bla-bla bla bladi-bla-bla bla bladi-bla-bla bla bladi-bla-bla bla bladi-bla-bla bla bladi-bla-bla bla bladi-bla-bla bla bladi-bla-bla bla bladi-bla-bla bla bladi-bla-bla bla bladi-bla-bla bla bladi-bla-bla bla bladi-bla-bla bla bladi-bla-bla bla bladi-bla-bla bla bladi-bla-bla bla bladi-bla-bla bla bladi-bla-bla bla bladi-bla-bla bla bladi-bla-bla bla bladi-bla-bla bla bladi-bla-bla.

Bla bla bladi-bla-bla bla bladi-bla-bla bla bladi-bla-bla bla bladi-bla-bla bla bladi-bla-bla bla bladi-bla-bla bla bladi-bla-bla bla bladi-bla-bla bla bladi-bla-bla bla bladi-bla-bla bla bladi-bla-bla bla bladi-bla-bla bla bladi-bla-bla bla bladi-bla-bla bla bladi-bla-bla bla bladi-bla-bla bla bladi-bla-bla bla bladi-bla-bla bla bladi-bla-bla bla bladi-bla-bla bla bladi-bla-bla bla bladi-bla-bla bla bladi-bla-bla bla bladi-bla-bla bla bladi-bla-bla.

The syntax is:

[[File:OrderSecurityException extends Exception.png|200px|thumb|right|OrderSecurityException class diagram]]

Worth noting are the arguments 200px and right. The former is of course the width of the image, and the latter is the float property for the image (what way the text floats around the image).

Nav links - "previous - TOC next" template

Below, we have navigation links created with our "Nav links" template to be used at the foot of pages in a book with ordered "chapters" or pages, so that the students can navigate the book. We use this very same page as the TOC, and META:Recording Videos as the "previous" and Meta:Bugs as the "next" links. Since we are on the same page as the TOC, the TOC will not be a link (otherwise it would be a link, typically leading to the Book's main page, e.g. Programming with Java.

« PreviousBook TOCNext »

{{Nav links|prev=META:Recording Videos|TOC=Meta:MediaWikiCodeExamples|next=Meta:Bugs}}

The arguments are pretty self-explanatory.

Code with syntax highlighting

This is a public final static int INLINE_SYNTAX; code with syntax highlighting inline in some text.

<source lang="Java" inline="yup">public final static int INLINE_SYNTAX;</source>

Below we have a syntax highlighted code in a block:

public class CoffeeCup2 {
  public static void main(String[] args) {
    // Create some empty objects in an anonymous method...
  }
}

Code used to produce the above:

<source lang="Java">
public class CoffeeCup2 {
  public static void main(String[] args) {
    // Create some empty objects in an anonymous method...
  }
}
</source>

Below is the same code with one line highlighted:

public class CoffeeCup2 {
  public static void main(String[] args) {
    // Create some empty objects in an anonymous method...
  }
}

Code used to produce the above:

<source lang="Java" highlight="3">
public class CoffeeCup2 {
  public static void main(String[] args) {
    // Create some empty objects in an anonymous method...
  }
}
</source>

Below is the same code with a few lines highlighted (strange lines):

public class CoffeeCup2 {
  public static void main(String[] args) {
    // Create some empty objects in an anonymous method...
  }
}

Code used to produce the above:

<source lang="Java" highlight="1,3">
public class CoffeeCup2 {
  public static void main(String[] args) {
    // Create some empty objects in an anonymous method...
  }
}
</source>

Below is the same code with an interval of lines highlighted:

public class CoffeeCup2 {
  public static void main(String[] args) {
    // Create some empty objects in an anonymous method...
  }
}

Code used to produce the above:

<source lang="Java" highlight="1-3">
public class CoffeeCup2 {
  public static void main(String[] args) {
    // Create some empty objects in an anonymous method...
  }
}
</source>

Expand - Collapse blocks

Expand using link to the right to see some hidden text.

The below was hidden until the user clicked "Expand":

sqlite> CREATE TABLE publishers
        (PublisherID INTEGER PRIMARY KEY, Name text);

Code used to produce the above expand-collapse thing:

<div class="mw-collapsible mw-collapsed">
Expand using link to the right to see some hidden text.
<div class="mw-collapsible-content">
The below was hidden until the user clicked "Expand":
<source lang="SQL">
sqlite> CREATE TABLE publishers
        (PublisherID INTEGER PRIMARY KEY, Name text);
</source>
</div>
</div>

Allow for super-long lines to get horizontal scroll bars

Sometimes, you want to show a really long command line or some other really long line of text, without it wrapping.

You can do this by putting the line (or lines) withing a div:

<div style="overflow: auto;">
<code>Loooooooooooooooooooooooooooooooooooooooong line of text, really looooooooooooooooooooooooooooooooooooooooooooooooong</code>
</div>

Result:

Looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong line of text, really looooooooooooooooooooooooooooooooooooooooooooooooong

Link to wiki search for a phrase

Sometimes it is useful to create a link to a wiki search for a word or phrase:

Read more:

Code:

Read more:
* [{{SERVER}}/mediawiki/index.php?title=Special%3ASearch&profile=default&search=%22unexpected+token%22&fulltext=Search Other pages discussing "unexpected token" on this wiki].

Creating a Term page (in the category Term)

Don't quote Wikipedia - their license isn't compatible with our. Create a blockquote with a quote from wikipedia with CC attribution links:

<blockquote>
In computer programming, an Application Programming Interface (API) is a set of subroutine definitions, protocols, and tools for building application software. In general terms, it is a set of clearly defined methods of communication between various software components. A good API makes it easier to develop a computer program by providing all the building blocks, which are then put together by the programmer. An API may be for a web-based system, operating system, database system, computer hardware or software library. An API specification can take many forms, but often includes specifications for routines, data structures, object classes, variables or remote calls. POSIX, Microsoft Windows API, the C++ Standard Template Library and Java APIs are examples of different forms of APIs. Documentation for the API is usually provided to facilitate usage.

Source: [https://en.wikipedia.org/wiki/Application_programming_interface Wikipedia] ([http://creativecommons.org/licenses/by-sa/3.0/ Creative Commons Attribution-ShareAlike License])
</blockquote>

Create some description of your own:

As an example we can mention that when you install the Java Runtime or Development Kit, you get access to a lot of predefined classes, necessary to write and run Java programs. This collection of classes are often called the Java API.

It is common to use also third-party-APIs (third-party meaning "written by someone else than yourself or the supplier of Java).

End with a category wiki tag (with a sort key after the pipe):

[[Category:Terms|API]]