User:Conrad.Irwin/MetaKeywords.php

Hello, you have come here looking for the meaning of the word User:Conrad.Irwin/MetaKeywords.php. In DICTIOUS you will not only get to know all the dictionary meanings for the word User:Conrad.Irwin/MetaKeywords.php, but we will also tell you about its etymology, its characteristics and you will know how to say User:Conrad.Irwin/MetaKeywords.php in singular and plural. Everything you need to know about the word User:Conrad.Irwin/MetaKeywords.php you have here. The definition of the word User:Conrad.Irwin/MetaKeywords.php will help you to be more precise and correct when speaking or writing your texts. Knowing the definition ofUser:Conrad.Irwin/MetaKeywords.php, as well as those of other words, enriches your vocabulary and provides you with more and better linguistic resources.
<?php
/*
     Extension:MetaKeywords Copyright (C) 2008 Conrad.Irwin

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA

*/

//Ideas from http://mediawiki.orghttps://dictious.com/en/Extension:Gadgets thanks to Duesentrieb
//           ]

$wgExtensionCredits = array( 
        'name' => 'MetaKeywords', 
        'author' => 'Conrad Irwin', 
        'url' => 'http://en.wiktionary.orghttps://dictious.com/en/User:Conrad.Irwin/MetaKeywords.php',
        'description' => 'lets wikis add meta keywords depending on namespace'
);
 
$wgHooks = 'wfMetaKeywordOutput';
$wgHooks = 'wfMetaKeywordClearCache';
 
//Adds customised keywords after the pagename of the <meta keywords> tag
function wfMetaKeywordOutput( &$out ){
    global $wgTitle, $wgMemc;
    $ns = $wgTitle->getNamespace();    
 
    //Keywords
    $opts = $wgMemc->get( "Metakeywords-opts" );
    if($opts === null ){ //Reload if not in cache
        $opts = wfMetaKeywordInput( 'keywords' );
    }
    $pagename = array_shift( $out->mKeywords );    
    
    if( $opts ){ //Namespace specific keywords
        array_unshift( $out->mKeywords, $opts);
    }elseif( $opts ){ //Global keywords
        array_unshift( $out->mKeywords, $opts);
    }
    if( $pagename ){ //No pagename for special pages
        array_unshift( $out->mKeywords, $pagename );
    }
    //Descriptions
    $opts = $wgMemc->get( "Metadescription-opts" );
 
    if($opts === null ){ //Reload if not in cache
        $opts = wfMetaKeywordInput( 'description', $pagename );
    }
    if( $opts ){ //Namespace specific descrption
        $out->addMeta('description',$opts);
    }elseif( $opts ){ //Otherwise global description
        $out->addMeta('description',$opts);
    }
    return true;
}
//Reads ]
function wfMetaKeywordInput( $type, $arg = false ){
    global $wgContLang, $wgMemc, $wgDBname;
 
    if ($arg) {
        $params = wfMsgForContentNoTrans("meta$type", $arg);
    } else {
        $params = wfMsgForContentNoTrans("meta$type");
    }
    $opts = array(0);  
 
    if (! wfEmptyMsg( "meta$type", $params ) ) {  
       $opts = wfMetaKeywordParse($params);
    }
    return $opts;
}
 
//Parses the syntax, ignores things it doesn't understand
function wfMetaKeywordParse( $params ){
    global $wgContLang;
    $lines = preg_split( '/(\r\n|\r|\n)/', $params );
 
    foreach( $lines as $l ){
        if( preg_match( '/^(+)\|(.+)$/',$l,$m ) ){
            $ns=false;
 
            if($m == '(main)'){
                $ns=0;
            }elseif($m == '(all)'){
                $ns='*';
            }elseif(is_numeric($m)){ //a namespace number
                $ns=$m;
            }else{ //normal namespace name
                $ns = $wgContLang->getNsIndex($m);
            }
            if($ns !== false ){
                $opts = $m;
            }
        }
    }
    return $opts;
}
//Updates the cache if ] or ] has been edited
function wfMetaKeywordClearCache( &$article, &$wgUser, &$text ) {
    global $wgMemc;
        $title = $article->mTitle;
 
        if( $title->getNamespace() == NS_MEDIAWIKI){
            $tt = $title->getText();
            if( $tt == 'Metakeywords' || $tt == 'Metadescription' ) {
                $opts = wfMetaKeywordParse( $text );
            $wgMemc->set($tt.'-opts',$opts,900);
        }
        }
        return true;
} ?>