Mediawiki创建空白页及小于84字节处理方法

一些用户创建空白页,因为他们不知道mediawiki是如何工作的,还没有删除的权利。

“这个页面是没必要存在的,除非添加更多内容,否则这个页面会标记进删除分类。 [[category:删除]]

可以通过使用PageContentSave钩子来解决。 这里是一个简短的例子做一个扩展:

 <?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 .= "";
           // 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;
} 


你需要注册这个钩子处理程序扩展设置文件:

评论

大侠名号:   验证暗号: 点击我更换图片

修远兮

在这里记录每一点自己需要的知识

添加创始人微信,一起交流心得

推荐文章RECOMMEND