set mediawiki

How to become a MediaWiki hacker

From MediaWiki.org

Jump to: navigation, search

Languages: 

English  • Deutsch  • Français  • 日本語  • Occitan  • Polski  • Српски / Srpski  • 中文

Some of this information may be outdated or incorrect. If you are familiar with the topic, please attempt to bring this article up to date.

How to become a MediaWiki hacker will explain and link to pages containing information on MediaWiki's development process, and answer questions from neophyte developers. If you plan to help us code and develop the software, but don't have the necessary skillset yet, this is a good place to start.

Contents

[hide]

<script type=text/javascript> // </script> [edit] Essential reading

[edit] Operating systems

The MediaWiki software is written in PHP and uses the MySQL database. Both have been ported to a variety of operating systems, including, but not limited to, most Unix variants and Microsoft Windows. It is therefore possible to install and use MediaWiki under both systems. Note that if you do use Windows, certain features involving external utilities will be unavailable, or only available with special downloads and configuration. OS-dependent bugs are occasionally observed, it is best to have some knowledge of the difference between the various platforms regardless of which OS you develop on.

[edit] The PHP programming language

If you have no knowledge of PHP (PHP stands for "PHP: Hypertext Preprocessor") but know how to program in other object-oriented programming languages, have no fear, PHP will be easy for you to learn.

If you have no knowledge of PHP or other object-oriented programming languages, you should familiarize yourself with concepts such as classes, objects, methods, events and inheritance.

If you have no knowledge of any programming language, PHP is a good language to start with, as it is reasonably similar to other modern languages, although it is specific in the way it is executed.

PHP scripts can run from the command line or a window manager is enough to call the interpreter. e.g. (Linux/UNIX)

/usr/bin/php -q < phpshell.php

Usually, for websites a PHP script is executed when you request a file with the ".php" extension (among others) from a webserver. As you do that, the web server, in our case Apache, calls the PHP interpreter (which may be built into the webserver), interprets the PHP file and returns the result to your browser. The PHP file can contain both regular HTML and PHP code, which makes it relatively simple to add dynamic functionality to a static webpage.

[edit] Related links

[edit] SQL and MySQL

Wikipedia currently uses MySQL as the database backend. Make sure MySQL support is compiled into PHP!

MediaWiki also supports PostgreSQL, but there can be some small bugs.

[edit] Installing MediaWiki

Get the latest sources from SVN before creating patches. See Download from SVN for how to get the sources from SVN

Follow the instructions in the INSTALL file in the source. You could also read the installation guide.

It's not necessary to download Wikipedia database dumps in order to develop MediaWiki features. In fact, in many cases it's easier to use a near-empty database with a few specially-crafted test pages. However, if for some reason you want to have a copy of Wikipedia, you can get a dump from meta:data dumps.

You may also find that you get an error complaining that access was denied to the wiki database. Make sure that you have created a file AdminSettings.php in your top-level MediaWiki install directory (the same place as LocalSettings.php is found). An AdminSettings.sample file is provided for you to customise - make sure your MySQL administration username and password is set correctly. See Manual:Upgrading for more details.

Rebuilding the link tables may take a long time, particularly if you've installed the English database, which is quite big. (Note also that you can skip the old table if you wish.) See Manual:Database layout on what rebuildall.php is good for.

Note that if you want to create a public mirror of Wikipedia, this probably isn't the best way to go about it. If you do set up a mirror this way, please tweak the code to note that you're looking at a mirror and include links back to the main site. See Forks and Mirrors for more info.

[edit] The MediaWiki codebase

The MediaWiki codebase is large and ugly. Don't be overwhelmed by it. When you're first starting off, aim to write features or fix bugs which are constrained to a small region of code.

You can browse the generated documentation (warning: huge page will be loaded).

One of the best ways to learn about MediaWiki is to read the code. Here are some starting points:

  • index.php is the main entry point, although where things go from there is not very obvious.
  • Article.php contains code for page view, delete, rollback, watch and unwatch. It also contains some general utilities for dealing with articles, such as fetching a revision or saving a page.
  • EditPage.php has about half of the code related to editing, the half that's close to the user interface. The rest is in Article.php and the various *Update.php files.
  • Parser.php has most of the code that converts wikitext to HTML. A few bits and pieces are in Skin.php
  • Linker.php has functions to generate the HTML for links and images
  • Code for most special pages is in the Special*.php files.
  • DatabaseFunctions.php contains stacks of functions for accessing the database.
  • OutputPage.php is the home of the OutputPage class, which is an output buffer. Send your text here and it will be sent to stdout just before the script exits.
  • Title.php is all about titles -- and that includes interwiki titles and "#" fragments. There are some functions in here that will fetch information about an article from the database.
  • User.php contains the User class, which represents user preferences and permissions.
  • Setup.php does all sorts of initialisation, and seems to account for a large proportion of running time. Among other things, it initialises lots of global variables, mostly containing objects.
  • DefaultSettings.php contains defaults for lots of global variables, which may or may not be overridden in LocalSettings.php. Don't use isset(), always add a default for any global variable you introduce.

For getting started with debugging, see How to debug.

See also Manual:Code.

[edit] Your first feature

Here are some ideas:

  • Code something that interests you.
  • Code a simple crowd-pleasing feature, an aesthetic improvement.
  • Write a special page to provide some handy information. You can even make a modular special page, there are examples in the extensions directory, and the extensions module.
  • Write a parser hook, see Manual:Extending wiki markup for more information.
  • Fix an annoying little bug that nobody else could be bothered with.

For more specific ideas, please come and talk to the developers on #mediawiki. Don't be put off for a lack of ideas. We have enough ideas between us to keep half a dozen programmers busy for a year.

It's a good idea to talk to a senior developer (e.g. Brion or Tim) on #mediawiki before you start, especially if you're not sure how your feature will affect other parts of the code.

When you have a feature ready to go, press for Subversion write access, so that you can commit it (for more on this, see commit access). Posting patches can be frustrating, although you may have to do it once or twice to demonstrate good faith. Before you commit your feature, make sure it can be disabled easily.

Don't ask for shell access to the Wikimedia servers. There is no way to restrict shell access to some sort of sandbox, so shell access is only given to people whom we really trust. It pains us to turn people down, but often we must. Wait until it is offered, or if it's taking a long time, discreetly test for support.

[edit] Testing

When adding features it's vital to verify you didn't break existing functionality.

  • There is a ParserTest framework in maintenance/ that tests parsing of wikitext. This is probably most suited for running tests of your own extension.
  • tests/ contains some smaller test cases using the PHPUnit framework. This may be suitable for running tests of particular functions
  • t/ contains a few tests using the TAP framework.

[edit] Posting a patch

If you have created and tested a patch, get a diff of the modified file by using:

svn diff path/to/modified_file.php > my.patch

Then post the patch as an attachment to the appropriate bug report.

Developer hub

From MediaWiki.org

Jump to: navigation, search

Users

System Administrators

Developers

This is the place to come if you want to contribute to the development of the MediaWiki software. For help installing or customising MediaWiki, please see the administrator help.

These pages are in the early stage of development. If you can't find the information you are looking for, or have found useful information somewhere we have not linked to, then please leave a comment on the talk page and someone will look into it.

Contents

[hide]

<script type=text/javascript> // </script> Primary developer resources

  • BugZilla - Bug tracker for MediaWiki and issues with Wikimedia projects (sometimes referred to as MediaZilla)
  • Subversion browser - Web-based viewer for the MediaWiki source code
  • Code documentation - Machine-generated documentation on the classes and other functions used in MediaWiki
  • SourceForge project - Was used in the past to host distribution files

Info on MediaWiki.org

Extending MediaWiki

There are 5 main extension points that allow developers to add features and functionality to MediaWiki or to change existing functionality. MediaWiki has been designed to allow for modification without changing the "core code". This makes it easy to update to a new version of MediaWiki without having to manually merge in old extension code changes. The extension points are:

Help for extension writers

Developer discussion

For more information about the above, please see Communication.

 

 

Mediawiki Skins

How to change Skins/Templates

You can change the Logo of your wiki by altering the $wgLogo variable in /includes/DefaultSettings.php to the name of the image you want to use as a logo.

Please note that this logo should be placed in the /skins/common/images/ folder.

Create MediaWiki Skin

You can create a skin all by yourself by following the steps provided below:

*       Go to the /skins folder within your Mediawiki directory;

*       Copy the /monobook directory and rename it with the name of your skin, for example:

mywikiskin;

*       Copy the MonoBook.php file and rename it with the name of your skin, for example:

MyWikiSkin.php;

*       Edit MyWikiSkin.php and change the class name to SkinMyWikiSkin, for example:

class SkinMyWikiSkin extends SkinTemplate;

*       In MyWikiSkin.php, change make the other class to have your skin name together with the word Template, for example:

class MyWikiSkinTemplate extends QuickTemplate;

*       In MyWikiSkin.php, make $this->skinname to have a string value of your skin name, for example:

'mywikiskin';

*       In MyWikiSkin.php, make $this->template to have a string value of your skin name properly capitalised with the word Template, for example:

'MyWikiSkinTemplate';

*       In your /mywikiskin directory edit the image and CSS files;

*       Edit and customise MyWikiSkin.php as you please;

*       In LocalSettings.php set

$wgDefaultSkin = 'mywikiskin'

You can now enjoy the new skin you have prepared!

 

Change Page Name

How to Change the Page Name

In order to change the name of a page, for example the name of the Main Page, you will first need to login as Administrator. You can do this by clicking on the log in/create account link at the top right corner of your page.

Then you should type in the admin username and password you set during the installation.

Now that you are logged in as administrator, you need to click on the [Move] link at the top of the page. A new page will open and you will be given the option to change the Title of the page.

 

 


 

 

Add Links to Posts

How to Add Links to Posts

The first thing you need to do in order to edit the page is to click on the [Edit] button at the top of the page.

In order to create links, you will need to specify them with tags as follows. A link in external link style can be of the forms:

target: http://meta.wikimedia.org/ is rendered as http://meta.wikimedia.org/

