Advertisement
drorsnir

SpecialBoilerplates_body.php

Mar 3rd, 2013
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.65 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Special:boilerplates, provides a list of MediaWiki:Multiboilerplate or $wgMultiBoilerplateOptions.
  4.  * This add-on use three new messages.
  5.  * For more info see http://mediawiki.org/wiki/Extension:Multiboilerplate
  6.  *
  7.  * @file
  8.  * @ingroup Extensions
  9.  * @author Al Maghi
  10.  */
  11.  
  12. class SpecialBoilerplates extends IncludableSpecialPage {
  13.  
  14.     function __construct() {
  15.         parent::__construct( 'Boilerplates' );
  16.         $this->mIncludable = true;
  17.     }
  18.  
  19.     function execute( $par ) {
  20.         global $wgOut, $wgMultiBoilerplateOptions;
  21.         if ( !isset($wgMultiBoilerplateOptions)) return true; // No options found in either configuration file, abort.
  22.         if( !$this->mIncluding ) {
  23.             $this->setHeaders();
  24.             $wgOut->addWikiMsg( "multiboilerplate-special-pagetext" );
  25.         }
  26.         if( is_array( $wgMultiBoilerplateOptions ) ) {
  27.             if( !$this->mIncluding ) $wgOut->addWikiMsg( "multiboilerplate-special-define-in-localsettings" );
  28.             foreach( $wgMultiBoilerplateOptions as $name => $template ) {
  29.                 $wgOut->addWikiText( "* [[$template]]\n" );
  30.             }
  31.         } else {
  32.             if( !$this->mIncluding ) $wgOut->addWikiMsg( "multiboilerplate-special-define-in-interface" ) ;
  33.             $things = explode( "\n", str_replace( "\r", "\n", str_replace( "\r\n", "\n", wfMessage( 'multiboilerplate' ) ) ) ); // Ensure line-endings are \n
  34.             foreach( $things as $row ) {
  35.                 if ( substr( ltrim( $row ), 0, 1 ) === '*' ) {         
  36.                     $row = ltrim( $row, '* ' ); // Remove the asterix (and a space if found) from the start of the line.
  37.                     $row = explode( '|', $row );
  38.                     if( !isset( $row[ 1 ] ) ) return true; // Invalid syntax, abort.
  39.                     $wgOut->addWikiText( "* [[$row[1]|$row[0]]]\n" );
  40.                 }
  41.             }
  42.         }
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement