开发者

Mediawiki inline template creation

Is it possible to create a wiki page, where you mark a single piece of text as a placeholder which can be put anywhere else on the wiki?

Let's say I have a wiki page containing a simple list. The first item in list must be always shown in the Main Page but the editing user should not edit two pages for that, just one page.

The list page:

Pineapples

{{SaveThisText|TodaysMeal|Dumplings}}

Beans

Oranges

Main Page:

Today, we'll have {{GetSavedText|TodaysMeal}}

...Main Page will result to "Today, we'll have Dumplings"

I know that it is possible to do this using templates but I want to avoid them, I want to edit the temp开发者_JAVA百科late like it's a part of page.


You can do this without writing any custom PHP, see:

http://www.mediawiki.org/wiki/Extension:Variables


This is definitely possible if you write a MediaWiki extension for it. This means that you could place a hook on GetSavedText and SaveThisText so their behaviour can be customized.

If you have a small wiki, you could just cycle through every page on the occurance of GetSavedText an search for {{SaveThisText|TodaysMeal|. Getting every page is easy:

// get existing pages
$db = wfGetDB ( DB_MASTER );
$results = $db->resultObject ( $db->query(
    "select distinct page_title from {$wgDBprefix}page " )
);
$existing_pages = array();
while ( $r = $results->next() )
    $title = Title::newFromText( $r->page_title );
    $article = new Article ( $title );
    $content = $article->getContent();

A more efficient approach would be to place a hook on the update of a page. If SaveThisText is present, you could update a line in a database table.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