自动向MediaWiki短页添加文本/内容

自动向MediaWiki短页添加文本/内容,mediawiki,wiki,mediawiki-extensions,Mediawiki,Wiki,Mediawiki Extensions,我们在内部为所有文档运行mediawiki。我们面临的问题是,一些用户创建空白页面,因为他们不知道mediawiki是如何工作的,也没有删除权限 我要做的是自动添加以下内容: :''此页不需要,因为它自创建以来一直为空'' ''除非添加更多内容,否则此页面应标记为删除。 [[类别:删除]] 所有小于84字节的页面(短页面)或空白页面 这在任何情况下都是可行的吗?这可以通过使用来解决。下面是一个在扩展中执行此操作的简短示例: <?php public static function onPa

我们在内部为所有文档运行mediawiki。我们面临的问题是,一些用户创建空白页面,因为他们不知道mediawiki是如何工作的,也没有删除权限

我要做的是自动添加以下内容:

:''此页不需要,因为它自创建以来一直为空'' ''除非添加更多内容,否则此页面应标记为删除。 [[类别:删除]]

所有小于84字节的页面(短页面)或空白页面


这在任何情况下都是可行的吗?

这可以通过使用来解决。下面是一个在扩展中执行此操作的简短示例:

<?php
public static function onPageContentSave( WikiPage &$wikiPage, User &$user, Content &$content, &$summary,
    $isMinor, $isWatch, $section, &$flags,  Status&$status
) {
    // check, if the content model is wikitext to avoid adding wikitext to pages, that doesn't handle wikitext (e.g.
    // some JavaScript/JSON/CSS pages)
    if ( $content->getModel() === CONTENT_MODEL_WIKITEXT ) {
        // check the size of the _new_ content
        if ( $content->getSize() <= 84 ) {
            // getNativeData returns the plain wikitext, which this Content object represent..
            $data = $content->getNativeData();
            // ..so it's possible to simply add/remove/replace wikitext like you want
            $data .= ":''This page is unnecessary since it has remained blank since creation'' '''Unless more content is added, this page should be marked for deletion.";
            $data .= "[[Category:ForDeletion]]";
            // the new wikitext ahs to be saved as a new Content object (Content doesn't support to replace/add content by itself)
            $content = new WikitextContent( $data );
        }
    } else {
        // this could be omitted, but would log a debug message to the debug log, if the page couldn't be checked for a smaller edit as 84 bytes.
        // Maybe you want to add some more info (Title and/or content model of the Content object
        wfDebug( 'Could not check for empty or small remaining size after edit. False content model' );
    }
    return true;
}

< P>我希望这有帮助,但是请考虑这个问题,有可能(页),可以没有更多的84字节,而上述实现不允许任何异常现在;p> 你是个超级明星。谢谢你,伙计。我现在就来试试。我们可以将这些内容添加到任何小于84字节的页面上,因为我们只希望在我们的维基上有记录良好的页面,并且不要有短篇文章
$wgHooks['PageContentSave'][] = 'ExtensionHooksClass::onPageContentSave';