[ Index ]

PHP Cross Reference of MediaWiki-1.24.0

title

Body

[close]

/extensions/Cite/ -> SpecialCite_body.php (source)

   1  <?php
   2  
   3  class SpecialCite extends SpecialPage {
   4  	function __construct() {
   5          parent::__construct( 'Cite' );
   6      }
   7  
   8  	function execute( $par ) {
   9          global $wgUseTidy;
  10  
  11          // Having tidy on causes whitespace and <pre> tags to
  12          // be generated around the output of the CiteOutput
  13          // class TODO FIXME.
  14          $wgUseTidy = false;
  15  
  16          $this->setHeaders();
  17          $this->outputHeader();
  18  
  19          $page = $par !== null ? $par : $this->getRequest()->getText( 'page' );
  20          $title = Title::newFromText( $page );
  21  
  22          $cform = new CiteForm( $title );
  23          $cform->execute();
  24  
  25          if ( $title && $title->exists() ) {
  26              $id = $this->getRequest()->getInt( 'id' );
  27              $cout = new CiteOutput( $title, $id );
  28              $cout->execute();
  29          }
  30      }
  31  }
  32  
  33  class CiteForm {
  34      /**
  35       * @var Title
  36       */
  37      public $mTitle;
  38  
  39  	function __construct( &$title ) {
  40          $this->mTitle =& $title;
  41      }
  42  
  43  	function execute() {
  44          global $wgOut, $wgScript;
  45  
  46          $wgOut->addHTML(
  47              Xml::openElement( 'form',
  48                  array(
  49                      'id' => 'specialcite',
  50                      'method' => 'get',
  51                      'action' => $wgScript
  52                  ) ) .
  53                  Html::hidden( 'title', SpecialPage::getTitleFor( 'Cite' )->getPrefixedDBkey() ) .
  54                  Xml::openElement( 'label' ) .
  55                      wfMessage( 'cite_page' )->escaped() . ' ' .
  56                      Xml::element( 'input',
  57                          array(
  58                              'type' => 'text',
  59                              'size' => 30,
  60                              'name' => 'page',
  61                              'value' => is_object( $this->mTitle ) ? $this->mTitle->getPrefixedText() : ''
  62                          ),
  63                          ''
  64                      ) .
  65                      ' ' .
  66                      Xml::element( 'input',
  67                          array(
  68                              'type' => 'submit',
  69                              'value' => wfMessage( 'cite_submit' )->escaped()
  70                          ),
  71                          ''
  72                      ) .
  73                  Xml::closeElement( 'label' ) .
  74              Xml::closeElement( 'form' )
  75          );
  76      }
  77  }
  78  
  79  class CiteOutput {
  80      /**
  81       * @var Title
  82       */
  83      public $mTitle;
  84  
  85      /**
  86       * @var Article
  87       */
  88      public $mArticle;
  89  
  90      public $mId;
  91  
  92      /**
  93       * @var Parser
  94       */
  95      public $mParser;
  96  
  97      /**
  98       * @var ParserOptions
  99       */
 100      public $mParserOptions;
 101  
 102      public $mSpTitle;
 103  
 104  	function __construct( $title, $id ) {
 105          global $wgHooks, $wgParser;
 106  
 107          $this->mTitle = $title;
 108          $this->mArticle = new Article( $title );
 109          $this->mId = $id;
 110  
 111          $wgHooks['ParserGetVariableValueVarCache'][] = array( $this, 'varCache' );
 112  
 113          $this->genParserOptions();
 114          $this->genParser();
 115  
 116          $wgParser->setHook( 'citation', array( $this, 'CiteParse' ) );
 117      }
 118  
 119  	function execute() {
 120          global $wgOut, $wgParser, $wgHooks;
 121  
 122          $wgHooks['ParserGetVariableValueTs'][] = array( $this, 'timestamp' );
 123  
 124          $msg = wfMessage( 'cite_text' )->inContentLanguage()->plain();
 125          if ( $msg == '' ) {
 126              # With MediaWiki 1.20 the plain text files were deleted and the text moved into SpecialCite.i18n.php
 127              # This code is kept for b/c in case an installation has its own file "cite_text-xx"
 128              # for a previously not supported language.
 129              global $wgContLang, $wgContLanguageCode;
 130              $dir = dirname( __FILE__ ) . DIRECTORY_SEPARATOR;
 131              $code = $wgContLang->lc( $wgContLanguageCode );
 132              if ( file_exists( "$dir}cite_text-$code" ) ) {
 133                  $msg = file_get_contents( "$dir}cite_text-$code" );
 134              } elseif( file_exists( "$dir}cite_text" ) ){
 135                  $msg = file_get_contents( "$dir}cite_text" );
 136              }
 137          }
 138          $ret = $wgParser->parse( $msg, $this->mTitle, $this->mParserOptions, false, true, $this->getRevId() );
 139          $wgOut->addModules( 'ext.specialcite' );
 140  
 141          # Introduced in 1.24
 142          if( method_exists( $wgOut, 'addParserOutputContent' ) ) {
 143              $wgOut->addParserOutputContent( $ret );
 144          } else {
 145              $wgOut->addHTML( $ret->getText() );
 146          }
 147      }
 148  
 149  	function genParserOptions() {
 150          global $wgUser;
 151          $this->mParserOptions = ParserOptions::newFromUser( $wgUser );
 152          $this->mParserOptions->setDateFormat( MW_DATE_DEFAULT );
 153          $this->mParserOptions->setEditSection( false );
 154      }
 155  
 156  	function genParser() {
 157          $this->mParser = new Parser;
 158          $this->mSpTitle = SpecialPage::getTitleFor( 'Cite' );
 159      }
 160  
 161  	function CiteParse( $in, $argv ) {
 162          $ret = $this->mParser->parse( $in, $this->mSpTitle, $this->mParserOptions, false );
 163  
 164          return $ret->getText();
 165      }
 166  
 167  	function varCache() {
 168          return false;
 169      }
 170  
 171  	function timestamp( &$parser, &$ts ) {
 172          if ( isset( $parser->mTagHooks['citation'] ) ) {
 173              $ts = wfTimestamp( TS_UNIX, $this->mArticle->getTimestamp() );
 174          }
 175  
 176          return true;
 177      }
 178  
 179  	function getRevId() {
 180          if ( $this->mId ) {
 181              return $this->mId;
 182          } else {
 183              return $this->mTitle->getLatestRevID();
 184          }
 185      }
 186  }


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