-1

We run mediawiki internally for all of our documentation. The problem we have is that some users create blank pages, as they do not really know how mediawiki works and also dont have deletion rights.

What i want to do is Automatically add this:

:''This page is unnecessary since it has remained blank since creation'' '''Unless more content is added, this page should be marked for deletion.

[[Category:ForDeletion]]

To all pages that are less than 84 bytes (short pages) or blank pages.

Is this in anyway possible in an easy way.?

Community
  • 1
  • 1
Stroes
  • 351
  • 2
  • 5
  • 23

1 Answers1

2

That could be solved by using the PageContentSave hook. Here is a short example doing it in an extension:

<?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;
}

You need to register this hook handler in your extension setup file:

$wgHooks['PageContentSave'][] = 'ExtensionHooksClass::onPageContentSave';

I hope that helps, but please consider the problem, that there are (maybe) pages, that are ok without having more then 84 bytes and the above implementation doesn't allow a any exceptions now ;)

Florian
  • 2,796
  • 1
  • 15
  • 25
  • You are a super star. thanks a lot man. i am going to try this now. – Stroes Sep 04 '15 at 06:21
  • We are ok with adding this content to any pages smaller than 84 bytes as we only want well documented pages on our wiki and refrain from having short articles – Stroes Sep 04 '15 at 06:21