[target label], with a blank space in between: [http://meta.wikimedia.org/ wikimedia] gives wikimedia

 

 

 

 

 

 

 

MediaWiki的架构

·         Currently 1.00/5

·         1

·         2

·         3

·         4

·         5

页面分类: MediaWiki技术文档

天下维客,你可以修改的网络知识库

跳转到: 导航, 搜索

欢迎翻译^_^

Template:H:h

Because the documentation in the source tree is sparse and the code is scary, here's some info for new developers on generally how the MediaWiki software works. The database (see also database layout) contains the wikitext of the pages and various auxiliary information about pages, users, etc. It also contains (in the "old" table) all previous versions of all pages, as the MediaWiki software maintains its own version control system. The current version of each page is stored in the "cur" table. The growing database size for Wikipedia's largest languages is shown here and database dumps (not including user passwords) can be downloaded here. As of February 2005, the "cur" table of the English Wikipedia holds 3 GB data and 500 MB index (download as 500 MB compressed dump) while the "old" table holds 80 GB data and 3 GB index (download as 29 GB compressed dump).

When viewing a page the wikitext is converted to XHTML (see also m:XHTML), or this XHTML code is taken from cache, and sent to the user, whose browser renders the XHTML.

The XHTML code for a given page depends on:

·         the mode, such as viewing or editing (see below).

·         the wikitext

·         the templates referred to

·         the values of variables

·         the existence of internally linked pages (gives view or edit link)

·         the skin

·         the user name itself

·         the status of the user (more links if a sysop, etc.)

·         the namespace (determines the link to the Talk page, or in the case of a Talk page, the page concerned)

·         whether the page is watched by the user (gives watch or unwatch link)

·         whether the user's Talk page has been recently edited (gives a message)

The result the user sees on the screen depends on:

·         the XHTML code

·         files referred to by the XHTML code, such as embedded images and a server-side css file.

·         the browser and browser settings, including possibly a local css file, and the screen resolution.

When the user presses the Edit button, the wikitext itself is sent to them, of the whole page or of one section only. When the user presses Preview, their new version of the wikitext is sent to the server, which sends the corresponding new version of the XHTML code, which is rendered again and displayed above or below the user's new version of the wikitext (which the server has also returned). After possibly more changes and more previews, the user presses Save, sending their "final" version to the server, which now records the edit and sends the XHTML of the new version (again). In some cases also an automatic conversion of wikitext takes place in this stage.

See also Differences between wikitext and the webpage.

[编辑]

General Architecture

General Architecture

User Layer

Web Clients

Network Layer

Apache Webserver

Logic Layer

Data Layer<td>

</td>

 

See also: How to become a MediaWiki hacker

For Wikimedia, see also Wikimedia servers.

Next: Database layout >

 

 

 

 

MediaWiki页面样式定制

  • Currently 3.00/5
  • 1
  • 2
  • 3
  • 4
  • 5

天下维客,你可以修改的网络知识库

跳转到: 导航, 搜索

欢迎翻译^_^

This page needs to be updated and cleaned up to be compatible with 1.5 as soon as possible! -- ilver§ide 09:40, 7 January 2006 (UTC)

目录

[隐藏]

<script type=text/javascript> if (window.showTocToggle) { var tocShowText = "显示"; var tocHideText = "隐藏"; showTocToggle(); } </script> [编辑]

Customizing the page layout

This is largely dependent on which skin you're using, how it's constructed and which version of mediawiki you have. See Explaining Skins for a brief explanation of Skins.

[编辑]

Questions

[编辑]

How do I customize the Quickbar/Navigation bar?

When using the older table formatted Skin pages, the left hand Quickbar is displayed by the Skin::quickBar function.

When using the newer PHPTal formatted pages, the navigation, search and toolbar blocks are laid out in the template spec file (/templates/xhtml_slim.pt under 1.3; /skins/MonoBook.php under 1.4).

---How does one access the /skins/Monobook.php file? via the Wiki?

You can't directly edit MonoBook.php via the wiki. If you have shell access to your server, use that and run an editor on the server to make changes. If you don't have shell access, decompress the MediaWiki-x.x.x.tar.gz file you downloaded and edit the skins/MonoBook.php and upload the edited version to your server. -dandaman32

Under 1.5, follow the instructions on Help:Navigation_bar

Under 1.4, you can add items to the navigation block by manipulating the $wgNavigationLinks array which is defined in /includes/DefaultSettings.php. Any changes should be made in /LocalSettings.php

Under 1.3, you can only add items by changing the xhtml_slim.pt file

Also see Quickbar for more details about editing the Quickbar/Navigation bar ---

[编辑]

How do I customize the logo in the top left corner?

The logo is a portlet block without a pBody section. It is identified by the p-logo id. The background image is specified by the wgLogo variable, which is defined in /includes/DefaultSettings.php. This location is relative to the web server root and not the system root. Redefine this in /LocalSettings.php to change the image. If set wrong there will be no image on the page, check your web server error log and adjust accordingly. However the size of the p-logo will need to be big enough for the logo if it is not to be clipped. This is set in the stylesheet, under the p-logo style, the default setting is:

.
     
     
#p-logo {
     
     
    z-index: 3;
     
     
    position:absolute; /*needed to use z-index */
     
     
    top: 0;
     
     
    left: 0;
     
     
    height: 155px;
     
     
    width: 12em;
     
     
    overflow: visible;
     
     
}
     
     

[编辑]

Reducing the size of the logo

Note that a tag is on top of the logo so if you are trying to reduce the size of the logo's portlet you will also need to change the #p-logo a and #p-logo a:hover rules. The default setting for these is:

 #p-logo a,
     
     
 #p-logo a:hover {
     
     
    display: block;
     
     
    height: 200px;
     
     
    width: 12.2em;
     
     
    background-repeat: no-repeat;
     
     
    background-position: 35% 50% !important;
     
     
    text-decoration: none;
     
     
 }
     
     

This simple customization will re-define the size of all of them at once...

 #p-logo,
     
     
 #p-logo a,
     
     
 #p-logo a:hover {
     
     
    height: 75px;
     
     
}
     
     

There is one more rule controlling the amount of space between the logo and first portlet in the side column - the padding on the top of #column-one. By default this is:

#column-one { padding-top: 160px; }
     
     

If you want to remove the logo completely, comment out the wgLogo variable. Then set the column-one padding to a small value, such as 21:

#column-one { padding-top: 21px; }
     
     

You dont have to go edit the css file directly. You can goto <Your Wiki URL>?title=MediaWiki:Monobook.css. Hit edit and make your changes there. This has preference over the monobook main css.


[编辑]

How do I change the icon in the browser's addressline ? (favicon)

See article How do I change the icon in browser's address-line? in MediaWiki_FAQ

[编辑]

How do I hide the table of contents by default?

Add __NOTOC__ anywhere inside your article source.

[编辑]

How do I remove the "edit" "discussion" and other tabs on my site for users that are not logged in?

(If you only want to disable anonymous editing see Preventing_Access)

