mediawiki:有没有一种方法可以自动创建重定向到当前页面的重定向页面? [英] mediawiki: is there a way to automatically create redirect pages that redirect to the current page?

查看:364
本文介绍了mediawiki:有没有一种方法可以自动创建重定向到当前页面的重定向页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的爱好是在个人Wiki网站上写东西: http://comp-arch.net . 当前正在使用mediawiki(尽管我经常后悔选择了它,因为我需要每页访问控制.)

My hobby is writing up stuff on a personal wiki site: http://comp-arch.net. Currently using mediawiki (although I often regret having chosen it, since I need per page access control.)

通常,我会创建在同一页面上定义多个术语或概念的页面.例如. http://semipublic.comp-arch.net/wiki/Invalidate_before_writing_versus_write_through_is_the_invalidate .

Often I create pages that define several terms or concepts on the same page. E.g. http://semipublic.comp-arch.net/wiki/Invalidate_before_writing_versus_write_through_is_the_invalidate.

通常,此类"A vs B"页面提供A和B的唯一定义.或者至少是到目前为止我撰写的唯一定义.
有时,我会在同一页面上定义两个以上的主题.

Oftentimes such "A versus B" pages provide the only definitions of A and B. Or at least the only definitions that I have so far gotten around to writing.
Sometimes I will define many more that two topics on the same page.

如果我创建这样的"A vs B"或包含多个定义D1,D2,... DN的其他分页,我想自动创建重定向页面,这样我可以说[其他页面中的[A]]或[[B]]或[[D1]] .. [[DN]].

If I create such an "A vs B" or other paging containing multiple definitions D1, D2, ... DN, I would like to automatically create redirect pages, so that I can say [[A]] or [[B]] or [[D1]] .. [[DN]] in other pages.

目前,我所知道的创建此类页面的唯一方法是手动创建.很难跟上.

At the moment the only way I know of to create such pages is manually. It's hard to keep up.

此外,在创建此类页面时,我想提供一些页面文本-通常是一个类别.

Furthermore, at the time I create such a page, I would like to provide some page text - typicaly a category.

这里是另一个示例:变体页面名称.我经常发现我想创建页面名称的多个变体,所有变体都链接到同一位置.例如 [[多线程]], [[多线程(MT)]], [[MT(多线程)]], [[MT]]

Here;s another example: variant page names. I often find that I want to create several variants of a page name, all linking to the same place. For example [[multithreading]], [[multithreading (MT)]], [[MT (multithreading)]], [[MT]]

请不要告诉我使用管道链接.那不是我想要的!

Please don;t tell me to use piped links. That's NOT what I want!

TWiki具有诸如

  • TOPICCREATE在主题保存时间自动创建主题或附加文件

除此之外,我还记得一个twiki插件,它的名字我不记得了,或者用谷歌搜索了,它包含了当前操作范围内某些子页面的文本.然后,您可以一起编辑所有这些页面,然后保存-然后将根据需要提取并分发文本. (顺便说一句,如果您能记住tghat包的名称,请提醒我.它存在某些问题,特别是wrt文件锁定(IIRC它仅锁定了用于编辑的顶层文件,对子主题设置了僵尸程序,因此您可能会丢失一些东西) ))

More than that, I remember a twiki plugin, whose name I cannot remember or google up, that included the text of certain subpages within your current opage. You could then edit all of these pages together, and save - and the text would be extracted and distributed as needed. (By the way, if you can remember the name of tghat package, please remind me. It had certain problems, particularly wrt file locking (IIRC it only locked the top file for editing, bot the sub-topics, so you could lose stuff.))

但是最后,加上参数化的模板,几乎是我需要的一切.

But this last, in combination with parameterized templtes, would be almost everything I need.

问:mediawiki有类似的东西吗?我找不到.

Q: does mediawiki have something similar? I can't find it.

我想我可以/应该写自己的机器人来执行这样的动作.

I suppose that I can / could should wrote my own robot to perform such actions.

推荐答案

可以做到这一点,尽管我不知道这种扩展是否已经存在.如果您不喜欢PHP编码,则可以使用 ArticleSave编写自己的PHP编码和/或 ArticleSaveComplete 挂钩.

It's possible to do this, although I don't know whether such extensions exist already. If you're not averse to a bit of PHP coding, you could write your own using the ArticleSave and/or ArticleSaveComplete hooks.

这是ArticleSaveComplete钩子的示例,该钩子将从页面上所有节标题创建重定向到要保存的页面:

Here's an example of an ArticleSaveComplete hook that will create redirects to the page being saved from all section titles on the page:

$wgHooks['ArticleSaveComplete'][] = 'createRedirectsFromSectionTitles';
function createRedirectsFromSectionTitles( &$page, &$user, $text ) {
    // do nothing for pages outside the main namespace:
    $title = $page->getTitle();
    if ( $title->getNamespace() != 0 ) return true;

    // extract section titles:
    // XXX: this is a very quick and dirty implementation;
    // it would be better to call the parser
    preg_match_all( '/^(=+)\s*(.*?)\s*\1\s*$/m', $text, $matches );

    // create a redirect for each title, unless they exist already:
    // (invalid titles and titles outside ns 0 are also skipped)
    foreach ( $matches[2] as $section ) {
        $nt = Title::newFromText( $section );
        if ( !$nt || $nt->getNamespace() != 0 || $nt->exists() ) continue;

        $redirPage = WikiPage::factory( $nt );
        if ( !$redirPage ) continue;  // can't happen; check anyway

        // initialize some variables that we can reuse:
        if ( !isset( $redirPrefix ) ) {
            $redirPrefix = MagicWord::get( 'redirect' )->getSynonym( 0 );
            $redirPrefix .= '[[' . $title->getPrefixedText() . '#';
        }
        if ( !isset( $reason ) ) {
            $reason = wfMsgForContent( 'editsummary-auto-redir-to-section' );
        }

        // create the page (if we can; errors are ignored):
        $redirText = $redirPrefix . $section . "]]\n";
        $flags = EDIT_NEW | EDIT_MINOR | EDIT_DEFER_UPDATES;
        $redirPage->doEdit( $redirText, $reason, $flags, false, $user );
    }
    return true;
}

注意:该代码大部分基于双重重定向修复程序代码,以及

Note: Much of this code is based on bits and pieces of the pagemove redirect creating code from Title.php and the double redirect fixer code, as well as the documentation for WikiPage::doEdit(). I have not actually tested this code, but I think it has at least a decent chance of working as is. Note that you'll need to create the MediaWiki:editsummary-auto-redir-to-section page on your wiki to set a meaningful edit summary for the redirect edits.

这篇关于mediawiki:有没有一种方法可以自动创建重定向到当前页面的重定向页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