[ Index ]

PHP Cross Reference of MediaWiki-1.24.0

title

Body

[close]

/includes/installer/ -> InstallDocFormatter.php (source)

   1  <?php
   2  /**
   3   * Installer-specific wikitext formatting.
   4   *
   5   * This program is free software; you can redistribute it and/or modify
   6   * it under the terms of the GNU General Public License as published by
   7   * the Free Software Foundation; either version 2 of the License, or
   8   * (at your option) any later version.
   9   *
  10   * This program is distributed in the hope that it will be useful,
  11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13   * GNU General Public License for more details.
  14   *
  15   * You should have received a copy of the GNU General Public License along
  16   * with this program; if not, write to the Free Software Foundation, Inc.,
  17   * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18   * http://www.gnu.org/copyleft/gpl.html
  19   *
  20   * @file
  21   */
  22  
  23  class InstallDocFormatter {
  24  	static function format( $text ) {
  25          $obj = new self( $text );
  26  
  27          return $obj->execute();
  28      }
  29  
  30  	protected function __construct( $text ) {
  31          $this->text = $text;
  32      }
  33  
  34  	protected function execute() {
  35          $text = $this->text;
  36          // Use Unix line endings, escape some wikitext stuff
  37          $text = str_replace( array( '<', '{{', '[[', '__', "\r" ),
  38              array( '&lt;', '&#123;&#123;', '&#91;&#91;', '&#95;&#95;', '' ), $text );
  39          // join word-wrapped lines into one
  40          do {
  41              $prev = $text;
  42              $text = preg_replace( "/\n([\\*#\t])([^\n]*?)\n([^\n#\\*:]+)/", "\n\\1\\2 \\3", $text );
  43          } while ( $text != $prev );
  44          // Replace tab indents with colons
  45          $text = preg_replace( '/^\t\t/m', '::', $text );
  46          $text = preg_replace( '/^\t/m', ':', $text );
  47          // turn (bug nnnn) into links
  48          $text = preg_replace_callback( '/bug (\d+)/', array( $this, 'replaceBugLinks' ), $text );
  49          // add links to manual to every global variable mentioned
  50          $text = preg_replace_callback(
  51              '/(\$wg[a-z0-9_]+)/i',
  52              array( $this, 'replaceConfigLinks' ),
  53              $text
  54          );
  55  
  56          return $text;
  57      }
  58  
  59  	protected function replaceBugLinks( $matches ) {
  60          return '<span class="config-plainlink">[https://bugzilla.wikimedia.org/' .
  61              $matches[1] . ' bug ' . $matches[1] . ']</span>';
  62      }
  63  
  64  	protected function replaceConfigLinks( $matches ) {
  65          return '<span class="config-plainlink">[https://www.mediawiki.org/wiki/Manual:' .
  66              $matches[1] . ' ' . $matches[1] . ']</span>';
  67      }
  68  }


Generated: Fri Nov 28 14:03:12 2014 Cross-referenced by PHPXref 0.7.1