Edit the file /includes/SkinTemplate.php. Find the function buildContentActionUrls(). A few lines into it you'll find

                if( $this->iscontent ) {
     
     

Modify this to read

                
     
     
                if( $wgUser->getId() != 0 && $this->iscontent ) {
     
     


Another possibility is to edit your skin.php, e.g. Monobook.php. I used this solution, as after the above alteration it still remained a "specialpage" tab on Mediawiki 1.5

So search for

foreach($this->data['content_actions'] as $key => $action) {
     
     

and insert in the line above (be sure to be in the php-part!)

if($this->data['loggedin']==1)
     
     

[编辑]

How do I remove the "edit" link that appears in longer pages next to the paragraphs? (e.g. to the right of this paragraph)

Add the following at the top of each page:

__NOEDITSECTION__
     
     

[编辑]

section "history" tab link for non-logged in users only

In the file includes/SkinTemplate.php find this:

$content_actions['history'] = array(
     
     
                                      'class' => ($action == 'history') ? 'selected' : false,
     
     
                                      'text' => wfMsg('history_short'),
     
     
                                      'href' => $this->mTitle->getLocalUrl( 'action=history')
     
     
                               );
     
     


and replace with;

if( $wgUser->isLoggedIn()){ 
     
     
                               $content_actions['history'] = array(
     
     
                                      'class' => ($action == 'history') ? 'selected' : false,
     
     
                                      'text' => wfMsg('history_short'),
     
     
                                      'href' => $this->mTitle->getLocalUrl( 'action=history')
     
     
                               );}
     
     

 

[编辑]

How to just remove the section "edit" link for non-logged in users only

In the file includes/Skin.php, replace

if( !$wgUser->getOption( 'editsection' ) ) {
     
     
                       $s .= ".editsection { display: none; }/n";
     
     
               }
     
     
 
     
     

By this piece of code.

 if( !$wgUser->getId() || !$wgUser->getOption( 'editsection' ) ) {
     
     
 $s .= ".editsection { display: none; }/n";
     
     
 }
     
     
 
     
     

Where the bit

!$wgUser->getId() ||
     
     

enables to identify that the user id registered.

This seems to work, but I think the browser has some caching issues or something. Sometimes the edit links will show up and a ctrl-r or f5 will clear it up. Also sometimes they don't show up after login and a refresh will fix it.


Another method with Mediawiki 1.5 is editing your skin. e.g. in MonoBook.php add this before </head>:

 
     
     
 <?php if(!$this->data['loggedin']) { ?>
     
     
      <style>
     
     
        <!--
     
     
        .editsection { display: none; }
     
     
        -->
     
     
      </style>
     
     
 <?php } ?>
     
     
 
     
     

This overrides the style for the edit section link. This seems to avoid the caching issue of the method above.

[编辑]

How do I remove the line of links to include the "Create an Account or Login" link at the top right of the screen for anonymous users?

You may have to clear your browser's cache to view the effect of this tweak. It seems to remain even if you refresh/load the page.

Edit the file: /includes/SkinTemplate.php Search for the word "login" and find the section that looks like this:

                        } else {
     
     

  
  
   
    
  
  
                                $personal_urls['login'] = array(
     
     
                                        'text' => wfMsg('userlogin'),
     
     
                                        'href' => $this->makeSpecialUrl('Userlogin', 'returnto=' . $this->thisurl )
     
     
                                );
     
     
                        }
     
     

Now change it to be like this:

                        } else {
     
     
                        }
     
     

You can still login by accessing the Special page through the Special Pages menu...

[编辑]

How do I remove the toolbox for users that are not logged in?

Edit the file: /skins/MonoBook.php Find the section that looks like this (by searching for p-tb):

        <div class="portlet" id="p-tb">
     
     

Now add the line in the middle like this:

        <div class="portlet" id="p-tb">
     
     
        <?php if($this->data['loggedin']) { ?>
     
     
        <h5><?php $this->msg('toolbox') ?></h5>
     
     

Go down to the bottom of the div block that you are editing and find the section that looks like this:

                    echo htmlspecialchars($this->data['nav_urls']['print']['href'])
     
     
                    ?>"><?php echo $this->msg('printableversion') ?></a></li>
     
     
              <?php } ?>
     
     
            </ul>
     
     
          </div>
     
     
        </div>
     
     
        <?php if( $this->data['language_urls'] ) { ?><div id="p-lang" class="portlet">
     
     
          <h5><?php $this->msg('otherlanguages') ?></h5>
     
     

and add the line (between the two /div's) that closes off your new "if" statement:

                    echo htmlspecialchars($this->data['nav_urls']['print']['href'])
     
     
                    ?>"><?php echo $this->msg('printableversion') ?></a></li>
     
     
              <?php } ?>
     
     
            </ul>
     
     
          </div>
     
     
        <?php } ?>
     
     
        </div>
     
     
        <?php if( $this->data['language_urls'] ) { ?><div id="p-lang" class="portlet">
     
     
          <h5><?php $this->msg('otherlanguages') ?></h5>
     
     

[编辑]

How do I remove the special page tab?

Edit the file: /includes/SkinTemplate.php

Change the following section:

        /* show special page tab */
     
     

  
  
   
    
  
  
                       $content_actions['article'] = array(
     
     
                               'class' => 'selected',
     
     
                               'text' => wfMsg('specialpage'),
     
     
                               'href' => $wgRequest->getRequestURL(), // @bug 2457, 2510
     
     
                       );
     
     


(by commenting out the whole block) to:

        /* show special page tab 
     
     

  
  
   
    
  
  
                       $content_actions['article'] = array(
     
     
                               'class' => 'selected',
     
     
                               'text' => wfMsg('specialpage'),
     
     
                               'href' => $wgRequest->getRequestURL(), // @bug 2457, 2510
     
     
                       );*/
     
     

[编辑]

How do I change the "content page", "discussion", etc. tags at the top of the page?

The file includes/SkinTemplate.php contains a function that builds the list called buildContentActionUrls. It decides what tabs to include for a given page and what code to run when the user clicks on a tab.

[编辑]

How do I add an editable Left Menu?

[编辑]

Skin MonoBook

New: Under 1.5 you just need to edit MediaWiki:Sidebar, see the line in format of link|Display name

The Sidebar is located at http://<yourhost>/wiki/index.php/MediaWiki:Sidebar

See Quickbar for more details about editing the Quickbar/Navigation bar

Note that the method below gives you more flexibility over the layout of the menu, such as including horizontal rules and sub-bullets, than the Sidebar menu... ---

  • Insert a new page into the Namespace MediaWiki; e.g.
MediaWiki:MenuNavigation
     
     

(the easiest way to do this is to create a link on your wiki with that page name. Alternately, typing the url http://www.wikiurl.net/index.php?title=Layout_customization&action=edit (replacing www.wikiurl.net with your own URL)). You must have SysOp privileges to do this.

  • Fill that page with links
  * [[Main Page]]
     
     
  * [[Special:Recentchanges| Recent changes]]
     
     
  * [[Special:Random| Random page]]
     
     
  ** [[an indented Link]]
     
     
<hr>
     
     
  * [[another Link]]
     
     
  * [http://www.Link.de a http link]
     
     
  • open file skins/Monobook.php
  • look for:
     <h5><?php $out = wfMsg( $bar ); if (wfNoMsg($bar, $out)) echo $bar; else echo $out; ?></h5>
     
     
     <div class='pBody'>
     
     
       <ul>
     
     
       <?php foreach($cont as $key => $val) { ?>
     
     
         <li id="<?php echo htmlspecialchars($val['id']) ?>"><a href="<?php echo htmlspecialchars($val['href']) ?>"><?php echo htmlspecialchars($val['text'])?></a></li>
     
     
        <?php } ?>
     
     
       </ul>
     
     
     </div>
     
     
  • Replace
       <ul>
     
     
       <?php foreach($cont as $key => $val) { ?>
     
     
         <li id="<?php echo htmlspecialchars($val['id']) ?>"><a href="<?php echo htmlspecialchars($val['href']) ?>"><?php echo htmlspecialchars($val['text'])?></a></li>
     
     
        <?php } ?>
     
     
       </ul>
     
     

with:

      <?php $this->msgWiki( 'MenuNavigation' ) ?>
     
     
  • The result should look like:
  <h5> <?php $out = wfMsg( $bar ); if (wfNoMsg($bar, $out)) echo $bar; else echo $out; ?></h5>
     
     
     <div class='pBody'>
     
     
       <?php $this->msgWiki( 'MenuNavigation' ) ?>
     
     
     </div>
     
     

  
  
   
    
  
  

This will remove the old Navigation menu and replace it with whatever you built in the MediaWiki:MenuNavigation page. If you want to keep the old Navigation menu functions and just add new ones, you must either duplicate the links in MediaWiki:MenuNavigation - OR- rather than replace the code section as described above, you must add the new code on its own line above or below the old code section.

[编辑]

How do I add a Google Search bar to the Search Results page?

Look here: How to add Google search to your MediaWiki Search Results Page

[编辑]

How do I move the location of the search box?

This is for the Monobook theme and involves modifying the Monobook.php file - you can see the effect here.

  • Find and select the following code in Monobook.php:
<div id="p-search" class="portlet">
     
     
          <h5><label for="searchInput"><?php $this->msg('search') ?></label></h5>
     
     
          <div class="pBody">
     
     
            <form name="searchform" action="<?php $this->text('searchaction') ?>" id="searchform">
     
     
              <input id="searchInput" name="search" type="text"
     
     
                <?php if($this->haveMsg('accesskey-search')) {
     
     
                  ?>accesskey="<?php $this->msg('accesskey-search') ?>"<?php }
     
     
                if( isset( $this->data['search'] ) ) {
     
     
                  ?> value="<?php $this->text('search') ?>"<?php } ?> />
     
     
              <input type='submit' name="go" class="searchButton" id="searchGoButton"
     
     
                value="<?php $this->msg('go') ?>"
     
     
                /> <input type='submit' name="fulltext"
     
     
                class="searchButton"
     
     
                value="<?php $this->msg('search') ?>" />
     
     
            </form>
     
     
          </div>
     
     
        </div>
     
     
 
     
     
  • Move it either up or down in the page code, depending on where you want it positioned.
  • A good place to put the search box is just below the logo. To do this, move or copy the above code directly below where you find the following:
        <div class="portlet" id="p-logo">
     
     
          <a style="background-image: url(<?php $this->text('logopath') ?>);"
     
     
            href="<?php echo htmlspecialchars($this->data['nav_urls']['mainpage']['href'])?>"
     
     
            title="<?php $this->msg('mainpage') ?>"></a>
     
     
        </div>
     
     

[编辑]

How do I edit the layout of all my wiki pages (headers, crumbtrails, etc)?

[编辑]

Custom Headers

You must modify the specific skin.php file you use to display a common header. Insert your header as a <div> section after the <body> tag.

[编辑]

Breadcrumb Trail

See User:Barre/Extensions/kw bread crumbs. This extension is not functional with 1.5.0 "out of the box," but a small change will remedy that. --Jcarroll 06:32, 20 October 2005 (UTC).

 

.

 

 

 

LocalSettings.php

·         Currently 2.00/5

·         1

·         2

·         3

·         4

·         5

页面分类: MediaWiki技术文档

天下维客,你可以修改的网络知识库

跳转到: 导航, 搜索

目录

[隐藏]

<script type=text/javascript> if (window.showTocToggle) { var tocShowText = "显示"; var tocHideText = "隐藏"; showTocToggle(); } </script> [编辑]

Overview

The file LocalSettings.php contains the local configuration of a MediaWiki installation. You should take your time to review the settings in this file. The file is usually generated by the web-based MediaWiki installer but you might want to tweak one or the other parameter (probably in concert with Apache settings).

Changing a setting usually means changing the value of a PHP variable. You might want to make yourself familiar with the PHP syntax first before going ahead. If you are too lazy, keep in mind that PHP variables are accessed by prepending a "$" character before the variable name; many variables are simply set to either

true

or

false

.

The default values of many more settings are set in includes/DefaultSettings.php, which should not be edited; if the variable you want to change is not already mentioned in your LocalSettings.php, copy the appropriate line from DefaultSettings and modify it appropriately. See Configuration settings index and the comments included in the settings files for help on what the variables do.

[编辑]

Standard Settings

[编辑]

Include Path

The IP (include path) variable holds the local file path to the base installation of your wiki. Make sure you refer to the fully qualified file path. Do not include a slash at the end of the path.

The DefaultSettings.php file gets loaded from the directory designated by the IP variable.

[编辑]

Site Name

The wgSitename variable holds the name of your wiki setup. This name gets included many times throughout the system. For instance, the Wikipedia tagline "'From Wikipedia, the free encyclopedia."' makes use of this setting.

[编辑]

Script Path

wgScriptPath is the URL path prefix to access the main MediaWiki script that is the central acting piece of code of MediaWiki. This setting should correspond to the Apache settings, especially if you are using Apache's rewrite rules.

[编辑]

Server name

wgServer can be used optionally to overwrite the automatic detection. When the wiki is accessed from either the localhost where it runs, from an intranet or from the internet, e-mail notifications and a few other computed messages would be usually delivered with the different URLs. Using wgServer overwrites the detection and the server name will be constant.

Add a line such as

$wgServer = 'http://www.domain.tld'; # add such a line, www.domain.tld being the server address of your wiki as seen from the internet.

{{SERVER}} can be used on wiki pages, it equals the value of $wgServer.

[编辑]

Script Name

wgScript is the name of the main (index) MediaWiki PHP script, named index.php by default. You might want to tweak the path to the script while changing the script name is probably not a good idea. However, if you feel the urge to do so, this is the place to make your changes. Make sure you know what you are doing.

[编辑]

Redirect Script Name

The wgRedirectScript variable specifies the URL path to the redirect script which handles redirects in MediaWiki. This setting is similar to wgScript as you can configure the exact name of the script. As mentioned above, this is probably not a good idea unless you really know what you are doing.

[编辑]

Article Path

wgArticlePath is the path to use when accessing a page in MediaWiki. The path should contain the path to the main script (usually making use of wgScript) and use the $1 placeholder for the article name.

if you are using Apache rewrite rules to create pretty and short URLs, you probably need to adjust wgArticlePath to address the right path. Note that wgArticlePath is used to construct URLs from within MediaWiki. If you make a mistake here, internal links will show up incorrectly while you still may be able to access the main page by specifying the correct URL manually.

Typical values are

"$wgScript/$1"

pass the article name with a / separator

"$wgScript?title=$1"

pass the article name as a parameter (old style)

"mypath/$1"

custom path. Use Apache rewrite rules to convert "mypath" to the proper path accessing the main script

[编辑]

Stylesheet Location

Use the wgStylePath variable to set the URL path to the place where the stylesheets (CSS) for the MediaWiki installation are located. The wgStyleDirectory should point the same place, but note that this is a local file system path for use in internal scripts accessing the file system.

[编辑]

Upload Location

The upload directory is the place where files uploaded by the users are stored. The wgUploadPath variable specifies the URL path, the wgUploadDirectory points to the local file system path.

[编辑]

Logo

The wgLogo variable specifies the relative URL pointing to the graphical logo that gets displayed on the top left corner by default. You might want to point the variable to the Upload Directory to be able to exchange the logo by updating uploaded files.

[编辑]

Contact Info

The wgEmergencyContact variable is the e-mail address of the user to contact when things happen. This e-mail address is used to send internal bug reports to. As an administrator, you want to include your e-mail address here.


The wgPasswordSender variable is the e-mail address where e-mail gets sent from, when passwords are sent out to users who have forgotten their passwords. Choose an address people can reply to in case of trouble or confusion.

[编辑]

Database Settings

MediaWiki needs access to the MySQL database to store pages, modifications, user information and a lot more things.

The wgDBserver contains the hostname where the database is hosted on. In most cases this will be just "localhost" as the database is run on the same system, but for distributed installations, you need to fill in the fully qualified domain name of the computer running the database.

wgDBname is the database name of the database to be used by MediaWiki. A single MySQL installation can store more than one database and you can even run many MediaWiki installations on a single server. Make sure you have stated the correct database name here and use different database names for different wiki installations on the the same database server.

The wgDBuser and wgDBpassword variables contain the login name and password to be used by MediaWiki to access the database. Make sure the specified user has the proper access rights to be able to manipulate the wiki's table on the database server.

Also keep in mind that the LocalSettings.php permissions should not allow other users to view this file as it contains security-related data.

[编辑]

User rights

The wgGroupPermissions is an associative array, controlling permissions for creating and editing pages for your different user groups. See Help:User rights

[编辑]

Force Capital Links

By default, all article names are forced to start with a capital (roman) letter unless they start with a non-alphabetical character. If you want to allow article names to start with a lowercase character you must adjust the wgCapitalLinks variable. Setting it to false allows lowercase characters, true chooses the default behaviour.

[编辑]

Enabling subpages

Subpages are enabled on a per-namespace basis. For example, to enable subpages in the main namespace:

$wgNamespacesWithSubpages[NS_MAIN] = 1;

$wgUseRCPatrol = true;

[编辑]

Advanced Settings

[编辑]

Direct SQL Queries

To allow SQL queries through the wiki's Special:Asksql page, you can enable direct SQL queries via the web interface. THIS IS VERY INSECURE. If you want to allow semipublic read-only SQL access for your sysops, you should define a MySQL user with limited privileges.

Review the MySQL documentation at http://www.mysql.com/doc/en/GRANT.html on how permissions can be granted in the database subsystem.

The wgAllowSysopQueries must be set to true if you want the direct SQL query feature to be turned on. The wgDBsqluser and the wgDBsqlpassword contain the login name and password to use to access the database with that feature.

[编辑]

Image Uploads

Before users are allowed to upload files to the MediaWiki system, you have to enable that feature. Make sure the Upload Directory is properly configured and writeable by the Apache web server process. Then set the wgEnableUploads to true to allow uploading in the web user interface.

i.e. Here's some example code from includes/DefaultSettings.php to put in LocalSettings.php.

$wgUploadPath       = "$wgScriptPath/uploads";      ## Wiki 1.5 defaults to /images, but allows more than just images

$wgUploadDirectory  = "$IP/uploads";                ## Wiki 1.5 defaults to /images, but allows more than just images

 

## To enable image uploads, make sure the above '$wgUploadPath' directory is writable by Apache User or group.

## <i>(i.e.  chmod og+w uploads images)</i>  then the following should be true:

$wgEnableUploads               = true;

$wgUseImageResize              = true;

$wgUseImageMagick              = true;

$wgImageMagickConvertCommand = "/usr/bin/convert";

## If you want to use image uploads under safe mode, create the directories images/archive, images/thumb and

## images/temp, and make them all writable. Then uncomment this, if it's not already uncommented:

$wgHashedUploadDirectory = false;

If you want to be able to resize images on the fly to support thumbnails, MediaWiki needs a working ImageMagick installation. Set the variable $wgUseImageMagick to true once you have installed and tested ImageMagick on your system. Make sure the wgImageMagickConvertCommand variable points to the proper location of the convert command of your installation and that the command is executable by the web server process.

Also, you may want to modify the list of accepted extensions:

$wgFileExtensions = array('png','jpg','jpeg','ogg','doc','xls','ppt','mp3','sxc','pdf','nse');

[编辑]

LaTeX inline equations

In order to render mathematical formulas in LaTeX, you need a working LaTeX installation on your system. Set the $wgUseTeX to true to enable that feature. Also make sure the wgMathPath, wgMathDirectory and wgTmpDirectory are set properly, but you might want to go with the default values unless you have a very good reason to change it.

See Also

·         Help:Formula

[编辑]

InterWiki support

InterWiki support is built into MediaWiki but you need to configure the prefix to be used for your internal links. This prefix is usually the same as wgSitename but in case you need to change that, you set the wgLocalInterwiki variable to the preferred name.

[编辑]

User Interface Language

MediaWiki allows for a variety of localized user interfaces languages instead of the english default. If you want to run your wiki in a non-english language, set the wgLanguageCode variable to the proper language code (e.g. "de" for german, "es" for spanish, etc.)

[编辑]

File cache

See File cache.

[编辑]

Setting Copyright of the site

This is not documented yet, but a little experimentation demonstrates that the following works.

·          $wgRightsPage

is the page on the wiki that covers the copyrights that it falls under. Usually, this will be Project:Copyrights.

·          $wgRightsText

is the text in the footer that follows "Content is available under". It will be linked to the page specified in

$wgRightsPage

.

·          $wgRightsIcon

is the URL of the image placed at the left of the footer.

·          $wgRightsUrl

is the page describing full details of your license. (For the GNU FDL, for example, this would be

http://www.gnu.org/licenses/fdl.html

.)

·          $wgEnableDublinCoreRdf

and

$wgEnableCreativeCommonsRdf

to add rdf meta data to wiki pages


Add something like this to LocalSettings.php

$wgRightsPage = "YourWiki:Copyright";

$wgRightsText = "copyright YourWiki";

Edit MediaWiki:Copyright to provide an appropriate message, using "$1" to indicate the position where the link to your copyright page will be.

Still required: explanation of the functions of the remaining variables:

$wgRightsUrl = "";

$wgRightsIcon = "";


To set a Creative Commons license do the following:

·         Choose your license: http://creativecommons.org/text/publish-website

·         Examine the returned HTML code, e.g.:

<a rel="license" href="<a href="http://creativecommons.org/licenses/by-nc-sa/2.5/" class="external free" target="_blank" title="http://creativecommons.org/licenses/by-nc-sa/2.5/" rel="nofollow">http://creativecommons.org/licenses/by-nc-sa/2.5/</a>">

<img alt="Creative Commons License" border="0" src="<img src="http://creativecommons.org/images/public/somerights20.png" alt="somerights20.png" />" />

</a>

This work is licensed under a

<a rel="license" href="<a href="http://creativecommons.org/licenses/by-nc-sa/2.5/" class="external free" target="_blank" title="http://creativecommons.org/licenses/by-nc-sa/2.5/" rel="nofollow">http://creativecommons.org/licenses/by-nc-sa/2.5/</a>">

Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License</a>.

·         For

$wgRightsURL

enter the href info from the first anchor:

$wgRightsUrl = "<a href="http://creativecommons.org/licenses/by-nc-sa/2.5/" class="external free" target="_blank" title="http://creativecommons.org/licenses/by-nc-sa/2.5/" rel="nofollow">http://creativecommons.org/licenses/by-nc-sa/2.5/</a>";

·         For

$wgRightsText

enter the text the second anchor links from (add the "a" to the Wiki variable for a more grammatically correct version)

$wgRightsText = "a Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License";

·         For

$wgRightsIcon

enter the src info from the img link in the first anchor. You want to copy the badge to your own site instead of using the one from the Creative Commons site.

$wgRightsIcon = "<img src="http://creativecommons.org/images/public/somerights20.png" alt="somerights20.png" />";

·         For using rdf meta data about copyright add one or both of the following lines to your LocalSettings.php

$wgEnableCreativeCommonsRdf = true;

$wgEnableDublinCoreRdf = true;

For more details about rdf meta-data see RDF_metadata

Note: If $wgRightsPage is non-empty, the link in the copyright/license notice will link to that page on your site. If $wgRightsPage is empty then the copyright/license notice will link to $wgRightsUrl instead.

[编辑]

Custom Namespaces

See Custom namespaces

[编辑]

Enabling a Debug Log

See WgDebugLogFile

[编辑]

Enabling calculations

include("extensions/calc.php");

[编辑]

开启ajax功能

Image:使用ajax搜索功能.png

开启ajax之后,使用即时搜索功能

目前可以确认,至少在版本1.7之后便引入了ajax支持,此功能默认关闭,添加以下行进行开启:

$wgUseAjax = true

$wgLocaltimezone = "Asia/Shanghai"; putenv("TZ=$wgLocaltimezone"); $wgLocalTZoffset = date("Z") / 60;

MediaWiki的导航条

·         Currently 1.00/5

·         1

·         2

·         3

·         4

·         5

页面分类: MediaWiki技术文档

天下维客,你可以修改的网络知识库

跳转到: 导航, 搜索

欢迎翻译^_^

Template:H:h

Image:MediaWiki-Sidebar.png

The MediaWiki sidebar

The navigation bar or side bar or sidebar is shown at the left hand side of each MediaWiki page by default. In versions 1.5 and newer, it can be modified using the MediaWiki:Sidebar page, see MediaWiki:Sidebar.

目录

[隐藏]

<script type=text/javascript> if (window.showTocToggle) { var tocShowText = "显示"; var tocHideText = "隐藏"; showTocToggle(); } </script> [编辑]

Format of the sidebar page

The sidebar page is laid out similar to the following:

navigation

    mainpage|mainpage

    mypage-url|My Page

 

tools

    Special:Allpages|All Pages

[编辑]

Headings

The items on the outer level

·         Navigation

·         Tools

are the headings used on the sidebar. In this manner, the bar can be split into sections.

[编辑]

Items

The second level items

·         mainpage|mainpage

·         mypage-url|My Page

are the actual items that appear on the sidebar; see below for instructions on setting these up.

[编辑]

Specifying items on the sidebar

All items on the sidebar take a format which is split by a pipe (|) character: link target|Display text

[编辑]

Locating the sidebar

In versions 1.4 and newer, it can be modified using the MediaWiki:Sidebar page. Find this page by using search. Or browse to:

http://your-web-site-or-server/wiki/index.php?&title=MediaWiki:Sidebar

Alternatively, put a [[MediaWiki:Sidebar]] text/link on one of your pages and follow it; it goes to the same place: MediaWiki:Sidebar.

In older then 1.4 ????????????

[编辑]

Link target

The left-hand portion of the pipe corresponds to the target of the link, and refers to:

·         a MediaWiki namespace page

OR

·         a wiki page name

If a MediaWiki namespace page of the same name exists, then the contents of that page are used to determine where the link points. For instance, the default contents of MediaWiki:Mainpage are Main Page - this is the name of the page to be used.

To link to an external URL, simply create the namespace page containing the URL, e.g. the contents of Special:Mypage-url (from the example above) might be http://www.domain.com.

·         With 1.5, you can create an external URL more simply: just insert the URL before the vertical bar, as in this example:

http://www.domain.com |Domain.com

Note:

·         The required space after the URL.

·         Currently, no support for going directly to a 'bookmark' (i.e. '#' indicator) of an article or page.

[编辑]

Display text

The right-hand portion of the pipe corresponds to the display form of the link, and is either:

·         a MediaWiki namespace page name

OR

·         plain text

If a MediaWiki namespace page of the same name exists, then the contents of that page are used to determine the text used for the link. For instance, the default contents of MediaWiki:Mainpage are Main Page - this is what is displayed.

You can also place the text here without using a namespace page; so if MediaWiki:My_Page doesn't exist, then the text My Page would be displayed, using the example above.

[编辑]

Other considerations

[编辑]

Allowing users to have individual sidebars

There is a discussion taking place surrounding a feature request which, if implemented, would provide a custom sidebar that users themselves can edit to their individual preferences. Discussion, and a current implementation using CSS and JavaScript can be found at Configurable Sidebar.

[编辑]

Allowing anyone to edit the sidebar

The MediaWiki namespace pages are protected, preventing ordinary users from editing the sidebar. To see a possible means to allow this, refer to discussion at the relevant FAQ page.

[编辑]

Navigation Bar versus the Toolbox area

·         Mediawiki:Sidebar is a page to edit the Navigation bar above(in monobook skin) the search box. You need to be logged in and part of the sysop group to be able to edit this page.

·         The toolbox is under the search bar is a dynamic element and cannot be easily customized. (It requires programming in PHP.) If you still want to do so, the best solution is to copy skins/MonoBook.php, creating a new skin. You can then make a custom skin to generate these links in your preferred fashion.

 

 

 

 

 

建立新的MediaWiki特殊页面

·         Currently 3.00/5

·         1

·         2

·         3

·         4

·         5

页面分类: MediaWiki技术文档

天下维客,你可以修改的网络知识库

跳转到: 导航, 搜索

欢迎翻译^_^

Image:Drafting table.jpg

Special pages, with the prefix "Special:", are fairly self contained MediaWiki extensions that do useful things that wouldn't fit in with the normal user interface.

MediaWiki 1.5 offers reflective extension loading, which means hooking up your extension to the system is fast and easy. The possibilities for special pages are limitless, only constrained by your programming ability.

This page gives MediaWiki 1.5 specific information. You can find the pre-1.5 version here: Writing a new special page, and if anyone is interested in maintaining the old version, feel free to branch it.

目录

[隐藏]

<script type=text/javascript> if (window.showTocToggle) { var tocShowText = "显示"; var tocHideText = "隐藏"; showTocToggle(); } </script> [编辑]

Abstract

A special page is, essentially, a PHP function that is called when someone browses to that page. You can pass off the handling of logic to a class (most special pages do that) or you can inline all of the logic in the function.

What makes special pages different from extra PHP pages littered on your server, however, is the fact that they build off the enormous amount of initialization and infrastructure that MediaWiki offers. Part of the problem is integrating the special page with MediaWiki (a very simple process), but the real deal is utilizing all of MediaWiki's resources, whether they are absolutely necessary, or just "kinda cool."

[编辑]

Tutorial

To add your own extension page, you will need to add two pages to the MediaWiki installation. I am using a naming convention that adds prefixes special to my extension's name since it's a special page. My special page would be viewable at Special:Example.

[编辑]

Extension page

This page resides at

extensions/SpecialExample.php

. It must be included in LocalSettings.php (which is how the system knows the extension exists) after the line that includes DefaultSettings.php. Add the following line to LocalSettings.php:

require_once('extensions/SpecialExample.php');

The file

extensions/SpecialExample.php

is responsible for registering the special page and adding the special page's default system messages. It's important to add the system messages here, because if they're inside the extension itself, Special:Allmessages can't get to it.

<?php

$wgExtensionFunctions[] = "wfExtensionSpecialExample";

function wfExtensionSpecialExample() {

    global $wgMessageCache;

    $wgMessageCache->addMessages(array('example' => 'An Example Special Page')); //will expand

    // the name 'example' above should NOT have any capital letter.

    SpecialPage::addPage( new SpecialPage( 'Example' ) );

}

//extension specific configuration options (like new user groups and perms) here

?>

Put your extension code inside the loading function definition shown above. As of 1.6, you no longer need to put a file in the includes directory and the loading function (wfExtensionSpecialExample) encapsulates any special classes that you define. If this is unclear, you might check out the BoardVote.php file in the extentions/BoardVote directory, as it does things the right way.

 

[编辑]

What happens

The extension page defines a few configuration options and also registers our extension function. Once all initialization is done, MediaWiki calls all the functions enumerated in

$wgExtensionFunctions

.

The function we assign serves two purposes:

1.    It initializes the system messages our extension will use (or at the very least, the title of the extension page)

2.    It registers our extension as a SpecialPage

Then, control is passed back to the flow of the script, and if the page requested is a special page, SpecialPage will call the proper special page, and if it's your page, it will include your page (determined by concatenating Special with the name of your page and '.php') and it will call your function,

wfSpecialExample

(which was determined by concatenating wfSpecial with the name of your special page).

So with this simple bit of code, we have told MediaWiki everything it needs to know about our extension. Congratulations: you've just made a shiny new, albeit boring, special page.

[编辑]

An analogy

wfSpecialExample()

= PHP page

Think of your function

wfSpecialExample

as an actual PHP page that's one level deep in a function. PHP pages can be transaction script style, but they can also share a domain model or act as controllers. Do not be limited by the fact that it is a "function": in this application, it should be treated as a full fledged PHP page, albeit one that piggybacks off a large amount of initialization and cleanup.

[编辑]

Forms

A special page usually does something, that is, it changes the state of MediaWiki. In order to do that, we usually implement HTML forms. This section offers some quick code for the most common things you need to do in forms.

//<b>Retrieving the URL for the action</b>

$titleObj = Title::makeTitle( NS_SPECIAL, 'NameOfExtensionPageWithoutNamespace' );

$action = $titleObj->escapeLocalURL();

$wgOut->addHTML('<form method="post"'.

    ' enctype="multipart/form-data" action="'.$action.'">');

//rest of form code, using addHTML(), here

[编辑]

Special Parameters

The most common way of passing parameters to pages is through GET (the query string). However, attempting to do Special:Allpages?var1=value will not get you far, as it will attempt to actually load a special page under the name of Allpages?var1=value. Instead, we use an alternative syntax, in which after the special page's name, there is a slash, and then an arbitrary string after it which is passed to the function. Sound confusing? It doesn't have to be.

An example of how this is done is the Special:Emailuser page. The recipient's username is passed to the special page as follows:

[[Special:Emailuser/username]]

The corresponding special page (

SpecialEmailuser.php

in this case) receives everything following the slash in the variable

$par

:

function wfSpecialEmailuser( $par )

$par

can then be parsed to extract an arbitrary number of variables. In this example,

$par

is simply the username of the recipient, and no parsing is necessary. Otherwise, you can emulate a directory structure or create your own special syntax for passing parameters (the former is preferred).

[编辑]

Global Variables

MediaWiki makes extensive use of globals. If anyone ever told you globals were bad, well, here's a professional system that uses globals fairly well. All globals are prefixed with

$wg

, and they contain loads of useful information about the context of the request.

[编辑]

Don't edit core code unless you absolutely have to

Reasons why you shouldn't cave into temptation and edit code elsewhere:

·         Upgrading becomes a pain in the arse, especially when they conflict

·         You fundamentally change the way MediaWiki works, which leads to logic errors

·         It's harder to distribute (you have to give out diffs)

·         Your changes are scattered over more pages

·         Greater chance your extension will clobber other extensions

·         It's unclean

·         Because there's often a solution that doesn't require core edits

If you find yourself in a real fix, you can always consider using a decorator on a global like $wgOut.

[编辑]

Advanced topics

The best way to go about learning about all the public methods and classes is to either read the source code or consult the API documentation. The list of stuff covered here is a quick, uncomprehensive reference for the most commonly used classes and methods, and probably is a bit more user friendly then the automatically generated docs.

[编辑]

SpecialPage

The first gut instinct of most people when out to create a new special page is to look at

SpecialPage.php

. In reality, very little to no knowledge is necessary of the SpecialPage class. Special Pages generally are not defined by extending the class

SpecialPage

: MediaWiki favors the reflective approach which calls a function that does all the heavy lifting.

How do we know this? By observing MediaWiki code, we note the list of basic SpecialPages:

$wgSpecialPages = array(

        'DoubleRedirects'      => new SpecialPage ( 'DoubleRedirects' ),

        'BrokenRedirects'      => new SpecialPage ( 'BrokenRedirects' ),

        'Disambiguations'      => new SpecialPage ( 'Disambiguations' ),

        //...

);

Not a single page in this array is not a

SpecialPage

,

IncludableSpecialPage

or

UnlistedSpecialPage

. How did the MediaWiki developers get all these different special pages by passing only the name of the special page? The magic is introspection: when a special page is executed, this function is called:

        function execute( $par ) {

               global $wgUser, $wgOut, $wgTitle;

 

               $this->setHeaders();

 

               if ( $this->userCanExecute( $wgUser ) ) {

                       if ( $this->mFile ) {

                               require_once( $this->mFile );

                       }

                       $func = $this->mFunction;

                       $func( $par, $this );

               } else {

                       $this->displayRestrictionError();

               }

        }

It does several things:

1.    Set the page title and other things using

SpecialPage::setHeaders()

Determines whether or not a user can access the page (one of the few things SpecialPage does)

Reflectively requires the file with relevant information

Reflectively calls the function

This is a framework and is not meant to be lightly overloaded.

[编辑]

SpecialPage::SpecialPage() constructor

Here is the API:

function SpecialPage( $name = '', $restriction = '', $listed = true, $function = false,

  $file = 'default', $includable = false )

At the very simplest, you would create a new SpecialPage like this:

$specialpage = new SpecialPage('NameOfSpecialPage');

At this point, MediaWiki knows enough about your special page in order to figure out what the function to call is. The second variable, restriction, is the second most used. The framework has the ability to check whether or not a user has permission to access the page, and throw an error if they don't. This may seem trivial to implement within your function, but it has the added benefit of not listing the special page to users that don't have the necessary priviledges, as well as listing the special page under Restricted special pages when they do.

By default, Special Pages are listed and they are not includable.

IncludableSpecialPage

or

UnlistedSpecialPage

are convenience classes that make this distinction more clear, rather than doing:

$specialpage = new SpecialPage('NameOfSpecialPage', 'sysop', false);

Where the meaning of the third parameter is not immediately evident to:

$specialpage = new UnlistedSpecialPage('NameOfSpecialPage', 'sysop');

This usage is smiled upon by developers, who use this:

'Recentchanges'     => new IncludableSpecialPage( 'Recentchanges' ),

'Whatlinkshere' => new UnlistedSpecialPage( 'Whatlinkshere' ),

Instead of using the parameters.

Finally, $function and $file do what they suggest: they allow you to specify exactly which file and function should be called. These are never (to my knowledge) used by the developers, and I don't recommend using them. Enforce good naming conventions.

[编辑]

SpecialPage::addPage()

You use this to pass an instance of the actual SpecialPage instance that handles your class. Do not modify the

$wgSpecialPages

array.

[编辑]

UnlistedSpecialPage

This creates a special page which is unlisted by default. The meaning of this should be self-evident. This is used for many pages including Userlogout, Specialpages (obviously), Contributions, Movepage and Blockme. Syntax is:

function UnlistedSpecialPage( $name, $restriction = '', $function = false, $file = 'default' )

[编辑]

IncludableSpecialPage

This creates a special page which is includable via the syntax: {{special:nameofpage}}. Recentchanges, Newpages and Allpages are includable. Syntax is:

function IncludableSpecialPage( $name, $restriction = '', $listed = true,

  $function = false, $file = 'default' )

[编辑]

Why Inherit

Under certain situations, creating a subclass special page is desirable. For instance, the Board Vote extension creates a subclass called

BoardVotePage

.

Why would you want to do this?

·         You want a custom user permissions checking beyond the almost-simplistic one permission handling the default page has (but you can always put it in your actual extension function if need be)

·         You don't want to add any extra pages to the

includes

directory, and keep it all in the

extensions

·         You don't want MediaWiki to reflectively call functions for whatever reason

·         You need your special page to execute before headers are sent (although the HEAD revision of the CVS gives you hooks to bypass this restriction)

·         You think that it's conceptually cleaner to put all the logic inside the special page

Most of the time, it's overkill. Inheritance should be your last resort. I do not recommend using the BoardVote extension as a base for your extensions: using MediaWiki's default hooks is far more intuitive.

[编辑]

OutputPage $wgOut

The global variable

$wgOut

is the variable you will use the most, because it is the way to send output to the browser (no, you don't use

echo

or

print

). If you want to use it somewhere, declare the variable global:

function randomFunction() {

  global $wgOut;

  $wgOut->addHTML('<b>This is not very random...</b>');

}

$wgOut contains an OutputPage object, which you can inspect by viewing

includes/OutputPage.php

(indeed, all of these can be inspected), but there are a few methods you should definitely know about.

[编辑]

OutputPage::addHTML()

Essentially the quick and dirty substitute for

echo

. It takes your input and adds it to the buffer: no questions asked. Be careful with it. You should use this for complicated forms and output in your page.

$wgOut->addHTML('<form action="'.$action.'" method="post">');

[编辑]

OutputPage::addWikiText()

For most output, you should be using this function. It's a bit of a black magic function: wikitext goes in, HTML comes out, and a whole lotta of arcane code and demon summonings happen in between.

$wgOut->addWikiText("This is some ''lovely'' [[wikitext]] that will '''get''' parsed nicely.");

What's worth noting is that the parser will view your chunks as cohesive wholes and paragraph accordingly. That is...

$wgOut->addWikiText('* Item 1');

$wgOut->addWikiText('* Item 2');

$wgOut->addWikiText('* Item 3');

Will output three lists with one item each, which probably wasn't intended.

[编辑]

wfMsg()

In most of the real special pages, you will rarely see

$wgOut->addWikitext()

without

wfMsg()

popping in.

wfMsg()

is MediaWiki's way of internationalization (i18n). An example:

$wgOut->addWikiText( wfMsg( 'flubbersuccess' ) );

wfMsg()

looks up the system message called

flubbersuccess

, and then returns it. The actual text of the message can come from a variety of places. Find out more about how to tell MediaWiki what to output in <a href="#MessageCache_.24wgMessageCache" title="">MessageCache</a>.

[编辑]

OutputPage::errorpage()

[编辑]

MessageCache $wgMessageCache

MessageCache is a class that will figure out what the string corresponding to the key (

flubbersuccess

) you give it. In most circumstances, they will come from these places, with the overriding one on the bottom:

1.    Default language file

Added on extension strings

The MediaWiki namespace

The default language file is all the stuff that comes bundled with Wikipedia. Since we're writing extensions, and we're implementing new functionality, this isn't very useful. Next is extension strings.

[编辑]

MessageCache::addMessages()

MessageCache::addMessages is usually used for adding messages for extensions, and they are internally marked as such. The syntax is very simple:

function addMessages( $messages )

Where $messages is an array that looks like:

array (

    'key1' => 'Value 1'

   ,'key2' => 'Value 2'

)

Whatever your key was, you can get the value using

wfMsg('key')

. This allows MediaWiki to pass a customized string from a page in the MediaWiki database, specifically MediaWiki:Key.

[编辑]

Title of your extension

MediaWiki does not set the title of your extension: that is your job. It will look for the name of your extension when Special:Specialpages is called or you actually load the special page (specifically right before your registered wfSpecial*() function is called).

I have come to the conclusion that the best place to define the name of your special page is right before it gets registered using

addPage()

. You definitely should not call it inside the actual function (whether it be an overloaded SpecialPage::execute() or your wfSpecial*() function): SpecialPages will never find out about it! (besides the fact that you will have to SpecialPage::setHeaders() again). The place where your extension can be found, as specified by what you pass into the SpecialPage constructor, is the key, except that it is not capitalized. This is because

getDescription()

, the internally used function that finds out the title (or, what they call description) of the special page,

strtolower

the name. "ThisIsACoolSpecialPage"'s key would be "thisisacoolspecialpage."

You can, theoretically, overload getDescription in order to avoid interacting with the message cache, but, as the source code states: "Derived classes can override this, but usually it is easier to keep the default behaviour. Messages can be added at run-time, see MessageCache.php". Furthermore, this prevents the MediaWiki namespace from overloading the message, as below.

[编辑]

MediaWiki namespace

So you've just installed a shiny new MediaWiki extension and realize: "Oh no, my wiki is in French, but the page is showing up as English!" Most people wouldn't care, but it's actually a quite simple task to fix (as long as the developer used the method explained on this page). No noodling around in source code. Let's say the name of the page is

DirtyPages

and the name comes out to "List of Dirty Pages" but you want it to be (and excuse my poor French) "Liste de Page-écrans Sales". Well, it's as simple as this:

1.    Navigate to MediaWiki:DirtyPages, this page may not exist, but edit it anyway

Insert "Liste de Page-écrans Sales" and save

And voila (pardon the pun), the change is applied.

This is also useful for customizing the title for your wiki within your language: for instance, the developer called it "List of Dirty Pages" but you don't like that name, so you rename it "List of Pages needing Cleanup".

But even further: this is a sound bit of advice that applies to every single message that uses MessageCache, ones that are core and ones added by extensions. Check out Special:Allmessages to learn more.

This means that if your extension has a large block of text, don't directly output it using wgOut, instead, add it to the message cache, and then when the time comes, do:

$wgOut->addHTML( wfMsg( 'dirtypageshelp' ) );

Then this message too can be customized at MediaWiki:Dirtypageshelp.

Note: this information should be covered elsewhere in Meta, but I can't seem to find it. Please add a link to that page if you know where it is)

[编辑]

WebRequest $wgRequest

The WebRequest superglobal is used to obtain information from the GET and POST arrays. Using this is recommended over directly accessing the superglobals, since the object does fun stuff like magic_quotes cleaning.

[编辑]

WebRequest::getVal()

[编辑]

WebRequest::get*()

[编辑]

WebRequest::wasPosted()

[编辑]

Database

MediaWiki has a load of convenience functions and wrappers for interacting with the database. It also has an interesting load balancing scheme in place. It's recommended you use these wrappers. Check out

Database.php

for a complete listing of all the convenience functions, because these docs will only tell you about the non-obvious caveats.

[编辑]

wfGetDB()

As this name suggests, this function gets you a reference of the database. There is no global that contains a database object.

When you call the function, you should pass it a parameter, the constant

DB_MASTER

or

DB_SLAVE

. Generally, you interact with the slave database when you're only performing read operations, and interact with the master when you're writing to the database. It's real easy to do, so do it, even if you only have one database.

[编辑]

User $wgUser

The User object is used to represent users on the system. The superglobal

$wgUser

represents the currently logged in user, and is usually what you will deal with when manipulating users.

[编辑]

User::isAllowed()

[编辑]

User::isBlocked()

[编辑]

Title

Title represents the name of a page in the wiki. This is useful because MediaWiki does all sorts of fun escaping and special case logic to page names, so instead of rolling your own convert title to URL function, you create a Title object with your page name, and then use escapeLocalURL to get a URL to that page.

[编辑]

Title::makeTitle()

[编辑]

Title::escapeLocalURL()

 

 

 

MediaWiki修改:以新窗口打开外部链接

·         Currently 1.00/5

·         1

·         2

·         3

·         4

·         5

页面分类: Mediawiki Hacks | MediaWiki技术文档

天下维客,你可以修改的网络知识库

(重定向自MediaWiki修改:以新窗口打开链接)

跳转到: 导航, 搜索

[编辑]

MediaWiki 1.4.x 及之前版本

1.    打开"Includes/Skin.php "Includes/Linker.php"

2.    找到"function getExternalLinkAttributes"

3.   

$r = ($class != '') ? " class='$class'" : " class='external'";

替换为

$r = ($class != '') ? " class='$class' target='_blank' " : " class='external' target='_blank' ";

说明: 这个修改对标准界面的侧栏链接不起作用,即点击后仍在当前窗口显示相应内容。

 

[编辑]

MediaWiki 1.5.x 及更高版本

1.    打开 "includes/Linker.php"

2.    找到 "function getExternalLinkAttributes"

3.    在下面一段代码之后

$r = ($class != '') ? " class='$class'" : " class='external'";

增加以下代码:

$r .= " target=/"_blank/"";

这样就能让所有的外部链接以新窗口形式打开了。

由于MediaWiki的页面缓冲机制,可能造成这个修改的效果不能迅速完全反映出来。可以参考如何清除MediaWiki的页面缓存来解决这个问题。

有些人不喜欢强制在新窗口中打开页面的网站。

 

 

 

MediaWiki扩展:简单时间线

·         Currently 1.00/5

·         1

·         2

·         3

·         4

·         5

页面分类: 待翻译文章 | MediaWiki extensions | MediaWiki技术文档

天下维客,你可以修改的网络知识库

跳转到: 导航, 搜索

本文取自元维基,欢迎共同翻译、整理与大家共享,促进中文wiki发展^_^

As the saying goes: a picture is worth a thousand words. This is certainly true for graphical timelines. A detailed listing of events and dates in tabular form may offer the reader a lot of specifics, but may fail to provide an overview, a grand perspective.

As of 1 June 2004 there is a wiki way to compose graphical time charts offline.

Syntax description at Help:EasyTimeline_syntax.


You can also use this tool outside Wikipedia, see the EasyTimeline project site, or activate it on other MediaWiki installations, see EasyTimeline activation.

For an overview of all charts prepared with EasyTimeline on all wikipedias (images and code) see EasyTimeline Index, refreshed weekly as part of the statistics job.

目录

[隐藏]

<script type=text/javascript> if (window.showTocToggle) { var tocShowText = "显示"; var tocHideText = "隐藏"; showTocToggle(); } </script> [编辑]

Charts examples

Three examples of what is possible. For more extensive examples see WW II - Pacific Theatre, History of Computing, Tour de France Sieger. A nice example of a diagram that is not a timeline at all is Vocal and instrumental pitch ranges.

|- |valign="top"| <timeline> ImageSize = width:160 height:550 PlotArea = width:50 height:530 left:50 bottom:10 DateFormat = yyyy Period = from:1919 till:1991 TimeAxis = orientation:vertical ScaleMajor = unit:year increment:5 start:1920

  1. there is no automatic collision detection,
  2. so shift texts up or down manually to avoid overlap

Define $dx = 25 # shift text to right side of bar PlotData=

 bar:Leaders color:red width:25 mark:(line,white) align:left fontsize:S

 from:start till:1922 shift:($dx,15)   text:Vladimir~Ilyich~<a href="/index.php?title=Lenin&action=edit" class="new" title="Lenin" rel="nofollow">Lenin</a>

 from:1922  till:1953 shift:($dx,5)    text:<a href="/index.php?title=Stalin&action=edit" class="new" title="Stalin" rel="nofollow">Josef Stalin</a>

 from:1953  till:1964 shift:($dx,5)    text:Nikita~<a href="/index.php?title=Khrushchev&action=edit" class="new" title="Khrushchev" rel="nofollow">Khrushchev</a>

 from:1964  till:1982 shift:($dx,5)    text:Leonid~<a href="/index.php?title=Brezhnev&action=edit" class="new" title="Brezhnev" rel="nofollow">Brezhnev</a>

 from:1982  till:1984 shift:($dx,-12)  text:Yuri~<a href="/index.php?title=Andropov&action=edit" class="new" title="Andropov" rel="nofollow">Andropov</a>

 from:1984  till:1985 shift:($dx,4)    text:Konstantin~<a href="/index.php?title=Chernenko&action=edit" class="new" title="Chernenko" rel="nofollow">Chernenko</a> fontsize:XS

 from:1985  till:end  shift:($dx,10)   text:Mikhail~<a href="/index.php?title=Gorbachev&action=edit" class="new" title="Gorbachev" rel="nofollow">Gorbachev</a>

</timeline>

| |valign="top"| <timeline> ImageSize = width:800 height:100 PlotArea = width:720 height:75 left:65 bottom:20 AlignBars = justify

Colors =

 id:epoch  value:rgb(0.7,0.7,1) # light yellow

 id:period value:rgb(1,0.7,0.7) # light red

 id:age    value:rgb(0.7,1,0.7) # light green

 id:era    value:rgb(1,1,0.7)   # light blue

 id:eon    value:rgb(1,0.7,1)   # light purple

 id:black  value:black

Period = from:-4500 till:0 TimeAxis = orientation:horizontal ScaleMajor = unit:year increment:500 start:-4500 ScaleMinor = unit:year increment:100 start:-4500

Define $markred = text:"*" textcolor:red shift:(0,3) fontsize:10

PlotData=

 align:center textcolor:black fontsize:8 mark:(line,black) width:25 shift:(0,-5)

 bar:eon color:eon

 at:      0   align:right  $markred

 at:   -545   align:left   $markred

 from: -545   till:    0   text:<a href="/index.php?title=Phanerozoic&action=edit" class="new" title="Phanerozoic" rel="nofollow">Phanerozoic</a>

 from:-4500   till:    0   text:<a href="/index.php?title=Precambrian&action=edit" class="new" title="Precambrian" rel="nofollow">Precambrian</a>

 bar:era color:era

 from:  -64.3 till:    0   text:C~z shift:(0,1.5)

 from: -251.1 till:  -64.3 text:<a href="/index.php?title=Mesozoic&action=edit" class="new" title="Mesozoic" rel="nofollow">Meso~zoic</a> shift:(0,1.5)

 from: -545   till: -251.1 text:<a href="/index.php?title=Paleozoic&action=edit" class="new" title="Paleozoic" rel="nofollow">Paleo~zoic</a> shift:(0,1.5)

 from:-4500   till: -545   text:<a href="/index.php?title=Proterozoic&action=edit" class="new" title="Proterozoic" rel="nofollow">Proterozoic</a>

 bar:period color:period

 fontsize:6

 from:   -1.6 till:    0

 from:  -64.3 till:   -1.6

 from: -146   till:  -64.3

 from: -208   till: -146

 from: -251.1 till: -208

 from: -286   till: -251.1

 from: -360   till: -286

 from: -408.5 till: -360

 from: -443.5 till: -408.5

 from: -490   till: -443.5

 from: -545   till: -490

 fontsize:8

 from: -900   till:  -545  text:<a href="/index.php?title=Neoproterozoic&action=edit" class="new" title="Neoproterozoic" rel="nofollow">Neoprote-~rozoic</a> shift:(0,1.8)

 from:-1600   till:  -900  text:<a href="/index.php?title=Mesoproterozoic&action=edit" class="new" title="Mesoproterozoic" rel="nofollow">Mesoproterozoic</a>

 from:-2500   till: -1600  text:<a href="/index.php?title=Paleoproterozoic&action=edit" class="new" title="Paleoproterozoic" rel="nofollow">Paleoproterozoic</a>

 from:-3800   till: -2500  text:<a href="/index.php?title=Archaean&action=edit" class="new" title="Archaean" rel="nofollow">Archaean</a>

 from: start  till: -3800  text:<a href="/index.php?title=Hadean&action=edit" class="new" title="Hadean" rel="nofollow">Hadean</a>

</timeline>

<timeline> ImageSize = width:800 height:120 PlotArea = width:720 height:95 left:65 bottom:20 AlignBars = justify

Colors =

   id:epoch  value:rgb(0.7,0.7,1) # light yellow

   id:period value:rgb(1,0.7,0.7) # light red

   id:age    value:rgb(0.7,1,0.7) # light green

   id:era    value:rgb(1,1,0.7)   # light blue

   id:eon    value:rgb(1,0.7,1)   # light purple

   id:filler value:gray(0.8)      # background bar

   id:black  value:black

Period = from:-545 till:0 TimeAxis = orientation:horizontal ScaleMajor = unit:year increment:100 start:-500 ScaleMinor = unit:year increment:10 start:-540

Define $markred = text:"*" textcolor:red shift:(0,3) fontsize:10 Define $markgreen = text:"*" textcolor:green shift:(0,3) fontsize:10

PlotData=

 align:center textcolor:black fontsize:8 mark:(line,black) width:25 shift:(0,-5)

 bar:eon color:eon

 at:      0   align:right  $markred

 at:   -545   align:left   $markred

 from: -545   till:    0   text:<a href="/index.php?title=Phanerozoic&action=edit" class="new" title="Phanerozoic" rel="nofollow">Phanerozoic</a>

 bar:era color:era

 at:      0   align:right  $markgreen

 at:    -64.3 align:left   $markgreen

 from:  -64.3 till:    0   text:<a href="/index.php?title=Cenozoic&action=edit" class="new" title="Cenozoic" rel="nofollow">Cenozoic</a>

 from: -251.1 till:  -64.3 text:<a href="/index.php?title=Mesozoic&action=edit" class="new" title="Mesozoic" rel="nofollow">Mesozoic</a>

 from: -545   till: -251.1 text:<a href="/index.php?title=Paleozoic&action=edit" class="new" title="Paleozoic" rel="nofollow">Paleozoic</a>

 bar:period color:period fontsize:8

 from:   -1.6 till:    0

 from:  -64.3 till:   -1.6 text:<a href="/index.php?title=Tertiary&action=edit" class="new" title="Tertiary" rel="nofollow">Tertiary</a>

 from: -146   till:  -64.3 text:<a href="/index.php?title=Cretaceous&action=edit" class="new" title="Cretaceous" rel="nofollow">Cretaceous</a>

 from: -208   till: -146   text:<a href="/index.php?title=Jurassic&action=edit" class="new" title="Jurassic" rel="nofollow">Jurassic</a>

 from: -251.1 till: -208   text:<a href="/index.php?title=Triassic&action=edit" class="new" title="Triassic" rel="nofollow">Triassic</a>

 from: -286   till: -251.1 text:<a href="/index.php?title=Permian&action=edit" class="new" title="Permian" rel="nofollow">Permian</a>

 from: -360   till: -286   text:<a href="/index.php?title=Carboniferous&action=edit" class="new" title="Carboniferous" rel="nofollow">Carboniferous</a>

 from: -408.5 till: -360   text:<a href="/index.php?title=Devonian&action=edit" class="new" title="Devonian" rel="nofollow">Devonian</a>

 from: -443.5 till: -408.5 text:<a href="/index.php?title=Silurian&action=edit" class="new" title="Silurian" rel="nofollow">Silurian</a>

 from: -490   till: -443.5 text:<a href="/index.php?title=Ordovician&action=edit" class="new" title="Ordovician" rel="nofollow">Ordovician</a>

 from: -545   till: -490   text:<a href="/index.php?title=Cambrian&action=edit" class="new" title="Cambrian" rel="nofollow">Cambrian</a>

 bar:age color:age fontsize:6

 from: start  till:  end

 from: -23    till:  -1.6  text:<a href="/index.php?title=Neogene&action=edit" class="new" title="Neogene" rel="nofollow">Neo-~gene</a>             shift:(0,0.5)

 from: -64.3  till: -23    text:<a href="/index.php?title=Paleogene&action=edit" class="new" title="Paleogene" rel="nofollow">Paleo~gene</a>          shift:(0,0.5)

 from: -286   till: -251.1 # mark end of Paleozoic

 from: -325   till:  -286  text:<a href="/index.php?title=Pennsylvanian&action=edit" class="new" title="Pennsylvanian" rel="nofollow">Pennsyl-~vanian</a> shift:(0,0.5)

 from: -360   till:  -325  text:<a href="/index.php?title=Mississippian&action=edit" class="new" title="Mississippian" rel="nofollow">Missis-~sippian</a> shift:(0,0.5)

</timeline>

<timeline> ImageSize = width:800 height:120 PlotArea = width:720 height:95 left:65 bottom:20 AlignBars = justify

Colors =

 id:epoch  value:rgb(0.7,0.7,1) # light yellow

 id:period value:rgb(1,0.7,0.7) # light red

 id:age    value:rgb(0.7,1,0.7) # light green

 id:era    value:rgb(1,1,0.7)   # light blue

 id:black  value:black

Period = from:-65.5 till:0 TimeAxis = orientation:horizontal ScaleMajor = unit:year increment:10 start:-60 ScaleMinor = unit:year increment:1 start:-65

Define $markgreen = text:"*" textcolor:green shift:(0,3) fontsize:10

PlotData=

 align:center textcolor:black fontsize:8 mark:(line,black) width:25 shift:(0,-5)

 bar:era color:era

 at:     0  align:right $markgreen

 at: start  align:left  $markgreen

 from:start  till:  0    text:<a href="/index.php?title=Cenozoic&action=edit" class="new" title="Cenozoic" rel="nofollow">Cenozoic</a>

 bar:period color:period

 from: -1.6  till:  0    text:<a href="/index.php?title=Quaternary&action=edit" class="new" title="Quaternary" rel="nofollow">Qua~ter~nary</a> fontsize:6 align:left shift:(-7,5)

 from:start  till: -1.6  text:<a href="/index.php?title=Tertiary&action=edit" class="new" title="Tertiary" rel="nofollow">Tertiary</a>

 bar:age color:age

 from: -1.6  till:  0

 from: -23   till:  -1.6 text:<a href="/index.php?title=Neogene&action=edit" class="new" title="Neogene" rel="nofollow">Neogene</a>

 from:start  till: -23   text:<a href="/index.php?title=Paleogene&action=edit" class="new" title="Paleogene" rel="nofollow">Paleogene</a>

 bar:epoch color:epoch

 from: -0.1  till:  0

 from: -1.6  till: -0.1  text:<a href="/index.php?title=Pleistoceen&action=edit" class="new" title="Pleistoceen" rel="nofollow">P</a>

 from: -5    till: -1.6  text:<a href="/index.php?title=Pliocene&action=edit" class="new" title="Pliocene" rel="nofollow">Plio~cene</a> shift:(0,1) fontsize:6

 from:-23    till: -5    text:<a href="/index.php?title=Miocene&action=edit" class="new" title="Miocene" rel="nofollow">Miocene</a>

 from:-38    till:-23    text:<a href="/index.php?title=Oligocene&action=edit" class="new" title="Oligocene" rel="nofollow">Oligocene</a>

 from:-55    till:-38    text:<a href="/index.php?title=Eocene&action=edit" class="new" title="Eocene" rel="nofollow">Eocene</a>

 from:start  till:-55    text:<a href="/index.php?title=Paleocene&action=edit" class="new" title="Paleocene" rel="nofollow">Paleocene</a>

</timeline> |- |colspan="3" align="left"|Template:Wikimedia Growth |}

[编辑]

Code example

Just to show you that the script syntax is reasonably intuitive: here is the script for the image to the left: Soviet Leaders.

# All measures are in pixels

 

ImageSize  = width:160 height:550

PlotArea   = left:50 right:0 bottom:10 top:10

AlignBars  = justify

 

DateFormat = yyyy

Period     = from:1919 till:1991

TimeAxis   = orientation:vertical

ScaleMajor = unit:year increment:5 start:1920

 

# there is no automatic collision detection,

# so shift texts up or down manually to avoid overlap

 

Define $dx = 25 # shift text to right side of bar

 

PlotData=

  bar:Leaders color:red width:25 mark:(line,white) align:left fontsize:S

 

  from:start till:1922 shift:($dx,15)   text:Vladimir~Ilyich~[[Lenin]]

  from:1922  till:1953 shift:($dx,5)    text:[[Stalin|Josef~Stalin]]

  from:1953  till:1964 shift:($dx,5)    text:Nikita~[[Khrushchev]]

  from:1964  till:1982 shift:($dx,5)    text:Leonid~[[Brezhnev]]

  from:1982  till:1984 shift:($dx,-12)  text:Yuri~[[Andropov]]

  from:1984  till:1985 shift:($dx,4)    text:Konstantin~[[Chernenko]] fontsize:XS

  from:1985  till:end  shift:($dx,10)   text:Mikhail~[[Gorbachev]]

Double and single brackets can be used like on wikipedia, language prefix is possible, e.g. [[de:foo|more about foo]]. Single brackets for external links are also supported.

[编辑]

Great Timelines Elsewhere

Here are two great sites that may serve as inspiration, it would be very easy to recreate most of those timelines verbatim and with roughly similar layout with EasyTimeline (not yet with images but that may change), but I'm afraid that would be 'not done'.

  • Hyperhistory e.g. click on button 'people' left, then on 'special lifelines', right.
  • I hope we will have a set like [1] in a years time (click on full size image for any map), possibly even with images. The main effort will be to gather all info without snatching everything from here (most of these maps are based exclusively on data from Britannica).

[编辑]

Unicode

EasyTimeline does not yet support unicode. This will be added later. So better not use it on unicode enabled Wikipedias yet.

Aug 2004: Minimal UTF-8 support has been added, meaning that EasyTimeline now recognizes UTF-8 encoded characters. However only extended ASCII accented characters can be shown and not even all of them (rendering package Ploticus has an incomplete ASCII set in its internal font). So full unicode support will have to wait until external font support has been added (planned late in 2004, other Wikipedia projects take priority right now).

[编辑]

Tips

For first time users EasyTimeline may not seem that easy at all. As with all script languages it takes some getting used to. Also the syntax description may be a bit bewildering due to its sheer size. Fortunately many elements of the script language are optional.

The 'Easy' in EasyTimeline conveys the message that once a timeline exists it is not so hard to understand, enhance or correct. Also translating for use on another wikipedia it is pretty straightforward.

Tips:

  • What most editors did so far: find a timeline that is similar to what you want to accomplish and use this as a model. This will get you started.
  • Put each timeline on a separate Template page: this makes it easier to edit, faster to preview, possible to include it in several pages
  • Feel free to ask Erik Zachte (the author of EasyTimeline) for help or advice.

[编辑]

See also

Presentation about EasyTimeline at Wikimania 2005 (abstract, slides, speaker notes)

原文参见: EasyTimeline

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值