RequireCategory

Summary: Require categories to be entered
Version: 2005-09-16
Prerequisites: requires at least PmWiki version: 2.0; last tested on PmWiki version:2.05
Status:
Maintainer:

Question

I there a way to have requirement for categories?

Answer

Put the following code into your config.php file:

## Require Markup
 function RequireCategory($pagename, &$page, &$new) {
   global $EnablePost, $MessagesFmt;
   if (isset($_POST['text']) && strpos(@$new['text'], '[[!') == false) {
     $EnablePost = 0;
     $MessagesFmt[] = "<h3 class='wikimessage'>The page must contain at
       least one category</h3>";
   }
 }
  array_unshift($EditFunctions, 'RequireCategory');

Notes and Comments

''The newest the latest. And please don't forget to end by date and name. Thanks)


This recipe is nice, but it really needs to exclude a few pages, like 'Site' pages, otherwise you have to put categories on them, which doesn't make any sense at all. However I got it to work by adding this line:

    && preg_match('/^Site\.|^PMWiki\.|WikiSandbox/', $pagename) == false

That enables Site, PMWiki and Sandbox pages to be exempted from the requirement.

-- KathrynAndersen 2006-05-02


the idea is simple, but the only is or not index is [[ if anyone tips this into his text without meaning categories, the system fails ...

-- curmetsefrog

Versions

date of publication : 2005-09-16 : RequireCategory - version 00001

See Also

PmWiki:Categories

Contributors

PM

User notes : If you use, used or reviewed this recipe, you can add your name. These statistics appear in the Cookbook listings and will help newcomers browsing through the wiki.

Array
(
    [post_max_size] => 64M
    [$_POST keys] => 
    [$_REQUEST keys] => n
    [$_SERVER] => Array
        (
            [CONTEXT_DOCUMENT_ROOT] => /home/pmwiki/public_html
            [CONTEXT_PREFIX] => 
            [DOCUMENT_ROOT] => /home/pmwiki/public_html
            [GATEWAY_INTERFACE] => CGI/1.1
            [HTTPS] => on
            [HTTP_ACCEPT] => */*
            [HTTP_ACCEPT_ENCODING] => gzip, br, zstd, deflate
            [HTTP_HOST] => www.pmwiki.org
            [HTTP_USER_AGENT] => Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)
            [HTTP_X_HTTPS] => 1
            [PATH] => /bin:/usr/bin
            [PHP_INI_SCAN_DIR] => /opt/cpanel/ea-php70/root/etc:/opt/cpanel/ea-php70/root/etc/php.d:.
            [QUERY_STRING] => n=Cookbook%2fRequireCategory
            [REDIRECT_HTTPS] => on
            [REDIRECT_QUERY_STRING] => n=Cookbook%2fRequireCategory
            [REDIRECT_SCRIPT_URI] => https://www.pmwiki.org/wiki/Cookbook/RequireCategory
            [REDIRECT_SCRIPT_URL] => /wiki/Cookbook/RequireCategory
            [REDIRECT_SSL_TLS_SNI] => www.pmwiki.org
            [REDIRECT_STATUS] => 200
            [REDIRECT_UNIQUE_ID] => afH701aUVQDPCz-rGs728QAAAJM
            [REDIRECT_URL] => /wiki/Cookbook/RequireCategory
            [REMOTE_ADDR] => 216.73.216.31
            [REMOTE_PORT] => 18479
            [REQUEST_METHOD] => GET
            [REQUEST_SCHEME] => https
            [REQUEST_URI] => /wiki/Cookbook/RequireCategory
            [SCRIPT_FILENAME] => /home/pmwiki/public_html/index.php
            [SCRIPT_NAME] => /index.php
            [SCRIPT_URI] => https://www.pmwiki.org/wiki/Cookbook/RequireCategory
            [SCRIPT_URL] => /wiki/Cookbook/RequireCategory
            [SERVER_ADDR] => 23.254.203.248
            [SERVER_ADMIN] => webmaster@pmwiki.org
            [SERVER_NAME] => www.pmwiki.org
            [SERVER_PORT] => 443
            [SERVER_PROTOCOL] => HTTP/1.1
            [SERVER_SIGNATURE] => 
            [SERVER_SOFTWARE] => Apache
            [SSL_TLS_SNI] => www.pmwiki.org
            [TZ] => America/Los_Angeles
            [UNIQUE_ID] => afH701aUVQDPCz-rGs728QAAAJM
            [PHP_SELF] => /index.php
            [REQUEST_TIME_FLOAT] => 1777466323.4371
            [REQUEST_TIME] => 1777466323
            [argv] => Array
                (
                    [0] => n=Cookbook%2fRequireCategory
                )

            [argc] => 1
        )

)