2004-02-26 13:37:26 +00:00
|
|
|
|
<?php
|
2004-09-02 23:28:24 +00:00
|
|
|
|
/**
|
2004-09-21 05:49:12 +00:00
|
|
|
|
* File for Parser and related classes
|
2004-09-02 23:28:24 +00:00
|
|
|
|
*
|
2004-09-03 23:00:01 +00:00
|
|
|
|
* @package MediaWiki
|
2005-04-12 01:29:21 +00:00
|
|
|
|
* @subpackage Parser
|
2004-09-02 23:28:24 +00:00
|
|
|
|
*/
|
|
|
|
|
|
|
2004-11-25 22:02:30 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* Update this version number when the ParserOutput format
|
|
|
|
|
|
* changes in an incompatible way, so the parser cache
|
|
|
|
|
|
* can automatically discard old data.
|
|
|
|
|
|
*/
|
2006-05-01 20:35:08 +00:00
|
|
|
|
define( 'MW_PARSER_VERSION', '1.6.1' );
|
2004-11-25 22:02:30 +00:00
|
|
|
|
|
2004-10-15 17:39:10 +00:00
|
|
|
|
define( 'RLH_FOR_UPDATE', 1 );
|
|
|
|
|
|
|
2004-03-20 15:03:26 +00:00
|
|
|
|
# Allowed values for $mOutputType
|
2004-08-22 17:24:50 +00:00
|
|
|
|
define( 'OT_HTML', 1 );
|
|
|
|
|
|
define( 'OT_WIKI', 2 );
|
|
|
|
|
|
define( 'OT_MSG' , 3 );
|
2006-08-14 07:10:31 +00:00
|
|
|
|
define( 'OT_PREPROCESS', 4 );
|
2004-02-26 13:37:26 +00:00
|
|
|
|
|
2006-07-03 11:07:00 +00:00
|
|
|
|
# Flags for setFunctionHook
|
|
|
|
|
|
define( 'SFH_NO_HASH', 1 );
|
|
|
|
|
|
|
2004-04-28 04:50:35 +00:00
|
|
|
|
# string parameter for extractTags which will cause it
|
|
|
|
|
|
# to strip HTML comments in addition to regular
|
|
|
|
|
|
# <XML>-style tags. This should not be anything we
|
|
|
|
|
|
# may want to use in wikisyntax
|
2004-08-07 18:24:12 +00:00
|
|
|
|
define( 'STRIP_COMMENTS', 'HTMLCommentStrip' );
|
2004-04-28 04:50:35 +00:00
|
|
|
|
|
2004-08-07 18:24:12 +00:00
|
|
|
|
# Constants needed for external link processing
|
2005-07-08 05:54:16 +00:00
|
|
|
|
define( 'HTTP_PROTOCOLS', 'http:\/\/|https:\/\/' );
|
2004-08-07 18:24:12 +00:00
|
|
|
|
# Everything except bracket, space, or control characters
|
2005-12-24 10:07:26 +00:00
|
|
|
|
define( 'EXT_LINK_URL_CLASS', '[^][<>"\\x00-\\x20\\x7F]' );
|
2006-06-07 09:18:34 +00:00
|
|
|
|
# Including space, but excluding newlines
|
|
|
|
|
|
define( 'EXT_LINK_TEXT_CLASS', '[^\]\\x0a\\x0d]' );
|
2004-08-07 18:24:12 +00:00
|
|
|
|
define( 'EXT_IMAGE_FNAME_CLASS', '[A-Za-z0-9_.,~%\\-+&;#*?!=()@\\x80-\\xFF]' );
|
|
|
|
|
|
define( 'EXT_IMAGE_EXTENSIONS', 'gif|png|jpg|jpeg' );
|
2006-06-07 09:18:34 +00:00
|
|
|
|
define( 'EXT_LINK_BRACKETED', '/\[(\b(' . wfUrlProtocols() . ')'.
|
|
|
|
|
|
EXT_LINK_URL_CLASS.'+) *('.EXT_LINK_TEXT_CLASS.'*?)\]/S' );
|
2004-08-14 22:38:46 +00:00
|
|
|
|
define( 'EXT_IMAGE_REGEX',
|
2005-07-08 05:54:16 +00:00
|
|
|
|
'/^('.HTTP_PROTOCOLS.')'. # Protocol
|
2004-08-07 18:24:12 +00:00
|
|
|
|
'('.EXT_LINK_URL_CLASS.'+)\\/'. # Hostname and path
|
|
|
|
|
|
'('.EXT_IMAGE_FNAME_CLASS.'+)\\.((?i)'.EXT_IMAGE_EXTENSIONS.')$/S' # Filename
|
|
|
|
|
|
);
|
2004-04-09 07:31:35 +00:00
|
|
|
|
|
2006-06-02 20:54:34 +00:00
|
|
|
|
// State constants for the definition list colon extraction
|
|
|
|
|
|
define( 'MW_COLON_STATE_TEXT', 0 );
|
|
|
|
|
|
define( 'MW_COLON_STATE_TAG', 1 );
|
|
|
|
|
|
define( 'MW_COLON_STATE_TAGSTART', 2 );
|
|
|
|
|
|
define( 'MW_COLON_STATE_CLOSETAG', 3 );
|
|
|
|
|
|
define( 'MW_COLON_STATE_TAGSLASH', 4 );
|
|
|
|
|
|
define( 'MW_COLON_STATE_COMMENT', 5 );
|
|
|
|
|
|
define( 'MW_COLON_STATE_COMMENTDASH', 6 );
|
|
|
|
|
|
define( 'MW_COLON_STATE_COMMENTDASHDASH', 7 );
|
|
|
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
|
/**
|
2004-09-21 05:49:12 +00:00
|
|
|
|
* PHP Parser
|
2005-07-03 07:15:53 +00:00
|
|
|
|
*
|
2004-09-21 05:49:12 +00:00
|
|
|
|
* Processes wiki markup
|
|
|
|
|
|
*
|
|
|
|
|
|
* <pre>
|
|
|
|
|
|
* There are three main entry points into the Parser class:
|
|
|
|
|
|
* parse()
|
|
|
|
|
|
* produces HTML output
|
|
|
|
|
|
* preSaveTransform().
|
|
|
|
|
|
* produces altered wiki markup.
|
|
|
|
|
|
* transformMsg()
|
|
|
|
|
|
* performs brace substitution on MediaWiki messages
|
|
|
|
|
|
*
|
|
|
|
|
|
* Globals used:
|
2006-03-01 01:57:53 +00:00
|
|
|
|
* objects: $wgLang, $wgContLang
|
2004-09-21 05:49:12 +00:00
|
|
|
|
*
|
|
|
|
|
|
* NOT $wgArticle, $wgUser or $wgTitle. Keep them away!
|
|
|
|
|
|
*
|
|
|
|
|
|
* settings:
|
|
|
|
|
|
* $wgUseTex*, $wgUseDynamicDates*, $wgInterwikiMagic*,
|
|
|
|
|
|
* $wgNamespacesWithSubpages, $wgAllowExternalImages*,
|
2006-08-10 21:28:49 +00:00
|
|
|
|
* $wgLocaltimezone, $wgAllowSpecialInclusion*,
|
|
|
|
|
|
* $wgMaxArticleSize*
|
2004-09-21 05:49:12 +00:00
|
|
|
|
*
|
|
|
|
|
|
* * only within ParserOptions
|
|
|
|
|
|
* </pre>
|
|
|
|
|
|
*
|
2004-09-03 23:00:01 +00:00
|
|
|
|
* @package MediaWiki
|
2004-09-02 23:28:24 +00:00
|
|
|
|
*/
|
2004-02-26 13:37:26 +00:00
|
|
|
|
class Parser
|
|
|
|
|
|
{
|
2004-09-21 05:49:12 +00:00
|
|
|
|
/**#@+
|
2006-04-19 15:46:24 +00:00
|
|
|
|
* @private
|
2004-09-21 05:49:12 +00:00
|
|
|
|
*/
|
2004-06-12 06:15:09 +00:00
|
|
|
|
# Persistent:
|
2006-07-03 11:07:00 +00:00
|
|
|
|
var $mTagHooks, $mFunctionHooks, $mFunctionSynonyms, $mVariables;
|
2004-07-12 19:49:20 +00:00
|
|
|
|
|
2004-02-29 08:43:29 +00:00
|
|
|
|
# Cleared with clearState():
|
2006-05-11 22:40:38 +00:00
|
|
|
|
var $mOutput, $mAutonumber, $mDTopen, $mStripState = array();
|
2006-07-03 11:07:00 +00:00
|
|
|
|
var $mIncludeCount, $mArgStack, $mLastSection, $mInPre;
|
2006-05-11 22:40:38 +00:00
|
|
|
|
var $mInterwikiLinkHolders, $mLinkHolders, $mUniqPrefix;
|
2006-08-10 21:28:49 +00:00
|
|
|
|
var $mIncludeSizes;
|
2006-05-11 22:40:38 +00:00
|
|
|
|
var $mTemplates, // cache of already loaded templates, avoids
|
2006-02-02 13:42:50 +00:00
|
|
|
|
// multiple SQL queries for the same string
|
|
|
|
|
|
$mTemplatePath; // stores an unsorted hash of all the templates already loaded
|
|
|
|
|
|
// in this path. Used for loop detection.
|
2004-02-29 08:43:29 +00:00
|
|
|
|
|
2006-02-02 13:42:50 +00:00
|
|
|
|
# Temporary
|
|
|
|
|
|
# These are variables reset at least once per parse regardless of $clearState
|
2006-05-11 22:40:38 +00:00
|
|
|
|
var $mOptions, // ParserOptions object
|
2005-12-30 09:33:11 +00:00
|
|
|
|
$mTitle, // Title context, used for self-link rendering and similar things
|
|
|
|
|
|
$mOutputType, // Output type, one of the OT_xxx constants
|
2006-08-14 07:10:31 +00:00
|
|
|
|
$ot, // Shortcut alias, see setOutputType()
|
2005-12-30 09:33:11 +00:00
|
|
|
|
$mRevisionId; // ID to display in {{REVISIONID}} tags
|
2005-07-03 07:15:53 +00:00
|
|
|
|
|
2004-09-21 05:49:12 +00:00
|
|
|
|
/**#@-*/
|
2004-02-29 08:43:29 +00:00
|
|
|
|
|
2004-09-21 05:49:12 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* Constructor
|
2005-07-03 07:15:53 +00:00
|
|
|
|
*
|
2006-04-19 15:46:24 +00:00
|
|
|
|
* @public
|
2004-09-21 05:49:12 +00:00
|
|
|
|
*/
|
2004-06-12 06:15:09 +00:00
|
|
|
|
function Parser() {
|
|
|
|
|
|
$this->mTagHooks = array();
|
2006-04-05 09:40:25 +00:00
|
|
|
|
$this->mFunctionHooks = array();
|
2006-07-03 11:07:00 +00:00
|
|
|
|
$this->mFunctionSynonyms = array( 0 => array(), 1 => array() );
|
|
|
|
|
|
$this->mFirstCall = true;
|
2004-02-26 13:37:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2006-07-03 11:07:00 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* Do various kinds of initialisation on the first call of the parser
|
|
|
|
|
|
*/
|
|
|
|
|
|
function firstCallInit() {
|
|
|
|
|
|
if ( !$this->mFirstCall ) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wfProfileIn( __METHOD__ );
|
|
|
|
|
|
global $wgAllowDisplayTitle, $wgAllowSlowParserFunctions;
|
|
|
|
|
|
|
|
|
|
|
|
$this->setHook( 'pre', array( $this, 'renderPreTag' ) );
|
|
|
|
|
|
|
2006-07-14 15:39:23 +00:00
|
|
|
|
$this->setFunctionHook( 'ns', array( 'CoreParserFunctions', 'ns' ), SFH_NO_HASH );
|
|
|
|
|
|
$this->setFunctionHook( 'urlencode', array( 'CoreParserFunctions', 'urlencode' ), SFH_NO_HASH );
|
|
|
|
|
|
$this->setFunctionHook( 'lcfirst', array( 'CoreParserFunctions', 'lcfirst' ), SFH_NO_HASH );
|
|
|
|
|
|
$this->setFunctionHook( 'ucfirst', array( 'CoreParserFunctions', 'ucfirst' ), SFH_NO_HASH );
|
|
|
|
|
|
$this->setFunctionHook( 'lc', array( 'CoreParserFunctions', 'lc' ), SFH_NO_HASH );
|
|
|
|
|
|
$this->setFunctionHook( 'uc', array( 'CoreParserFunctions', 'uc' ), SFH_NO_HASH );
|
|
|
|
|
|
$this->setFunctionHook( 'localurl', array( 'CoreParserFunctions', 'localurl' ), SFH_NO_HASH );
|
|
|
|
|
|
$this->setFunctionHook( 'localurle', array( 'CoreParserFunctions', 'localurle' ), SFH_NO_HASH );
|
|
|
|
|
|
$this->setFunctionHook( 'fullurl', array( 'CoreParserFunctions', 'fullurl' ), SFH_NO_HASH );
|
|
|
|
|
|
$this->setFunctionHook( 'fullurle', array( 'CoreParserFunctions', 'fullurle' ), SFH_NO_HASH );
|
|
|
|
|
|
$this->setFunctionHook( 'formatnum', array( 'CoreParserFunctions', 'formatnum' ), SFH_NO_HASH );
|
|
|
|
|
|
$this->setFunctionHook( 'grammar', array( 'CoreParserFunctions', 'grammar' ), SFH_NO_HASH );
|
|
|
|
|
|
$this->setFunctionHook( 'plural', array( 'CoreParserFunctions', 'plural' ), SFH_NO_HASH );
|
|
|
|
|
|
$this->setFunctionHook( 'numberofpages', array( 'CoreParserFunctions', 'numberofpages' ), SFH_NO_HASH );
|
|
|
|
|
|
$this->setFunctionHook( 'numberofusers', array( 'CoreParserFunctions', 'numberofusers' ), SFH_NO_HASH );
|
|
|
|
|
|
$this->setFunctionHook( 'numberofarticles', array( 'CoreParserFunctions', 'numberofarticles' ), SFH_NO_HASH );
|
|
|
|
|
|
$this->setFunctionHook( 'numberoffiles', array( 'CoreParserFunctions', 'numberoffiles' ), SFH_NO_HASH );
|
|
|
|
|
|
$this->setFunctionHook( 'numberofadmins', array( 'CoreParserFunctions', 'numberofadmins' ), SFH_NO_HASH );
|
|
|
|
|
|
$this->setFunctionHook( 'language', array( 'CoreParserFunctions', 'language' ), SFH_NO_HASH );
|
2006-08-18 17:30:35 +00:00
|
|
|
|
$this->setFunctionHook( 'padleft', array( 'CoreParserFunctions', 'padleft' ), SFH_NO_HASH );
|
|
|
|
|
|
$this->setFunctionHook( 'padright', array( 'CoreParserFunctions', 'padright' ), SFH_NO_HASH );
|
2006-07-03 11:07:00 +00:00
|
|
|
|
|
|
|
|
|
|
if ( $wgAllowDisplayTitle ) {
|
2006-07-14 15:39:23 +00:00
|
|
|
|
$this->setFunctionHook( 'displaytitle', array( 'CoreParserFunctions', 'displaytitle' ), SFH_NO_HASH );
|
2006-07-03 11:07:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
if ( $wgAllowSlowParserFunctions ) {
|
2006-07-14 15:39:23 +00:00
|
|
|
|
$this->setFunctionHook( 'pagesinnamespace', array( 'CoreParserFunctions', 'pagesinnamespace' ), SFH_NO_HASH );
|
2006-07-03 11:07:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$this->initialiseVariables();
|
|
|
|
|
|
|
|
|
|
|
|
$this->mFirstCall = false;
|
|
|
|
|
|
wfProfileOut( __METHOD__ );
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2004-09-21 05:49:12 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* Clear Parser state
|
|
|
|
|
|
*
|
2006-04-19 15:46:24 +00:00
|
|
|
|
* @private
|
2004-09-21 05:49:12 +00:00
|
|
|
|
*/
|
2004-06-12 06:15:09 +00:00
|
|
|
|
function clearState() {
|
2006-08-06 14:01:47 +00:00
|
|
|
|
wfProfileIn( __METHOD__ );
|
2006-07-03 11:07:00 +00:00
|
|
|
|
if ( $this->mFirstCall ) {
|
|
|
|
|
|
$this->firstCallInit();
|
|
|
|
|
|
}
|
2004-02-26 13:37:26 +00:00
|
|
|
|
$this->mOutput = new ParserOutput;
|
|
|
|
|
|
$this->mAutonumber = 0;
|
2005-01-31 22:59:55 +00:00
|
|
|
|
$this->mLastSection = '';
|
2004-02-26 13:37:26 +00:00
|
|
|
|
$this->mDTopen = false;
|
2004-03-20 15:03:26 +00:00
|
|
|
|
$this->mIncludeCount = array();
|
2004-03-26 21:25:48 +00:00
|
|
|
|
$this->mStripState = array();
|
2004-04-11 16:46:06 +00:00
|
|
|
|
$this->mArgStack = array();
|
2004-06-01 22:19:22 +00:00
|
|
|
|
$this->mInPre = false;
|
2005-06-03 05:46:24 +00:00
|
|
|
|
$this->mInterwikiLinkHolders = array(
|
|
|
|
|
|
'texts' => array(),
|
|
|
|
|
|
'titles' => array()
|
|
|
|
|
|
);
|
2005-04-27 07:48:14 +00:00
|
|
|
|
$this->mLinkHolders = array(
|
|
|
|
|
|
'namespaces' => array(),
|
|
|
|
|
|
'dbkeys' => array(),
|
|
|
|
|
|
'queries' => array(),
|
|
|
|
|
|
'texts' => array(),
|
|
|
|
|
|
'titles' => array()
|
|
|
|
|
|
);
|
2005-11-27 06:04:41 +00:00
|
|
|
|
$this->mRevisionId = null;
|
2006-05-26 12:11:54 +00:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Prefix for temporary replacement strings for the multipass parser.
|
|
|
|
|
|
* \x07 should never appear in input as it's disallowed in XML.
|
|
|
|
|
|
* Using it at the front also gives us a little extra robustness
|
|
|
|
|
|
* since it shouldn't match when butted up against identifier-like
|
|
|
|
|
|
* string constructs.
|
|
|
|
|
|
*/
|
|
|
|
|
|
$this->mUniqPrefix = "\x07UNIQ" . Parser::getRandomString();
|
2005-12-24 23:05:18 +00:00
|
|
|
|
|
2006-02-02 13:42:50 +00:00
|
|
|
|
# Clear these on every parse, bug 4549
|
|
|
|
|
|
$this->mTemplates = array();
|
|
|
|
|
|
$this->mTemplatePath = array();
|
|
|
|
|
|
|
2006-05-23 07:19:01 +00:00
|
|
|
|
$this->mShowToc = true;
|
|
|
|
|
|
$this->mForceTocPosition = false;
|
2006-08-10 21:28:49 +00:00
|
|
|
|
$this->mIncludeSizes = array(
|
|
|
|
|
|
'pre-expand' => 0,
|
|
|
|
|
|
'post-expand' => 0,
|
|
|
|
|
|
'arg' => 0
|
|
|
|
|
|
);
|
2006-07-02 17:43:32 +00:00
|
|
|
|
|
2005-12-24 23:05:18 +00:00
|
|
|
|
wfRunHooks( 'ParserClearState', array( &$this ) );
|
2006-08-06 14:01:47 +00:00
|
|
|
|
wfProfileOut( __METHOD__ );
|
2004-02-26 13:37:26 +00:00
|
|
|
|
}
|
2004-04-12 23:59:37 +00:00
|
|
|
|
|
2006-08-14 07:10:31 +00:00
|
|
|
|
function setOutputType( $ot ) {
|
|
|
|
|
|
$this->mOutputType = $ot;
|
|
|
|
|
|
// Shortcut alias
|
|
|
|
|
|
$this->ot = array(
|
|
|
|
|
|
'html' => $ot == OT_HTML,
|
|
|
|
|
|
'wiki' => $ot == OT_WIKI,
|
|
|
|
|
|
'msg' => $ot == OT_MSG,
|
|
|
|
|
|
'pre' => $ot == OT_PREPROCESS,
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2006-01-24 18:36:45 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* Accessor for mUniqPrefix.
|
|
|
|
|
|
*
|
2006-04-19 15:46:24 +00:00
|
|
|
|
* @public
|
2006-01-24 18:36:45 +00:00
|
|
|
|
*/
|
2006-08-06 14:01:47 +00:00
|
|
|
|
function uniqPrefix() {
|
2006-01-24 18:36:45 +00:00
|
|
|
|
return $this->mUniqPrefix;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2006-01-07 13:09:30 +00:00
|
|
|
|
/**
|
2005-12-30 09:33:11 +00:00
|
|
|
|
* Convert wikitext to HTML
|
|
|
|
|
|
* Do not call this function recursively.
|
2004-09-21 05:49:12 +00:00
|
|
|
|
*
|
2006-04-19 15:46:24 +00:00
|
|
|
|
* @private
|
2005-01-31 22:59:55 +00:00
|
|
|
|
* @param string $text Text we want to parse
|
|
|
|
|
|
* @param Title &$title A title object
|
|
|
|
|
|
* @param array $options
|
|
|
|
|
|
* @param boolean $linestart
|
|
|
|
|
|
* @param boolean $clearState
|
2005-11-27 06:04:41 +00:00
|
|
|
|
* @param int $revid number to pass in {{REVISIONID}}
|
2004-09-21 05:49:12 +00:00
|
|
|
|
* @return ParserOutput a ParserOutput
|
|
|
|
|
|
*/
|
2005-11-27 06:04:41 +00:00
|
|
|
|
function parse( $text, &$title, $options, $linestart = true, $clearState = true, $revid = null ) {
|
2005-12-30 09:33:11 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* First pass--just handle <nowiki> sections, pass the rest off
|
|
|
|
|
|
* to internalParse() which does all the real work.
|
|
|
|
|
|
*/
|
2006-01-07 13:31:29 +00:00
|
|
|
|
|
2006-01-23 20:57:57 +00:00
|
|
|
|
global $wgUseTidy, $wgAlwaysUseTidy, $wgContLang;
|
2004-08-22 17:24:50 +00:00
|
|
|
|
$fname = 'Parser::parse';
|
2004-02-26 13:37:26 +00:00
|
|
|
|
wfProfileIn( $fname );
|
|
|
|
|
|
|
|
|
|
|
|
if ( $clearState ) {
|
|
|
|
|
|
$this->clearState();
|
|
|
|
|
|
}
|
2004-04-12 23:59:37 +00:00
|
|
|
|
|
2004-02-29 08:43:29 +00:00
|
|
|
|
$this->mOptions = $options;
|
|
|
|
|
|
$this->mTitle =& $title;
|
2006-07-10 18:25:56 +00:00
|
|
|
|
$oldRevisionId = $this->mRevisionId;
|
|
|
|
|
|
if( $revid !== null ) {
|
|
|
|
|
|
$this->mRevisionId = $revid;
|
|
|
|
|
|
}
|
2006-08-14 07:10:31 +00:00
|
|
|
|
$this->setOutputType( OT_HTML );
|
2004-04-12 23:59:37 +00:00
|
|
|
|
|
2004-12-19 08:00:50 +00:00
|
|
|
|
//$text = $this->strip( $text, $this->mStripState );
|
|
|
|
|
|
// VOODOO MAGIC FIX! Sometimes the above segfaults in PHP5.
|
|
|
|
|
|
$x =& $this->mStripState;
|
2005-07-03 07:15:53 +00:00
|
|
|
|
|
2005-07-02 09:15:51 +00:00
|
|
|
|
wfRunHooks( 'ParserBeforeStrip', array( &$this, &$text, &$x ) );
|
2004-12-19 08:00:50 +00:00
|
|
|
|
$text = $this->strip( $text, $x );
|
2005-07-02 09:15:51 +00:00
|
|
|
|
wfRunHooks( 'ParserAfterStrip', array( &$this, &$text, &$x ) );
|
2004-10-08 04:27:07 +00:00
|
|
|
|
|
2005-04-21 06:30:48 +00:00
|
|
|
|
$text = $this->internalParse( $text );
|
2005-03-15 06:07:58 +00:00
|
|
|
|
|
2004-03-06 01:49:16 +00:00
|
|
|
|
$text = $this->unstrip( $text, $this->mStripState );
|
2005-07-03 07:15:53 +00:00
|
|
|
|
|
2004-04-15 14:59:46 +00:00
|
|
|
|
# Clean up special characters, only run once, next-to-last before doBlockLevels
|
2005-04-21 01:33:32 +00:00
|
|
|
|
$fixtags = array(
|
|
|
|
|
|
# french spaces, last one Guillemet-left
|
|
|
|
|
|
# only if there is something before the space
|
|
|
|
|
|
'/(.) (?=\\?|:|;|!|\\302\\273)/' => '\\1 \\2',
|
|
|
|
|
|
# french spaces, Guillemet-right
|
|
|
|
|
|
'/(\\302\\253) /' => '\\1 ',
|
|
|
|
|
|
);
|
|
|
|
|
|
$text = preg_replace( array_keys($fixtags), array_values($fixtags), $text );
|
2005-07-03 07:15:53 +00:00
|
|
|
|
|
2004-04-15 14:59:46 +00:00
|
|
|
|
# only once and last
|
|
|
|
|
|
$text = $this->doBlockLevels( $text, $linestart );
|
2004-10-08 04:27:07 +00:00
|
|
|
|
|
2004-10-15 17:39:10 +00:00
|
|
|
|
$this->replaceLinkHolders( $text );
|
2005-04-26 20:50:16 +00:00
|
|
|
|
|
2006-03-01 01:57:53 +00:00
|
|
|
|
# the position of the parserConvert() call should not be changed. it
|
2006-02-28 05:18:36 +00:00
|
|
|
|
# assumes that the links are all replaced and the only thing left
|
2005-04-26 20:50:16 +00:00
|
|
|
|
# is the <nowiki> mark.
|
2006-03-01 01:57:53 +00:00
|
|
|
|
# Side-effects: this calls $this->mOutput->setTitleText()
|
|
|
|
|
|
$text = $wgContLang->parserConvert( $text, $this );
|
2005-04-26 20:50:16 +00:00
|
|
|
|
|
2004-06-02 12:29:15 +00:00
|
|
|
|
$text = $this->unstripNoWiki( $text, $this->mStripState );
|
2005-07-02 09:15:51 +00:00
|
|
|
|
|
|
|
|
|
|
wfRunHooks( 'ParserBeforeTidy', array( &$this, &$text ) );
|
2005-07-03 07:15:53 +00:00
|
|
|
|
|
2005-04-21 11:40:58 +00:00
|
|
|
|
$text = Sanitizer::normalizeCharReferences( $text );
|
2006-01-07 13:31:29 +00:00
|
|
|
|
|
2006-01-23 20:57:57 +00:00
|
|
|
|
if (($wgUseTidy and $this->mOptions->mTidy) or $wgAlwaysUseTidy) {
|
2004-10-15 17:39:10 +00:00
|
|
|
|
$text = Parser::tidy($text);
|
2006-03-24 16:36:29 +00:00
|
|
|
|
} else {
|
|
|
|
|
|
# attempt to sanitize at least some nesting problems
|
|
|
|
|
|
# (bug #2702 and quite a few others)
|
2006-07-11 17:40:11 +00:00
|
|
|
|
$tidyregs = array(
|
|
|
|
|
|
# ''Something [http://www.cool.com cool''] -->
|
2006-03-24 16:36:29 +00:00
|
|
|
|
# <i>Something</i><a href="http://www.cool.com"..><i>cool></i></a>
|
|
|
|
|
|
'/(<([bi])>)(<([bi])>)?([^<]*)(<\/?a[^<]*>)([^<]*)(<\/\\4>)?(<\/\\2>)/' =>
|
|
|
|
|
|
'\\1\\3\\5\\8\\9\\6\\1\\3\\7\\8\\9',
|
|
|
|
|
|
# fix up an anchor inside another anchor, only
|
|
|
|
|
|
# at least for a single single nested link (bug 3695)
|
|
|
|
|
|
'/(<a[^>]+>)([^<]*)(<a[^>]+>[^<]*)<\/a>(.*)<\/a>/' =>
|
|
|
|
|
|
'\\1\\2</a>\\3</a>\\1\\4</a>',
|
|
|
|
|
|
# fix div inside inline elements- doBlockLevels won't wrap a line which
|
|
|
|
|
|
# contains a div, so fix it up here; replace
|
|
|
|
|
|
# div with escaped text
|
|
|
|
|
|
'/(<([aib]) [^>]+>)([^<]*)(<div([^>]*)>)(.*)(<\/div>)([^<]*)(<\/\\2>)/' =>
|
|
|
|
|
|
'\\1\\3<div\\5>\\6</div>\\8\\9',
|
|
|
|
|
|
# remove empty italic or bold tag pairs, some
|
|
|
|
|
|
# introduced by rules above
|
2006-07-11 17:40:11 +00:00
|
|
|
|
'/<([bi])><\/\\1>/' => '',
|
2006-03-24 16:36:29 +00:00
|
|
|
|
);
|
|
|
|
|
|
|
2006-07-11 17:40:11 +00:00
|
|
|
|
$text = preg_replace(
|
2006-03-24 16:36:29 +00:00
|
|
|
|
array_keys( $tidyregs ),
|
|
|
|
|
|
array_values( $tidyregs ),
|
|
|
|
|
|
$text );
|
2004-10-15 17:39:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2005-07-02 09:15:51 +00:00
|
|
|
|
wfRunHooks( 'ParserAfterTidy', array( &$this, &$text ) );
|
|
|
|
|
|
|
2006-08-10 21:28:49 +00:00
|
|
|
|
# Information on include size limits, for the benefit of users who try to skirt them
|
|
|
|
|
|
if ( max( $this->mIncludeSizes ) > 1000 ) {
|
|
|
|
|
|
$max = $this->mOptions->getMaxIncludeSize();
|
|
|
|
|
|
$text .= "<!-- \n" .
|
|
|
|
|
|
"Pre-expand include size: {$this->mIncludeSizes['pre-expand']} bytes\n" .
|
|
|
|
|
|
"Post-expand include size: {$this->mIncludeSizes['post-expand']} bytes\n" .
|
|
|
|
|
|
"Template argument size: {$this->mIncludeSizes['arg']} bytes\n" .
|
|
|
|
|
|
"Maximum: $max bytes\n" .
|
|
|
|
|
|
"-->\n";
|
|
|
|
|
|
}
|
2004-03-06 01:49:16 +00:00
|
|
|
|
$this->mOutput->setText( $text );
|
2006-07-10 18:25:56 +00:00
|
|
|
|
$this->mRevisionId = $oldRevisionId;
|
2004-03-06 01:49:16 +00:00
|
|
|
|
wfProfileOut( $fname );
|
2005-12-30 09:33:11 +00:00
|
|
|
|
|
2004-03-06 01:49:16 +00:00
|
|
|
|
return $this->mOutput;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2006-08-06 14:01:47 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* Recursive parser entry point that can be called from an extension tag
|
|
|
|
|
|
* hook.
|
|
|
|
|
|
*/
|
|
|
|
|
|
function recursiveTagParse( $text ) {
|
|
|
|
|
|
wfProfileIn( __METHOD__ );
|
|
|
|
|
|
$x =& $this->mStripState;
|
|
|
|
|
|
wfRunHooks( 'ParserBeforeStrip', array( &$this, &$text, &$x ) );
|
|
|
|
|
|
$text = $this->strip( $text, $x );
|
|
|
|
|
|
wfRunHooks( 'ParserAfterStrip', array( &$this, &$text, &$x ) );
|
|
|
|
|
|
$text = $this->internalParse( $text );
|
|
|
|
|
|
wfProfileOut( __METHOD__ );
|
|
|
|
|
|
return $text;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2006-08-14 07:10:31 +00:00
|
|
|
|
/**
|
2006-08-15 02:24:59 +00:00
|
|
|
|
* Expand templates and variables in the text, producing valid, static wikitext.
|
|
|
|
|
|
* Also removes comments.
|
2006-08-14 07:10:31 +00:00
|
|
|
|
*/
|
2006-08-15 02:40:20 +00:00
|
|
|
|
function preprocess( $text, $title, $options ) {
|
2006-08-14 07:10:31 +00:00
|
|
|
|
wfProfileIn( __METHOD__ );
|
|
|
|
|
|
$this->clearState();
|
|
|
|
|
|
$this->setOutputType( OT_PREPROCESS );
|
|
|
|
|
|
$this->mOptions = $options;
|
|
|
|
|
|
$this->mTitle = $title;
|
|
|
|
|
|
$x =& $this->mStripState;
|
|
|
|
|
|
wfRunHooks( 'ParserBeforeStrip', array( &$this, &$text, &$x ) );
|
|
|
|
|
|
$text = $this->strip( $text, $x );
|
|
|
|
|
|
wfRunHooks( 'ParserAfterStrip', array( &$this, &$text, &$x ) );
|
2006-08-15 02:40:20 +00:00
|
|
|
|
if ( $this->mOptions->getRemoveComments() ) {
|
2006-08-15 02:24:59 +00:00
|
|
|
|
$text = Sanitizer::removeHTMLcomments( $text );
|
|
|
|
|
|
}
|
2006-08-14 07:10:31 +00:00
|
|
|
|
$text = $this->replaceVariables( $text );
|
|
|
|
|
|
$text = $this->unstrip( $text, $x );
|
|
|
|
|
|
$text = $this->unstripNowiki( $text, $x );
|
|
|
|
|
|
wfProfileOut( __METHOD__ );
|
|
|
|
|
|
return $text;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2004-09-21 05:49:12 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* Get a random string
|
|
|
|
|
|
*
|
2006-04-19 15:46:24 +00:00
|
|
|
|
* @private
|
2004-09-21 05:49:12 +00:00
|
|
|
|
* @static
|
|
|
|
|
|
*/
|
|
|
|
|
|
function getRandomString() {
|
2004-03-06 01:49:16 +00:00
|
|
|
|
return dechex(mt_rand(0, 0x7fffffff)) . dechex(mt_rand(0, 0x7fffffff));
|
|
|
|
|
|
}
|
2004-03-26 17:14:23 +00:00
|
|
|
|
|
2006-02-28 05:18:36 +00:00
|
|
|
|
function &getTitle() { return $this->mTitle; }
|
|
|
|
|
|
function getOptions() { return $this->mOptions; }
|
|
|
|
|
|
|
2006-07-03 11:07:00 +00:00
|
|
|
|
function getFunctionLang() {
|
|
|
|
|
|
global $wgLang, $wgContLang;
|
|
|
|
|
|
return $this->mOptions->getInterfaceMessage() ? $wgLang : $wgContLang;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2005-07-03 07:15:53 +00:00
|
|
|
|
/**
|
2006-06-01 19:38:14 +00:00
|
|
|
|
* Replaces all occurrences of HTML-style comments and the given tags
|
|
|
|
|
|
* in the text with a random marker and returns teh next text. The output
|
|
|
|
|
|
* parameter $matches will be an associative array filled with data in
|
|
|
|
|
|
* the form:
|
|
|
|
|
|
* 'UNIQ-xxxxx' => array(
|
|
|
|
|
|
* 'element',
|
|
|
|
|
|
* 'tag content',
|
|
|
|
|
|
* array( 'param' => 'x' ),
|
|
|
|
|
|
* '<element param="x">tag content</element>' ) )
|
2005-07-03 07:15:53 +00:00
|
|
|
|
*
|
2006-06-01 19:38:14 +00:00
|
|
|
|
* @param $elements list of element names. Comments are always extracted.
|
|
|
|
|
|
* @param $text Source text string.
|
|
|
|
|
|
* @param $uniq_prefix
|
2004-09-21 05:49:12 +00:00
|
|
|
|
*
|
2006-04-19 15:46:24 +00:00
|
|
|
|
* @private
|
2004-09-21 05:49:12 +00:00
|
|
|
|
* @static
|
|
|
|
|
|
*/
|
2006-06-01 06:16:55 +00:00
|
|
|
|
function extractTagsAndParams($elements, $text, &$matches, $uniq_prefix = ''){
|
2006-08-06 14:01:47 +00:00
|
|
|
|
static $n = 1;
|
2004-06-08 18:11:28 +00:00
|
|
|
|
$stripped = '';
|
2006-06-01 06:16:55 +00:00
|
|
|
|
$matches = array();
|
2005-07-03 07:15:53 +00:00
|
|
|
|
|
2006-06-01 19:38:14 +00:00
|
|
|
|
$taglist = implode( '|', $elements );
|
|
|
|
|
|
$start = "/<($taglist)(\\s+[^>]*?|\\s*?)(\/?>)|<(!--)/i";
|
2004-03-26 17:14:23 +00:00
|
|
|
|
|
2004-06-08 18:11:28 +00:00
|
|
|
|
while ( '' != $text ) {
|
2005-06-03 08:12:48 +00:00
|
|
|
|
$p = preg_split( $start, $text, 2, PREG_SPLIT_DELIM_CAPTURE );
|
2004-03-26 17:14:23 +00:00
|
|
|
|
$stripped .= $p[0];
|
2006-06-01 19:38:14 +00:00
|
|
|
|
if( count( $p ) < 5 ) {
|
2005-06-03 08:12:48 +00:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
2006-06-01 19:38:14 +00:00
|
|
|
|
if( count( $p ) > 5 ) {
|
|
|
|
|
|
// comment
|
|
|
|
|
|
$element = $p[4];
|
|
|
|
|
|
$attributes = '';
|
|
|
|
|
|
$close = '';
|
|
|
|
|
|
$inside = $p[5];
|
2006-04-08 04:40:09 +00:00
|
|
|
|
} else {
|
2006-06-01 19:38:14 +00:00
|
|
|
|
// tag
|
|
|
|
|
|
$element = $p[1];
|
|
|
|
|
|
$attributes = $p[2];
|
|
|
|
|
|
$close = $p[3];
|
|
|
|
|
|
$inside = $p[4];
|
2006-04-08 04:40:09 +00:00
|
|
|
|
}
|
2005-07-03 07:15:53 +00:00
|
|
|
|
|
2006-08-06 14:01:47 +00:00
|
|
|
|
$marker = "$uniq_prefix-$element-" . sprintf('%08X', $n++) . '-QINU';
|
2005-06-03 08:12:48 +00:00
|
|
|
|
$stripped .= $marker;
|
2005-07-03 07:15:53 +00:00
|
|
|
|
|
2006-06-01 19:38:14 +00:00
|
|
|
|
if ( $close === '/>' ) {
|
2005-11-13 04:47:03 +00:00
|
|
|
|
// Empty element tag, <tag />
|
2006-06-01 06:16:55 +00:00
|
|
|
|
$content = null;
|
2005-11-13 04:47:03 +00:00
|
|
|
|
$text = $inside;
|
2006-06-01 19:38:14 +00:00
|
|
|
|
$tail = null;
|
2004-03-26 17:14:23 +00:00
|
|
|
|
} else {
|
2006-06-01 19:38:14 +00:00
|
|
|
|
if( $element == '!--' ) {
|
|
|
|
|
|
$end = '/(-->)/';
|
2006-06-01 06:16:55 +00:00
|
|
|
|
} else {
|
2006-06-01 19:38:14 +00:00
|
|
|
|
$end = "/(<\\/$element\\s*>)/i";
|
2006-06-01 06:16:55 +00:00
|
|
|
|
}
|
2006-06-01 19:38:14 +00:00
|
|
|
|
$q = preg_split( $end, $inside, 2, PREG_SPLIT_DELIM_CAPTURE );
|
2006-06-01 06:16:55 +00:00
|
|
|
|
$content = $q[0];
|
2006-06-01 19:38:14 +00:00
|
|
|
|
if( count( $q ) < 3 ) {
|
2005-11-13 04:47:03 +00:00
|
|
|
|
# No end tag -- let it run out to the end of the text.
|
2006-06-01 19:38:14 +00:00
|
|
|
|
$tail = '';
|
2006-06-01 08:24:22 +00:00
|
|
|
|
$text = '';
|
2005-11-13 04:47:03 +00:00
|
|
|
|
} else {
|
2006-06-01 19:38:14 +00:00
|
|
|
|
$tail = $q[1];
|
|
|
|
|
|
$text = $q[2];
|
2005-11-13 04:47:03 +00:00
|
|
|
|
}
|
2004-03-26 17:14:23 +00:00
|
|
|
|
}
|
2006-06-01 06:16:55 +00:00
|
|
|
|
|
|
|
|
|
|
$matches[$marker] = array( $element,
|
|
|
|
|
|
$content,
|
|
|
|
|
|
Sanitizer::decodeTagAttributes( $attributes ),
|
2006-06-01 19:38:14 +00:00
|
|
|
|
"<$element$attributes$close$content$tail" );
|
2004-03-26 17:14:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
return $stripped;
|
2004-04-12 23:59:37 +00:00
|
|
|
|
}
|
2004-03-26 17:14:23 +00:00
|
|
|
|
|
2004-09-21 05:49:12 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* Strips and renders nowiki, pre, math, hiero
|
|
|
|
|
|
* If $render is set, performs necessary rendering operations on plugins
|
|
|
|
|
|
* Returns the text, and fills an array with data needed in unstrip()
|
|
|
|
|
|
* If the $state is already a valid strip state, it adds to the state
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param bool $stripcomments when set, HTML comments <!-- like this -->
|
|
|
|
|
|
* will be stripped in addition to other tags. This is important
|
|
|
|
|
|
* for section editing, where these comments cause confusion when
|
|
|
|
|
|
* counting the sections in the wikisource
|
2006-06-13 10:11:12 +00:00
|
|
|
|
*
|
|
|
|
|
|
* @param array dontstrip contains tags which should not be stripped;
|
|
|
|
|
|
* used to prevent stipping of <gallery> when saving (fixes bug 2700)
|
2004-09-21 05:49:12 +00:00
|
|
|
|
*
|
2006-04-19 15:46:24 +00:00
|
|
|
|
* @private
|
2004-09-21 05:49:12 +00:00
|
|
|
|
*/
|
2006-06-13 10:11:12 +00:00
|
|
|
|
function strip( $text, &$state, $stripcomments = false , $dontstrip = array () ) {
|
2006-08-06 14:01:47 +00:00
|
|
|
|
wfProfileIn( __METHOD__ );
|
2004-03-20 15:03:26 +00:00
|
|
|
|
$render = ($this->mOutputType == OT_HTML);
|
2004-07-12 19:49:20 +00:00
|
|
|
|
|
2005-12-21 14:02:20 +00:00
|
|
|
|
$uniq_prefix = $this->mUniqPrefix;
|
2006-06-01 19:38:14 +00:00
|
|
|
|
$commentState = array();
|
2006-06-01 06:16:55 +00:00
|
|
|
|
|
|
|
|
|
|
$elements = array_merge(
|
2006-06-06 22:56:38 +00:00
|
|
|
|
array( 'nowiki', 'gallery' ),
|
2006-06-01 06:16:55 +00:00
|
|
|
|
array_keys( $this->mTagHooks ) );
|
2005-06-25 06:24:46 +00:00
|
|
|
|
global $wgRawHtml;
|
|
|
|
|
|
if( $wgRawHtml ) {
|
2006-06-01 06:16:55 +00:00
|
|
|
|
$elements[] = 'html';
|
2004-07-24 22:59:44 +00:00
|
|
|
|
}
|
2005-08-29 23:34:37 +00:00
|
|
|
|
if( $this->mOptions->getUseTeX() ) {
|
2006-06-01 06:16:55 +00:00
|
|
|
|
$elements[] = 'math';
|
2004-02-26 13:37:26 +00:00
|
|
|
|
}
|
2006-06-01 06:16:55 +00:00
|
|
|
|
|
2006-06-13 10:11:12 +00:00
|
|
|
|
# Removing $dontstrip tags from $elements list (currently only 'gallery', fixing bug 2700)
|
|
|
|
|
|
foreach ( $elements AS $k => $v ) {
|
|
|
|
|
|
if ( !in_array ( $v , $dontstrip ) ) continue;
|
|
|
|
|
|
unset ( $elements[$k] );
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2006-06-01 06:16:55 +00:00
|
|
|
|
$matches = array();
|
|
|
|
|
|
$text = Parser::extractTagsAndParams( $elements, $text, $matches, $uniq_prefix );
|
2006-06-13 10:11:12 +00:00
|
|
|
|
|
2006-06-01 06:16:55 +00:00
|
|
|
|
foreach( $matches as $marker => $data ) {
|
|
|
|
|
|
list( $element, $content, $params, $tag ) = $data;
|
|
|
|
|
|
if( $render ) {
|
2006-06-01 08:31:12 +00:00
|
|
|
|
$tagName = strtolower( $element );
|
2006-08-06 14:01:47 +00:00
|
|
|
|
wfProfileIn( __METHOD__."-render-$tagName" );
|
2006-06-01 08:31:12 +00:00
|
|
|
|
switch( $tagName ) {
|
2006-06-01 19:38:14 +00:00
|
|
|
|
case '!--':
|
|
|
|
|
|
// Comment
|
|
|
|
|
|
if( substr( $tag, -3 ) == '-->' ) {
|
|
|
|
|
|
$output = $tag;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
// Unclosed comment in input.
|
|
|
|
|
|
// Close it so later stripping can remove it
|
|
|
|
|
|
$output = "$tag-->";
|
|
|
|
|
|
}
|
|
|
|
|
|
break;
|
2006-06-01 06:16:55 +00:00
|
|
|
|
case 'html':
|
|
|
|
|
|
if( $wgRawHtml ) {
|
|
|
|
|
|
$output = $content;
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
// Shouldn't happen otherwise. :)
|
|
|
|
|
|
case 'nowiki':
|
|
|
|
|
|
$output = wfEscapeHTMLTagsOnly( $content );
|
|
|
|
|
|
break;
|
|
|
|
|
|
case 'math':
|
2006-06-06 10:00:53 +00:00
|
|
|
|
$output = MathRenderer::renderMath( $content );
|
2006-06-01 06:16:55 +00:00
|
|
|
|
break;
|
|
|
|
|
|
case 'gallery':
|
2006-06-24 00:12:34 +00:00
|
|
|
|
$output = $this->renderImageGallery( $content, $params );
|
2006-06-01 06:16:55 +00:00
|
|
|
|
break;
|
|
|
|
|
|
default:
|
|
|
|
|
|
if( isset( $this->mTagHooks[$tagName] ) ) {
|
|
|
|
|
|
$output = call_user_func_array( $this->mTagHooks[$tagName],
|
|
|
|
|
|
array( $content, $params, $this ) );
|
2005-11-13 04:47:03 +00:00
|
|
|
|
} else {
|
2006-06-07 06:40:24 +00:00
|
|
|
|
throw new MWException( "Invalid call hook $element" );
|
2005-11-13 04:47:03 +00:00
|
|
|
|
}
|
2004-06-09 12:15:42 +00:00
|
|
|
|
}
|
2006-08-06 14:01:47 +00:00
|
|
|
|
wfProfileOut( __METHOD__."-render-$tagName" );
|
2006-06-01 06:16:55 +00:00
|
|
|
|
} else {
|
|
|
|
|
|
// Just stripping tags; keep the source
|
2006-06-01 19:38:14 +00:00
|
|
|
|
$output = $tag;
|
|
|
|
|
|
}
|
2006-08-06 14:01:47 +00:00
|
|
|
|
|
|
|
|
|
|
// Unstrip the output, because unstrip() is no longer recursive so
|
|
|
|
|
|
// it won't do it itself
|
|
|
|
|
|
$output = $this->unstrip( $output, $state );
|
|
|
|
|
|
|
2006-06-01 19:38:14 +00:00
|
|
|
|
if( !$stripcomments && $element == '!--' ) {
|
|
|
|
|
|
$commentState[$marker] = $output;
|
2006-08-06 14:01:47 +00:00
|
|
|
|
} elseif ( $element == 'html' || $element == 'nowiki' ) {
|
|
|
|
|
|
$state['nowiki'][$marker] = $output;
|
2006-06-01 19:38:14 +00:00
|
|
|
|
} else {
|
2006-08-06 14:01:47 +00:00
|
|
|
|
$state['general'][$marker] = $output;
|
2004-06-09 12:15:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2006-07-11 17:40:11 +00:00
|
|
|
|
|
2006-03-26 02:38:01 +00:00
|
|
|
|
# Unstrip comments unless explicitly told otherwise.
|
|
|
|
|
|
# (The comments are always stripped prior to this point, so as to
|
|
|
|
|
|
# not invoke any extension tags / parser hooks contained within
|
|
|
|
|
|
# a comment.)
|
2006-06-01 19:38:14 +00:00
|
|
|
|
if ( !$stripcomments ) {
|
2006-06-01 06:16:55 +00:00
|
|
|
|
// Put them all back and forget them
|
|
|
|
|
|
$text = strtr( $text, $commentState );
|
2004-04-11 16:46:06 +00:00
|
|
|
|
}
|
2006-05-29 23:02:21 +00:00
|
|
|
|
|
2006-08-06 14:01:47 +00:00
|
|
|
|
wfProfileOut( __METHOD__ );
|
2004-03-26 17:14:23 +00:00
|
|
|
|
return $text;
|
2004-03-06 01:49:16 +00:00
|
|
|
|
}
|
2004-02-26 13:37:26 +00:00
|
|
|
|
|
2004-09-21 05:49:12 +00:00
|
|
|
|
/**
|
2006-06-01 06:16:55 +00:00
|
|
|
|
* Restores pre, math, and other extensions removed by strip()
|
2004-09-21 05:49:12 +00:00
|
|
|
|
*
|
|
|
|
|
|
* always call unstripNoWiki() after this one
|
2006-04-19 15:46:24 +00:00
|
|
|
|
* @private
|
2004-09-21 05:49:12 +00:00
|
|
|
|
*/
|
2004-06-12 06:15:09 +00:00
|
|
|
|
function unstrip( $text, &$state ) {
|
2006-08-06 14:01:47 +00:00
|
|
|
|
if ( !isset( $state['general'] ) ) {
|
2005-08-02 15:42:03 +00:00
|
|
|
|
return $text;
|
|
|
|
|
|
}
|
2006-01-07 13:31:29 +00:00
|
|
|
|
|
2006-08-06 14:01:47 +00:00
|
|
|
|
wfProfileIn( __METHOD__ );
|
|
|
|
|
|
# TODO: good candidate for FSS
|
|
|
|
|
|
$text = strtr( $text, $state['general'] );
|
|
|
|
|
|
wfProfileOut( __METHOD__ );
|
2004-03-06 01:49:16 +00:00
|
|
|
|
return $text;
|
2004-02-26 13:37:26 +00:00
|
|
|
|
}
|
2004-09-21 05:49:12 +00:00
|
|
|
|
|
|
|
|
|
|
/**
|
2006-06-01 06:16:55 +00:00
|
|
|
|
* Always call this after unstrip() to preserve the order
|
2004-09-21 05:49:12 +00:00
|
|
|
|
*
|
2006-04-19 15:46:24 +00:00
|
|
|
|
* @private
|
2004-09-21 05:49:12 +00:00
|
|
|
|
*/
|
2004-06-12 06:15:09 +00:00
|
|
|
|
function unstripNoWiki( $text, &$state ) {
|
2006-08-06 14:01:47 +00:00
|
|
|
|
if ( !isset( $state['nowiki'] ) ) {
|
2005-08-02 15:42:03 +00:00
|
|
|
|
return $text;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2006-08-06 14:01:47 +00:00
|
|
|
|
wfProfileIn( __METHOD__ );
|
|
|
|
|
|
# TODO: good candidate for FSS
|
|
|
|
|
|
$text = strtr( $text, $state['nowiki'] );
|
|
|
|
|
|
wfProfileOut( __METHOD__ );
|
|
|
|
|
|
|
2004-06-02 12:29:15 +00:00
|
|
|
|
return $text;
|
|
|
|
|
|
}
|
2004-04-12 23:59:37 +00:00
|
|
|
|
|
2004-09-21 05:49:12 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* Add an item to the strip state
|
|
|
|
|
|
* Returns the unique tag which must be inserted into the stripped text
|
|
|
|
|
|
* The tag will be replaced with the original text in unstrip()
|
|
|
|
|
|
*
|
2006-04-19 15:46:24 +00:00
|
|
|
|
* @private
|
2004-09-21 05:49:12 +00:00
|
|
|
|
*/
|
2004-06-12 06:15:09 +00:00
|
|
|
|
function insertStripItem( $text, &$state ) {
|
2005-12-21 14:02:20 +00:00
|
|
|
|
$rnd = $this->mUniqPrefix . '-item' . Parser::getRandomString();
|
2004-04-09 15:29:33 +00:00
|
|
|
|
if ( !$state ) {
|
2006-06-01 06:16:55 +00:00
|
|
|
|
$state = array();
|
2004-04-09 15:29:33 +00:00
|
|
|
|
}
|
2006-08-06 14:01:47 +00:00
|
|
|
|
$state['general'][$rnd] = $text;
|
2004-04-09 15:29:33 +00:00
|
|
|
|
return $rnd;
|
|
|
|
|
|
}
|
2004-04-12 23:59:37 +00:00
|
|
|
|
|
2004-09-21 05:49:12 +00:00
|
|
|
|
/**
|
2005-04-20 21:58:57 +00:00
|
|
|
|
* Interface with html tidy, used if $wgUseTidy = true.
|
|
|
|
|
|
* If tidy isn't able to correct the markup, the original will be
|
|
|
|
|
|
* returned in all its glory with a warning comment appended.
|
2004-09-21 05:49:12 +00:00
|
|
|
|
*
|
2005-04-20 21:58:57 +00:00
|
|
|
|
* Either the external tidy program or the in-process tidy extension
|
|
|
|
|
|
* will be used depending on availability. Override the default
|
|
|
|
|
|
* $wgTidyInternal setting to disable the internal if it's not working.
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param string $text Hideous HTML input
|
|
|
|
|
|
* @return string Corrected HTML output
|
2006-04-19 15:46:24 +00:00
|
|
|
|
* @public
|
2004-09-25 18:22:21 +00:00
|
|
|
|
* @static
|
2004-09-21 05:49:12 +00:00
|
|
|
|
*/
|
2005-04-20 21:58:57 +00:00
|
|
|
|
function tidy( $text ) {
|
|
|
|
|
|
global $wgTidyInternal;
|
|
|
|
|
|
$wrappedtext = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"'.
|
|
|
|
|
|
' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html>'.
|
|
|
|
|
|
'<head><title>test</title></head><body>'.$text.'</body></html>';
|
|
|
|
|
|
if( $wgTidyInternal ) {
|
|
|
|
|
|
$correctedtext = Parser::internalTidy( $wrappedtext );
|
|
|
|
|
|
} else {
|
|
|
|
|
|
$correctedtext = Parser::externalTidy( $wrappedtext );
|
|
|
|
|
|
}
|
|
|
|
|
|
if( is_null( $correctedtext ) ) {
|
|
|
|
|
|
wfDebug( "Tidy error detected!\n" );
|
|
|
|
|
|
return $text . "\n<!-- Tidy found serious XHTML errors -->\n";
|
|
|
|
|
|
}
|
|
|
|
|
|
return $correctedtext;
|
|
|
|
|
|
}
|
2005-07-03 07:15:53 +00:00
|
|
|
|
|
2005-04-20 21:58:57 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* Spawn an external HTML tidy process and get corrected markup back from it.
|
|
|
|
|
|
*
|
2006-04-19 15:46:24 +00:00
|
|
|
|
* @private
|
2005-04-20 21:58:57 +00:00
|
|
|
|
* @static
|
|
|
|
|
|
*/
|
|
|
|
|
|
function externalTidy( $text ) {
|
2004-05-06 12:50:04 +00:00
|
|
|
|
global $wgTidyConf, $wgTidyBin, $wgTidyOpts;
|
2005-04-20 21:58:57 +00:00
|
|
|
|
$fname = 'Parser::externalTidy';
|
2004-05-29 04:51:29 +00:00
|
|
|
|
wfProfileIn( $fname );
|
2004-07-12 19:49:20 +00:00
|
|
|
|
|
2004-05-06 12:50:04 +00:00
|
|
|
|
$cleansource = '';
|
2005-03-26 22:23:48 +00:00
|
|
|
|
$opts = ' -utf8';
|
2004-05-07 09:06:45 +00:00
|
|
|
|
|
2004-05-06 12:50:04 +00:00
|
|
|
|
$descriptorspec = array(
|
2004-06-08 18:11:28 +00:00
|
|
|
|
0 => array('pipe', 'r'),
|
|
|
|
|
|
1 => array('pipe', 'w'),
|
|
|
|
|
|
2 => array('file', '/dev/null', 'a')
|
2004-05-06 12:50:04 +00:00
|
|
|
|
);
|
2005-04-21 06:30:48 +00:00
|
|
|
|
$pipes = array();
|
2004-09-25 18:22:21 +00:00
|
|
|
|
$process = proc_open("$wgTidyBin -config $wgTidyConf $wgTidyOpts$opts", $descriptorspec, $pipes);
|
2004-05-06 12:50:04 +00:00
|
|
|
|
if (is_resource($process)) {
|
2006-02-07 11:05:00 +00:00
|
|
|
|
// Theoretically, this style of communication could cause a deadlock
|
2006-03-11 17:13:49 +00:00
|
|
|
|
// here. If the stdout buffer fills up, then writes to stdin could
|
2006-02-07 11:05:00 +00:00
|
|
|
|
// block. This doesn't appear to happen with tidy, because tidy only
|
2006-03-11 17:13:49 +00:00
|
|
|
|
// writes to stdout after it's finished reading from stdin. Search
|
2006-02-07 11:05:00 +00:00
|
|
|
|
// for tidyParseStdin and tidySaveStdout in console/tidy.c
|
2005-04-20 21:58:57 +00:00
|
|
|
|
fwrite($pipes[0], $text);
|
2004-05-06 12:50:04 +00:00
|
|
|
|
fclose($pipes[0]);
|
|
|
|
|
|
while (!feof($pipes[1])) {
|
|
|
|
|
|
$cleansource .= fgets($pipes[1], 1024);
|
|
|
|
|
|
}
|
|
|
|
|
|
fclose($pipes[1]);
|
2005-04-21 06:30:48 +00:00
|
|
|
|
proc_close($process);
|
2004-05-06 12:50:04 +00:00
|
|
|
|
}
|
2004-05-29 04:51:29 +00:00
|
|
|
|
|
|
|
|
|
|
wfProfileOut( $fname );
|
2004-07-12 19:49:20 +00:00
|
|
|
|
|
2004-05-06 21:06:23 +00:00
|
|
|
|
if( $cleansource == '' && $text != '') {
|
2005-04-20 21:58:57 +00:00
|
|
|
|
// Some kind of error happened, so we couldn't get the corrected text.
|
|
|
|
|
|
// Just give up; we'll use the source text and append a warning.
|
|
|
|
|
|
return null;
|
2004-05-06 13:38:23 +00:00
|
|
|
|
} else {
|
2004-05-06 19:01:05 +00:00
|
|
|
|
return $cleansource;
|
2004-05-06 13:38:23 +00:00
|
|
|
|
}
|
2004-05-06 12:50:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2005-04-20 21:58:57 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* Use the HTML tidy PECL extension to use the tidy library in-process,
|
|
|
|
|
|
* saving the overhead of spawning a new process. Currently written to
|
|
|
|
|
|
* the PHP 4.3.x version of the extension, may not work on PHP 5.
|
|
|
|
|
|
*
|
|
|
|
|
|
* 'pear install tidy' should be able to compile the extension module.
|
|
|
|
|
|
*
|
2006-04-19 15:46:24 +00:00
|
|
|
|
* @private
|
2005-04-20 21:58:57 +00:00
|
|
|
|
* @static
|
|
|
|
|
|
*/
|
|
|
|
|
|
function internalTidy( $text ) {
|
|
|
|
|
|
global $wgTidyConf;
|
|
|
|
|
|
$fname = 'Parser::internalTidy';
|
|
|
|
|
|
wfProfileIn( $fname );
|
2005-07-03 07:15:53 +00:00
|
|
|
|
|
2005-04-20 21:58:57 +00:00
|
|
|
|
tidy_load_config( $wgTidyConf );
|
|
|
|
|
|
tidy_set_encoding( 'utf8' );
|
|
|
|
|
|
tidy_parse_string( $text );
|
|
|
|
|
|
tidy_clean_repair();
|
|
|
|
|
|
if( tidy_get_status() == 2 ) {
|
|
|
|
|
|
// 2 is magic number for fatal error
|
|
|
|
|
|
// http://www.php.net/manual/en/function.tidy-get-status.php
|
|
|
|
|
|
$cleansource = null;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
$cleansource = tidy_get_output();
|
|
|
|
|
|
}
|
|
|
|
|
|
wfProfileOut( $fname );
|
|
|
|
|
|
return $cleansource;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2004-09-21 05:49:12 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* parse the wiki syntax used to render tables
|
|
|
|
|
|
*
|
2006-04-19 15:46:24 +00:00
|
|
|
|
* @private
|
2004-09-21 05:49:12 +00:00
|
|
|
|
*/
|
2004-06-12 06:15:09 +00:00
|
|
|
|
function doTableStuff ( $t ) {
|
2004-07-10 03:09:26 +00:00
|
|
|
|
$fname = 'Parser::doTableStuff';
|
|
|
|
|
|
wfProfileIn( $fname );
|
2004-07-12 19:49:20 +00:00
|
|
|
|
|
2004-02-29 08:43:29 +00:00
|
|
|
|
$t = explode ( "\n" , $t ) ;
|
|
|
|
|
|
$td = array () ; # Is currently a td tag open?
|
2004-07-12 19:49:20 +00:00
|
|
|
|
$ltd = array () ; # Was it TD or TH?
|
|
|
|
|
|
$tr = array () ; # Is currently a tr tag open?
|
|
|
|
|
|
$ltr = array () ; # tr attributes
|
2006-02-06 15:47:14 +00:00
|
|
|
|
$has_opened_tr = array(); # Did this table open a <tr> element?
|
2004-08-04 16:37:48 +00:00
|
|
|
|
$indent_level = 0; # indent level of the table
|
2004-07-12 19:49:20 +00:00
|
|
|
|
foreach ( $t AS $k => $x )
|
|
|
|
|
|
{
|
|
|
|
|
|
$x = trim ( $x ) ;
|
|
|
|
|
|
$fc = substr ( $x , 0 , 1 ) ;
|
2004-08-16 20:01:21 +00:00
|
|
|
|
if ( preg_match( '/^(:*)\{\|(.*)$/', $x, $matches ) ) {
|
2004-08-04 16:37:48 +00:00
|
|
|
|
$indent_level = strlen( $matches[1] );
|
2006-01-07 13:31:29 +00:00
|
|
|
|
|
2005-08-29 23:34:37 +00:00
|
|
|
|
$attributes = $this->unstripForHTML( $matches[2] );
|
|
|
|
|
|
|
2005-04-09 08:36:29 +00:00
|
|
|
|
$t[$k] = str_repeat( '<dl><dd>', $indent_level ) .
|
2005-08-29 23:34:37 +00:00
|
|
|
|
'<table' . Sanitizer::fixTagAttributes ( $attributes, 'table' ) . '>' ;
|
2004-07-12 19:49:20 +00:00
|
|
|
|
array_push ( $td , false ) ;
|
|
|
|
|
|
array_push ( $ltd , '' ) ;
|
|
|
|
|
|
array_push ( $tr , false ) ;
|
|
|
|
|
|
array_push ( $ltr , '' ) ;
|
2006-02-06 15:47:14 +00:00
|
|
|
|
array_push ( $has_opened_tr, false );
|
2004-07-12 19:49:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
else if ( count ( $td ) == 0 ) { } # Don't do any of the following
|
2004-08-16 20:01:21 +00:00
|
|
|
|
else if ( '|}' == substr ( $x , 0 , 2 ) ) {
|
2005-04-09 08:36:29 +00:00
|
|
|
|
$z = "</table>" . substr ( $x , 2);
|
2004-07-12 19:49:20 +00:00
|
|
|
|
$l = array_pop ( $ltd ) ;
|
2006-02-06 15:47:14 +00:00
|
|
|
|
if ( !array_pop ( $has_opened_tr ) ) $z = "<tr><td></td></tr>" . $z ;
|
2004-07-12 19:49:20 +00:00
|
|
|
|
if ( array_pop ( $tr ) ) $z = '</tr>' . $z ;
|
2004-08-16 20:01:21 +00:00
|
|
|
|
if ( array_pop ( $td ) ) $z = '</'.$l.'>' . $z ;
|
2004-07-12 19:49:20 +00:00
|
|
|
|
array_pop ( $ltr ) ;
|
2004-08-22 17:24:50 +00:00
|
|
|
|
$t[$k] = $z . str_repeat( '</dd></dl>', $indent_level );
|
2004-07-12 19:49:20 +00:00
|
|
|
|
}
|
2004-08-16 20:01:21 +00:00
|
|
|
|
else if ( '|-' == substr ( $x , 0 , 2 ) ) { # Allows for |---------------
|
2004-07-12 19:49:20 +00:00
|
|
|
|
$x = substr ( $x , 1 ) ;
|
|
|
|
|
|
while ( $x != '' && substr ( $x , 0 , 1 ) == '-' ) $x = substr ( $x , 1 ) ;
|
|
|
|
|
|
$z = '' ;
|
|
|
|
|
|
$l = array_pop ( $ltd ) ;
|
2006-02-06 15:47:14 +00:00
|
|
|
|
array_pop ( $has_opened_tr );
|
|
|
|
|
|
array_push ( $has_opened_tr , true ) ;
|
2004-07-12 19:49:20 +00:00
|
|
|
|
if ( array_pop ( $tr ) ) $z = '</tr>' . $z ;
|
2004-08-16 20:01:21 +00:00
|
|
|
|
if ( array_pop ( $td ) ) $z = '</'.$l.'>' . $z ;
|
2004-07-12 19:49:20 +00:00
|
|
|
|
array_pop ( $ltr ) ;
|
|
|
|
|
|
$t[$k] = $z ;
|
|
|
|
|
|
array_push ( $tr , false ) ;
|
|
|
|
|
|
array_push ( $td , false ) ;
|
|
|
|
|
|
array_push ( $ltd , '' ) ;
|
2005-08-29 23:34:37 +00:00
|
|
|
|
$attributes = $this->unstripForHTML( $x );
|
|
|
|
|
|
array_push ( $ltr , Sanitizer::fixTagAttributes ( $attributes, 'tr' ) ) ;
|
2004-07-12 19:49:20 +00:00
|
|
|
|
}
|
2004-08-16 20:01:21 +00:00
|
|
|
|
else if ( '|' == $fc || '!' == $fc || '|+' == substr ( $x , 0 , 2 ) ) { # Caption
|
2004-10-01 21:20:47 +00:00
|
|
|
|
# $x is a table row
|
2004-08-16 20:01:21 +00:00
|
|
|
|
if ( '|+' == substr ( $x , 0 , 2 ) ) {
|
2004-07-12 19:49:20 +00:00
|
|
|
|
$fc = '+' ;
|
2004-02-29 08:43:29 +00:00
|
|
|
|
$x = substr ( $x , 1 ) ;
|
|
|
|
|
|
}
|
2004-07-12 19:49:20 +00:00
|
|
|
|
$after = substr ( $x , 1 ) ;
|
|
|
|
|
|
if ( $fc == '!' ) $after = str_replace ( '!!' , '||' , $after ) ;
|
2006-07-11 17:40:11 +00:00
|
|
|
|
|
2006-04-03 08:36:17 +00:00
|
|
|
|
// Split up multiple cells on the same line.
|
|
|
|
|
|
// FIXME: This can result in improper nesting of tags processed
|
|
|
|
|
|
// by earlier parser steps, but should avoid splitting up eg
|
|
|
|
|
|
// attribute values containing literal "||".
|
|
|
|
|
|
$after = wfExplodeMarkup( '||', $after );
|
2006-07-11 17:40:11 +00:00
|
|
|
|
|
2004-07-12 19:49:20 +00:00
|
|
|
|
$t[$k] = '' ;
|
2004-10-01 21:20:47 +00:00
|
|
|
|
|
|
|
|
|
|
# Loop through each table cell
|
2004-07-12 19:49:20 +00:00
|
|
|
|
foreach ( $after AS $theline )
|
2004-02-29 08:43:29 +00:00
|
|
|
|
{
|
2004-07-12 19:49:20 +00:00
|
|
|
|
$z = '' ;
|
|
|
|
|
|
if ( $fc != '+' )
|
2004-02-29 08:43:29 +00:00
|
|
|
|
{
|
2004-07-12 19:49:20 +00:00
|
|
|
|
$tra = array_pop ( $ltr ) ;
|
2005-02-06 12:46:31 +00:00
|
|
|
|
if ( !array_pop ( $tr ) ) $z = '<tr'.$tra.">\n" ;
|
2004-07-12 19:49:20 +00:00
|
|
|
|
array_push ( $tr , true ) ;
|
|
|
|
|
|
array_push ( $ltr , '' ) ;
|
2006-02-06 15:47:14 +00:00
|
|
|
|
array_pop ( $has_opened_tr );
|
|
|
|
|
|
array_push ( $has_opened_tr , true ) ;
|
2004-02-29 08:43:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2004-07-12 19:49:20 +00:00
|
|
|
|
$l = array_pop ( $ltd ) ;
|
2004-08-16 20:01:21 +00:00
|
|
|
|
if ( array_pop ( $td ) ) $z = '</'.$l.'>' . $z ;
|
2004-07-12 19:49:20 +00:00
|
|
|
|
if ( $fc == '|' ) $l = 'td' ;
|
|
|
|
|
|
else if ( $fc == '!' ) $l = 'th' ;
|
|
|
|
|
|
else if ( $fc == '+' ) $l = 'caption' ;
|
|
|
|
|
|
else $l = '' ;
|
|
|
|
|
|
array_push ( $ltd , $l ) ;
|
2004-10-01 21:20:47 +00:00
|
|
|
|
|
|
|
|
|
|
# Cell parameters
|
2004-07-12 19:49:20 +00:00
|
|
|
|
$y = explode ( '|' , $theline , 2 ) ;
|
2004-10-01 21:20:47 +00:00
|
|
|
|
# Note that a '|' inside an invalid link should not
|
|
|
|
|
|
# be mistaken as delimiting cell parameters
|
|
|
|
|
|
if ( strpos( $y[0], '[[' ) !== false ) {
|
|
|
|
|
|
$y = array ($theline);
|
|
|
|
|
|
}
|
|
|
|
|
|
if ( count ( $y ) == 1 )
|
|
|
|
|
|
$y = "{$z}<{$l}>{$y[0]}" ;
|
2005-08-29 23:34:37 +00:00
|
|
|
|
else {
|
|
|
|
|
|
$attributes = $this->unstripForHTML( $y[0] );
|
|
|
|
|
|
$y = "{$z}<{$l}".Sanitizer::fixTagAttributes($attributes, $l).">{$y[1]}" ;
|
|
|
|
|
|
}
|
2004-07-12 19:49:20 +00:00
|
|
|
|
$t[$k] .= $y ;
|
|
|
|
|
|
array_push ( $td , true ) ;
|
2004-02-28 05:55:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2004-07-12 19:49:20 +00:00
|
|
|
|
}
|
2004-02-29 08:43:29 +00:00
|
|
|
|
|
|
|
|
|
|
# Closing open td, tr && table
|
|
|
|
|
|
while ( count ( $td ) > 0 )
|
|
|
|
|
|
{
|
2006-02-03 18:22:53 +00:00
|
|
|
|
$l = array_pop ( $ltd ) ;
|
2004-06-08 18:11:28 +00:00
|
|
|
|
if ( array_pop ( $td ) ) $t[] = '</td>' ;
|
|
|
|
|
|
if ( array_pop ( $tr ) ) $t[] = '</tr>' ;
|
2006-02-22 08:37:14 +00:00
|
|
|
|
if ( !array_pop ( $has_opened_tr ) ) $t[] = "<tr><td></td></tr>" ;
|
2004-06-08 18:11:28 +00:00
|
|
|
|
$t[] = '</table>' ;
|
2004-02-28 05:55:13 +00:00
|
|
|
|
}
|
2004-02-26 13:37:26 +00:00
|
|
|
|
|
2004-02-29 08:43:29 +00:00
|
|
|
|
$t = implode ( "\n" , $t ) ;
|
2006-03-24 16:37:43 +00:00
|
|
|
|
# special case: don't return empty table
|
|
|
|
|
|
if($t == "<table>\n<tr><td></td></tr>\n</table>")
|
|
|
|
|
|
$t = '';
|
2004-07-10 03:09:26 +00:00
|
|
|
|
wfProfileOut( $fname );
|
2004-02-29 08:43:29 +00:00
|
|
|
|
return $t ;
|
2004-02-28 05:55:13 +00:00
|
|
|
|
}
|
2004-02-26 13:37:26 +00:00
|
|
|
|
|
2004-09-21 05:49:12 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* Helper function for parse() that transforms wiki markup into
|
|
|
|
|
|
* HTML. Only called for $mOutputType == OT_HTML.
|
|
|
|
|
|
*
|
2006-04-19 15:46:24 +00:00
|
|
|
|
* @private
|
2004-09-21 05:49:12 +00:00
|
|
|
|
*/
|
2005-04-21 06:30:48 +00:00
|
|
|
|
function internalParse( $text ) {
|
|
|
|
|
|
$args = array();
|
|
|
|
|
|
$isMain = true;
|
2004-06-08 18:11:28 +00:00
|
|
|
|
$fname = 'Parser::internalParse';
|
2004-02-26 13:37:26 +00:00
|
|
|
|
wfProfileIn( $fname );
|
2004-04-11 16:46:06 +00:00
|
|
|
|
|
2006-08-06 14:01:47 +00:00
|
|
|
|
# Hook to suspend the parser in this state
|
|
|
|
|
|
if ( !wfRunHooks( 'ParserBeforeInternalParse', array( &$this, &$text, &$x ) ) ) {
|
|
|
|
|
|
wfProfileOut( $fname );
|
|
|
|
|
|
return $text ;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2005-08-07 14:33:40 +00:00
|
|
|
|
# Remove <noinclude> tags and <includeonly> sections
|
2005-10-25 07:35:48 +00:00
|
|
|
|
$text = strtr( $text, array( '<onlyinclude>' => '' , '</onlyinclude>' => '' ) );
|
2005-08-07 14:33:40 +00:00
|
|
|
|
$text = strtr( $text, array( '<noinclude>' => '', '</noinclude>' => '') );
|
|
|
|
|
|
$text = preg_replace( '/<includeonly>.*?<\/includeonly>/s', '', $text );
|
2006-07-11 17:40:11 +00:00
|
|
|
|
|
2005-08-23 21:49:48 +00:00
|
|
|
|
$text = Sanitizer::removeHTMLtags( $text, array( &$this, 'attributeStripCallback' ) );
|
2006-05-23 07:19:01 +00:00
|
|
|
|
|
2004-04-11 16:46:06 +00:00
|
|
|
|
$text = $this->replaceVariables( $text, $args );
|
2004-02-26 13:37:26 +00:00
|
|
|
|
|
2006-05-23 07:19:01 +00:00
|
|
|
|
// Tables need to come after variable replacement for things to work
|
|
|
|
|
|
// properly; putting them before other transformations should keep
|
|
|
|
|
|
// exciting things like link expansions from showing up in surprising
|
|
|
|
|
|
// places.
|
|
|
|
|
|
$text = $this->doTableStuff( $text );
|
|
|
|
|
|
|
2004-06-08 18:11:28 +00:00
|
|
|
|
$text = preg_replace( '/(^|\n)-----*/', '\\1<hr />', $text );
|
2004-02-26 13:37:26 +00:00
|
|
|
|
|
2006-05-23 07:19:01 +00:00
|
|
|
|
$text = $this->stripToc( $text );
|
2006-06-13 11:37:09 +00:00
|
|
|
|
$this->stripNoGallery( $text );
|
2004-02-26 13:37:26 +00:00
|
|
|
|
$text = $this->doHeadings( $text );
|
2004-02-29 08:43:29 +00:00
|
|
|
|
if($this->mOptions->getUseDynamicDates()) {
|
2005-04-20 15:42:08 +00:00
|
|
|
|
$df =& DateFormatter::getInstance();
|
|
|
|
|
|
$text = $df->reformat( $this->mOptions->getDateFormat(), $text );
|
2004-02-26 13:37:26 +00:00
|
|
|
|
}
|
2004-05-26 16:29:04 +00:00
|
|
|
|
$text = $this->doAllQuotes( $text );
|
2004-11-28 03:29:50 +00:00
|
|
|
|
$text = $this->replaceInternalLinks( $text );
|
2005-07-03 07:15:53 +00:00
|
|
|
|
$text = $this->replaceExternalLinks( $text );
|
|
|
|
|
|
|
2004-10-25 05:24:23 +00:00
|
|
|
|
# replaceInternalLinks may sometimes leave behind
|
|
|
|
|
|
# absolute URLs, which have to be masked to hide them from replaceExternalLinks
|
2005-12-21 14:02:20 +00:00
|
|
|
|
$text = str_replace($this->mUniqPrefix."NOPARSE", "", $text);
|
2005-07-03 07:15:53 +00:00
|
|
|
|
|
2004-09-26 17:59:08 +00:00
|
|
|
|
$text = $this->doMagicLinks( $text );
|
2004-05-13 17:16:50 +00:00
|
|
|
|
$text = $this->formatHeadings( $text, $isMain );
|
2004-04-12 16:10:17 +00:00
|
|
|
|
|
2004-02-26 13:37:26 +00:00
|
|
|
|
wfProfileOut( $fname );
|
|
|
|
|
|
return $text;
|
|
|
|
|
|
}
|
2004-08-07 12:35:59 +00:00
|
|
|
|
|
2004-09-21 05:49:12 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* Replace special strings like "ISBN xxx" and "RFC xxx" with
|
|
|
|
|
|
* magic external links.
|
|
|
|
|
|
*
|
2006-04-19 15:46:24 +00:00
|
|
|
|
* @private
|
2004-09-21 05:49:12 +00:00
|
|
|
|
*/
|
|
|
|
|
|
function &doMagicLinks( &$text ) {
|
2006-08-06 14:01:47 +00:00
|
|
|
|
wfProfileIn( __METHOD__ );
|
|
|
|
|
|
$text = preg_replace_callback(
|
|
|
|
|
|
'!(?: # Start cases
|
2006-08-12 06:12:54 +00:00
|
|
|
|
<a.*?</a> | # Skip link text
|
2006-08-06 14:01:47 +00:00
|
|
|
|
<.*?> | # Skip stuff inside HTML elements
|
|
|
|
|
|
(?:RFC|PMID)\s+([0-9]+) | # RFC or PMID, capture number as m[1]
|
|
|
|
|
|
ISBN\s+([0-9Xx-]+) # ISBN, capture number as m[2]
|
|
|
|
|
|
)!x', array( &$this, 'magicLinkCallback' ), $text );
|
|
|
|
|
|
wfProfileOut( __METHOD__ );
|
|
|
|
|
|
return $text;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function magicLinkCallback( $m ) {
|
|
|
|
|
|
if ( substr( $m[0], 0, 1 ) == '<' ) {
|
|
|
|
|
|
# Skip HTML element
|
|
|
|
|
|
return $m[0];
|
|
|
|
|
|
} elseif ( substr( $m[0], 0, 4 ) == 'ISBN' ) {
|
|
|
|
|
|
$isbn = $m[2];
|
|
|
|
|
|
$num = strtr( $isbn, array(
|
|
|
|
|
|
'-' => '',
|
|
|
|
|
|
' ' => '',
|
|
|
|
|
|
'x' => 'X',
|
|
|
|
|
|
));
|
|
|
|
|
|
$titleObj = Title::makeTitle( NS_SPECIAL, 'Booksources' );
|
|
|
|
|
|
$text = '<a href="' .
|
|
|
|
|
|
$titleObj->escapeLocalUrl( "isbn=$num" ) .
|
|
|
|
|
|
"\" class=\"internal\">ISBN $isbn</a>";
|
|
|
|
|
|
} else {
|
|
|
|
|
|
if ( substr( $m[0], 0, 3 ) == 'RFC' ) {
|
|
|
|
|
|
$keyword = 'RFC';
|
|
|
|
|
|
$urlmsg = 'rfcurl';
|
|
|
|
|
|
$id = $m[1];
|
|
|
|
|
|
} elseif ( substr( $m[0], 0, 4 ) == 'PMID' ) {
|
|
|
|
|
|
$keyword = 'PMID';
|
|
|
|
|
|
$urlmsg = 'pubmedurl';
|
|
|
|
|
|
$id = $m[1];
|
|
|
|
|
|
} else {
|
|
|
|
|
|
throw new MWException( __METHOD__.': unrecognised match type "' .
|
|
|
|
|
|
substr($m[0], 0, 20 ) . '"' );
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$url = wfMsg( $urlmsg, $id);
|
|
|
|
|
|
$sk =& $this->mOptions->getSkin();
|
|
|
|
|
|
$la = $sk->getExternalLinkAttributes( $url, $keyword.$id );
|
|
|
|
|
|
$text = "<a href=\"{$url}\"{$la}>{$keyword} {$id}</a>";
|
|
|
|
|
|
}
|
2004-08-04 01:53:29 +00:00
|
|
|
|
return $text;
|
|
|
|
|
|
}
|
2004-07-12 19:49:20 +00:00
|
|
|
|
|
2004-09-21 05:49:12 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* Parse headers and return html
|
|
|
|
|
|
*
|
2006-04-19 15:46:24 +00:00
|
|
|
|
* @private
|
2004-09-21 05:49:12 +00:00
|
|
|
|
*/
|
|
|
|
|
|
function doHeadings( $text ) {
|
2004-06-08 18:11:28 +00:00
|
|
|
|
$fname = 'Parser::doHeadings';
|
2004-06-05 04:51:24 +00:00
|
|
|
|
wfProfileIn( $fname );
|
2004-02-26 13:37:26 +00:00
|
|
|
|
for ( $i = 6; $i >= 1; --$i ) {
|
2005-11-29 09:55:50 +00:00
|
|
|
|
$h = str_repeat( '=', $i );
|
2006-06-06 00:51:34 +00:00
|
|
|
|
$text = preg_replace( "/^{$h}(.+){$h}\\s*$/m",
|
2004-02-26 13:37:26 +00:00
|
|
|
|
"<h{$i}>\\1</h{$i}>\\2", $text );
|
|
|
|
|
|
}
|
2004-06-05 04:51:24 +00:00
|
|
|
|
wfProfileOut( $fname );
|
2004-02-26 13:37:26 +00:00
|
|
|
|
return $text;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2004-09-21 05:49:12 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* Replace single quotes with HTML markup
|
2006-04-19 15:46:24 +00:00
|
|
|
|
* @private
|
2004-09-21 05:49:12 +00:00
|
|
|
|
* @return string the altered text
|
|
|
|
|
|
*/
|
|
|
|
|
|
function doAllQuotes( $text ) {
|
2004-06-08 18:11:28 +00:00
|
|
|
|
$fname = 'Parser::doAllQuotes';
|
2004-06-05 04:51:24 +00:00
|
|
|
|
wfProfileIn( $fname );
|
2004-06-08 18:11:28 +00:00
|
|
|
|
$outtext = '';
|
2004-05-27 16:08:12 +00:00
|
|
|
|
$lines = explode( "\n", $text );
|
2004-05-26 16:29:04 +00:00
|
|
|
|
foreach ( $lines as $line ) {
|
2004-08-06 20:47:21 +00:00
|
|
|
|
$outtext .= $this->doQuotes ( $line ) . "\n";
|
2004-05-26 16:29:04 +00:00
|
|
|
|
}
|
2004-06-05 04:51:24 +00:00
|
|
|
|
$outtext = substr($outtext, 0,-1);
|
|
|
|
|
|
wfProfileOut( $fname );
|
|
|
|
|
|
return $outtext;
|
2004-05-26 16:29:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2004-09-21 05:49:12 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* Helper function for doAllQuotes()
|
2006-04-19 15:46:24 +00:00
|
|
|
|
* @private
|
2004-09-21 05:49:12 +00:00
|
|
|
|
*/
|
|
|
|
|
|
function doQuotes( $text ) {
|
2004-11-20 11:28:37 +00:00
|
|
|
|
$arr = preg_split( "/(''+)/", $text, -1, PREG_SPLIT_DELIM_CAPTURE );
|
|
|
|
|
|
if ( count( $arr ) == 1 )
|
2004-08-06 20:47:21 +00:00
|
|
|
|
return $text;
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2004-08-06 21:13:30 +00:00
|
|
|
|
# First, do some preliminary work. This may shift some apostrophes from
|
|
|
|
|
|
# being mark-up to being text. It also counts the number of occurrences
|
|
|
|
|
|
# of bold and italics mark-ups.
|
2004-08-06 20:47:21 +00:00
|
|
|
|
$i = 0;
|
2004-08-06 21:13:30 +00:00
|
|
|
|
$numbold = 0;
|
|
|
|
|
|
$numitalics = 0;
|
2004-11-20 11:28:37 +00:00
|
|
|
|
foreach ( $arr as $r )
|
2004-08-06 20:47:21 +00:00
|
|
|
|
{
|
2004-11-20 11:28:37 +00:00
|
|
|
|
if ( ( $i % 2 ) == 1 )
|
2004-08-06 20:47:21 +00:00
|
|
|
|
{
|
|
|
|
|
|
# If there are ever four apostrophes, assume the first is supposed to
|
|
|
|
|
|
# be text, and the remaining three constitute mark-up for bold text.
|
2004-11-20 11:28:37 +00:00
|
|
|
|
if ( strlen( $arr[$i] ) == 4 )
|
2004-08-06 20:47:21 +00:00
|
|
|
|
{
|
|
|
|
|
|
$arr[$i-1] .= "'";
|
|
|
|
|
|
$arr[$i] = "'''";
|
|
|
|
|
|
}
|
|
|
|
|
|
# If there are more than 5 apostrophes in a row, assume they're all
|
|
|
|
|
|
# text except for the last 5.
|
2004-11-20 11:28:37 +00:00
|
|
|
|
else if ( strlen( $arr[$i] ) > 5 )
|
2004-08-06 20:47:21 +00:00
|
|
|
|
{
|
2004-11-20 11:28:37 +00:00
|
|
|
|
$arr[$i-1] .= str_repeat( "'", strlen( $arr[$i] ) - 5 );
|
2004-08-06 20:47:21 +00:00
|
|
|
|
$arr[$i] = "'''''";
|
|
|
|
|
|
}
|
2004-08-06 21:13:30 +00:00
|
|
|
|
# Count the number of occurrences of bold and italics mark-ups.
|
2004-08-07 12:37:20 +00:00
|
|
|
|
# We are not counting sequences of five apostrophes.
|
2004-11-20 11:28:37 +00:00
|
|
|
|
if ( strlen( $arr[$i] ) == 2 ) $numitalics++; else
|
|
|
|
|
|
if ( strlen( $arr[$i] ) == 3 ) $numbold++; else
|
|
|
|
|
|
if ( strlen( $arr[$i] ) == 5 ) { $numitalics++; $numbold++; }
|
2004-05-26 16:29:04 +00:00
|
|
|
|
}
|
2004-08-06 20:47:21 +00:00
|
|
|
|
$i++;
|
2004-05-26 16:29:04 +00:00
|
|
|
|
}
|
2004-08-07 12:35:59 +00:00
|
|
|
|
|
2004-08-06 20:47:21 +00:00
|
|
|
|
# If there is an odd number of both bold and italics, it is likely
|
|
|
|
|
|
# that one of the bold ones was meant to be an apostrophe followed
|
|
|
|
|
|
# by italics. Which one we cannot know for certain, but it is more
|
|
|
|
|
|
# likely to be one that has a single-letter word before it.
|
2004-11-20 11:28:37 +00:00
|
|
|
|
if ( ( $numbold % 2 == 1 ) && ( $numitalics % 2 == 1 ) )
|
2004-08-06 20:47:21 +00:00
|
|
|
|
{
|
|
|
|
|
|
$i = 0;
|
|
|
|
|
|
$firstsingleletterword = -1;
|
|
|
|
|
|
$firstmultiletterword = -1;
|
|
|
|
|
|
$firstspace = -1;
|
2004-11-20 11:28:37 +00:00
|
|
|
|
foreach ( $arr as $r )
|
2004-08-06 20:47:21 +00:00
|
|
|
|
{
|
2004-11-20 11:28:37 +00:00
|
|
|
|
if ( ( $i % 2 == 1 ) and ( strlen( $r ) == 3 ) )
|
2004-08-06 20:47:21 +00:00
|
|
|
|
{
|
|
|
|
|
|
$x1 = substr ($arr[$i-1], -1);
|
|
|
|
|
|
$x2 = substr ($arr[$i-1], -2, 1);
|
2004-08-22 17:24:50 +00:00
|
|
|
|
if ($x1 == ' ') {
|
2004-08-06 20:47:21 +00:00
|
|
|
|
if ($firstspace == -1) $firstspace = $i;
|
2004-08-22 17:24:50 +00:00
|
|
|
|
} else if ($x2 == ' ') {
|
2004-08-06 20:47:21 +00:00
|
|
|
|
if ($firstsingleletterword == -1) $firstsingleletterword = $i;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
if ($firstmultiletterword == -1) $firstmultiletterword = $i;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
$i++;
|
|
|
|
|
|
}
|
2004-08-07 12:35:59 +00:00
|
|
|
|
|
2004-08-06 20:47:21 +00:00
|
|
|
|
# If there is a single-letter word, use it!
|
|
|
|
|
|
if ($firstsingleletterword > -1)
|
|
|
|
|
|
{
|
|
|
|
|
|
$arr [ $firstsingleletterword ] = "''";
|
|
|
|
|
|
$arr [ $firstsingleletterword-1 ] .= "'";
|
|
|
|
|
|
}
|
|
|
|
|
|
# If not, but there's a multi-letter word, use that one.
|
|
|
|
|
|
else if ($firstmultiletterword > -1)
|
|
|
|
|
|
{
|
|
|
|
|
|
$arr [ $firstmultiletterword ] = "''";
|
|
|
|
|
|
$arr [ $firstmultiletterword-1 ] .= "'";
|
|
|
|
|
|
}
|
|
|
|
|
|
# ... otherwise use the first one that has neither.
|
2004-08-14 08:32:57 +00:00
|
|
|
|
# (notice that it is possible for all three to be -1 if, for example,
|
|
|
|
|
|
# there is only one pentuple-apostrophe in the line)
|
|
|
|
|
|
else if ($firstspace > -1)
|
2004-08-06 20:47:21 +00:00
|
|
|
|
{
|
|
|
|
|
|
$arr [ $firstspace ] = "''";
|
|
|
|
|
|
$arr [ $firstspace-1 ] .= "'";
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2004-08-07 12:35:59 +00:00
|
|
|
|
|
2004-08-06 20:47:21 +00:00
|
|
|
|
# Now let's actually convert our apostrophic mush to HTML!
|
|
|
|
|
|
$output = '';
|
|
|
|
|
|
$buffer = '';
|
|
|
|
|
|
$state = '';
|
|
|
|
|
|
$i = 0;
|
|
|
|
|
|
foreach ($arr as $r)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (($i % 2) == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
if ($state == 'both')
|
|
|
|
|
|
$buffer .= $r;
|
|
|
|
|
|
else
|
|
|
|
|
|
$output .= $r;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
if (strlen ($r) == 2)
|
|
|
|
|
|
{
|
2004-09-11 08:40:26 +00:00
|
|
|
|
if ($state == 'i')
|
|
|
|
|
|
{ $output .= '</i>'; $state = ''; }
|
|
|
|
|
|
else if ($state == 'bi')
|
|
|
|
|
|
{ $output .= '</i>'; $state = 'b'; }
|
|
|
|
|
|
else if ($state == 'ib')
|
|
|
|
|
|
{ $output .= '</b></i><b>'; $state = 'b'; }
|
2004-08-06 20:47:21 +00:00
|
|
|
|
else if ($state == 'both')
|
2004-09-11 08:40:26 +00:00
|
|
|
|
{ $output .= '<b><i>'.$buffer.'</i>'; $state = 'b'; }
|
|
|
|
|
|
else # $state can be 'b' or ''
|
|
|
|
|
|
{ $output .= '<i>'; $state .= 'i'; }
|
2004-08-06 20:47:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
else if (strlen ($r) == 3)
|
|
|
|
|
|
{
|
2004-09-11 08:40:26 +00:00
|
|
|
|
if ($state == 'b')
|
|
|
|
|
|
{ $output .= '</b>'; $state = ''; }
|
|
|
|
|
|
else if ($state == 'bi')
|
|
|
|
|
|
{ $output .= '</i></b><i>'; $state = 'i'; }
|
|
|
|
|
|
else if ($state == 'ib')
|
|
|
|
|
|
{ $output .= '</b>'; $state = 'i'; }
|
2004-08-06 20:47:21 +00:00
|
|
|
|
else if ($state == 'both')
|
2004-09-11 08:40:26 +00:00
|
|
|
|
{ $output .= '<i><b>'.$buffer.'</b>'; $state = 'i'; }
|
|
|
|
|
|
else # $state can be 'i' or ''
|
|
|
|
|
|
{ $output .= '<b>'; $state .= 'b'; }
|
2004-08-06 20:47:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
else if (strlen ($r) == 5)
|
|
|
|
|
|
{
|
2004-09-11 08:40:26 +00:00
|
|
|
|
if ($state == 'b')
|
|
|
|
|
|
{ $output .= '</b><i>'; $state = 'i'; }
|
|
|
|
|
|
else if ($state == 'i')
|
|
|
|
|
|
{ $output .= '</i><b>'; $state = 'b'; }
|
|
|
|
|
|
else if ($state == 'bi')
|
|
|
|
|
|
{ $output .= '</i></b>'; $state = ''; }
|
|
|
|
|
|
else if ($state == 'ib')
|
|
|
|
|
|
{ $output .= '</b></i>'; $state = ''; }
|
2004-08-06 20:47:21 +00:00
|
|
|
|
else if ($state == 'both')
|
2004-09-11 08:40:26 +00:00
|
|
|
|
{ $output .= '<i><b>'.$buffer.'</b></i>'; $state = ''; }
|
2004-08-06 20:47:21 +00:00
|
|
|
|
else # ($state == '')
|
|
|
|
|
|
{ $buffer = ''; $state = 'both'; }
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
$i++;
|
2004-05-26 16:29:04 +00:00
|
|
|
|
}
|
2004-08-07 12:37:20 +00:00
|
|
|
|
# Now close all remaining tags. Notice that the order is important.
|
2004-09-11 08:40:26 +00:00
|
|
|
|
if ($state == 'b' || $state == 'ib')
|
|
|
|
|
|
$output .= '</b>';
|
|
|
|
|
|
if ($state == 'i' || $state == 'bi' || $state == 'ib')
|
|
|
|
|
|
$output .= '</i>';
|
|
|
|
|
|
if ($state == 'bi')
|
|
|
|
|
|
$output .= '</b>';
|
2004-08-07 12:37:20 +00:00
|
|
|
|
if ($state == 'both')
|
2004-09-11 08:40:26 +00:00
|
|
|
|
$output .= '<b><i>'.$buffer.'</i></b>';
|
2004-08-06 20:47:21 +00:00
|
|
|
|
return $output;
|
2004-05-26 16:29:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2004-09-21 05:49:12 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* Replace external links
|
|
|
|
|
|
*
|
2004-10-25 05:24:23 +00:00
|
|
|
|
* Note: this is all very hackish and the order of execution matters a lot.
|
|
|
|
|
|
* Make sure to run maintenance/parserTests.php if you change this code.
|
2004-09-21 05:49:12 +00:00
|
|
|
|
*
|
2006-04-19 15:46:24 +00:00
|
|
|
|
* @private
|
2004-09-21 05:49:12 +00:00
|
|
|
|
*/
|
|
|
|
|
|
function replaceExternalLinks( $text ) {
|
2005-04-27 20:19:35 +00:00
|
|
|
|
global $wgContLang;
|
2004-06-08 18:11:28 +00:00
|
|
|
|
$fname = 'Parser::replaceExternalLinks';
|
2004-02-26 13:37:26 +00:00
|
|
|
|
wfProfileIn( $fname );
|
2004-08-07 08:54:52 +00:00
|
|
|
|
|
2004-08-07 18:24:12 +00:00
|
|
|
|
$sk =& $this->mOptions->getSkin();
|
2005-07-03 07:15:53 +00:00
|
|
|
|
|
2004-08-07 18:24:12 +00:00
|
|
|
|
$bits = preg_split( EXT_LINK_BRACKETED, $text, -1, PREG_SPLIT_DELIM_CAPTURE );
|
|
|
|
|
|
|
|
|
|
|
|
$s = $this->replaceFreeExternalLinks( array_shift( $bits ) );
|
|
|
|
|
|
|
|
|
|
|
|
$i = 0;
|
|
|
|
|
|
while ( $i<count( $bits ) ) {
|
|
|
|
|
|
$url = $bits[$i++];
|
|
|
|
|
|
$protocol = $bits[$i++];
|
|
|
|
|
|
$text = $bits[$i++];
|
|
|
|
|
|
$trail = $bits[$i++];
|
2004-08-14 22:38:46 +00:00
|
|
|
|
|
2004-10-11 16:57:49 +00:00
|
|
|
|
# The characters '<' and '>' (which were escaped by
|
|
|
|
|
|
# removeHTMLtags()) should not be included in
|
|
|
|
|
|
# URLs, per RFC 2396.
|
|
|
|
|
|
if (preg_match('/&(lt|gt);/', $url, $m2, PREG_OFFSET_CAPTURE)) {
|
2004-10-11 19:15:24 +00:00
|
|
|
|
$text = substr($url, $m2[0][1]) . ' ' . $text;
|
2004-10-11 16:57:49 +00:00
|
|
|
|
$url = substr($url, 0, $m2[0][1]);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2004-08-07 18:24:12 +00:00
|
|
|
|
# If the link text is an image URL, replace it with an <img> tag
|
|
|
|
|
|
# This happened by accident in the original parser, but some people used it extensively
|
2005-04-27 07:48:14 +00:00
|
|
|
|
$img = $this->maybeMakeExternalImage( $text );
|
2004-08-07 18:24:12 +00:00
|
|
|
|
if ( $img !== false ) {
|
|
|
|
|
|
$text = $img;
|
|
|
|
|
|
}
|
2004-04-12 23:59:37 +00:00
|
|
|
|
|
2004-08-07 18:24:12 +00:00
|
|
|
|
$dtrail = '';
|
2004-08-07 08:54:52 +00:00
|
|
|
|
|
2005-01-15 23:56:26 +00:00
|
|
|
|
# Set linktype for CSS - if URL==text, link is essentially free
|
|
|
|
|
|
$linktype = ($text == $url) ? 'free' : 'text';
|
|
|
|
|
|
|
2004-08-07 18:24:12 +00:00
|
|
|
|
# No link text, e.g. [http://domain.tld/some.link]
|
|
|
|
|
|
if ( $text == '' ) {
|
2006-05-13 19:29:24 +00:00
|
|
|
|
# Autonumber if allowed. See bug #5918
|
|
|
|
|
|
if ( strpos( wfUrlProtocols(), substr($protocol, 0, strpos($protocol, ':')) ) !== false ) {
|
2004-08-22 17:24:50 +00:00
|
|
|
|
$text = '[' . ++$this->mAutonumber . ']';
|
2005-01-15 23:56:26 +00:00
|
|
|
|
$linktype = 'autonumber';
|
2004-08-14 22:38:46 +00:00
|
|
|
|
} else {
|
2004-08-07 18:24:12 +00:00
|
|
|
|
# Otherwise just use the URL
|
2004-08-14 22:38:46 +00:00
|
|
|
|
$text = htmlspecialchars( $url );
|
2005-01-15 23:56:26 +00:00
|
|
|
|
$linktype = 'free';
|
2004-08-07 18:24:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
# Have link text, e.g. [http://domain.tld/some.link text]s
|
|
|
|
|
|
# Check for trail
|
2005-04-27 07:48:14 +00:00
|
|
|
|
list( $dtrail, $trail ) = Linker::splitTrail( $trail );
|
2004-08-07 18:24:12 +00:00
|
|
|
|
}
|
2004-08-14 22:38:46 +00:00
|
|
|
|
|
2005-04-26 20:50:16 +00:00
|
|
|
|
$text = $wgContLang->markNoConversion($text);
|
2006-07-11 19:54:20 +00:00
|
|
|
|
|
|
|
|
|
|
$url = Sanitizer::cleanUrl( $url );
|
2005-01-30 04:11:22 +00:00
|
|
|
|
|
2004-08-07 18:24:12 +00:00
|
|
|
|
# Process the trail (i.e. everything after this link up until start of the next link),
|
|
|
|
|
|
# replacing any non-bracketed links
|
|
|
|
|
|
$trail = $this->replaceFreeExternalLinks( $trail );
|
|
|
|
|
|
|
|
|
|
|
|
# Use the encoded URL
|
|
|
|
|
|
# This means that users can paste URLs directly into the text
|
|
|
|
|
|
# Funny characters like ö aren't valid in URLs anyway
|
|
|
|
|
|
# This was changed in August 2004
|
2006-05-22 21:17:38 +00:00
|
|
|
|
$s .= $sk->makeExternalLink( $url, $text, false, $linktype, $this->mTitle->getNamespace() ) . $dtrail . $trail;
|
2006-01-26 13:29:14 +00:00
|
|
|
|
|
2006-03-17 01:02:14 +00:00
|
|
|
|
# Register link in the output object.
|
|
|
|
|
|
# Replace unnecessary URL escape codes with the referenced character
|
|
|
|
|
|
# This prevents spammers from hiding links from the filters
|
|
|
|
|
|
$pasteurized = Parser::replaceUnusualEscapes( $url );
|
|
|
|
|
|
$this->mOutput->addExternalLink( $pasteurized );
|
2004-08-07 18:24:12 +00:00
|
|
|
|
}
|
2004-08-07 08:54:52 +00:00
|
|
|
|
|
2004-08-07 18:24:12 +00:00
|
|
|
|
wfProfileOut( $fname );
|
|
|
|
|
|
return $s;
|
|
|
|
|
|
}
|
2004-02-26 13:37:26 +00:00
|
|
|
|
|
2004-09-21 05:49:12 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* Replace anything that looks like a URL with a link
|
2006-04-19 15:46:24 +00:00
|
|
|
|
* @private
|
2004-09-21 05:49:12 +00:00
|
|
|
|
*/
|
2004-08-07 18:24:12 +00:00
|
|
|
|
function replaceFreeExternalLinks( $text ) {
|
2005-04-26 20:50:16 +00:00
|
|
|
|
global $wgContLang;
|
2004-11-26 12:10:24 +00:00
|
|
|
|
$fname = 'Parser::replaceFreeExternalLinks';
|
|
|
|
|
|
wfProfileIn( $fname );
|
2005-07-03 07:15:53 +00:00
|
|
|
|
|
2005-10-30 11:24:43 +00:00
|
|
|
|
$bits = preg_split( '/(\b(?:' . wfUrlProtocols() . '))/S', $text, -1, PREG_SPLIT_DELIM_CAPTURE );
|
2004-08-07 18:24:12 +00:00
|
|
|
|
$s = array_shift( $bits );
|
|
|
|
|
|
$i = 0;
|
2004-08-07 08:54:52 +00:00
|
|
|
|
|
2004-02-29 08:43:29 +00:00
|
|
|
|
$sk =& $this->mOptions->getSkin();
|
2004-02-26 13:37:26 +00:00
|
|
|
|
|
2004-08-07 18:24:12 +00:00
|
|
|
|
while ( $i < count( $bits ) ){
|
|
|
|
|
|
$protocol = $bits[$i++];
|
|
|
|
|
|
$remainder = $bits[$i++];
|
2004-08-07 08:54:52 +00:00
|
|
|
|
|
2004-08-07 18:24:12 +00:00
|
|
|
|
if ( preg_match( '/^('.EXT_LINK_URL_CLASS.'+)(.*)$/s', $remainder, $m ) ) {
|
|
|
|
|
|
# Found some characters after the protocol that look promising
|
|
|
|
|
|
$url = $protocol . $m[1];
|
2004-02-26 13:37:26 +00:00
|
|
|
|
$trail = $m[2];
|
2004-08-14 22:38:46 +00:00
|
|
|
|
|
2006-03-24 16:38:34 +00:00
|
|
|
|
# special case: handle urls as url args:
|
|
|
|
|
|
# http://www.example.com/foo?=http://www.example.com/bar
|
|
|
|
|
|
if(strlen($trail) == 0 &&
|
|
|
|
|
|
isset($bits[$i]) &&
|
|
|
|
|
|
preg_match('/^'. wfUrlProtocols() . '$/S', $bits[$i]) &&
|
|
|
|
|
|
preg_match( '/^('.EXT_LINK_URL_CLASS.'+)(.*)$/s', $bits[$i + 1], $m ))
|
|
|
|
|
|
{
|
|
|
|
|
|
# add protocol, arg
|
2006-05-01 20:22:44 +00:00
|
|
|
|
$url .= $bits[$i] . $m[1]; # protocol, url as arg to previous link
|
2006-03-24 16:38:34 +00:00
|
|
|
|
$i += 2;
|
|
|
|
|
|
$trail = $m[2];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2004-10-11 16:57:49 +00:00
|
|
|
|
# The characters '<' and '>' (which were escaped by
|
|
|
|
|
|
# removeHTMLtags()) should not be included in
|
|
|
|
|
|
# URLs, per RFC 2396.
|
|
|
|
|
|
if (preg_match('/&(lt|gt);/', $url, $m2, PREG_OFFSET_CAPTURE)) {
|
|
|
|
|
|
$trail = substr($url, $m2[0][1]) . $trail;
|
|
|
|
|
|
$url = substr($url, 0, $m2[0][1]);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2004-08-07 18:45:30 +00:00
|
|
|
|
# Move trailing punctuation to $trail
|
|
|
|
|
|
$sep = ',;\.:!?';
|
|
|
|
|
|
# If there is no left bracket, then consider right brackets fair game too
|
|
|
|
|
|
if ( strpos( $url, '(' ) === false ) {
|
|
|
|
|
|
$sep .= ')';
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2004-08-07 18:24:12 +00:00
|
|
|
|
$numSepChars = strspn( strrev( $url ), $sep );
|
|
|
|
|
|
if ( $numSepChars ) {
|
|
|
|
|
|
$trail = substr( $url, -$numSepChars ) . $trail;
|
|
|
|
|
|
$url = substr( $url, 0, -$numSepChars );
|
2004-07-13 00:01:33 +00:00
|
|
|
|
}
|
2004-07-12 22:57:13 +00:00
|
|
|
|
|
2006-07-11 19:54:20 +00:00
|
|
|
|
$url = Sanitizer::cleanUrl( $url );
|
2004-08-10 11:24:24 +00:00
|
|
|
|
|
2004-08-07 18:24:12 +00:00
|
|
|
|
# Is this an external image?
|
2005-04-27 07:48:14 +00:00
|
|
|
|
$text = $this->maybeMakeExternalImage( $url );
|
2004-08-07 18:24:12 +00:00
|
|
|
|
if ( $text === false ) {
|
|
|
|
|
|
# Not an image, make a link
|
2006-05-22 21:17:38 +00:00
|
|
|
|
$text = $sk->makeExternalLink( $url, $wgContLang->markNoConversion($url), true, 'free', $this->mTitle->getNamespace() );
|
2006-03-17 01:02:14 +00:00
|
|
|
|
# Register it in the output object...
|
|
|
|
|
|
# Replace unnecessary URL escape codes with their equivalent characters
|
|
|
|
|
|
$pasteurized = Parser::replaceUnusualEscapes( $url );
|
|
|
|
|
|
$this->mOutput->addExternalLink( $pasteurized );
|
2004-08-07 18:24:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
$s .= $text . $trail;
|
2004-03-21 11:28:44 +00:00
|
|
|
|
} else {
|
2004-08-07 18:24:12 +00:00
|
|
|
|
$s .= $protocol . $remainder;
|
2004-03-21 11:28:44 +00:00
|
|
|
|
}
|
2004-02-26 13:37:26 +00:00
|
|
|
|
}
|
2005-07-25 07:00:20 +00:00
|
|
|
|
wfProfileOut( $fname );
|
2004-02-26 13:37:26 +00:00
|
|
|
|
return $s;
|
|
|
|
|
|
}
|
2004-08-14 22:38:46 +00:00
|
|
|
|
|
2006-01-26 13:29:14 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* Replace unusual URL escape codes with their equivalent characters
|
2006-03-11 17:13:49 +00:00
|
|
|
|
* @param string
|
2006-01-26 13:29:14 +00:00
|
|
|
|
* @return string
|
|
|
|
|
|
* @static
|
2006-03-17 01:02:14 +00:00
|
|
|
|
* @fixme This can merge genuinely required bits in the path or query string,
|
|
|
|
|
|
* breaking legit URLs. A proper fix would treat the various parts of
|
|
|
|
|
|
* the URL differently; as a workaround, just use the output for
|
|
|
|
|
|
* statistical records, not for actual linking/output.
|
2006-01-26 13:29:14 +00:00
|
|
|
|
*/
|
2006-07-10 15:41:30 +00:00
|
|
|
|
static function replaceUnusualEscapes( $url ) {
|
2006-03-11 17:13:49 +00:00
|
|
|
|
return preg_replace_callback( '/%[0-9A-Fa-f]{2}/',
|
2006-01-26 13:29:14 +00:00
|
|
|
|
array( 'Parser', 'replaceUnusualEscapesCallback' ), $url );
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Callback function used in replaceUnusualEscapes().
|
|
|
|
|
|
* Replaces unusual URL escape codes with their equivalent character
|
|
|
|
|
|
* @static
|
2006-04-19 15:46:24 +00:00
|
|
|
|
* @private
|
2006-01-26 13:29:14 +00:00
|
|
|
|
*/
|
2006-07-10 15:41:30 +00:00
|
|
|
|
private static function replaceUnusualEscapesCallback( $matches ) {
|
2006-01-26 13:29:14 +00:00
|
|
|
|
$char = urldecode( $matches[0] );
|
|
|
|
|
|
$ord = ord( $char );
|
|
|
|
|
|
// Is it an unsafe or HTTP reserved character according to RFC 1738?
|
|
|
|
|
|
if ( $ord > 32 && $ord < 127 && strpos( '<>"#{}|\^~[]`;/?', $char ) === false ) {
|
|
|
|
|
|
// No, shouldn't be escaped
|
|
|
|
|
|
return $char;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
// Yes, leave it escaped
|
|
|
|
|
|
return $matches[0];
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2004-09-21 05:49:12 +00:00
|
|
|
|
/**
|
2005-10-26 22:13:02 +00:00
|
|
|
|
* make an image if it's allowed, either through the global
|
|
|
|
|
|
* option or through the exception
|
2006-04-19 15:46:24 +00:00
|
|
|
|
* @private
|
2004-09-21 05:49:12 +00:00
|
|
|
|
*/
|
2005-04-27 07:48:14 +00:00
|
|
|
|
function maybeMakeExternalImage( $url ) {
|
2004-08-07 18:24:12 +00:00
|
|
|
|
$sk =& $this->mOptions->getSkin();
|
2005-10-26 22:13:02 +00:00
|
|
|
|
$imagesfrom = $this->mOptions->getAllowExternalImagesFrom();
|
|
|
|
|
|
$imagesexception = !empty($imagesfrom);
|
2004-08-07 18:24:12 +00:00
|
|
|
|
$text = false;
|
2006-01-07 13:09:30 +00:00
|
|
|
|
if ( $this->mOptions->getAllowExternalImages()
|
2005-10-26 22:13:02 +00:00
|
|
|
|
|| ( $imagesexception && strpos( $url, $imagesfrom ) === 0 ) ) {
|
2004-08-07 18:24:12 +00:00
|
|
|
|
if ( preg_match( EXT_IMAGE_REGEX, $url ) ) {
|
|
|
|
|
|
# Image found
|
2005-04-27 07:48:14 +00:00
|
|
|
|
$text = $sk->makeExternalImage( htmlspecialchars( $url ) );
|
2004-08-07 18:24:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return $text;
|
|
|
|
|
|
}
|
2005-07-03 07:15:53 +00:00
|
|
|
|
|
2004-09-21 05:49:12 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* Process [[ ]] wikilinks
|
|
|
|
|
|
*
|
2006-04-19 15:46:24 +00:00
|
|
|
|
* @private
|
2004-09-21 05:49:12 +00:00
|
|
|
|
*/
|
|
|
|
|
|
function replaceInternalLinks( $s ) {
|
2006-01-05 02:05:53 +00:00
|
|
|
|
global $wgContLang;
|
2004-06-08 18:11:28 +00:00
|
|
|
|
static $fname = 'Parser::replaceInternalLinks' ;
|
2004-10-23 13:00:33 +00:00
|
|
|
|
|
2004-02-28 23:38:08 +00:00
|
|
|
|
wfProfileIn( $fname );
|
2004-02-26 13:37:26 +00:00
|
|
|
|
|
2004-06-08 18:11:28 +00:00
|
|
|
|
wfProfileIn( $fname.'-setup' );
|
2004-02-28 23:38:08 +00:00
|
|
|
|
static $tc = FALSE;
|
2004-05-25 14:26:14 +00:00
|
|
|
|
# the % is needed to support urlencoded titles as well
|
2004-06-08 18:11:28 +00:00
|
|
|
|
if ( !$tc ) { $tc = Title::legalChars() . '#%'; }
|
2005-07-03 07:15:53 +00:00
|
|
|
|
|
2004-02-29 08:43:29 +00:00
|
|
|
|
$sk =& $this->mOptions->getSkin();
|
2004-02-26 13:37:26 +00:00
|
|
|
|
|
2004-10-05 03:55:41 +00:00
|
|
|
|
#split the entire text string on occurences of [[
|
2004-06-08 18:11:28 +00:00
|
|
|
|
$a = explode( '[[', ' ' . $s );
|
2004-10-05 03:55:41 +00:00
|
|
|
|
#get the first element (all text up to first [[), and remove the space we added
|
2004-05-26 16:29:04 +00:00
|
|
|
|
$s = array_shift( $a );
|
|
|
|
|
|
$s = substr( $s, 1 );
|
|
|
|
|
|
|
2004-02-26 13:37:26 +00:00
|
|
|
|
# Match a link having the form [[namespace:link|alternate]]trail
|
2004-02-28 23:38:08 +00:00
|
|
|
|
static $e1 = FALSE;
|
2005-01-13 09:13:22 +00:00
|
|
|
|
if ( !$e1 ) { $e1 = "/^([{$tc}]+)(?:\\|(.+?))?]](.*)\$/sD"; }
|
2004-10-05 03:55:41 +00:00
|
|
|
|
# Match cases where there is no "]]", which might still be images
|
|
|
|
|
|
static $e1_img = FALSE;
|
|
|
|
|
|
if ( !$e1_img ) { $e1_img = "/^([{$tc}]+)\\|(.*)\$/sD"; }
|
2004-02-26 13:37:26 +00:00
|
|
|
|
# Match the end of a line for a word that's not followed by whitespace,
|
|
|
|
|
|
# e.g. in the case of 'The Arab al[[Razi]]', 'al' will be matched
|
2005-07-30 20:03:38 +00:00
|
|
|
|
$e2 = wfMsgForContent( 'linkprefix' );
|
2004-02-26 13:37:26 +00:00
|
|
|
|
|
2004-09-24 13:14:52 +00:00
|
|
|
|
$useLinkPrefixExtension = $wgContLang->linkPrefixExtension();
|
2004-04-12 23:59:37 +00:00
|
|
|
|
|
2005-02-21 11:28:07 +00:00
|
|
|
|
if( is_null( $this->mTitle ) ) {
|
2006-08-06 14:01:47 +00:00
|
|
|
|
throw new MWException( __METHOD__.": \$this->mTitle is null\n" );
|
2005-02-21 11:28:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
$nottalk = !$this->mTitle->isTalkPage();
|
2004-02-26 13:37:26 +00:00
|
|
|
|
|
2004-06-02 22:54:01 +00:00
|
|
|
|
if ( $useLinkPrefixExtension ) {
|
|
|
|
|
|
if ( preg_match( $e2, $s, $m ) ) {
|
|
|
|
|
|
$first_prefix = $m[2];
|
|
|
|
|
|
} else {
|
|
|
|
|
|
$first_prefix = false;
|
|
|
|
|
|
}
|
2004-05-26 16:29:04 +00:00
|
|
|
|
} else {
|
2004-06-02 22:54:01 +00:00
|
|
|
|
$prefix = '';
|
2004-05-26 16:29:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2004-11-23 07:41:07 +00:00
|
|
|
|
$selflink = $this->mTitle->getPrefixedText();
|
2006-07-19 20:13:39 +00:00
|
|
|
|
$checkVariantLink = sizeof($wgContLang->getVariants())>1;
|
2004-11-28 03:29:50 +00:00
|
|
|
|
$useSubpages = $this->areSubpagesAllowed();
|
2006-08-06 14:01:47 +00:00
|
|
|
|
wfProfileOut( $fname.'-setup' );
|
2005-07-03 07:15:53 +00:00
|
|
|
|
|
2004-10-05 03:55:41 +00:00
|
|
|
|
# Loop for each link
|
|
|
|
|
|
for ($k = 0; isset( $a[$k] ); $k++) {
|
|
|
|
|
|
$line = $a[$k];
|
2004-06-02 22:54:01 +00:00
|
|
|
|
if ( $useLinkPrefixExtension ) {
|
2004-11-22 10:05:11 +00:00
|
|
|
|
wfProfileIn( $fname.'-prefixhandling' );
|
2004-06-02 22:54:01 +00:00
|
|
|
|
if ( preg_match( $e2, $s, $m ) ) {
|
|
|
|
|
|
$prefix = $m[2];
|
|
|
|
|
|
$s = $m[1];
|
|
|
|
|
|
} else {
|
|
|
|
|
|
$prefix='';
|
|
|
|
|
|
}
|
|
|
|
|
|
# first link
|
|
|
|
|
|
if($first_prefix) {
|
|
|
|
|
|
$prefix = $first_prefix;
|
|
|
|
|
|
$first_prefix = false;
|
|
|
|
|
|
}
|
2004-11-22 10:05:11 +00:00
|
|
|
|
wfProfileOut( $fname.'-prefixhandling' );
|
2004-06-02 22:39:06 +00:00
|
|
|
|
}
|
2004-07-12 19:49:20 +00:00
|
|
|
|
|
2004-10-05 03:55:41 +00:00
|
|
|
|
$might_be_img = false;
|
2005-07-03 07:15:53 +00:00
|
|
|
|
|
2006-08-06 14:01:47 +00:00
|
|
|
|
wfProfileIn( "$fname-e1" );
|
2004-05-26 16:29:04 +00:00
|
|
|
|
if ( preg_match( $e1, $line, $m ) ) { # page with normal text or alt
|
|
|
|
|
|
$text = $m[2];
|
2005-04-12 06:07:23 +00:00
|
|
|
|
# If we get a ] at the beginning of $m[3] that means we have a link that's something like:
|
|
|
|
|
|
# [[Image:Foo.jpg|[http://example.com desc]]] <- having three ] in a row fucks up,
|
|
|
|
|
|
# the real problem is with the $e1 regex
|
|
|
|
|
|
# See bug 1300.
|
2005-05-18 09:21:47 +00:00
|
|
|
|
#
|
|
|
|
|
|
# Still some problems for cases where the ] is meant to be outside punctuation,
|
|
|
|
|
|
# and no image is in sight. See bug 2095.
|
|
|
|
|
|
#
|
2006-03-24 16:40:31 +00:00
|
|
|
|
if( $text !== '' &&
|
2006-08-06 14:01:47 +00:00
|
|
|
|
substr( $m[3], 0, 1 ) === ']' &&
|
2006-03-24 16:40:31 +00:00
|
|
|
|
strpos($text, '[') !== false
|
|
|
|
|
|
)
|
|
|
|
|
|
{
|
2005-04-12 06:07:23 +00:00
|
|
|
|
$text .= ']'; # so that replaceExternalLinks($text) works later
|
2006-08-06 14:01:47 +00:00
|
|
|
|
$m[3] = substr( $m[3], 1 );
|
2005-04-12 06:07:23 +00:00
|
|
|
|
}
|
2004-05-26 16:29:04 +00:00
|
|
|
|
# fix up urlencoded title texts
|
2006-08-06 14:01:47 +00:00
|
|
|
|
if( strpos( $m[1], '%' ) !== false ) {
|
2006-03-24 16:43:57 +00:00
|
|
|
|
# Should anchors '#' also be rejected?
|
|
|
|
|
|
$m[1] = str_replace( array('<', '>'), array('<', '>'), urldecode($m[1]) );
|
2006-08-06 14:01:47 +00:00
|
|
|
|
}
|
2004-05-26 16:29:04 +00:00
|
|
|
|
$trail = $m[3];
|
2004-10-05 03:55:41 +00:00
|
|
|
|
} elseif( preg_match($e1_img, $line, $m) ) { # Invalid, but might be an image with a link in its caption
|
|
|
|
|
|
$might_be_img = true;
|
|
|
|
|
|
$text = $m[2];
|
2006-08-06 14:01:47 +00:00
|
|
|
|
if ( strpos( $m[1], '%' ) !== false ) {
|
|
|
|
|
|
$m[1] = urldecode($m[1]);
|
|
|
|
|
|
}
|
2004-10-05 03:55:41 +00:00
|
|
|
|
$trail = "";
|
2004-10-05 00:21:52 +00:00
|
|
|
|
} else { # Invalid form; output directly
|
|
|
|
|
|
$s .= $prefix . '[[' . $line ;
|
2006-08-06 14:01:47 +00:00
|
|
|
|
wfProfileOut( "$fname-e1" );
|
2004-10-05 00:21:52 +00:00
|
|
|
|
continue;
|
2004-02-26 13:37:26 +00:00
|
|
|
|
}
|
2006-08-06 14:01:47 +00:00
|
|
|
|
wfProfileOut( "$fname-e1" );
|
|
|
|
|
|
wfProfileIn( "$fname-misc" );
|
2004-05-26 16:29:04 +00:00
|
|
|
|
|
2004-09-24 18:29:01 +00:00
|
|
|
|
# Don't allow internal links to pages containing
|
|
|
|
|
|
# PROTO: where PROTO is a valid URL protocol; these
|
|
|
|
|
|
# should be external links.
|
2005-10-30 11:24:43 +00:00
|
|
|
|
if (preg_match('/^(\b(?:' . wfUrlProtocols() . '))/', $m[1])) {
|
2004-09-24 18:29:01 +00:00
|
|
|
|
$s .= $prefix . '[[' . $line ;
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2004-09-25 20:35:38 +00:00
|
|
|
|
# Make subpage if necessary
|
2004-11-28 03:29:50 +00:00
|
|
|
|
if( $useSubpages ) {
|
|
|
|
|
|
$link = $this->maybeDoSubpageLink( $m[1], $text );
|
|
|
|
|
|
} else {
|
|
|
|
|
|
$link = $m[1];
|
|
|
|
|
|
}
|
2004-09-25 20:35:38 +00:00
|
|
|
|
|
|
|
|
|
|
$noforce = (substr($m[1], 0, 1) != ':');
|
|
|
|
|
|
if (!$noforce) {
|
|
|
|
|
|
# Strip off leading ':'
|
|
|
|
|
|
$link = substr($link, 1);
|
|
|
|
|
|
}
|
2005-07-03 07:15:53 +00:00
|
|
|
|
|
2006-08-06 14:01:47 +00:00
|
|
|
|
wfProfileOut( "$fname-misc" );
|
|
|
|
|
|
wfProfileIn( "$fname-title" );
|
2005-08-01 23:58:51 +00:00
|
|
|
|
$nt = Title::newFromText( $this->unstripNoWiki($link, $this->mStripState) );
|
2004-05-26 16:29:04 +00:00
|
|
|
|
if( !$nt ) {
|
2004-06-08 18:11:28 +00:00
|
|
|
|
$s .= $prefix . '[[' . $line;
|
2006-08-06 14:01:47 +00:00
|
|
|
|
wfProfileOut( "$fname-title" );
|
2004-05-26 16:29:04 +00:00
|
|
|
|
continue;
|
2004-02-26 13:37:26 +00:00
|
|
|
|
}
|
2004-10-04 03:47:39 +00:00
|
|
|
|
|
2006-07-19 20:13:39 +00:00
|
|
|
|
#check other language variants of the link
|
|
|
|
|
|
#if the article does not exist
|
|
|
|
|
|
if( $checkVariantLink
|
|
|
|
|
|
&& $nt->getArticleID() == 0 ) {
|
|
|
|
|
|
$wgContLang->findVariantLink($link, $nt);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2004-05-26 16:29:04 +00:00
|
|
|
|
$ns = $nt->getNamespace();
|
|
|
|
|
|
$iw = $nt->getInterWiki();
|
2006-08-06 14:01:47 +00:00
|
|
|
|
wfProfileOut( "$fname-title" );
|
|
|
|
|
|
|
2004-10-05 03:55:41 +00:00
|
|
|
|
if ($might_be_img) { # if this is actually an invalid link
|
2006-08-06 14:01:47 +00:00
|
|
|
|
wfProfileIn( "$fname-might_be_img" );
|
2004-10-05 03:55:41 +00:00
|
|
|
|
if ($ns == NS_IMAGE && $noforce) { #but might be an image
|
|
|
|
|
|
$found = false;
|
|
|
|
|
|
while (isset ($a[$k+1]) ) {
|
|
|
|
|
|
#look at the next 'line' to see if we can close it there
|
2005-09-18 01:19:33 +00:00
|
|
|
|
$spliced = array_splice( $a, $k + 1, 1 );
|
|
|
|
|
|
$next_line = array_shift( $spliced );
|
2006-08-06 14:01:47 +00:00
|
|
|
|
$m = explode( ']]', $next_line, 3 );
|
|
|
|
|
|
if ( count( $m ) == 3 ) {
|
|
|
|
|
|
# the first ]] closes the inner link, the second the image
|
2004-10-05 03:55:41 +00:00
|
|
|
|
$found = true;
|
2006-08-06 14:01:47 +00:00
|
|
|
|
$text .= "[[{$m[0]}]]{$m[1]}";
|
2004-10-05 03:55:41 +00:00
|
|
|
|
$trail = $m[2];
|
|
|
|
|
|
break;
|
2006-08-06 14:01:47 +00:00
|
|
|
|
} elseif ( count( $m ) == 2 ) {
|
2004-10-05 03:55:41 +00:00
|
|
|
|
#if there's exactly one ]] that's fine, we'll keep looking
|
2006-08-06 14:01:47 +00:00
|
|
|
|
$text .= "[[{$m[0]}]]{$m[1]}";
|
2004-10-05 03:55:41 +00:00
|
|
|
|
} else {
|
|
|
|
|
|
#if $next_line is invalid too, we need look no further
|
|
|
|
|
|
$text .= '[[' . $next_line;
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if ( !$found ) {
|
|
|
|
|
|
# we couldn't find the end of this imageLink, so output it raw
|
2004-10-06 19:22:42 +00:00
|
|
|
|
#but don't ignore what might be perfectly normal links in the text we've examined
|
|
|
|
|
|
$text = $this->replaceInternalLinks($text);
|
2006-08-06 14:01:47 +00:00
|
|
|
|
$s .= "{$prefix}[[$link|$text";
|
2004-10-05 03:55:41 +00:00
|
|
|
|
# note: no $trail, because without an end, there *is* no trail
|
2006-08-06 14:01:47 +00:00
|
|
|
|
wfProfileOut( "$fname-might_be_img" );
|
2004-10-05 03:55:41 +00:00
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
} else { #it's not an image, so output it raw
|
2006-08-06 14:01:47 +00:00
|
|
|
|
$s .= "{$prefix}[[$link|$text";
|
2004-10-05 03:55:41 +00:00
|
|
|
|
# note: no $trail, because without an end, there *is* no trail
|
2006-08-06 14:01:47 +00:00
|
|
|
|
wfProfileOut( "$fname-might_be_img" );
|
2004-10-05 03:55:41 +00:00
|
|
|
|
continue;
|
|
|
|
|
|
}
|
2006-08-06 14:01:47 +00:00
|
|
|
|
wfProfileOut( "$fname-might_be_img" );
|
2004-10-05 03:55:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$wasblank = ( '' == $text );
|
|
|
|
|
|
if( $wasblank ) $text = $link;
|
|
|
|
|
|
|
2004-08-16 20:01:21 +00:00
|
|
|
|
# Link not escaped by : , create the various objects
|
2004-05-26 16:29:04 +00:00
|
|
|
|
if( $noforce ) {
|
2004-08-16 20:01:21 +00:00
|
|
|
|
|
|
|
|
|
|
# Interwikis
|
2006-08-06 14:01:47 +00:00
|
|
|
|
wfProfileIn( "$fname-interwiki" );
|
2004-09-24 13:14:52 +00:00
|
|
|
|
if( $iw && $this->mOptions->getInterwikiMagic() && $nottalk && $wgContLang->getLanguageName( $iw ) ) {
|
2005-12-30 09:33:11 +00:00
|
|
|
|
$this->mOutput->addLanguageLink( $nt->getFullText() );
|
2005-04-13 10:14:01 +00:00
|
|
|
|
$s = rtrim($s . "\n");
|
|
|
|
|
|
$s .= trim($prefix . $trail, "\n") == '' ? '': $prefix . $trail;
|
2006-08-06 14:01:47 +00:00
|
|
|
|
wfProfileOut( "$fname-interwiki" );
|
2004-05-26 16:29:04 +00:00
|
|
|
|
continue;
|
|
|
|
|
|
}
|
2006-08-06 14:01:47 +00:00
|
|
|
|
wfProfileOut( "$fname-interwiki" );
|
2005-07-03 07:15:53 +00:00
|
|
|
|
|
2004-08-07 03:50:46 +00:00
|
|
|
|
if ( $ns == NS_IMAGE ) {
|
2004-11-23 07:41:07 +00:00
|
|
|
|
wfProfileIn( "$fname-image" );
|
2005-04-12 04:03:21 +00:00
|
|
|
|
if ( !wfIsBadImage( $nt->getDBkey() ) ) {
|
|
|
|
|
|
# recursively parse links inside the image caption
|
|
|
|
|
|
# actually, this will parse them in any other parameters, too,
|
|
|
|
|
|
# but it might be hard to fix that, and it doesn't matter ATM
|
|
|
|
|
|
$text = $this->replaceExternalLinks($text);
|
|
|
|
|
|
$text = $this->replaceInternalLinks($text);
|
2005-07-03 07:15:53 +00:00
|
|
|
|
|
2005-04-12 04:03:21 +00:00
|
|
|
|
# cloak any absolute URLs inside the image markup, so replaceExternalLinks() won't touch them
|
2005-12-28 22:58:54 +00:00
|
|
|
|
$s .= $prefix . $this->armorLinks( $this->makeImage( $nt, $text ) ) . $trail;
|
2006-01-07 13:09:30 +00:00
|
|
|
|
$this->mOutput->addImage( $nt->getDBkey() );
|
2005-07-03 07:15:53 +00:00
|
|
|
|
|
2005-04-12 04:03:21 +00:00
|
|
|
|
wfProfileOut( "$fname-image" );
|
|
|
|
|
|
continue;
|
2006-07-04 03:40:37 +00:00
|
|
|
|
} else {
|
|
|
|
|
|
# We still need to record the image's presence on the page
|
|
|
|
|
|
$this->mOutput->addImage( $nt->getDBkey() );
|
2005-04-12 04:03:21 +00:00
|
|
|
|
}
|
2004-11-23 07:41:07 +00:00
|
|
|
|
wfProfileOut( "$fname-image" );
|
2005-04-12 04:03:21 +00:00
|
|
|
|
|
2004-05-27 01:10:01 +00:00
|
|
|
|
}
|
2005-07-03 07:15:53 +00:00
|
|
|
|
|
2004-08-07 03:50:46 +00:00
|
|
|
|
if ( $ns == NS_CATEGORY ) {
|
2004-11-23 07:41:07 +00:00
|
|
|
|
wfProfileIn( "$fname-category" );
|
2005-04-13 08:26:08 +00:00
|
|
|
|
$s = rtrim($s . "\n"); # bug 87
|
2004-05-26 16:29:04 +00:00
|
|
|
|
|
2004-09-07 22:08:01 +00:00
|
|
|
|
if ( $wasblank ) {
|
|
|
|
|
|
if ( $this->mTitle->getNamespace() == NS_CATEGORY ) {
|
|
|
|
|
|
$sortkey = $this->mTitle->getText();
|
|
|
|
|
|
} else {
|
|
|
|
|
|
$sortkey = $this->mTitle->getPrefixedText();
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
$sortkey = $text;
|
|
|
|
|
|
}
|
2005-12-05 08:19:52 +00:00
|
|
|
|
$sortkey = Sanitizer::decodeCharReferences( $sortkey );
|
2006-06-23 09:20:44 +00:00
|
|
|
|
$sortkey = str_replace( "\n", '', $sortkey );
|
2005-04-28 03:33:54 +00:00
|
|
|
|
$sortkey = $wgContLang->convertCategoryKey( $sortkey );
|
2005-12-30 09:33:11 +00:00
|
|
|
|
$this->mOutput->addCategory( $nt->getDBkey(), $sortkey );
|
2005-07-03 07:15:53 +00:00
|
|
|
|
|
2005-04-09 00:31:40 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* Strip the whitespace Category links produce, see bug 87
|
|
|
|
|
|
* @todo We might want to use trim($tmp, "\n") here.
|
|
|
|
|
|
*/
|
2005-04-13 08:26:08 +00:00
|
|
|
|
$s .= trim($prefix . $trail, "\n") == '' ? '': $prefix . $trail;
|
2005-07-03 07:15:53 +00:00
|
|
|
|
|
2004-11-23 07:41:07 +00:00
|
|
|
|
wfProfileOut( "$fname-category" );
|
2004-05-26 16:29:04 +00:00
|
|
|
|
continue;
|
|
|
|
|
|
}
|
2004-02-26 13:37:26 +00:00
|
|
|
|
}
|
2004-10-08 04:27:07 +00:00
|
|
|
|
|
2004-11-23 07:41:07 +00:00
|
|
|
|
if( ( $nt->getPrefixedText() === $selflink ) &&
|
2004-10-13 04:30:19 +00:00
|
|
|
|
( $nt->getFragment() === '' ) ) {
|
2004-05-26 16:29:04 +00:00
|
|
|
|
# Self-links are handled specially; generally de-link and change to bold.
|
2004-06-08 18:11:28 +00:00
|
|
|
|
$s .= $prefix . $sk->makeSelfLinkObj( $nt, $text, '', $trail );
|
2004-05-26 16:29:04 +00:00
|
|
|
|
continue;
|
2004-04-20 21:08:24 +00:00
|
|
|
|
}
|
2004-03-20 12:10:25 +00:00
|
|
|
|
|
2004-10-05 03:55:41 +00:00
|
|
|
|
# Special and Media are pseudo-namespaces; no pages actually exist in them
|
2004-08-07 03:50:46 +00:00
|
|
|
|
if( $ns == NS_MEDIA ) {
|
2005-12-21 14:02:20 +00:00
|
|
|
|
$link = $sk->makeMediaLinkObj( $nt, $text );
|
|
|
|
|
|
# Cloak with NOPARSE to avoid replacement in replaceExternalLinks
|
2005-12-28 22:58:54 +00:00
|
|
|
|
$s .= $prefix . $this->armorLinks( $link ) . $trail;
|
2005-12-30 09:33:11 +00:00
|
|
|
|
$this->mOutput->addImage( $nt->getDBkey() );
|
2004-06-05 02:22:16 +00:00
|
|
|
|
continue;
|
2004-08-07 03:50:46 +00:00
|
|
|
|
} elseif( $ns == NS_SPECIAL ) {
|
2005-12-29 00:31:18 +00:00
|
|
|
|
$s .= $this->makeKnownLinkHolder( $nt, $text, '', $trail, $prefix );
|
2004-05-26 16:29:04 +00:00
|
|
|
|
continue;
|
2005-12-05 07:08:04 +00:00
|
|
|
|
} elseif( $ns == NS_IMAGE ) {
|
2006-07-10 19:49:22 +00:00
|
|
|
|
$img = new Image( $nt );
|
2005-12-05 07:08:04 +00:00
|
|
|
|
if( $img->exists() ) {
|
|
|
|
|
|
// Force a blue link if the file exists; may be a remote
|
|
|
|
|
|
// upload on the shared repository, and we want to see its
|
|
|
|
|
|
// auto-generated page.
|
2005-12-29 00:31:18 +00:00
|
|
|
|
$s .= $this->makeKnownLinkHolder( $nt, $text, '', $trail, $prefix );
|
2006-08-18 05:00:16 +00:00
|
|
|
|
$this->mOutput->addLink( $nt );
|
2005-12-05 07:08:04 +00:00
|
|
|
|
continue;
|
|
|
|
|
|
}
|
2004-05-26 16:29:04 +00:00
|
|
|
|
}
|
2005-08-20 13:47:12 +00:00
|
|
|
|
$s .= $this->makeLinkHolder( $nt, $text, '', $trail, $prefix );
|
2004-02-28 23:38:08 +00:00
|
|
|
|
}
|
2004-02-26 13:37:26 +00:00
|
|
|
|
wfProfileOut( $fname );
|
|
|
|
|
|
return $s;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2005-04-27 07:48:14 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* Make a link placeholder. The text returned can be later resolved to a real link with
|
2005-07-03 07:15:53 +00:00
|
|
|
|
* replaceLinkHolders(). This is done for two reasons: firstly to avoid further
|
2006-08-06 14:01:47 +00:00
|
|
|
|
* parsing of interwiki links, and secondly to allow all existence checks and
|
2005-04-27 07:48:14 +00:00
|
|
|
|
* article length checks (for stub links) to be bundled into a single query.
|
|
|
|
|
|
*
|
|
|
|
|
|
*/
|
|
|
|
|
|
function makeLinkHolder( &$nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
|
2006-08-06 14:01:47 +00:00
|
|
|
|
wfProfileIn( __METHOD__ );
|
2005-04-27 07:48:14 +00:00
|
|
|
|
if ( ! is_object($nt) ) {
|
|
|
|
|
|
# Fail gracefully
|
|
|
|
|
|
$retVal = "<!-- ERROR -->{$prefix}{$text}{$trail}";
|
|
|
|
|
|
} else {
|
|
|
|
|
|
# Separate the link trail from the rest of the link
|
|
|
|
|
|
list( $inside, $trail ) = Linker::splitTrail( $trail );
|
2005-07-03 07:15:53 +00:00
|
|
|
|
|
2005-04-27 07:48:14 +00:00
|
|
|
|
if ( $nt->isExternal() ) {
|
2005-06-03 05:46:24 +00:00
|
|
|
|
$nr = array_push( $this->mInterwikiLinkHolders['texts'], $prefix.$text.$inside );
|
2005-06-26 13:38:43 +00:00
|
|
|
|
$this->mInterwikiLinkHolders['titles'][] = $nt;
|
2005-04-27 07:48:14 +00:00
|
|
|
|
$retVal = '<!--IWLINK '. ($nr-1) ."-->{$trail}";
|
|
|
|
|
|
} else {
|
|
|
|
|
|
$nr = array_push( $this->mLinkHolders['namespaces'], $nt->getNamespace() );
|
|
|
|
|
|
$this->mLinkHolders['dbkeys'][] = $nt->getDBkey();
|
|
|
|
|
|
$this->mLinkHolders['queries'][] = $query;
|
|
|
|
|
|
$this->mLinkHolders['texts'][] = $prefix.$text.$inside;
|
2005-06-26 13:38:43 +00:00
|
|
|
|
$this->mLinkHolders['titles'][] = $nt;
|
2005-04-27 07:48:14 +00:00
|
|
|
|
|
|
|
|
|
|
$retVal = '<!--LINK '. ($nr-1) ."-->{$trail}";
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2006-08-06 14:01:47 +00:00
|
|
|
|
wfProfileOut( __METHOD__ );
|
2005-04-27 07:48:14 +00:00
|
|
|
|
return $retVal;
|
|
|
|
|
|
}
|
2006-01-07 13:31:29 +00:00
|
|
|
|
|
2005-12-29 00:31:18 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* Render a forced-blue link inline; protect against double expansion of
|
|
|
|
|
|
* URLs if we're in a mode that prepends full URL prefixes to internal links.
|
|
|
|
|
|
* Since this little disaster has to split off the trail text to avoid
|
|
|
|
|
|
* breaking URLs in the following text without breaking trails on the
|
|
|
|
|
|
* wiki links, it's been made into a horrible function.
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param Title $nt
|
|
|
|
|
|
* @param string $text
|
|
|
|
|
|
* @param string $query
|
|
|
|
|
|
* @param string $trail
|
|
|
|
|
|
* @param string $prefix
|
|
|
|
|
|
* @return string HTML-wikitext mix oh yuck
|
|
|
|
|
|
*/
|
|
|
|
|
|
function makeKnownLinkHolder( $nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
|
|
|
|
|
|
list( $inside, $trail ) = Linker::splitTrail( $trail );
|
|
|
|
|
|
$sk =& $this->mOptions->getSkin();
|
|
|
|
|
|
$link = $sk->makeKnownLinkObj( $nt, $text, $query, $inside, $prefix );
|
|
|
|
|
|
return $this->armorLinks( $link ) . $trail;
|
|
|
|
|
|
}
|
2006-01-07 13:31:29 +00:00
|
|
|
|
|
2005-12-28 22:58:54 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* Insert a NOPARSE hacky thing into any inline links in a chunk that's
|
|
|
|
|
|
* going to go through further parsing steps before inline URL expansion.
|
|
|
|
|
|
*
|
|
|
|
|
|
* In particular this is important when using action=render, which causes
|
|
|
|
|
|
* full URLs to be included.
|
|
|
|
|
|
*
|
|
|
|
|
|
* Oh man I hate our multi-layer parser!
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param string more-or-less HTML
|
|
|
|
|
|
* @return string less-or-more HTML with NOPARSE bits
|
|
|
|
|
|
*/
|
|
|
|
|
|
function armorLinks( $text ) {
|
|
|
|
|
|
return preg_replace( "/\b(" . wfUrlProtocols() . ')/',
|
|
|
|
|
|
"{$this->mUniqPrefix}NOPARSE$1", $text );
|
|
|
|
|
|
}
|
2005-04-27 07:48:14 +00:00
|
|
|
|
|
2004-11-28 03:29:50 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* Return true if subpage links should be expanded on this page.
|
|
|
|
|
|
* @return bool
|
|
|
|
|
|
*/
|
|
|
|
|
|
function areSubpagesAllowed() {
|
|
|
|
|
|
# Some namespaces don't allow subpages
|
|
|
|
|
|
global $wgNamespacesWithSubpages;
|
|
|
|
|
|
return !empty($wgNamespacesWithSubpages[$this->mTitle->getNamespace()]);
|
|
|
|
|
|
}
|
2005-07-03 07:15:53 +00:00
|
|
|
|
|
2004-09-25 20:13:14 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* Handle link to subpage if necessary
|
2004-10-15 17:39:10 +00:00
|
|
|
|
* @param string $target the source of the link
|
|
|
|
|
|
* @param string &$text the link text, modified as necessary
|
2004-09-25 20:13:14 +00:00
|
|
|
|
* @return string the full name of the link
|
2006-04-19 15:46:24 +00:00
|
|
|
|
* @private
|
2004-09-25 20:13:14 +00:00
|
|
|
|
*/
|
2004-09-25 20:35:38 +00:00
|
|
|
|
function maybeDoSubpageLink($target, &$text) {
|
2004-09-25 20:13:14 +00:00
|
|
|
|
# Valid link forms:
|
|
|
|
|
|
# Foobar -- normal
|
|
|
|
|
|
# :Foobar -- override special treatment of prefix (images, language links)
|
|
|
|
|
|
# /Foobar -- convert to CurrentPage/Foobar
|
|
|
|
|
|
# /Foobar/ -- convert to CurrentPage/Foobar, strip the initial / from text
|
2004-12-07 01:23:32 +00:00
|
|
|
|
# ../ -- convert to CurrentPage, from CurrentPage/CurrentSubPage
|
|
|
|
|
|
# ../Foobar -- convert to CurrentPage/Foobar, from CurrentPage/CurrentSubPage
|
2004-09-25 20:13:14 +00:00
|
|
|
|
|
2004-09-27 04:44:00 +00:00
|
|
|
|
$fname = 'Parser::maybeDoSubpageLink';
|
|
|
|
|
|
wfProfileIn( $fname );
|
2004-12-07 01:23:32 +00:00
|
|
|
|
$ret = $target; # default return value is no change
|
2005-07-03 07:15:53 +00:00
|
|
|
|
|
|
|
|
|
|
# Some namespaces don't allow subpages,
|
2004-12-07 01:23:32 +00:00
|
|
|
|
# so only perform processing if subpages are allowed
|
2005-07-03 07:15:53 +00:00
|
|
|
|
if( $this->areSubpagesAllowed() ) {
|
2004-12-07 01:23:32 +00:00
|
|
|
|
# Look at the first character
|
|
|
|
|
|
if( $target != '' && $target{0} == '/' ) {
|
|
|
|
|
|
# / at end means we don't want the slash to be shown
|
|
|
|
|
|
if( substr( $target, -1, 1 ) == '/' ) {
|
|
|
|
|
|
$target = substr( $target, 1, -1 );
|
|
|
|
|
|
$noslash = $target;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
$noslash = substr( $target, 1 );
|
|
|
|
|
|
}
|
2005-07-03 07:15:53 +00:00
|
|
|
|
|
2004-09-25 20:13:14 +00:00
|
|
|
|
$ret = $this->mTitle->getPrefixedText(). '/' . trim($noslash);
|
|
|
|
|
|
if( '' === $text ) {
|
|
|
|
|
|
$text = $target;
|
|
|
|
|
|
} # this might be changed for ugliness reasons
|
|
|
|
|
|
} else {
|
2004-12-07 01:23:32 +00:00
|
|
|
|
# check for .. subpage backlinks
|
|
|
|
|
|
$dotdotcount = 0;
|
|
|
|
|
|
$nodotdot = $target;
|
|
|
|
|
|
while( strncmp( $nodotdot, "../", 3 ) == 0 ) {
|
|
|
|
|
|
++$dotdotcount;
|
|
|
|
|
|
$nodotdot = substr( $nodotdot, 3 );
|
|
|
|
|
|
}
|
|
|
|
|
|
if($dotdotcount > 0) {
|
|
|
|
|
|
$exploded = explode( '/', $this->mTitle->GetPrefixedText() );
|
|
|
|
|
|
if( count( $exploded ) > $dotdotcount ) { # not allowed to go below top level page
|
|
|
|
|
|
$ret = implode( '/', array_slice( $exploded, 0, -$dotdotcount ) );
|
|
|
|
|
|
# / at the end means don't show full path
|
|
|
|
|
|
if( substr( $nodotdot, -1, 1 ) == '/' ) {
|
|
|
|
|
|
$nodotdot = substr( $nodotdot, 0, -1 );
|
|
|
|
|
|
if( '' === $text ) {
|
|
|
|
|
|
$text = $nodotdot;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
$nodotdot = trim( $nodotdot );
|
|
|
|
|
|
if( $nodotdot != '' ) {
|
|
|
|
|
|
$ret .= '/' . $nodotdot;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2004-09-25 20:13:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2004-09-27 04:44:00 +00:00
|
|
|
|
wfProfileOut( $fname );
|
2004-09-25 20:13:14 +00:00
|
|
|
|
return $ret;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2004-09-21 05:49:12 +00:00
|
|
|
|
/**#@+
|
|
|
|
|
|
* Used by doBlockLevels()
|
2006-04-19 15:46:24 +00:00
|
|
|
|
* @private
|
2004-09-21 05:49:12 +00:00
|
|
|
|
*/
|
2004-06-12 06:15:09 +00:00
|
|
|
|
/* private */ function closeParagraph() {
|
2004-06-08 18:11:28 +00:00
|
|
|
|
$result = '';
|
2004-04-04 01:45:02 +00:00
|
|
|
|
if ( '' != $this->mLastSection ) {
|
2004-06-08 18:11:28 +00:00
|
|
|
|
$result = '</' . $this->mLastSection . ">\n";
|
2004-02-26 13:37:26 +00:00
|
|
|
|
}
|
2004-04-15 14:25:34 +00:00
|
|
|
|
$this->mInPre = false;
|
2004-06-08 18:11:28 +00:00
|
|
|
|
$this->mLastSection = '';
|
2004-04-09 13:40:50 +00:00
|
|
|
|
return $result;
|
2004-02-26 13:37:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
# getCommon() returns the length of the longest common substring
|
|
|
|
|
|
# of both arguments, starting at the beginning of both.
|
|
|
|
|
|
#
|
2004-06-12 06:15:09 +00:00
|
|
|
|
/* private */ function getCommon( $st1, $st2 ) {
|
2004-02-26 13:37:26 +00:00
|
|
|
|
$fl = strlen( $st1 );
|
|
|
|
|
|
$shorter = strlen( $st2 );
|
|
|
|
|
|
if ( $fl < $shorter ) { $shorter = $fl; }
|
|
|
|
|
|
|
|
|
|
|
|
for ( $i = 0; $i < $shorter; ++$i ) {
|
|
|
|
|
|
if ( $st1{$i} != $st2{$i} ) { break; }
|
|
|
|
|
|
}
|
|
|
|
|
|
return $i;
|
|
|
|
|
|
}
|
|
|
|
|
|
# These next three functions open, continue, and close the list
|
|
|
|
|
|
# element appropriate to the prefix character passed into them.
|
|
|
|
|
|
#
|
2004-08-16 15:23:46 +00:00
|
|
|
|
/* private */ function openList( $char ) {
|
2004-02-26 13:37:26 +00:00
|
|
|
|
$result = $this->closeParagraph();
|
|
|
|
|
|
|
2004-06-08 18:11:28 +00:00
|
|
|
|
if ( '*' == $char ) { $result .= '<ul><li>'; }
|
|
|
|
|
|
else if ( '#' == $char ) { $result .= '<ol><li>'; }
|
|
|
|
|
|
else if ( ':' == $char ) { $result .= '<dl><dd>'; }
|
|
|
|
|
|
else if ( ';' == $char ) {
|
|
|
|
|
|
$result .= '<dl><dt>';
|
2004-02-26 13:37:26 +00:00
|
|
|
|
$this->mDTopen = true;
|
|
|
|
|
|
}
|
2004-06-08 18:11:28 +00:00
|
|
|
|
else { $result = '<!-- ERR 1 -->'; }
|
2004-02-26 13:37:26 +00:00
|
|
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2004-06-12 06:15:09 +00:00
|
|
|
|
/* private */ function nextItem( $char ) {
|
2004-06-08 18:11:28 +00:00
|
|
|
|
if ( '*' == $char || '#' == $char ) { return '</li><li>'; }
|
|
|
|
|
|
else if ( ':' == $char || ';' == $char ) {
|
2004-08-16 15:29:17 +00:00
|
|
|
|
$close = '</dd>';
|
2004-06-08 18:11:28 +00:00
|
|
|
|
if ( $this->mDTopen ) { $close = '</dt>'; }
|
|
|
|
|
|
if ( ';' == $char ) {
|
2004-02-26 13:37:26 +00:00
|
|
|
|
$this->mDTopen = true;
|
2004-06-08 18:11:28 +00:00
|
|
|
|
return $close . '<dt>';
|
2004-02-26 13:37:26 +00:00
|
|
|
|
} else {
|
|
|
|
|
|
$this->mDTopen = false;
|
2004-06-08 18:11:28 +00:00
|
|
|
|
return $close . '<dd>';
|
2004-02-26 13:37:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2004-06-08 18:11:28 +00:00
|
|
|
|
return '<!-- ERR 2 -->';
|
2004-02-26 13:37:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2004-08-16 20:01:21 +00:00
|
|
|
|
/* private */ function closeList( $char ) {
|
2004-06-08 18:11:28 +00:00
|
|
|
|
if ( '*' == $char ) { $text = '</li></ul>'; }
|
|
|
|
|
|
else if ( '#' == $char ) { $text = '</li></ol>'; }
|
|
|
|
|
|
else if ( ':' == $char ) {
|
2004-02-26 13:37:26 +00:00
|
|
|
|
if ( $this->mDTopen ) {
|
|
|
|
|
|
$this->mDTopen = false;
|
2004-06-08 18:11:28 +00:00
|
|
|
|
$text = '</dt></dl>';
|
2004-02-26 13:37:26 +00:00
|
|
|
|
} else {
|
2004-06-08 18:11:28 +00:00
|
|
|
|
$text = '</dd></dl>';
|
2004-02-26 13:37:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2004-06-08 18:11:28 +00:00
|
|
|
|
else { return '<!-- ERR 3 -->'; }
|
2004-02-26 13:37:26 +00:00
|
|
|
|
return $text."\n";
|
|
|
|
|
|
}
|
2004-09-21 05:49:12 +00:00
|
|
|
|
/**#@-*/
|
2004-02-26 13:37:26 +00:00
|
|
|
|
|
2004-09-21 05:49:12 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* Make lists from lines starting with ':', '*', '#', etc.
|
|
|
|
|
|
*
|
2006-04-19 15:46:24 +00:00
|
|
|
|
* @private
|
2004-09-21 05:49:12 +00:00
|
|
|
|
* @return string the lists rendered as HTML
|
|
|
|
|
|
*/
|
|
|
|
|
|
function doBlockLevels( $text, $linestart ) {
|
2004-06-08 18:11:28 +00:00
|
|
|
|
$fname = 'Parser::doBlockLevels';
|
2004-02-26 13:37:26 +00:00
|
|
|
|
wfProfileIn( $fname );
|
2004-07-12 19:49:20 +00:00
|
|
|
|
|
2004-02-26 13:37:26 +00:00
|
|
|
|
# Parsing through the text line by line. The main thing
|
|
|
|
|
|
# happening here is handling of block-level elements p, pre,
|
|
|
|
|
|
# and making lists from lines starting with * # : etc.
|
|
|
|
|
|
#
|
2004-04-29 06:16:21 +00:00
|
|
|
|
$textLines = explode( "\n", $text );
|
2004-04-11 16:46:06 +00:00
|
|
|
|
|
2005-04-21 06:30:48 +00:00
|
|
|
|
$lastPrefix = $output = '';
|
2004-04-11 16:46:06 +00:00
|
|
|
|
$this->mDTopen = $inBlockElem = false;
|
2004-04-29 06:16:21 +00:00
|
|
|
|
$prefixLength = 0;
|
|
|
|
|
|
$paragraphStack = false;
|
|
|
|
|
|
|
|
|
|
|
|
if ( !$linestart ) {
|
|
|
|
|
|
$output .= array_shift( $textLines );
|
|
|
|
|
|
}
|
|
|
|
|
|
foreach ( $textLines as $oLine ) {
|
|
|
|
|
|
$lastPrefixLength = strlen( $lastPrefix );
|
2004-08-16 15:29:17 +00:00
|
|
|
|
$preCloseMatch = preg_match('/<\\/pre/i', $oLine );
|
|
|
|
|
|
$preOpenMatch = preg_match('/<pre/i', $oLine );
|
2004-07-14 18:46:02 +00:00
|
|
|
|
if ( !$this->mInPre ) {
|
2004-04-29 06:16:21 +00:00
|
|
|
|
# Multiple prefixes may abut each other for nested lists.
|
2004-06-08 18:11:28 +00:00
|
|
|
|
$prefixLength = strspn( $oLine, '*#:;' );
|
2004-04-29 06:16:21 +00:00
|
|
|
|
$pref = substr( $oLine, 0, $prefixLength );
|
2004-07-12 19:49:20 +00:00
|
|
|
|
|
2004-04-29 06:16:21 +00:00
|
|
|
|
# eh?
|
2004-06-08 18:11:28 +00:00
|
|
|
|
$pref2 = str_replace( ';', ':', $pref );
|
2004-04-29 06:16:21 +00:00
|
|
|
|
$t = substr( $oLine, $prefixLength );
|
2004-07-14 18:46:02 +00:00
|
|
|
|
$this->mInPre = !empty($preOpenMatch);
|
2004-04-16 11:21:51 +00:00
|
|
|
|
} else {
|
2004-04-29 06:16:21 +00:00
|
|
|
|
# Don't interpret any other prefixes in preformatted text
|
|
|
|
|
|
$prefixLength = 0;
|
2004-04-16 11:21:51 +00:00
|
|
|
|
$pref = $pref2 = '';
|
2004-04-29 06:16:21 +00:00
|
|
|
|
$t = $oLine;
|
2004-04-16 11:21:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2004-04-29 06:16:21 +00:00
|
|
|
|
# List generation
|
|
|
|
|
|
if( $prefixLength && 0 == strcmp( $lastPrefix, $pref2 ) ) {
|
|
|
|
|
|
# Same as the last item, so no need to deal with nesting or opening stuff
|
|
|
|
|
|
$output .= $this->nextItem( substr( $pref, -1 ) );
|
|
|
|
|
|
$paragraphStack = false;
|
2004-04-16 11:21:51 +00:00
|
|
|
|
|
2004-08-16 15:29:17 +00:00
|
|
|
|
if ( substr( $pref, -1 ) == ';') {
|
2004-04-29 06:16:21 +00:00
|
|
|
|
# The one nasty exception: definition lists work like this:
|
|
|
|
|
|
# ; title : definition text
|
|
|
|
|
|
# So we check for : in the remainder text to split up the
|
|
|
|
|
|
# title and definition, without b0rking links.
|
2005-04-21 06:30:48 +00:00
|
|
|
|
$term = $t2 = '';
|
2004-09-27 21:01:39 +00:00
|
|
|
|
if ($this->findColonNoLinks($t, $term, $t2) !== false) {
|
|
|
|
|
|
$t = $t2;
|
2004-06-08 18:11:28 +00:00
|
|
|
|
$output .= $term . $this->nextItem( ':' );
|
2004-04-16 11:21:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2004-04-29 06:16:21 +00:00
|
|
|
|
} elseif( $prefixLength || $lastPrefixLength ) {
|
|
|
|
|
|
# Either open or close a level...
|
|
|
|
|
|
$commonPrefixLength = $this->getCommon( $pref, $lastPrefix );
|
|
|
|
|
|
$paragraphStack = false;
|
|
|
|
|
|
|
|
|
|
|
|
while( $commonPrefixLength < $lastPrefixLength ) {
|
|
|
|
|
|
$output .= $this->closeList( $lastPrefix{$lastPrefixLength-1} );
|
|
|
|
|
|
--$lastPrefixLength;
|
2004-04-16 11:21:51 +00:00
|
|
|
|
}
|
2004-04-29 06:16:21 +00:00
|
|
|
|
if ( $prefixLength <= $commonPrefixLength && $commonPrefixLength > 0 ) {
|
|
|
|
|
|
$output .= $this->nextItem( $pref{$commonPrefixLength-1} );
|
2004-04-16 11:21:51 +00:00
|
|
|
|
}
|
2004-04-29 06:16:21 +00:00
|
|
|
|
while ( $prefixLength > $commonPrefixLength ) {
|
|
|
|
|
|
$char = substr( $pref, $commonPrefixLength, 1 );
|
|
|
|
|
|
$output .= $this->openList( $char );
|
2004-04-16 11:21:51 +00:00
|
|
|
|
|
2004-06-08 18:11:28 +00:00
|
|
|
|
if ( ';' == $char ) {
|
2004-04-29 06:16:21 +00:00
|
|
|
|
# FIXME: This is dupe of code above
|
2004-09-27 21:01:39 +00:00
|
|
|
|
if ($this->findColonNoLinks($t, $term, $t2) !== false) {
|
|
|
|
|
|
$t = $t2;
|
2004-08-22 17:24:50 +00:00
|
|
|
|
$output .= $term . $this->nextItem( ':' );
|
2004-02-26 13:37:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2004-04-29 06:16:21 +00:00
|
|
|
|
++$commonPrefixLength;
|
2004-02-26 13:37:26 +00:00
|
|
|
|
}
|
2004-04-29 06:16:21 +00:00
|
|
|
|
$lastPrefix = $pref2;
|
2004-02-26 13:37:26 +00:00
|
|
|
|
}
|
2004-04-29 06:16:21 +00:00
|
|
|
|
if( 0 == $prefixLength ) {
|
2004-11-26 10:49:46 +00:00
|
|
|
|
wfProfileIn( "$fname-paragraph" );
|
2004-04-29 06:16:21 +00:00
|
|
|
|
# No prefix (not in list)--go to paragraph mode
|
2004-04-09 13:40:50 +00:00
|
|
|
|
// XXX: use a stack for nestable elements like span, table and div
|
2006-06-09 21:59:26 +00:00
|
|
|
|
$openmatch = preg_match('/(<table|<blockquote|<h1|<h2|<h3|<h4|<h5|<h6|<pre|<tr|<p|<ul|<ol|<li|<\\/center|<\\/tr|<\\/td|<\\/th)/iS', $t );
|
2004-04-12 23:59:37 +00:00
|
|
|
|
$closematch = preg_match(
|
2004-06-08 18:11:28 +00:00
|
|
|
|
'/(<\\/table|<\\/blockquote|<\\/h1|<\\/h2|<\\/h3|<\\/h4|<\\/h5|<\\/h6|'.
|
2006-06-09 21:59:26 +00:00
|
|
|
|
'<td|<th|<div|<\\/div|<hr|<\\/pre|<\\/p|'.$this->mUniqPrefix.'-pre|<\\/li|<\\/ul|<\\/ol|<center)/iS', $t );
|
2004-04-09 13:40:50 +00:00
|
|
|
|
if ( $openmatch or $closematch ) {
|
2004-04-29 06:16:21 +00:00
|
|
|
|
$paragraphStack = false;
|
2006-04-28 18:56:37 +00:00
|
|
|
|
# TODO bug 5718: paragraph closed
|
2004-04-29 06:16:21 +00:00
|
|
|
|
$output .= $this->closeParagraph();
|
2005-07-22 22:14:05 +00:00
|
|
|
|
if ( $preOpenMatch and !$preCloseMatch ) {
|
|
|
|
|
|
$this->mInPre = true;
|
|
|
|
|
|
}
|
2004-08-16 15:23:46 +00:00
|
|
|
|
if ( $closematch ) {
|
2004-04-09 13:40:50 +00:00
|
|
|
|
$inBlockElem = false;
|
2004-04-09 14:55:12 +00:00
|
|
|
|
} else {
|
|
|
|
|
|
$inBlockElem = true;
|
2004-04-09 13:40:50 +00:00
|
|
|
|
}
|
2004-06-02 12:29:15 +00:00
|
|
|
|
} else if ( !$inBlockElem && !$this->mInPre ) {
|
2004-08-22 17:24:50 +00:00
|
|
|
|
if ( ' ' == $t{0} and ( $this->mLastSection == 'pre' or trim($t) != '' ) ) {
|
2004-04-10 15:11:14 +00:00
|
|
|
|
// pre
|
2004-04-10 03:09:52 +00:00
|
|
|
|
if ($this->mLastSection != 'pre') {
|
2004-04-29 06:16:21 +00:00
|
|
|
|
$paragraphStack = false;
|
|
|
|
|
|
$output .= $this->closeParagraph().'<pre>';
|
2004-04-10 15:11:14 +00:00
|
|
|
|
$this->mLastSection = 'pre';
|
2004-04-10 03:09:52 +00:00
|
|
|
|
}
|
2004-09-12 13:07:52 +00:00
|
|
|
|
$t = substr( $t, 1 );
|
2004-04-12 23:59:37 +00:00
|
|
|
|
} else {
|
2004-04-10 15:11:14 +00:00
|
|
|
|
// paragraph
|
|
|
|
|
|
if ( '' == trim($t) ) {
|
2004-04-29 06:16:21 +00:00
|
|
|
|
if ( $paragraphStack ) {
|
2004-05-31 00:58:57 +00:00
|
|
|
|
$output .= $paragraphStack.'<br />';
|
2004-04-29 06:16:21 +00:00
|
|
|
|
$paragraphStack = false;
|
2004-04-10 15:11:14 +00:00
|
|
|
|
$this->mLastSection = 'p';
|
|
|
|
|
|
} else {
|
|
|
|
|
|
if ($this->mLastSection != 'p' ) {
|
2004-04-29 06:16:21 +00:00
|
|
|
|
$output .= $this->closeParagraph();
|
2004-04-10 15:11:14 +00:00
|
|
|
|
$this->mLastSection = '';
|
2004-06-08 18:11:28 +00:00
|
|
|
|
$paragraphStack = '<p>';
|
2004-04-10 15:11:14 +00:00
|
|
|
|
} else {
|
2004-04-29 06:16:21 +00:00
|
|
|
|
$paragraphStack = '</p><p>';
|
2004-04-10 15:11:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
2004-04-29 06:16:21 +00:00
|
|
|
|
if ( $paragraphStack ) {
|
|
|
|
|
|
$output .= $paragraphStack;
|
|
|
|
|
|
$paragraphStack = false;
|
2004-04-10 15:11:14 +00:00
|
|
|
|
$this->mLastSection = 'p';
|
|
|
|
|
|
} else if ($this->mLastSection != 'p') {
|
2004-04-29 06:16:21 +00:00
|
|
|
|
$output .= $this->closeParagraph().'<p>';
|
2004-04-10 15:11:14 +00:00
|
|
|
|
$this->mLastSection = 'p';
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2004-04-09 13:40:50 +00:00
|
|
|
|
}
|
2004-04-12 23:59:37 +00:00
|
|
|
|
}
|
2004-11-26 10:49:46 +00:00
|
|
|
|
wfProfileOut( "$fname-paragraph" );
|
2004-02-26 13:37:26 +00:00
|
|
|
|
}
|
2005-07-13 15:17:28 +00:00
|
|
|
|
// somewhere above we forget to get out of pre block (bug 785)
|
|
|
|
|
|
if($preCloseMatch && $this->mInPre) {
|
|
|
|
|
|
$this->mInPre = false;
|
|
|
|
|
|
}
|
2004-04-29 06:16:21 +00:00
|
|
|
|
if ($paragraphStack === false) {
|
|
|
|
|
|
$output .= $t."\n";
|
2004-04-10 15:11:14 +00:00
|
|
|
|
}
|
2004-02-26 13:37:26 +00:00
|
|
|
|
}
|
2004-04-29 06:16:21 +00:00
|
|
|
|
while ( $prefixLength ) {
|
|
|
|
|
|
$output .= $this->closeList( $pref2{$prefixLength-1} );
|
|
|
|
|
|
--$prefixLength;
|
2004-02-26 13:37:26 +00:00
|
|
|
|
}
|
2004-06-08 18:11:28 +00:00
|
|
|
|
if ( '' != $this->mLastSection ) {
|
|
|
|
|
|
$output .= '</' . $this->mLastSection . '>';
|
|
|
|
|
|
$this->mLastSection = '';
|
2004-02-26 13:37:26 +00:00
|
|
|
|
}
|
2004-04-12 23:59:37 +00:00
|
|
|
|
|
2004-02-26 13:37:26 +00:00
|
|
|
|
wfProfileOut( $fname );
|
2004-04-29 06:16:21 +00:00
|
|
|
|
return $output;
|
2004-02-26 13:37:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2004-09-27 21:01:39 +00:00
|
|
|
|
/**
|
2006-06-02 20:54:34 +00:00
|
|
|
|
* Split up a string on ':', ignoring any occurences inside tags
|
|
|
|
|
|
* to prevent illegal overlapping.
|
2004-10-15 17:39:10 +00:00
|
|
|
|
* @param string $str the string to split
|
|
|
|
|
|
* @param string &$before set to everything before the ':'
|
|
|
|
|
|
* @param string &$after set to everything after the ':'
|
2004-09-27 21:01:39 +00:00
|
|
|
|
* return string the position of the ':', or false if none found
|
|
|
|
|
|
*/
|
|
|
|
|
|
function findColonNoLinks($str, &$before, &$after) {
|
|
|
|
|
|
$fname = 'Parser::findColonNoLinks';
|
|
|
|
|
|
wfProfileIn( $fname );
|
2006-07-11 17:40:11 +00:00
|
|
|
|
|
2006-06-02 20:54:34 +00:00
|
|
|
|
$pos = strpos( $str, ':' );
|
|
|
|
|
|
if( $pos === false ) {
|
|
|
|
|
|
// Nothing to find!
|
|
|
|
|
|
wfProfileOut( $fname );
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
2006-07-11 17:40:11 +00:00
|
|
|
|
|
2006-06-02 23:56:19 +00:00
|
|
|
|
$lt = strpos( $str, '<' );
|
|
|
|
|
|
if( $lt === false || $lt > $pos ) {
|
2006-06-02 20:54:34 +00:00
|
|
|
|
// Easy; no tag nesting to worry about
|
|
|
|
|
|
$before = substr( $str, 0, $pos );
|
|
|
|
|
|
$after = substr( $str, $pos+1 );
|
|
|
|
|
|
wfProfileOut( $fname );
|
|
|
|
|
|
return $pos;
|
|
|
|
|
|
}
|
2006-07-11 17:40:11 +00:00
|
|
|
|
|
2006-06-02 20:54:34 +00:00
|
|
|
|
// Ugly state machine to walk through avoiding tags.
|
|
|
|
|
|
$state = MW_COLON_STATE_TEXT;
|
|
|
|
|
|
$stack = 0;
|
|
|
|
|
|
$len = strlen( $str );
|
|
|
|
|
|
for( $i = 0; $i < $len; $i++ ) {
|
|
|
|
|
|
$c = $str{$i};
|
2006-07-11 17:40:11 +00:00
|
|
|
|
|
2006-06-02 20:54:34 +00:00
|
|
|
|
switch( $state ) {
|
|
|
|
|
|
// (Using the number is a performance hack for common cases)
|
|
|
|
|
|
case 0: // MW_COLON_STATE_TEXT:
|
|
|
|
|
|
switch( $c ) {
|
|
|
|
|
|
case "<":
|
|
|
|
|
|
// Could be either a <start> tag or an </end> tag
|
|
|
|
|
|
$state = MW_COLON_STATE_TAGSTART;
|
|
|
|
|
|
break;
|
|
|
|
|
|
case ":":
|
|
|
|
|
|
if( $stack == 0 ) {
|
|
|
|
|
|
// We found it!
|
|
|
|
|
|
$before = substr( $str, 0, $i );
|
|
|
|
|
|
$after = substr( $str, $i + 1 );
|
|
|
|
|
|
wfProfileOut( $fname );
|
|
|
|
|
|
return $i;
|
|
|
|
|
|
}
|
|
|
|
|
|
// Embedded in a tag; don't break it.
|
|
|
|
|
|
break;
|
|
|
|
|
|
default:
|
2006-06-02 23:56:19 +00:00
|
|
|
|
// Skip ahead looking for something interesting
|
|
|
|
|
|
$colon = strpos( $str, ':', $i );
|
|
|
|
|
|
if( $colon === false ) {
|
|
|
|
|
|
// Nothing else interesting
|
|
|
|
|
|
wfProfileOut( $fname );
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
$lt = strpos( $str, '<', $i );
|
|
|
|
|
|
if( $stack === 0 ) {
|
|
|
|
|
|
if( $lt === false || $colon < $lt ) {
|
|
|
|
|
|
// We found it!
|
|
|
|
|
|
$before = substr( $str, 0, $colon );
|
|
|
|
|
|
$after = substr( $str, $colon + 1 );
|
|
|
|
|
|
wfProfileOut( $fname );
|
|
|
|
|
|
return $i;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if( $lt === false ) {
|
|
|
|
|
|
// Nothing else interesting to find; abort!
|
|
|
|
|
|
// We're nested, but there's no close tags left. Abort!
|
|
|
|
|
|
break 2;
|
|
|
|
|
|
}
|
|
|
|
|
|
// Skip ahead to next tag start
|
|
|
|
|
|
$i = $lt;
|
|
|
|
|
|
$state = MW_COLON_STATE_TAGSTART;
|
2006-06-02 20:54:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
|
|
|
case 1: // MW_COLON_STATE_TAG:
|
|
|
|
|
|
// In a <tag>
|
|
|
|
|
|
switch( $c ) {
|
|
|
|
|
|
case ">":
|
|
|
|
|
|
$stack++;
|
|
|
|
|
|
$state = MW_COLON_STATE_TEXT;
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "/":
|
|
|
|
|
|
// Slash may be followed by >?
|
|
|
|
|
|
$state = MW_COLON_STATE_TAGSLASH;
|
|
|
|
|
|
break;
|
|
|
|
|
|
default:
|
|
|
|
|
|
// ignore
|
|
|
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
|
|
|
case 2: // MW_COLON_STATE_TAGSTART:
|
|
|
|
|
|
switch( $c ) {
|
|
|
|
|
|
case "/":
|
|
|
|
|
|
$state = MW_COLON_STATE_CLOSETAG;
|
2004-09-27 21:01:39 +00:00
|
|
|
|
break;
|
2006-06-02 20:54:34 +00:00
|
|
|
|
case "!":
|
|
|
|
|
|
$state = MW_COLON_STATE_COMMENT;
|
|
|
|
|
|
break;
|
|
|
|
|
|
case ">":
|
|
|
|
|
|
// Illegal early close? This shouldn't happen D:
|
|
|
|
|
|
$state = MW_COLON_STATE_TEXT;
|
|
|
|
|
|
break;
|
|
|
|
|
|
default:
|
|
|
|
|
|
$state = MW_COLON_STATE_TAG;
|
|
|
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
|
|
|
case 3: // MW_COLON_STATE_CLOSETAG:
|
|
|
|
|
|
// In a </tag>
|
|
|
|
|
|
if( $c == ">" ) {
|
|
|
|
|
|
$stack--;
|
|
|
|
|
|
if( $stack < 0 ) {
|
|
|
|
|
|
wfDebug( "Invalid input in $fname; too many close tags\n" );
|
|
|
|
|
|
wfProfileOut( $fname );
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
$state = MW_COLON_STATE_TEXT;
|
|
|
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
|
|
|
case MW_COLON_STATE_TAGSLASH:
|
|
|
|
|
|
if( $c == ">" ) {
|
|
|
|
|
|
// Yes, a self-closed tag <blah/>
|
|
|
|
|
|
$state = MW_COLON_STATE_TEXT;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
// Probably we're jumping the gun, and this is an attribute
|
|
|
|
|
|
$state = MW_COLON_STATE_TAG;
|
|
|
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
|
|
|
case 5: // MW_COLON_STATE_COMMENT:
|
|
|
|
|
|
if( $c == "-" ) {
|
|
|
|
|
|
$state = MW_COLON_STATE_COMMENTDASH;
|
|
|
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
|
|
|
case MW_COLON_STATE_COMMENTDASH:
|
|
|
|
|
|
if( $c == "-" ) {
|
|
|
|
|
|
$state = MW_COLON_STATE_COMMENTDASHDASH;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
$state = MW_COLON_STATE_COMMENT;
|
|
|
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
|
|
|
case MW_COLON_STATE_COMMENTDASHDASH:
|
|
|
|
|
|
if( $c == ">" ) {
|
|
|
|
|
|
$state = MW_COLON_STATE_TEXT;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
$state = MW_COLON_STATE_COMMENT;
|
2004-09-27 21:01:39 +00:00
|
|
|
|
}
|
2006-06-02 20:54:34 +00:00
|
|
|
|
break;
|
|
|
|
|
|
default:
|
2006-06-07 06:40:24 +00:00
|
|
|
|
throw new MWException( "State machine error in $fname" );
|
2004-09-27 21:01:39 +00:00
|
|
|
|
}
|
2006-06-02 20:54:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
if( $stack > 0 ) {
|
|
|
|
|
|
wfDebug( "Invalid input in $fname; not enough close tags (stack $stack, state $state)\n" );
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
2004-09-27 21:01:39 +00:00
|
|
|
|
wfProfileOut( $fname );
|
2006-06-02 20:54:34 +00:00
|
|
|
|
return false;
|
2004-09-27 21:01:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2004-09-21 05:49:12 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* Return value of a magic variable (like PAGENAME)
|
|
|
|
|
|
*
|
2006-04-19 15:46:24 +00:00
|
|
|
|
* @private
|
2004-09-21 05:49:12 +00:00
|
|
|
|
*/
|
2004-03-20 15:03:26 +00:00
|
|
|
|
function getVariableValue( $index ) {
|
2005-11-27 06:04:41 +00:00
|
|
|
|
global $wgContLang, $wgSitename, $wgServer, $wgServerName, $wgScriptPath;
|
2005-07-03 07:15:53 +00:00
|
|
|
|
|
2004-11-21 14:07:24 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* Some of these require message or data lookups and can be
|
|
|
|
|
|
* expensive to check many times.
|
|
|
|
|
|
*/
|
|
|
|
|
|
static $varCache = array();
|
2005-11-26 23:04:05 +00:00
|
|
|
|
if ( wfRunHooks( 'ParserGetVariableValueVarCache', array( &$this, &$varCache ) ) )
|
|
|
|
|
|
if ( isset( $varCache[$index] ) )
|
|
|
|
|
|
return $varCache[$index];
|
|
|
|
|
|
|
|
|
|
|
|
$ts = time();
|
|
|
|
|
|
wfRunHooks( 'ParserGetVariableValueTs', array( &$this, &$ts ) );
|
2005-07-03 07:15:53 +00:00
|
|
|
|
|
2004-03-20 15:03:26 +00:00
|
|
|
|
switch ( $index ) {
|
2006-07-14 15:39:23 +00:00
|
|
|
|
case 'currentmonth':
|
2006-06-20 21:03:47 +00:00
|
|
|
|
return $varCache[$index] = $wgContLang->formatNum( date( 'm', $ts ) );
|
2006-07-14 15:39:23 +00:00
|
|
|
|
case 'currentmonthname':
|
2006-06-20 21:03:47 +00:00
|
|
|
|
return $varCache[$index] = $wgContLang->getMonthName( date( 'n', $ts ) );
|
2006-07-14 15:39:23 +00:00
|
|
|
|
case 'currentmonthnamegen':
|
2006-06-20 21:03:47 +00:00
|
|
|
|
return $varCache[$index] = $wgContLang->getMonthNameGen( date( 'n', $ts ) );
|
2006-07-14 15:39:23 +00:00
|
|
|
|
case 'currentmonthabbrev':
|
2006-06-20 21:03:47 +00:00
|
|
|
|
return $varCache[$index] = $wgContLang->getMonthAbbreviation( date( 'n', $ts ) );
|
2006-07-14 15:39:23 +00:00
|
|
|
|
case 'currentday':
|
2006-06-20 21:03:47 +00:00
|
|
|
|
return $varCache[$index] = $wgContLang->formatNum( date( 'j', $ts ) );
|
2006-07-14 15:39:23 +00:00
|
|
|
|
case 'currentday2':
|
2006-06-20 21:03:47 +00:00
|
|
|
|
return $varCache[$index] = $wgContLang->formatNum( date( 'd', $ts ) );
|
2006-07-14 15:39:23 +00:00
|
|
|
|
case 'pagename':
|
2004-04-24 20:19:05 +00:00
|
|
|
|
return $this->mTitle->getText();
|
2006-07-14 15:39:23 +00:00
|
|
|
|
case 'pagenamee':
|
2004-08-12 13:32:04 +00:00
|
|
|
|
return $this->mTitle->getPartialURL();
|
2006-07-14 15:39:23 +00:00
|
|
|
|
case 'fullpagename':
|
2005-11-21 17:50:10 +00:00
|
|
|
|
return $this->mTitle->getPrefixedText();
|
2006-07-14 15:39:23 +00:00
|
|
|
|
case 'fullpagenamee':
|
2006-01-06 21:03:50 +00:00
|
|
|
|
return $this->mTitle->getPrefixedURL();
|
2006-07-14 15:39:23 +00:00
|
|
|
|
case 'subpagename':
|
2006-03-04 23:29:46 +00:00
|
|
|
|
return $this->mTitle->getSubpageText();
|
2006-07-14 15:39:23 +00:00
|
|
|
|
case 'subpagenamee':
|
2006-04-02 16:19:29 +00:00
|
|
|
|
return $this->mTitle->getSubpageUrlForm();
|
2006-07-14 15:39:23 +00:00
|
|
|
|
case 'basepagename':
|
2006-05-14 03:51:36 +00:00
|
|
|
|
return $this->mTitle->getBaseText();
|
2006-07-14 15:39:23 +00:00
|
|
|
|
case 'basepagenamee':
|
2006-05-14 03:51:36 +00:00
|
|
|
|
return wfUrlEncode( str_replace( ' ', '_', $this->mTitle->getBaseText() ) );
|
2006-07-14 15:39:23 +00:00
|
|
|
|
case 'talkpagename':
|
2006-04-12 15:38:17 +00:00
|
|
|
|
if( $this->mTitle->canTalk() ) {
|
|
|
|
|
|
$talkPage = $this->mTitle->getTalkPage();
|
|
|
|
|
|
return $talkPage->getPrefixedText();
|
|
|
|
|
|
} else {
|
|
|
|
|
|
return '';
|
|
|
|
|
|
}
|
2006-07-14 15:39:23 +00:00
|
|
|
|
case 'talkpagenamee':
|
2006-04-12 15:38:17 +00:00
|
|
|
|
if( $this->mTitle->canTalk() ) {
|
|
|
|
|
|
$talkPage = $this->mTitle->getTalkPage();
|
|
|
|
|
|
return $talkPage->getPrefixedUrl();
|
|
|
|
|
|
} else {
|
|
|
|
|
|
return '';
|
|
|
|
|
|
}
|
2006-07-14 15:39:23 +00:00
|
|
|
|
case 'subjectpagename':
|
2006-04-12 15:38:17 +00:00
|
|
|
|
$subjPage = $this->mTitle->getSubjectPage();
|
|
|
|
|
|
return $subjPage->getPrefixedText();
|
2006-07-14 15:39:23 +00:00
|
|
|
|
case 'subjectpagenamee':
|
2006-04-12 15:38:17 +00:00
|
|
|
|
$subjPage = $this->mTitle->getSubjectPage();
|
|
|
|
|
|
return $subjPage->getPrefixedUrl();
|
2006-07-14 15:39:23 +00:00
|
|
|
|
case 'revisionid':
|
2005-11-27 06:04:41 +00:00
|
|
|
|
return $this->mRevisionId;
|
2006-07-14 15:39:23 +00:00
|
|
|
|
case 'namespace':
|
2006-05-24 19:55:48 +00:00
|
|
|
|
return str_replace('_',' ',$wgContLang->getNsText( $this->mTitle->getNamespace() ) );
|
2006-07-14 15:39:23 +00:00
|
|
|
|
case 'namespacee':
|
2005-11-21 17:50:10 +00:00
|
|
|
|
return wfUrlencode( $wgContLang->getNsText( $this->mTitle->getNamespace() ) );
|
2006-07-14 15:39:23 +00:00
|
|
|
|
case 'talkspace':
|
2006-05-24 19:55:48 +00:00
|
|
|
|
return $this->mTitle->canTalk() ? str_replace('_',' ',$this->mTitle->getTalkNsText()) : '';
|
2006-07-14 15:39:23 +00:00
|
|
|
|
case 'talkspacee':
|
2006-04-12 15:38:17 +00:00
|
|
|
|
return $this->mTitle->canTalk() ? wfUrlencode( $this->mTitle->getTalkNsText() ) : '';
|
2006-07-14 15:39:23 +00:00
|
|
|
|
case 'subjectspace':
|
2006-04-12 15:38:17 +00:00
|
|
|
|
return $this->mTitle->getSubjectNsText();
|
2006-07-14 15:39:23 +00:00
|
|
|
|
case 'subjectspacee':
|
2006-04-12 15:38:17 +00:00
|
|
|
|
return( wfUrlencode( $this->mTitle->getSubjectNsText() ) );
|
2006-07-14 15:39:23 +00:00
|
|
|
|
case 'currentdayname':
|
2006-06-20 21:03:47 +00:00
|
|
|
|
return $varCache[$index] = $wgContLang->getWeekdayName( date( 'w', $ts ) + 1 );
|
2006-07-14 15:39:23 +00:00
|
|
|
|
case 'currentyear':
|
2006-06-20 21:03:47 +00:00
|
|
|
|
return $varCache[$index] = $wgContLang->formatNum( date( 'Y', $ts ), true );
|
2006-07-14 15:39:23 +00:00
|
|
|
|
case 'currenttime':
|
2006-06-20 21:03:47 +00:00
|
|
|
|
return $varCache[$index] = $wgContLang->time( wfTimestamp( TS_MW, $ts ), false, false );
|
2006-08-14 22:43:50 +00:00
|
|
|
|
case 'currenthour':
|
|
|
|
|
|
return $varCache[$index] = $wgContLang->formatNum( date( 'H', $ts ), true );
|
2006-07-14 15:39:23 +00:00
|
|
|
|
case 'currentweek':
|
2006-01-13 16:10:12 +00:00
|
|
|
|
// @bug 4594 PHP5 has it zero padded, PHP4 does not, cast to
|
|
|
|
|
|
// int to remove the padding
|
2006-06-20 21:03:47 +00:00
|
|
|
|
return $varCache[$index] = $wgContLang->formatNum( (int)date( 'W', $ts ) );
|
2006-07-14 15:39:23 +00:00
|
|
|
|
case 'currentdow':
|
2006-06-20 21:03:47 +00:00
|
|
|
|
return $varCache[$index] = $wgContLang->formatNum( date( 'w', $ts ) );
|
2006-07-14 15:39:23 +00:00
|
|
|
|
case 'numberofarticles':
|
2005-04-09 01:35:42 +00:00
|
|
|
|
return $varCache[$index] = $wgContLang->formatNum( wfNumberOfArticles() );
|
2006-07-14 15:39:23 +00:00
|
|
|
|
case 'numberoffiles':
|
2005-06-26 03:23:24 +00:00
|
|
|
|
return $varCache[$index] = $wgContLang->formatNum( wfNumberOfFiles() );
|
2006-07-14 15:39:23 +00:00
|
|
|
|
case 'numberofusers':
|
2006-04-29 01:58:39 +00:00
|
|
|
|
return $varCache[$index] = $wgContLang->formatNum( wfNumberOfUsers() );
|
2006-07-14 15:39:23 +00:00
|
|
|
|
case 'numberofpages':
|
2006-05-13 17:30:42 +00:00
|
|
|
|
return $varCache[$index] = $wgContLang->formatNum( wfNumberOfPages() );
|
2006-07-14 15:39:23 +00:00
|
|
|
|
case 'numberofadmins':
|
2006-06-16 13:58:42 +00:00
|
|
|
|
return $varCache[$index] = $wgContLang->formatNum( wfNumberOfAdmins() );
|
2006-07-14 15:39:23 +00:00
|
|
|
|
case 'currenttimestamp':
|
2006-06-20 21:03:47 +00:00
|
|
|
|
return $varCache[$index] = wfTimestampNow();
|
2006-07-14 15:39:23 +00:00
|
|
|
|
case 'currentversion':
|
2006-05-13 17:30:42 +00:00
|
|
|
|
global $wgVersion;
|
|
|
|
|
|
return $wgVersion;
|
2006-07-14 15:39:23 +00:00
|
|
|
|
case 'sitename':
|
2004-04-05 10:38:40 +00:00
|
|
|
|
return $wgSitename;
|
2006-07-14 15:39:23 +00:00
|
|
|
|
case 'server':
|
2004-04-05 10:38:40 +00:00
|
|
|
|
return $wgServer;
|
2006-07-14 15:39:23 +00:00
|
|
|
|
case 'servername':
|
2005-06-24 02:54:52 +00:00
|
|
|
|
return $wgServerName;
|
2006-07-14 15:39:23 +00:00
|
|
|
|
case 'scriptpath':
|
2005-06-19 16:09:00 +00:00
|
|
|
|
return $wgScriptPath;
|
2006-07-14 15:39:23 +00:00
|
|
|
|
case 'directionmark':
|
2006-05-28 21:30:43 +00:00
|
|
|
|
return $wgContLang->getDirMark();
|
2006-07-14 15:39:23 +00:00
|
|
|
|
case 'contentlanguage':
|
2006-06-08 13:30:35 +00:00
|
|
|
|
global $wgContLanguageCode;
|
|
|
|
|
|
return $wgContLanguageCode;
|
2004-03-20 15:03:26 +00:00
|
|
|
|
default:
|
2005-11-25 06:53:20 +00:00
|
|
|
|
$ret = null;
|
|
|
|
|
|
if ( wfRunHooks( 'ParserGetVariableValueSwitch', array( &$this, &$varCache, &$index, &$ret ) ) )
|
|
|
|
|
|
return $ret;
|
|
|
|
|
|
else
|
|
|
|
|
|
return null;
|
2004-03-20 15:03:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2004-09-21 05:49:12 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* initialise the magic variables (like CURRENTMONTHNAME)
|
|
|
|
|
|
*
|
2006-04-19 15:46:24 +00:00
|
|
|
|
* @private
|
2004-09-21 05:49:12 +00:00
|
|
|
|
*/
|
2004-06-12 06:15:09 +00:00
|
|
|
|
function initialiseVariables() {
|
2004-09-27 04:44:00 +00:00
|
|
|
|
$fname = 'Parser::initialiseVariables';
|
2004-09-26 17:59:08 +00:00
|
|
|
|
wfProfileIn( $fname );
|
2006-07-14 16:36:35 +00:00
|
|
|
|
$variableIDs = MagicWord::getVariableIDs();
|
2006-07-03 11:07:00 +00:00
|
|
|
|
|
2004-03-20 15:03:26 +00:00
|
|
|
|
$this->mVariables = array();
|
2006-07-14 16:36:35 +00:00
|
|
|
|
foreach ( $variableIDs as $id ) {
|
2004-03-20 15:03:26 +00:00
|
|
|
|
$mw =& MagicWord::get( $id );
|
2005-01-18 11:52:06 +00:00
|
|
|
|
$mw->addToArray( $this->mVariables, $id );
|
2004-03-20 15:03:26 +00:00
|
|
|
|
}
|
2004-09-26 17:59:08 +00:00
|
|
|
|
wfProfileOut( $fname );
|
2004-03-20 15:03:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2005-10-19 06:24:30 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* parse any parentheses in format ((title|part|part))
|
|
|
|
|
|
* and call callbacks to get a replacement text for any found piece
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param string $text The text to parse
|
|
|
|
|
|
* @param array $callbacks rules in form:
|
|
|
|
|
|
* '{' => array( # opening parentheses
|
|
|
|
|
|
* 'end' => '}', # closing parentheses
|
|
|
|
|
|
* 'cb' => array(2 => callback, # replacement callback to call if {{..}} is found
|
2006-08-06 14:01:47 +00:00
|
|
|
|
* 3 => callback # replacement callback to call if {{{..}}} is found
|
2005-10-19 06:24:30 +00:00
|
|
|
|
* )
|
|
|
|
|
|
* )
|
2006-08-06 14:01:47 +00:00
|
|
|
|
* 'min' => 2, # Minimum parenthesis count in cb
|
|
|
|
|
|
* 'max' => 3, # Maximum parenthesis count in cb
|
2006-04-19 15:46:24 +00:00
|
|
|
|
* @private
|
2005-10-19 06:24:30 +00:00
|
|
|
|
*/
|
|
|
|
|
|
function replace_callback ($text, $callbacks) {
|
2006-08-06 14:01:47 +00:00
|
|
|
|
wfProfileIn( __METHOD__ );
|
2005-10-19 06:24:30 +00:00
|
|
|
|
$openingBraceStack = array(); # this array will hold a stack of parentheses which are not closed yet
|
|
|
|
|
|
$lastOpeningBrace = -1; # last not closed parentheses
|
|
|
|
|
|
|
2006-08-06 14:01:47 +00:00
|
|
|
|
$validOpeningBraces = implode( '', array_keys( $callbacks ) );
|
|
|
|
|
|
|
|
|
|
|
|
$i = 0;
|
|
|
|
|
|
while ( $i < strlen( $text ) ) {
|
|
|
|
|
|
# Find next opening brace, closing brace or pipe
|
|
|
|
|
|
if ( $lastOpeningBrace == -1 ) {
|
|
|
|
|
|
$currentClosing = '';
|
|
|
|
|
|
$search = $validOpeningBraces;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
$currentClosing = $openingBraceStack[$lastOpeningBrace]['braceEnd'];
|
|
|
|
|
|
$search = $validOpeningBraces . '|' . $currentClosing;
|
2005-10-19 06:24:30 +00:00
|
|
|
|
}
|
2006-08-06 14:01:47 +00:00
|
|
|
|
$rule = null;
|
|
|
|
|
|
$i += strcspn( $text, $search, $i );
|
|
|
|
|
|
if ( $i < strlen( $text ) ) {
|
|
|
|
|
|
if ( $text[$i] == '|' ) {
|
|
|
|
|
|
$found = 'pipe';
|
|
|
|
|
|
} elseif ( $text[$i] == $currentClosing ) {
|
|
|
|
|
|
$found = 'close';
|
|
|
|
|
|
} else {
|
|
|
|
|
|
$found = 'open';
|
|
|
|
|
|
$rule = $callbacks[$text[$i]];
|
2005-10-19 06:24:30 +00:00
|
|
|
|
}
|
2006-08-06 14:01:47 +00:00
|
|
|
|
} else {
|
|
|
|
|
|
# All done
|
2005-10-19 06:24:30 +00:00
|
|
|
|
break;
|
2006-08-06 14:01:47 +00:00
|
|
|
|
}
|
2005-10-19 06:24:30 +00:00
|
|
|
|
|
2006-08-06 14:01:47 +00:00
|
|
|
|
if ( $found == 'open' ) {
|
|
|
|
|
|
# found opening brace, let's add it to parentheses stack
|
2005-10-19 06:24:30 +00:00
|
|
|
|
$piece = array('brace' => $text[$i],
|
|
|
|
|
|
'braceEnd' => $rule['end'],
|
|
|
|
|
|
'title' => '',
|
|
|
|
|
|
'parts' => null);
|
|
|
|
|
|
|
2006-08-06 14:01:47 +00:00
|
|
|
|
# count opening brace characters
|
|
|
|
|
|
$piece['count'] = strspn( $text, $piece['brace'], $i );
|
|
|
|
|
|
$piece['startAt'] = $piece['partStart'] = $i + $piece['count'];
|
|
|
|
|
|
$i += $piece['count'];
|
|
|
|
|
|
|
|
|
|
|
|
# we need to add to stack only if opening brace count is enough for one of the rules
|
|
|
|
|
|
if ( $piece['count'] >= $rule['min'] ) {
|
|
|
|
|
|
$lastOpeningBrace ++;
|
|
|
|
|
|
$openingBraceStack[$lastOpeningBrace] = $piece;
|
|
|
|
|
|
}
|
|
|
|
|
|
} elseif ( $found == 'close' ) {
|
|
|
|
|
|
# lets check if it is enough characters for closing brace
|
|
|
|
|
|
$maxCount = $openingBraceStack[$lastOpeningBrace]['count'];
|
|
|
|
|
|
$count = strspn( $text, $text[$i], $i, $maxCount );
|
|
|
|
|
|
|
|
|
|
|
|
# check for maximum matching characters (if there are 5 closing
|
|
|
|
|
|
# characters, we will probably need only 3 - depending on the rules)
|
|
|
|
|
|
$matchingCount = 0;
|
|
|
|
|
|
$matchingCallback = null;
|
|
|
|
|
|
$cbType = $callbacks[$openingBraceStack[$lastOpeningBrace]['brace']];
|
|
|
|
|
|
if ( $count > $cbType['max'] ) {
|
|
|
|
|
|
# The specified maximum exists in the callback array, unless the caller
|
|
|
|
|
|
# has made an error
|
|
|
|
|
|
$matchingCount = $cbType['max'];
|
|
|
|
|
|
} else {
|
|
|
|
|
|
# Count is less than the maximum
|
|
|
|
|
|
# Skip any gaps in the callback array to find the true largest match
|
|
|
|
|
|
# Need to use array_key_exists not isset because the callback can be null
|
|
|
|
|
|
$matchingCount = $count;
|
|
|
|
|
|
while ( $matchingCount > 0 && !array_key_exists( $matchingCount, $cbType['cb'] ) ) {
|
|
|
|
|
|
--$matchingCount;
|
2005-10-19 06:24:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2006-08-06 14:01:47 +00:00
|
|
|
|
if ($matchingCount <= 0) {
|
|
|
|
|
|
$i += $count;
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
$matchingCallback = $cbType['cb'][$matchingCount];
|
2005-10-19 06:24:30 +00:00
|
|
|
|
|
2006-08-06 14:01:47 +00:00
|
|
|
|
# let's set a title or last part (if '|' was found)
|
|
|
|
|
|
if (null === $openingBraceStack[$lastOpeningBrace]['parts']) {
|
|
|
|
|
|
$openingBraceStack[$lastOpeningBrace]['title'] =
|
|
|
|
|
|
substr($text, $openingBraceStack[$lastOpeningBrace]['partStart'],
|
|
|
|
|
|
$i - $openingBraceStack[$lastOpeningBrace]['partStart']);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
$openingBraceStack[$lastOpeningBrace]['parts'][] =
|
|
|
|
|
|
substr($text, $openingBraceStack[$lastOpeningBrace]['partStart'],
|
|
|
|
|
|
$i - $openingBraceStack[$lastOpeningBrace]['partStart']);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$pieceStart = $openingBraceStack[$lastOpeningBrace]['startAt'] - $matchingCount;
|
|
|
|
|
|
$pieceEnd = $i + $matchingCount;
|
|
|
|
|
|
|
|
|
|
|
|
if( is_callable( $matchingCallback ) ) {
|
|
|
|
|
|
$cbArgs = array (
|
|
|
|
|
|
'text' => substr($text, $pieceStart, $pieceEnd - $pieceStart),
|
|
|
|
|
|
'title' => trim($openingBraceStack[$lastOpeningBrace]['title']),
|
|
|
|
|
|
'parts' => $openingBraceStack[$lastOpeningBrace]['parts'],
|
|
|
|
|
|
'lineStart' => (($pieceStart > 0) && ($text[$pieceStart-1] == "\n")),
|
|
|
|
|
|
);
|
|
|
|
|
|
# finally we can call a user callback and replace piece of text
|
|
|
|
|
|
$replaceWith = call_user_func( $matchingCallback, $cbArgs );
|
|
|
|
|
|
$text = substr($text, 0, $pieceStart) . $replaceWith . substr($text, $pieceEnd);
|
|
|
|
|
|
$i = $pieceStart + strlen($replaceWith);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
# null value for callback means that parentheses should be parsed, but not replaced
|
|
|
|
|
|
$i += $matchingCount;
|
|
|
|
|
|
}
|
2005-10-19 06:24:30 +00:00
|
|
|
|
|
2006-08-06 14:01:47 +00:00
|
|
|
|
# reset last opening parentheses, but keep it in case there are unused characters
|
|
|
|
|
|
$piece = array('brace' => $openingBraceStack[$lastOpeningBrace]['brace'],
|
|
|
|
|
|
'braceEnd' => $openingBraceStack[$lastOpeningBrace]['braceEnd'],
|
|
|
|
|
|
'count' => $openingBraceStack[$lastOpeningBrace]['count'],
|
|
|
|
|
|
'title' => '',
|
|
|
|
|
|
'parts' => null,
|
|
|
|
|
|
'startAt' => $openingBraceStack[$lastOpeningBrace]['startAt']);
|
|
|
|
|
|
$openingBraceStack[$lastOpeningBrace--] = null;
|
|
|
|
|
|
|
|
|
|
|
|
if ($matchingCount < $piece['count']) {
|
|
|
|
|
|
$piece['count'] -= $matchingCount;
|
|
|
|
|
|
$piece['startAt'] -= $matchingCount;
|
|
|
|
|
|
$piece['partStart'] = $piece['startAt'];
|
|
|
|
|
|
# do we still qualify for any callback with remaining count?
|
|
|
|
|
|
$currentCbList = $callbacks[$piece['brace']]['cb'];
|
|
|
|
|
|
while ( $piece['count'] ) {
|
|
|
|
|
|
if ( array_key_exists( $piece['count'], $currentCbList ) ) {
|
|
|
|
|
|
$lastOpeningBrace++;
|
|
|
|
|
|
$openingBraceStack[$lastOpeningBrace] = $piece;
|
|
|
|
|
|
break;
|
2005-10-19 06:24:30 +00:00
|
|
|
|
}
|
2006-08-06 14:01:47 +00:00
|
|
|
|
--$piece['count'];
|
2005-10-19 06:24:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2006-08-06 14:01:47 +00:00
|
|
|
|
} elseif ( $found == 'pipe' ) {
|
2005-10-19 06:24:30 +00:00
|
|
|
|
# lets set a title if it is a first separator, or next part otherwise
|
2006-08-06 14:01:47 +00:00
|
|
|
|
if (null === $openingBraceStack[$lastOpeningBrace]['parts']) {
|
|
|
|
|
|
$openingBraceStack[$lastOpeningBrace]['title'] =
|
|
|
|
|
|
substr($text, $openingBraceStack[$lastOpeningBrace]['partStart'],
|
|
|
|
|
|
$i - $openingBraceStack[$lastOpeningBrace]['partStart']);
|
|
|
|
|
|
$openingBraceStack[$lastOpeningBrace]['parts'] = array();
|
|
|
|
|
|
} else {
|
|
|
|
|
|
$openingBraceStack[$lastOpeningBrace]['parts'][] =
|
|
|
|
|
|
substr($text, $openingBraceStack[$lastOpeningBrace]['partStart'],
|
|
|
|
|
|
$i - $openingBraceStack[$lastOpeningBrace]['partStart']);
|
2005-10-19 06:24:30 +00:00
|
|
|
|
}
|
2006-08-06 14:01:47 +00:00
|
|
|
|
$openingBraceStack[$lastOpeningBrace]['partStart'] = ++$i;
|
2005-10-19 06:24:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2006-08-06 14:01:47 +00:00
|
|
|
|
wfProfileOut( __METHOD__ );
|
2005-10-19 06:24:30 +00:00
|
|
|
|
return $text;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2004-09-21 05:49:12 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* Replace magic variables, templates, and template arguments
|
|
|
|
|
|
* with the appropriate text. Templates are substituted recursively,
|
|
|
|
|
|
* taking care to avoid infinite loops.
|
|
|
|
|
|
*
|
|
|
|
|
|
* Note that the substitution depends on value of $mOutputType:
|
|
|
|
|
|
* OT_WIKI: only {{subst:}} templates
|
|
|
|
|
|
* OT_MSG: only magic variables
|
|
|
|
|
|
* OT_HTML: all templates and magic variables
|
2005-07-03 07:15:53 +00:00
|
|
|
|
*
|
2004-09-21 05:49:12 +00:00
|
|
|
|
* @param string $tex The text to transform
|
|
|
|
|
|
* @param array $args Key-value pairs representing template parameters to substitute
|
2006-02-01 04:41:53 +00:00
|
|
|
|
* @param bool $argsOnly Only do argument (triple-brace) expansion, not double-brace expansion
|
2006-04-19 15:46:24 +00:00
|
|
|
|
* @private
|
2004-09-21 05:49:12 +00:00
|
|
|
|
*/
|
2006-02-01 04:41:53 +00:00
|
|
|
|
function replaceVariables( $text, $args = array(), $argsOnly = false ) {
|
2004-08-16 15:23:46 +00:00
|
|
|
|
# Prevent too big inclusions
|
2006-08-10 21:28:49 +00:00
|
|
|
|
if( strlen( $text ) > $this->mOptions->getMaxIncludeSize() ) {
|
2004-11-21 14:07:24 +00:00
|
|
|
|
return $text;
|
|
|
|
|
|
}
|
2004-07-24 00:37:24 +00:00
|
|
|
|
|
2006-08-06 14:01:47 +00:00
|
|
|
|
$fname = __METHOD__ /*. '-L' . count( $this->mArgStack )*/;
|
2004-02-26 13:37:26 +00:00
|
|
|
|
wfProfileIn( $fname );
|
2004-04-12 23:59:37 +00:00
|
|
|
|
|
2004-04-11 16:46:06 +00:00
|
|
|
|
# This function is called recursively. To keep track of arguments we need a stack:
|
|
|
|
|
|
array_push( $this->mArgStack, $args );
|
2004-04-09 15:29:33 +00:00
|
|
|
|
|
2005-10-19 06:24:30 +00:00
|
|
|
|
$braceCallbacks = array();
|
2006-02-01 04:41:53 +00:00
|
|
|
|
if ( !$argsOnly ) {
|
|
|
|
|
|
$braceCallbacks[2] = array( &$this, 'braceSubstitution' );
|
|
|
|
|
|
}
|
2006-08-14 07:10:31 +00:00
|
|
|
|
if ( !$this->mOutputType != OT_MSG ) {
|
2005-10-19 06:24:30 +00:00
|
|
|
|
$braceCallbacks[3] = array( &$this, 'argSubstitution' );
|
2004-05-23 03:39:24 +00:00
|
|
|
|
}
|
2006-08-06 14:01:47 +00:00
|
|
|
|
if ( $braceCallbacks ) {
|
|
|
|
|
|
$callbacks = array(
|
|
|
|
|
|
'{' => array(
|
|
|
|
|
|
'end' => '}',
|
|
|
|
|
|
'cb' => $braceCallbacks,
|
|
|
|
|
|
'min' => $argsOnly ? 3 : 2,
|
|
|
|
|
|
'max' => isset( $braceCallbacks[3] ) ? 3 : 2,
|
|
|
|
|
|
),
|
|
|
|
|
|
'[' => array(
|
|
|
|
|
|
'end' => ']',
|
|
|
|
|
|
'cb' => array(2=>null),
|
|
|
|
|
|
'min' => 2,
|
|
|
|
|
|
'max' => 2,
|
|
|
|
|
|
)
|
|
|
|
|
|
);
|
|
|
|
|
|
$text = $this->replace_callback ($text, $callbacks);
|
2004-04-12 23:59:37 +00:00
|
|
|
|
|
2006-08-06 14:01:47 +00:00
|
|
|
|
array_pop( $this->mArgStack );
|
|
|
|
|
|
}
|
2004-05-26 12:30:36 +00:00
|
|
|
|
wfProfileOut( $fname );
|
2004-04-11 16:46:06 +00:00
|
|
|
|
return $text;
|
2004-03-20 15:03:26 +00:00
|
|
|
|
}
|
2006-07-11 17:40:11 +00:00
|
|
|
|
|
2004-09-21 23:30:46 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* Replace magic variables
|
2006-04-19 15:46:24 +00:00
|
|
|
|
* @private
|
2004-09-21 23:30:46 +00:00
|
|
|
|
*/
|
|
|
|
|
|
function variableSubstitution( $matches ) {
|
2005-12-26 21:43:30 +00:00
|
|
|
|
$fname = 'Parser::variableSubstitution';
|
2005-01-18 11:52:06 +00:00
|
|
|
|
$varname = $matches[1];
|
2004-11-28 04:05:05 +00:00
|
|
|
|
wfProfileIn( $fname );
|
2004-09-21 23:30:46 +00:00
|
|
|
|
$skip = false;
|
|
|
|
|
|
if ( $this->mOutputType == OT_WIKI ) {
|
|
|
|
|
|
# Do only magic variables prefixed by SUBST
|
2006-07-14 15:39:23 +00:00
|
|
|
|
$mwSubst =& MagicWord::get( 'subst' );
|
2005-01-18 11:52:06 +00:00
|
|
|
|
if (!$mwSubst->matchStartAndRemove( $varname ))
|
2004-09-21 23:30:46 +00:00
|
|
|
|
$skip = true;
|
|
|
|
|
|
# Note that if we don't substitute the variable below,
|
|
|
|
|
|
# we don't remove the {{subst:}} magic word, in case
|
|
|
|
|
|
# it is a template rather than a magic variable.
|
|
|
|
|
|
}
|
2005-01-18 11:52:06 +00:00
|
|
|
|
if ( !$skip && array_key_exists( $varname, $this->mVariables ) ) {
|
|
|
|
|
|
$id = $this->mVariables[$varname];
|
|
|
|
|
|
$text = $this->getVariableValue( $id );
|
2004-09-21 23:30:46 +00:00
|
|
|
|
$this->mOutput->mContainsOldMagic = true;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
$text = $matches[0];
|
|
|
|
|
|
}
|
2004-11-28 04:05:05 +00:00
|
|
|
|
wfProfileOut( $fname );
|
2004-09-21 23:30:46 +00:00
|
|
|
|
return $text;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2004-07-31 14:13:07 +00:00
|
|
|
|
# Split template arguments
|
|
|
|
|
|
function getTemplateArgs( $argsString ) {
|
|
|
|
|
|
if ( $argsString === '' ) {
|
|
|
|
|
|
return array();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$args = explode( '|', substr( $argsString, 1 ) );
|
|
|
|
|
|
|
|
|
|
|
|
# If any of the arguments contains a '[[' but no ']]', it needs to be
|
|
|
|
|
|
# merged with the next arg because the '|' character between belongs
|
|
|
|
|
|
# to the link syntax and not the template parameter syntax.
|
|
|
|
|
|
$argc = count($args);
|
2005-07-03 07:15:53 +00:00
|
|
|
|
|
2004-07-31 14:13:07 +00:00
|
|
|
|
for ( $i = 0; $i < $argc-1; $i++ ) {
|
2004-08-22 17:24:50 +00:00
|
|
|
|
if ( substr_count ( $args[$i], '[[' ) != substr_count ( $args[$i], ']]' ) ) {
|
|
|
|
|
|
$args[$i] .= '|'.$args[$i+1];
|
2004-07-31 14:13:07 +00:00
|
|
|
|
array_splice($args, $i+1, 1);
|
|
|
|
|
|
$i--;
|
|
|
|
|
|
$argc--;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return $args;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2004-09-21 05:49:12 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* Return the text of a template, after recursively
|
|
|
|
|
|
* replacing any variables or templates within the template.
|
|
|
|
|
|
*
|
2005-10-19 06:24:30 +00:00
|
|
|
|
* @param array $piece The parts of the template
|
|
|
|
|
|
* $piece['text']: matched text
|
|
|
|
|
|
* $piece['title']: the title, i.e. the part before the |
|
|
|
|
|
|
* $piece['parts']: the parameter array
|
2004-09-21 05:49:12 +00:00
|
|
|
|
* @return string the text of the template
|
2006-04-19 15:46:24 +00:00
|
|
|
|
* @private
|
2004-09-21 05:49:12 +00:00
|
|
|
|
*/
|
2005-10-19 06:24:30 +00:00
|
|
|
|
function braceSubstitution( $piece ) {
|
2006-04-29 13:15:19 +00:00
|
|
|
|
global $wgContLang, $wgLang, $wgAllowDisplayTitle, $action;
|
2006-08-06 14:01:47 +00:00
|
|
|
|
$fname = __METHOD__ /*. '-L' . count( $this->mArgStack )*/;
|
2004-11-28 04:05:05 +00:00
|
|
|
|
wfProfileIn( $fname );
|
2006-08-06 14:01:47 +00:00
|
|
|
|
wfProfileIn( __METHOD__.'-setup' );
|
2005-07-03 07:15:53 +00:00
|
|
|
|
|
2006-03-11 17:13:49 +00:00
|
|
|
|
# Flags
|
2006-02-01 04:41:53 +00:00
|
|
|
|
$found = false; # $text has been filled
|
|
|
|
|
|
$nowiki = false; # wiki markup in $text should be escaped
|
|
|
|
|
|
$noparse = false; # Unsafe HTML tags should not be stripped, etc.
|
|
|
|
|
|
$noargs = false; # Don't replace triple-brace arguments in $text
|
|
|
|
|
|
$replaceHeadings = false; # Make the edit section links go to the template not the article
|
|
|
|
|
|
$isHTML = false; # $text is HTML, armour it against wikitext transformation
|
|
|
|
|
|
$forceRawInterwiki = false; # Force interwiki transclusion to be done in raw mode not rendered
|
2004-07-12 19:49:20 +00:00
|
|
|
|
|
2006-02-01 04:41:53 +00:00
|
|
|
|
# Title object, where $text came from
|
2004-04-11 16:46:06 +00:00
|
|
|
|
$title = NULL;
|
2004-04-12 23:59:37 +00:00
|
|
|
|
|
2005-10-19 06:24:30 +00:00
|
|
|
|
$linestart = '';
|
2004-09-25 05:16:38 +00:00
|
|
|
|
|
2006-08-14 07:10:31 +00:00
|
|
|
|
|
2004-04-11 16:46:06 +00:00
|
|
|
|
# $part1 is the bit before the first |, and must contain only title characters
|
|
|
|
|
|
# $args is a list of arguments, starting from index 0, not including $part1
|
2004-04-12 23:59:37 +00:00
|
|
|
|
|
2006-08-17 22:20:06 +00:00
|
|
|
|
$titleText = $part1 = $piece['title'];
|
2004-09-25 05:16:38 +00:00
|
|
|
|
# If the third subpattern matched anything, it will start with |
|
2004-07-31 14:13:07 +00:00
|
|
|
|
|
2005-10-19 06:24:30 +00:00
|
|
|
|
if (null == $piece['parts']) {
|
|
|
|
|
|
$replaceWith = $this->variableSubstitution (array ($piece['text'], $piece['title']));
|
|
|
|
|
|
if ($replaceWith != $piece['text']) {
|
|
|
|
|
|
$text = $replaceWith;
|
|
|
|
|
|
$found = true;
|
|
|
|
|
|
$noparse = true;
|
2006-02-01 04:41:53 +00:00
|
|
|
|
$noargs = true;
|
2005-10-19 06:24:30 +00:00
|
|
|
|
}
|
2004-05-23 03:39:24 +00:00
|
|
|
|
}
|
2004-03-20 15:03:26 +00:00
|
|
|
|
|
2005-10-19 06:24:30 +00:00
|
|
|
|
$args = (null == $piece['parts']) ? array() : $piece['parts'];
|
|
|
|
|
|
$argc = count( $args );
|
2006-08-06 14:01:47 +00:00
|
|
|
|
wfProfileOut( __METHOD__.'-setup' );
|
2005-10-19 06:24:30 +00:00
|
|
|
|
|
2004-03-20 15:03:26 +00:00
|
|
|
|
# SUBST
|
2006-08-06 14:01:47 +00:00
|
|
|
|
wfProfileIn( __METHOD__.'-modifiers' );
|
2004-05-23 03:39:24 +00:00
|
|
|
|
if ( !$found ) {
|
2006-07-14 15:39:23 +00:00
|
|
|
|
$mwSubst =& MagicWord::get( 'subst' );
|
2006-08-14 07:10:31 +00:00
|
|
|
|
if ( $mwSubst->matchStartAndRemove( $part1 ) xor $this->ot['wiki'] ) {
|
2004-09-22 00:15:54 +00:00
|
|
|
|
# One of two possibilities is true:
|
|
|
|
|
|
# 1) Found SUBST but not in the PST phase
|
|
|
|
|
|
# 2) Didn't find SUBST and in the PST phase
|
|
|
|
|
|
# In either case, return without further processing
|
2005-10-19 06:24:30 +00:00
|
|
|
|
$text = $piece['text'];
|
2004-03-20 15:03:26 +00:00
|
|
|
|
$found = true;
|
2004-09-22 00:15:54 +00:00
|
|
|
|
$noparse = true;
|
2006-02-01 04:41:53 +00:00
|
|
|
|
$noargs = true;
|
2004-03-20 15:03:26 +00:00
|
|
|
|
}
|
2004-02-26 13:37:26 +00:00
|
|
|
|
}
|
2004-04-12 23:59:37 +00:00
|
|
|
|
|
2006-02-01 04:41:53 +00:00
|
|
|
|
# MSG, MSGNW, INT and RAW
|
2004-03-20 15:03:26 +00:00
|
|
|
|
if ( !$found ) {
|
|
|
|
|
|
# Check for MSGNW:
|
2006-07-14 15:39:23 +00:00
|
|
|
|
$mwMsgnw =& MagicWord::get( 'msgnw' );
|
2004-04-11 16:46:06 +00:00
|
|
|
|
if ( $mwMsgnw->matchStartAndRemove( $part1 ) ) {
|
2004-03-20 15:03:26 +00:00
|
|
|
|
$nowiki = true;
|
2005-06-12 13:39:28 +00:00
|
|
|
|
} else {
|
|
|
|
|
|
# Remove obsolete MSG:
|
2006-07-14 15:39:23 +00:00
|
|
|
|
$mwMsg =& MagicWord::get( 'msg' );
|
2005-06-12 13:39:28 +00:00
|
|
|
|
$mwMsg->matchStartAndRemove( $part1 );
|
2004-03-20 15:03:26 +00:00
|
|
|
|
}
|
2006-02-01 04:41:53 +00:00
|
|
|
|
|
|
|
|
|
|
# Check for RAW:
|
2006-07-14 15:39:23 +00:00
|
|
|
|
$mwRaw =& MagicWord::get( 'raw' );
|
2006-02-01 04:41:53 +00:00
|
|
|
|
if ( $mwRaw->matchStartAndRemove( $part1 ) ) {
|
|
|
|
|
|
$forceRawInterwiki = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2005-06-12 13:39:28 +00:00
|
|
|
|
# Check if it is an internal message
|
2006-07-14 15:39:23 +00:00
|
|
|
|
$mwInt =& MagicWord::get( 'int' );
|
2004-04-11 16:46:06 +00:00
|
|
|
|
if ( $mwInt->matchStartAndRemove( $part1 ) ) {
|
2006-08-10 21:28:49 +00:00
|
|
|
|
$text = $linestart . wfMsgReal( $part1, $args, true );
|
|
|
|
|
|
$found = true;
|
2004-03-20 15:03:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2006-08-06 14:01:47 +00:00
|
|
|
|
wfProfileOut( __METHOD__.'-modifiers' );
|
2004-04-12 23:59:37 +00:00
|
|
|
|
|
2006-07-03 11:07:00 +00:00
|
|
|
|
# Parser functions
|
2004-04-05 10:38:40 +00:00
|
|
|
|
if ( !$found ) {
|
2006-07-03 11:07:00 +00:00
|
|
|
|
wfProfileIn( __METHOD__ . '-pfunc' );
|
|
|
|
|
|
|
|
|
|
|
|
$colonPos = strpos( $part1, ':' );
|
|
|
|
|
|
if ( $colonPos !== false ) {
|
|
|
|
|
|
# Case sensitive functions
|
|
|
|
|
|
$function = substr( $part1, 0, $colonPos );
|
|
|
|
|
|
if ( isset( $this->mFunctionSynonyms[1][$function] ) ) {
|
|
|
|
|
|
$function = $this->mFunctionSynonyms[1][$function];
|
2004-04-05 10:38:40 +00:00
|
|
|
|
} else {
|
2006-07-03 11:07:00 +00:00
|
|
|
|
# Case insensitive functions
|
|
|
|
|
|
$function = strtolower( $function );
|
|
|
|
|
|
if ( isset( $this->mFunctionSynonyms[0][$function] ) ) {
|
|
|
|
|
|
$function = $this->mFunctionSynonyms[0][$function];
|
2006-04-30 18:02:03 +00:00
|
|
|
|
} else {
|
2006-07-03 11:07:00 +00:00
|
|
|
|
$function = false;
|
2006-04-30 18:02:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2006-07-03 11:07:00 +00:00
|
|
|
|
if ( $function ) {
|
2006-04-18 02:48:48 +00:00
|
|
|
|
$funcArgs = array_map( 'trim', $args );
|
|
|
|
|
|
$funcArgs = array_merge( array( &$this, trim( substr( $part1, $colonPos + 1 ) ) ), $funcArgs );
|
2006-04-05 09:40:25 +00:00
|
|
|
|
$result = call_user_func_array( $this->mFunctionHooks[$function], $funcArgs );
|
|
|
|
|
|
$found = true;
|
2006-04-27 08:21:42 +00:00
|
|
|
|
|
|
|
|
|
|
// The text is usually already parsed, doesn't need triple-brace tags expanded, etc.
|
2006-04-27 15:46:33 +00:00
|
|
|
|
//$noargs = true;
|
|
|
|
|
|
//$noparse = true;
|
2006-07-03 11:07:00 +00:00
|
|
|
|
|
2006-04-05 09:40:25 +00:00
|
|
|
|
if ( is_array( $result ) ) {
|
2006-07-03 11:07:00 +00:00
|
|
|
|
if ( isset( $result[0] ) ) {
|
|
|
|
|
|
$text = $linestart . $result[0];
|
|
|
|
|
|
unset( $result[0] );
|
|
|
|
|
|
}
|
2006-04-05 09:40:25 +00:00
|
|
|
|
|
|
|
|
|
|
// Extract flags into the local scope
|
|
|
|
|
|
// This allows callers to set flags such as nowiki, noparse, found, etc.
|
|
|
|
|
|
extract( $result );
|
|
|
|
|
|
} else {
|
|
|
|
|
|
$text = $linestart . $result;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2006-07-11 17:40:11 +00:00
|
|
|
|
wfProfileOut( __METHOD__ . '-pfunc' );
|
2006-04-05 09:40:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2004-08-16 15:23:46 +00:00
|
|
|
|
# Template table test
|
2004-07-24 00:37:24 +00:00
|
|
|
|
|
|
|
|
|
|
# Did we encounter this template already? If yes, it is in the cache
|
|
|
|
|
|
# and we need to check for loops.
|
2006-02-01 04:41:53 +00:00
|
|
|
|
if ( !$found && isset( $this->mTemplates[$piece['title']] ) ) {
|
2004-09-24 18:29:01 +00:00
|
|
|
|
$found = true;
|
|
|
|
|
|
|
2004-07-24 00:37:24 +00:00
|
|
|
|
# Infinite loop test
|
|
|
|
|
|
if ( isset( $this->mTemplatePath[$part1] ) ) {
|
|
|
|
|
|
$noparse = true;
|
2006-02-01 04:41:53 +00:00
|
|
|
|
$noargs = true;
|
2004-07-24 00:37:24 +00:00
|
|
|
|
$found = true;
|
2005-02-11 09:02:15 +00:00
|
|
|
|
$text = $linestart .
|
2006-08-17 22:20:06 +00:00
|
|
|
|
"[[$part1]]<!-- WARNING: template loop detected -->";
|
2006-08-06 14:01:47 +00:00
|
|
|
|
wfDebug( __METHOD__.": template loop broken at '$part1'\n" );
|
2005-02-11 09:02:15 +00:00
|
|
|
|
} else {
|
|
|
|
|
|
# set $text to cached message.
|
2006-02-01 04:41:53 +00:00
|
|
|
|
$text = $linestart . $this->mTemplates[$piece['title']];
|
2004-08-07 12:35:59 +00:00
|
|
|
|
}
|
2004-04-11 16:46:06 +00:00
|
|
|
|
}
|
2004-07-24 00:37:24 +00:00
|
|
|
|
|
2004-03-20 15:03:26 +00:00
|
|
|
|
# Load from database
|
2005-02-11 09:02:15 +00:00
|
|
|
|
$lastPathLevel = $this->mTemplatePath;
|
2004-03-20 15:03:26 +00:00
|
|
|
|
if ( !$found ) {
|
2006-07-04 08:11:44 +00:00
|
|
|
|
wfProfileIn( __METHOD__ . '-loadtpl' );
|
2004-09-25 20:13:14 +00:00
|
|
|
|
$ns = NS_TEMPLATE;
|
2006-03-24 16:44:52 +00:00
|
|
|
|
# declaring $subpage directly in the function call
|
|
|
|
|
|
# does not work correctly with references and breaks
|
|
|
|
|
|
# {{/subpage}}-style inclusions
|
|
|
|
|
|
$subpage = '';
|
|
|
|
|
|
$part1 = $this->maybeDoSubpageLink( $part1, $subpage );
|
2004-09-25 20:13:14 +00:00
|
|
|
|
if ($subpage !== '') {
|
|
|
|
|
|
$ns = $this->mTitle->getNamespace();
|
|
|
|
|
|
}
|
|
|
|
|
|
$title = Title::newFromText( $part1, $ns );
|
2005-07-03 07:15:53 +00:00
|
|
|
|
|
2006-06-16 22:30:39 +00:00
|
|
|
|
|
2006-01-31 03:44:08 +00:00
|
|
|
|
if ( !is_null( $title ) ) {
|
2006-08-17 22:20:06 +00:00
|
|
|
|
$titleText = $title->getPrefixedText();
|
2006-06-17 08:55:44 +00:00
|
|
|
|
$checkVariantLink = sizeof($wgContLang->getVariants())>1;
|
|
|
|
|
|
# Check for language variants if the template is not found
|
|
|
|
|
|
if($checkVariantLink && $title->getArticleID() == 0){
|
|
|
|
|
|
$wgContLang->findVariantLink($part1, $title);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2006-01-31 03:44:08 +00:00
|
|
|
|
if ( !$title->isExternal() ) {
|
2006-08-14 07:10:31 +00:00
|
|
|
|
if ( $title->getNamespace() == NS_SPECIAL && $this->mOptions->getAllowSpecialInclusion() && $this->ot['html'] ) {
|
2006-08-10 21:28:49 +00:00
|
|
|
|
$text = SpecialPage::capturePath( $title );
|
|
|
|
|
|
if ( is_string( $text ) ) {
|
|
|
|
|
|
$found = true;
|
|
|
|
|
|
$noparse = true;
|
|
|
|
|
|
$noargs = true;
|
|
|
|
|
|
$isHTML = true;
|
|
|
|
|
|
$this->disableCache();
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
$articleContent = $this->fetchTemplate( $title );
|
|
|
|
|
|
if ( $articleContent !== false ) {
|
|
|
|
|
|
$found = true;
|
|
|
|
|
|
$text = $articleContent;
|
|
|
|
|
|
$replaceHeadings = true;
|
2005-05-28 11:09:22 +00:00
|
|
|
|
}
|
2004-04-12 23:59:37 +00:00
|
|
|
|
}
|
2004-02-26 13:37:26 +00:00
|
|
|
|
|
2006-01-31 03:44:08 +00:00
|
|
|
|
# If the title is valid but undisplayable, make a link to it
|
2006-08-14 07:10:31 +00:00
|
|
|
|
if ( !$found && ( $this->ot['html'] || $this->ot['pre'] ) ) {
|
2006-08-17 22:20:06 +00:00
|
|
|
|
$text = "[[$titleText]]";
|
2006-01-31 03:44:08 +00:00
|
|
|
|
$found = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
} elseif ( $title->isTrans() ) {
|
|
|
|
|
|
// Interwiki transclusion
|
2006-08-14 07:10:31 +00:00
|
|
|
|
if ( $this->ot['html'] && !$forceRawInterwiki ) {
|
2006-01-31 03:44:08 +00:00
|
|
|
|
$text = $this->interwikiTransclude( $title, 'render' );
|
|
|
|
|
|
$isHTML = true;
|
|
|
|
|
|
$noparse = true;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
$text = $this->interwikiTransclude( $title, 'raw' );
|
2006-02-01 04:41:53 +00:00
|
|
|
|
$replaceHeadings = true;
|
2006-01-31 03:44:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
$found = true;
|
2005-02-05 07:14:25 +00:00
|
|
|
|
}
|
2006-07-11 17:40:11 +00:00
|
|
|
|
|
2006-02-01 04:41:53 +00:00
|
|
|
|
# Template cache array insertion
|
|
|
|
|
|
# Use the original $piece['title'] not the mangled $part1, so that
|
|
|
|
|
|
# modifiers such as RAW: produce separate cache entries
|
|
|
|
|
|
if( $found ) {
|
2006-06-04 02:41:52 +00:00
|
|
|
|
if( $isHTML ) {
|
|
|
|
|
|
// A special page; don't store it in the template cache.
|
|
|
|
|
|
} else {
|
|
|
|
|
|
$this->mTemplates[$piece['title']] = $text;
|
|
|
|
|
|
}
|
2006-02-01 04:41:53 +00:00
|
|
|
|
$text = $linestart . $text;
|
|
|
|
|
|
}
|
2004-03-20 15:03:26 +00:00
|
|
|
|
}
|
2006-07-11 17:40:11 +00:00
|
|
|
|
wfProfileOut( __METHOD__ . '-loadtpl' );
|
2004-03-20 15:03:26 +00:00
|
|
|
|
}
|
2004-04-12 23:59:37 +00:00
|
|
|
|
|
2006-08-10 21:28:49 +00:00
|
|
|
|
if ( $found && !$this->incrementIncludeSize( 'pre-expand', strlen( $text ) ) ) {
|
|
|
|
|
|
# Error, oversize inclusion
|
|
|
|
|
|
$text = $linestart .
|
2006-08-17 22:20:06 +00:00
|
|
|
|
"[[$titleText]]<!-- WARNING: template omitted, pre-expand include size too large -->";
|
2006-08-10 21:28:49 +00:00
|
|
|
|
$noparse = true;
|
|
|
|
|
|
$noargs = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2004-04-11 16:46:06 +00:00
|
|
|
|
# Recursive parsing, escaping and link table handling
|
|
|
|
|
|
# Only for HTML output
|
2006-08-14 07:10:31 +00:00
|
|
|
|
if ( $nowiki && $found && ( $this->ot['html'] || $this->ot['pre'] ) ) {
|
2004-04-11 16:46:06 +00:00
|
|
|
|
$text = wfEscapeWikiText( $text );
|
2006-08-14 07:10:31 +00:00
|
|
|
|
} elseif ( !$this->ot['msg'] && $found ) {
|
2006-04-27 08:21:42 +00:00
|
|
|
|
if ( $noargs ) {
|
|
|
|
|
|
$assocArgs = array();
|
|
|
|
|
|
} else {
|
2006-02-01 04:41:53 +00:00
|
|
|
|
# Clean up argument array
|
|
|
|
|
|
$assocArgs = array();
|
|
|
|
|
|
$index = 1;
|
|
|
|
|
|
foreach( $args as $arg ) {
|
|
|
|
|
|
$eqpos = strpos( $arg, '=' );
|
|
|
|
|
|
if ( $eqpos === false ) {
|
|
|
|
|
|
$assocArgs[$index++] = $arg;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
$name = trim( substr( $arg, 0, $eqpos ) );
|
|
|
|
|
|
$value = trim( substr( $arg, $eqpos+1 ) );
|
|
|
|
|
|
if ( $value === false ) {
|
|
|
|
|
|
$value = '';
|
|
|
|
|
|
}
|
|
|
|
|
|
if ( $name !== false ) {
|
|
|
|
|
|
$assocArgs[$name] = $value;
|
|
|
|
|
|
}
|
2004-04-11 16:46:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2004-07-24 00:37:24 +00:00
|
|
|
|
|
2006-02-01 04:41:53 +00:00
|
|
|
|
# Add a new element to the templace recursion path
|
|
|
|
|
|
$this->mTemplatePath[$part1] = 1;
|
2005-11-16 10:16:46 +00:00
|
|
|
|
}
|
2006-01-07 13:31:29 +00:00
|
|
|
|
|
2006-02-01 04:41:53 +00:00
|
|
|
|
if ( !$noparse ) {
|
|
|
|
|
|
# If there are any <onlyinclude> tags, only include them
|
|
|
|
|
|
if ( in_string( '<onlyinclude>', $text ) && in_string( '</onlyinclude>', $text ) ) {
|
|
|
|
|
|
preg_match_all( '/<onlyinclude>(.*?)\n?<\/onlyinclude>/s', $text, $m );
|
|
|
|
|
|
$text = '';
|
|
|
|
|
|
foreach ($m[1] as $piece)
|
|
|
|
|
|
$text .= $piece;
|
|
|
|
|
|
}
|
|
|
|
|
|
# Remove <noinclude> sections and <includeonly> tags
|
|
|
|
|
|
$text = preg_replace( '/<noinclude>.*?<\/noinclude>/s', '', $text );
|
|
|
|
|
|
$text = strtr( $text, array( '<includeonly>' => '' , '</includeonly>' => '' ) );
|
|
|
|
|
|
|
2006-08-14 07:10:31 +00:00
|
|
|
|
if( $this->ot['html'] || $this->ot['pre'] ) {
|
2006-02-01 04:41:53 +00:00
|
|
|
|
# Strip <nowiki>, <pre>, etc.
|
|
|
|
|
|
$text = $this->strip( $text, $this->mStripState );
|
2006-08-14 07:10:31 +00:00
|
|
|
|
if ( $this->ot['html'] ) {
|
|
|
|
|
|
$text = Sanitizer::removeHTMLtags( $text, array( &$this, 'replaceVariables' ), $assocArgs );
|
2006-08-15 02:40:20 +00:00
|
|
|
|
} elseif ( $this->ot['pre'] && $this->mOptions->getRemoveComments() ) {
|
|
|
|
|
|
$text = Sanitizer::removeHTMLcomments( $text );
|
2006-08-14 07:10:31 +00:00
|
|
|
|
}
|
2006-02-01 04:41:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
$text = $this->replaceVariables( $text, $assocArgs );
|
2004-04-12 23:59:37 +00:00
|
|
|
|
|
2006-02-01 04:41:53 +00:00
|
|
|
|
# If the template begins with a table or block-level
|
|
|
|
|
|
# element, it should be treated as beginning a new line.
|
2006-08-14 07:10:31 +00:00
|
|
|
|
if (!$piece['lineStart'] && preg_match('/^({\\||:|;|#|\*)/', $text)) /*}*/{
|
2006-02-01 04:41:53 +00:00
|
|
|
|
$text = "\n" . $text;
|
|
|
|
|
|
}
|
|
|
|
|
|
} elseif ( !$noargs ) {
|
|
|
|
|
|
# $noparse and !$noargs
|
|
|
|
|
|
# Just replace the arguments, not any double-brace items
|
|
|
|
|
|
# This is used for rendered interwiki transclusion
|
|
|
|
|
|
$text = $this->replaceVariables( $text, $assocArgs, true );
|
2004-09-25 16:06:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2005-02-11 09:02:15 +00:00
|
|
|
|
# Prune lower levels off the recursion check path
|
|
|
|
|
|
$this->mTemplatePath = $lastPathLevel;
|
2005-07-03 07:15:53 +00:00
|
|
|
|
|
2006-08-10 21:28:49 +00:00
|
|
|
|
if ( $found && !$this->incrementIncludeSize( 'post-expand', strlen( $text ) ) ) {
|
|
|
|
|
|
# Error, oversize inclusion
|
|
|
|
|
|
$text = $linestart .
|
2006-08-17 22:20:06 +00:00
|
|
|
|
"[[$titleText]]<!-- WARNING: template omitted, post-expand include size too large -->";
|
2006-08-10 21:28:49 +00:00
|
|
|
|
$noparse = true;
|
|
|
|
|
|
$noargs = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2004-09-25 16:06:10 +00:00
|
|
|
|
if ( !$found ) {
|
2004-11-28 04:05:05 +00:00
|
|
|
|
wfProfileOut( $fname );
|
2005-10-19 06:24:30 +00:00
|
|
|
|
return $piece['text'];
|
2004-09-25 16:06:10 +00:00
|
|
|
|
} else {
|
2006-07-04 08:11:44 +00:00
|
|
|
|
wfProfileIn( __METHOD__ . '-placeholders' );
|
2005-05-28 11:09:22 +00:00
|
|
|
|
if ( $isHTML ) {
|
|
|
|
|
|
# Replace raw HTML by a placeholder
|
2005-07-03 07:15:53 +00:00
|
|
|
|
# Add a blank line preceding, to prevent it from mucking up
|
2005-05-28 11:09:22 +00:00
|
|
|
|
# immediately preceding headings
|
|
|
|
|
|
$text = "\n\n" . $this->insertStripItem( $text, $this->mStripState );
|
|
|
|
|
|
} else {
|
|
|
|
|
|
# replace ==section headers==
|
|
|
|
|
|
# XXX this needs to go away once we have a better parser.
|
2006-08-14 07:10:31 +00:00
|
|
|
|
if ( !$this->ot['wiki'] && !$this->ot['pre'] && $replaceHeadings ) {
|
2005-05-28 11:09:22 +00:00
|
|
|
|
if( !is_null( $title ) )
|
|
|
|
|
|
$encodedname = base64_encode($title->getPrefixedDBkey());
|
|
|
|
|
|
else
|
|
|
|
|
|
$encodedname = base64_encode("");
|
|
|
|
|
|
$m = preg_split('/(^={1,6}.*?={1,6}\s*?$)/m', $text, -1,
|
|
|
|
|
|
PREG_SPLIT_DELIM_CAPTURE);
|
|
|
|
|
|
$text = '';
|
|
|
|
|
|
$nsec = 0;
|
|
|
|
|
|
for( $i = 0; $i < count($m); $i += 2 ) {
|
|
|
|
|
|
$text .= $m[$i];
|
|
|
|
|
|
if (!isset($m[$i + 1]) || $m[$i + 1] == "") continue;
|
|
|
|
|
|
$hl = $m[$i + 1];
|
|
|
|
|
|
if( strstr($hl, "<!--MWTEMPLATESECTION") ) {
|
|
|
|
|
|
$text .= $hl;
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
preg_match('/^(={1,6})(.*?)(={1,6})\s*?$/m', $hl, $m2);
|
|
|
|
|
|
$text .= $m2[1] . $m2[2] . "<!--MWTEMPLATESECTION="
|
|
|
|
|
|
. $encodedname . "&" . base64_encode("$nsec") . "-->" . $m2[3];
|
2005-07-03 07:15:53 +00:00
|
|
|
|
|
2005-05-28 11:09:22 +00:00
|
|
|
|
$nsec++;
|
2004-09-21 11:54:45 +00:00
|
|
|
|
}
|
2004-09-21 06:54:18 +00:00
|
|
|
|
}
|
2004-09-21 04:33:51 +00:00
|
|
|
|
}
|
2006-07-04 08:11:44 +00:00
|
|
|
|
wfProfileOut( __METHOD__ . '-placeholders' );
|
2004-09-25 05:16:38 +00:00
|
|
|
|
}
|
2005-07-03 07:15:53 +00:00
|
|
|
|
|
2005-02-11 09:02:15 +00:00
|
|
|
|
# Prune lower levels off the recursion check path
|
|
|
|
|
|
$this->mTemplatePath = $lastPathLevel;
|
2005-07-03 07:15:53 +00:00
|
|
|
|
|
2004-09-25 05:16:38 +00:00
|
|
|
|
if ( !$found ) {
|
2004-11-28 04:05:05 +00:00
|
|
|
|
wfProfileOut( $fname );
|
2005-10-19 06:24:30 +00:00
|
|
|
|
return $piece['text'];
|
2004-09-25 05:16:38 +00:00
|
|
|
|
} else {
|
2004-11-28 04:05:05 +00:00
|
|
|
|
wfProfileOut( $fname );
|
2004-05-02 23:18:25 +00:00
|
|
|
|
return $text;
|
2004-03-20 15:03:26 +00:00
|
|
|
|
}
|
2004-02-26 13:37:26 +00:00
|
|
|
|
}
|
2006-01-07 13:31:29 +00:00
|
|
|
|
|
2006-01-11 02:19:41 +00:00
|
|
|
|
/**
|
2006-03-11 17:13:49 +00:00
|
|
|
|
* Fetch the unparsed text of a template and register a reference to it.
|
2006-01-11 02:19:41 +00:00
|
|
|
|
*/
|
|
|
|
|
|
function fetchTemplate( $title ) {
|
|
|
|
|
|
$text = false;
|
|
|
|
|
|
// Loop to fetch the article, with up to 1 redirect
|
|
|
|
|
|
for ( $i = 0; $i < 2 && is_object( $title ); $i++ ) {
|
|
|
|
|
|
$rev = Revision::newFromTitle( $title );
|
|
|
|
|
|
$this->mOutput->addTemplate( $title, $title->getArticleID() );
|
|
|
|
|
|
if ( !$rev ) {
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
$text = $rev->getText();
|
|
|
|
|
|
if ( $text === false ) {
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
// Redirect?
|
|
|
|
|
|
$title = Title::newFromRedirect( $text );
|
|
|
|
|
|
}
|
|
|
|
|
|
return $text;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2005-07-03 07:15:53 +00:00
|
|
|
|
/**
|
2006-01-31 03:44:08 +00:00
|
|
|
|
* Transclude an interwiki link.
|
2005-07-03 07:15:53 +00:00
|
|
|
|
*/
|
2006-01-31 03:44:08 +00:00
|
|
|
|
function interwikiTransclude( $title, $action ) {
|
|
|
|
|
|
global $wgEnableScaryTranscluding, $wgCanonicalNamespaceNames;
|
2005-07-03 07:15:53 +00:00
|
|
|
|
|
|
|
|
|
|
if (!$wgEnableScaryTranscluding)
|
|
|
|
|
|
return wfMsg('scarytranscludedisabled');
|
|
|
|
|
|
|
2006-01-31 03:44:08 +00:00
|
|
|
|
// The namespace will actually only be 0 or 10, depending on whether there was a leading :
|
|
|
|
|
|
// But we'll handle it generally anyway
|
|
|
|
|
|
if ( $title->getNamespace() ) {
|
|
|
|
|
|
// Use the canonical namespace, which should work anywhere
|
|
|
|
|
|
$articleName = $wgCanonicalNamespaceNames[$title->getNamespace()] . ':' . $title->getDBkey();
|
|
|
|
|
|
} else {
|
|
|
|
|
|
$articleName = $title->getDBkey();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$url = str_replace('$1', urlencode($articleName), Title::getInterwikiLink($title->getInterwiki()));
|
|
|
|
|
|
$url .= "?action=$action";
|
2005-07-03 07:48:04 +00:00
|
|
|
|
if (strlen($url) > 255)
|
|
|
|
|
|
return wfMsg('scarytranscludetoolong');
|
2006-01-31 03:44:08 +00:00
|
|
|
|
return $this->fetchScaryTemplateMaybeFromCache($url);
|
2005-07-03 07:15:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function fetchScaryTemplateMaybeFromCache($url) {
|
2006-01-31 03:44:08 +00:00
|
|
|
|
global $wgTranscludeCacheExpiry;
|
2005-08-15 13:06:33 +00:00
|
|
|
|
$dbr =& wfGetDB(DB_SLAVE);
|
2005-07-03 07:15:53 +00:00
|
|
|
|
$obj = $dbr->selectRow('transcache', array('tc_time', 'tc_contents'),
|
|
|
|
|
|
array('tc_url' => $url));
|
|
|
|
|
|
if ($obj) {
|
|
|
|
|
|
$time = $obj->tc_time;
|
|
|
|
|
|
$text = $obj->tc_contents;
|
2006-01-31 03:44:08 +00:00
|
|
|
|
if ($time && time() < $time + $wgTranscludeCacheExpiry ) {
|
2005-07-03 07:15:53 +00:00
|
|
|
|
return $text;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2006-07-02 15:57:59 +00:00
|
|
|
|
$text = Http::get($url);
|
2005-07-03 07:15:53 +00:00
|
|
|
|
if (!$text)
|
2005-07-05 18:26:34 +00:00
|
|
|
|
return wfMsg('scarytranscludefailed', $url);
|
2005-07-03 07:15:53 +00:00
|
|
|
|
|
2005-08-15 13:06:33 +00:00
|
|
|
|
$dbw =& wfGetDB(DB_MASTER);
|
2006-01-31 03:44:08 +00:00
|
|
|
|
$dbw->replace('transcache', array('tc_url'), array(
|
2005-07-03 07:15:53 +00:00
|
|
|
|
'tc_url' => $url,
|
|
|
|
|
|
'tc_time' => time(),
|
|
|
|
|
|
'tc_contents' => $text));
|
|
|
|
|
|
return $text;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2004-09-21 05:49:12 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* Triple brace replacement -- used for template arguments
|
2006-04-19 15:46:24 +00:00
|
|
|
|
* @private
|
2004-09-21 05:49:12 +00:00
|
|
|
|
*/
|
2004-06-12 06:15:09 +00:00
|
|
|
|
function argSubstitution( $matches ) {
|
2005-10-19 06:24:30 +00:00
|
|
|
|
$arg = trim( $matches['title'] );
|
|
|
|
|
|
$text = $matches['text'];
|
2004-05-23 03:39:24 +00:00
|
|
|
|
$inputArgs = end( $this->mArgStack );
|
|
|
|
|
|
|
|
|
|
|
|
if ( array_key_exists( $arg, $inputArgs ) ) {
|
2004-09-21 23:56:25 +00:00
|
|
|
|
$text = $inputArgs[$arg];
|
2006-08-14 07:10:31 +00:00
|
|
|
|
} else if (($this->mOutputType == OT_HTML || $this->mOutputType == OT_PREPROCESS ) &&
|
|
|
|
|
|
null != $matches['parts'] && count($matches['parts']) > 0) {
|
2005-10-19 06:24:30 +00:00
|
|
|
|
$text = $matches['parts'][0];
|
2004-05-23 03:39:24 +00:00
|
|
|
|
}
|
2006-08-10 21:28:49 +00:00
|
|
|
|
if ( !$this->incrementIncludeSize( 'arg', strlen( $text ) ) ) {
|
|
|
|
|
|
$text = $matches['text'] .
|
|
|
|
|
|
'<!-- WARNING: argument omitted, expansion size too large -->';
|
|
|
|
|
|
}
|
2004-07-12 19:49:20 +00:00
|
|
|
|
|
2004-05-23 03:39:24 +00:00
|
|
|
|
return $text;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2004-09-21 05:49:12 +00:00
|
|
|
|
/**
|
2006-08-10 21:28:49 +00:00
|
|
|
|
* Increment an include size counter
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param string $type The type of expansion
|
|
|
|
|
|
* @param integer $size The size of the text
|
|
|
|
|
|
* @return boolean False if this inclusion would take it over the maximum, true otherwise
|
2004-09-21 05:49:12 +00:00
|
|
|
|
*/
|
2006-08-10 21:28:49 +00:00
|
|
|
|
function incrementIncludeSize( $type, $size ) {
|
|
|
|
|
|
if ( $this->mIncludeSizes[$type] + $size > $this->mOptions->getMaxIncludeSize() ) {
|
2004-04-11 16:46:06 +00:00
|
|
|
|
return false;
|
2006-08-10 21:28:49 +00:00
|
|
|
|
} else {
|
|
|
|
|
|
$this->mIncludeSizes[$type] += $size;
|
|
|
|
|
|
return true;
|
2004-04-11 16:46:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2006-06-13 11:37:09 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* Detect __NOGALLERY__ magic word and set a placeholder
|
|
|
|
|
|
*/
|
|
|
|
|
|
function stripNoGallery( &$text ) {
|
|
|
|
|
|
# if the string __NOGALLERY__ (not case-sensitive) occurs in the HTML,
|
|
|
|
|
|
# do not add TOC
|
2006-07-14 15:39:23 +00:00
|
|
|
|
$mw = MagicWord::get( 'nogallery' );
|
2006-06-13 11:37:09 +00:00
|
|
|
|
$this->mOutput->mNoGallery = $mw->matchAndRemove( $text ) ;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2006-05-23 07:19:01 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* Detect __TOC__ magic word and set a placeholder
|
|
|
|
|
|
*/
|
|
|
|
|
|
function stripToc( $text ) {
|
|
|
|
|
|
# if the string __NOTOC__ (not case-sensitive) occurs in the HTML,
|
|
|
|
|
|
# do not add TOC
|
2006-07-14 15:39:23 +00:00
|
|
|
|
$mw = MagicWord::get( 'notoc' );
|
2006-05-23 07:19:01 +00:00
|
|
|
|
if( $mw->matchAndRemove( $text ) ) {
|
|
|
|
|
|
$this->mShowToc = false;
|
|
|
|
|
|
}
|
2006-07-11 17:40:11 +00:00
|
|
|
|
|
2006-07-14 15:39:23 +00:00
|
|
|
|
$mw = MagicWord::get( 'toc' );
|
2006-05-23 07:19:01 +00:00
|
|
|
|
if( $mw->match( $text ) ) {
|
|
|
|
|
|
$this->mShowToc = true;
|
|
|
|
|
|
$this->mForceTocPosition = true;
|
2006-07-11 17:40:11 +00:00
|
|
|
|
|
2006-05-23 07:19:01 +00:00
|
|
|
|
// Set a placeholder. At the end we'll fill it in with the TOC.
|
|
|
|
|
|
$text = $mw->replace( '<!--MWTOC-->', $text, 1 );
|
2006-07-11 17:40:11 +00:00
|
|
|
|
|
2006-05-23 07:19:01 +00:00
|
|
|
|
// Only keep the first one.
|
|
|
|
|
|
$text = $mw->replace( '', $text );
|
|
|
|
|
|
}
|
|
|
|
|
|
return $text;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2004-09-21 05:49:12 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* This function accomplishes several tasks:
|
|
|
|
|
|
* 1) Auto-number headings if that option is enabled
|
|
|
|
|
|
* 2) Add an [edit] link to sections for logged in users who have enabled the option
|
|
|
|
|
|
* 3) Add a Table of contents on the top for users who have enabled the option
|
|
|
|
|
|
* 4) Auto-anchor headings
|
2005-07-03 07:15:53 +00:00
|
|
|
|
*
|
2004-09-21 05:49:12 +00:00
|
|
|
|
* It loops through all headlines, collects the necessary data, then splits up the
|
|
|
|
|
|
* string and re-inserts the newly formatted headlines.
|
2005-07-03 07:15:53 +00:00
|
|
|
|
*
|
2005-01-31 22:59:55 +00:00
|
|
|
|
* @param string $text
|
|
|
|
|
|
* @param boolean $isMain
|
2006-04-19 15:46:24 +00:00
|
|
|
|
* @private
|
2004-09-21 05:49:12 +00:00
|
|
|
|
*/
|
2005-01-31 22:59:55 +00:00
|
|
|
|
function formatHeadings( $text, $isMain=true ) {
|
2005-12-04 18:27:59 +00:00
|
|
|
|
global $wgMaxTocLevel, $wgContLang;
|
2004-07-12 19:49:20 +00:00
|
|
|
|
|
2004-03-21 11:28:44 +00:00
|
|
|
|
$doNumberHeadings = $this->mOptions->getNumberHeadings();
|
2006-05-14 21:52:28 +00:00
|
|
|
|
if( !$this->mTitle->userCanEdit() ) {
|
|
|
|
|
|
$showEditLink = 0;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
$showEditLink = $this->mOptions->getEditSection();
|
|
|
|
|
|
}
|
2004-02-26 13:37:26 +00:00
|
|
|
|
|
|
|
|
|
|
# Inhibit editsection links if requested in the page
|
2006-07-14 15:39:23 +00:00
|
|
|
|
$esw =& MagicWord::get( 'noeditsection' );
|
2004-03-21 11:28:44 +00:00
|
|
|
|
if( $esw->matchAndRemove( $text ) ) {
|
|
|
|
|
|
$showEditLink = 0;
|
2004-02-26 13:37:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2004-04-03 04:38:09 +00:00
|
|
|
|
# Get all headlines for numbering them and adding funky stuff like [edit]
|
|
|
|
|
|
# links - this is for later, but we need the number of headlines right now
|
2005-01-06 00:13:49 +00:00
|
|
|
|
$numMatches = preg_match_all( '/<H([1-6])(.*?'.'>)(.*?)<\/H[1-6] *>/i', $text, $matches );
|
2004-04-03 04:38:09 +00:00
|
|
|
|
|
|
|
|
|
|
# if there are fewer than 4 headlines in the article, do not show TOC
|
2006-05-23 10:01:45 +00:00
|
|
|
|
# unless it's been explicitly enabled.
|
|
|
|
|
|
$enoughToc = $this->mShowToc &&
|
|
|
|
|
|
(($numMatches >= 4) || $this->mForceTocPosition);
|
2004-04-03 04:38:09 +00:00
|
|
|
|
|
2006-05-01 20:35:08 +00:00
|
|
|
|
# Allow user to stipulate that a page should have a "new section"
|
|
|
|
|
|
# link added via __NEWSECTIONLINK__
|
2006-07-14 15:39:23 +00:00
|
|
|
|
$mw =& MagicWord::get( 'newsectionlink' );
|
2006-05-01 20:35:08 +00:00
|
|
|
|
if( $mw->matchAndRemove( $text ) )
|
|
|
|
|
|
$this->mOutput->setNewSection( true );
|
|
|
|
|
|
|
2006-05-23 10:01:45 +00:00
|
|
|
|
# if the string __FORCETOC__ (not case-sensitive) occurs in the HTML,
|
|
|
|
|
|
# override above conditions and always show TOC above first header
|
2006-07-14 15:39:23 +00:00
|
|
|
|
$mw =& MagicWord::get( 'forcetoc' );
|
2006-05-23 10:01:45 +00:00
|
|
|
|
if ($mw->matchAndRemove( $text ) ) {
|
2006-05-23 07:19:01 +00:00
|
|
|
|
$this->mShowToc = true;
|
2006-05-23 10:01:45 +00:00
|
|
|
|
$enoughToc = true;
|
2004-04-03 04:38:09 +00:00
|
|
|
|
}
|
2004-07-12 19:49:20 +00:00
|
|
|
|
|
2005-01-15 23:21:52 +00:00
|
|
|
|
# Never ever show TOC if no headers
|
|
|
|
|
|
if( $numMatches < 1 ) {
|
2006-05-23 10:01:45 +00:00
|
|
|
|
$enoughToc = false;
|
2005-01-15 23:21:52 +00:00
|
|
|
|
}
|
2004-04-03 04:38:09 +00:00
|
|
|
|
|
2004-02-26 13:37:26 +00:00
|
|
|
|
# We need this to perform operations on the HTML
|
2004-02-29 08:43:29 +00:00
|
|
|
|
$sk =& $this->mOptions->getSkin();
|
2004-02-26 13:37:26 +00:00
|
|
|
|
|
|
|
|
|
|
# headline counter
|
2004-03-21 11:28:44 +00:00
|
|
|
|
$headlineCount = 0;
|
2004-09-21 04:33:51 +00:00
|
|
|
|
$sectionCount = 0; # headlineCount excluding template sections
|
2004-02-26 13:37:26 +00:00
|
|
|
|
|
|
|
|
|
|
# Ugh .. the TOC should have neat indentation levels which can be
|
|
|
|
|
|
# passed to the skin functions. These are determined here
|
2004-06-08 18:11:28 +00:00
|
|
|
|
$toc = '';
|
|
|
|
|
|
$full = '';
|
2004-03-08 02:50:04 +00:00
|
|
|
|
$head = array();
|
2004-03-21 11:28:44 +00:00
|
|
|
|
$sublevelCount = array();
|
2005-01-15 23:21:52 +00:00
|
|
|
|
$levelCount = array();
|
|
|
|
|
|
$toclevel = 0;
|
2004-03-29 14:48:07 +00:00
|
|
|
|
$level = 0;
|
|
|
|
|
|
$prevlevel = 0;
|
2005-01-15 23:21:52 +00:00
|
|
|
|
$toclevel = 0;
|
|
|
|
|
|
$prevtoclevel = 0;
|
|
|
|
|
|
|
2004-03-21 11:28:44 +00:00
|
|
|
|
foreach( $matches[3] as $headline ) {
|
2004-09-21 04:33:51 +00:00
|
|
|
|
$istemplate = 0;
|
2005-01-15 23:21:52 +00:00
|
|
|
|
$templatetitle = '';
|
2004-09-21 08:31:25 +00:00
|
|
|
|
$templatesection = 0;
|
2005-01-15 23:21:52 +00:00
|
|
|
|
$numbering = '';
|
2004-09-21 08:31:25 +00:00
|
|
|
|
|
2004-09-21 18:20:56 +00:00
|
|
|
|
if (preg_match("/<!--MWTEMPLATESECTION=([^&]+)&([^_]+)-->/", $headline, $mat)) {
|
2004-09-21 04:33:51 +00:00
|
|
|
|
$istemplate = 1;
|
2004-09-21 08:31:25 +00:00
|
|
|
|
$templatetitle = base64_decode($mat[1]);
|
|
|
|
|
|
$templatesection = 1 + (int)base64_decode($mat[2]);
|
2004-09-21 18:20:56 +00:00
|
|
|
|
$headline = preg_replace("/<!--MWTEMPLATESECTION=([^&]+)&([^_]+)-->/", "", $headline);
|
2004-09-21 04:33:51 +00:00
|
|
|
|
}
|
2004-09-21 08:31:25 +00:00
|
|
|
|
|
2005-01-15 23:21:52 +00:00
|
|
|
|
if( $toclevel ) {
|
2004-03-21 11:28:44 +00:00
|
|
|
|
$prevlevel = $level;
|
2005-01-15 23:21:52 +00:00
|
|
|
|
$prevtoclevel = $toclevel;
|
2004-03-21 11:28:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
$level = $matches[1][$headlineCount];
|
2005-07-03 07:15:53 +00:00
|
|
|
|
|
2006-05-23 10:01:45 +00:00
|
|
|
|
if( $doNumberHeadings || $enoughToc ) {
|
2005-07-03 07:15:53 +00:00
|
|
|
|
|
2005-01-15 23:21:52 +00:00
|
|
|
|
if ( $level > $prevlevel ) {
|
|
|
|
|
|
# Increase TOC level
|
|
|
|
|
|
$toclevel++;
|
|
|
|
|
|
$sublevelCount[$toclevel] = 0;
|
2006-04-25 19:43:46 +00:00
|
|
|
|
if( $toclevel<$wgMaxTocLevel ) {
|
|
|
|
|
|
$toc .= $sk->tocIndent();
|
|
|
|
|
|
}
|
2005-01-15 23:21:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
elseif ( $level < $prevlevel && $toclevel > 1 ) {
|
|
|
|
|
|
# Decrease TOC level, find level to jump to
|
|
|
|
|
|
|
|
|
|
|
|
if ( $toclevel == 2 && $level <= $levelCount[1] ) {
|
|
|
|
|
|
# Can only go down to level 1
|
|
|
|
|
|
$toclevel = 1;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
for ($i = $toclevel; $i > 0; $i--) {
|
|
|
|
|
|
if ( $levelCount[$i] == $level ) {
|
|
|
|
|
|
# Found last matching level
|
|
|
|
|
|
$toclevel = $i;
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
elseif ( $levelCount[$i] < $level ) {
|
|
|
|
|
|
# Found first matching level below current level
|
|
|
|
|
|
$toclevel = $i + 1;
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2006-04-25 19:43:46 +00:00
|
|
|
|
if( $toclevel<$wgMaxTocLevel ) {
|
|
|
|
|
|
$toc .= $sk->tocUnindent( $prevtoclevel - $toclevel );
|
|
|
|
|
|
}
|
2005-01-15 23:21:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
else {
|
|
|
|
|
|
# No change in level, end TOC line
|
2006-04-25 19:43:46 +00:00
|
|
|
|
if( $toclevel<$wgMaxTocLevel ) {
|
|
|
|
|
|
$toc .= $sk->tocLineEnd();
|
|
|
|
|
|
}
|
2005-01-15 23:21:52 +00:00
|
|
|
|
}
|
2005-07-03 07:15:53 +00:00
|
|
|
|
|
2005-01-15 23:21:52 +00:00
|
|
|
|
$levelCount[$toclevel] = $level;
|
|
|
|
|
|
|
|
|
|
|
|
# count number of headlines for each level
|
|
|
|
|
|
@$sublevelCount[$toclevel]++;
|
2004-03-29 14:48:07 +00:00
|
|
|
|
$dot = 0;
|
2005-01-15 23:21:52 +00:00
|
|
|
|
for( $i = 1; $i <= $toclevel; $i++ ) {
|
2004-03-29 14:48:07 +00:00
|
|
|
|
if( !empty( $sublevelCount[$i] ) ) {
|
2004-03-21 11:28:44 +00:00
|
|
|
|
if( $dot ) {
|
2004-06-08 18:11:28 +00:00
|
|
|
|
$numbering .= '.';
|
2004-03-21 11:28:44 +00:00
|
|
|
|
}
|
2004-09-24 13:14:52 +00:00
|
|
|
|
$numbering .= $wgContLang->formatNum( $sublevelCount[$i] );
|
2004-04-12 23:59:37 +00:00
|
|
|
|
$dot = 1;
|
2004-02-26 13:37:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2004-03-21 11:28:44 +00:00
|
|
|
|
# The canonized header is a version of the header text safe to use for links
|
|
|
|
|
|
# Avoid insertion of weird stuff like <math> by expanding the relevant sections
|
2004-04-11 16:46:06 +00:00
|
|
|
|
$canonized_headline = $this->unstrip( $headline, $this->mStripState );
|
2005-01-22 09:13:02 +00:00
|
|
|
|
$canonized_headline = $this->unstripNoWiki( $canonized_headline, $this->mStripState );
|
2004-04-12 23:59:37 +00:00
|
|
|
|
|
2004-08-26 18:48:13 +00:00
|
|
|
|
# Remove link placeholders by the link text.
|
2004-09-20 23:02:08 +00:00
|
|
|
|
# <!--LINK number-->
|
2005-07-03 07:15:53 +00:00
|
|
|
|
# turns into
|
2004-08-26 18:48:13 +00:00
|
|
|
|
# link text with suffix
|
2004-09-20 23:02:08 +00:00
|
|
|
|
$canonized_headline = preg_replace( '/<!--LINK ([0-9]*)-->/e',
|
2005-04-27 07:48:14 +00:00
|
|
|
|
"\$this->mLinkHolders['texts'][\$1]",
|
2004-09-20 23:02:08 +00:00
|
|
|
|
$canonized_headline );
|
2005-01-22 09:34:56 +00:00
|
|
|
|
$canonized_headline = preg_replace( '/<!--IWLINK ([0-9]*)-->/e',
|
2005-06-03 05:46:24 +00:00
|
|
|
|
"\$this->mInterwikiLinkHolders['texts'][\$1]",
|
2005-01-22 09:34:56 +00:00
|
|
|
|
$canonized_headline );
|
2004-09-20 23:02:08 +00:00
|
|
|
|
|
2004-03-21 11:28:44 +00:00
|
|
|
|
# strip out HTML
|
2004-06-08 18:11:28 +00:00
|
|
|
|
$canonized_headline = preg_replace( '/<.*?' . '>/','',$canonized_headline );
|
2004-04-12 23:59:37 +00:00
|
|
|
|
$tocline = trim( $canonized_headline );
|
2006-03-04 03:24:33 +00:00
|
|
|
|
# Save headline for section edit hint before it's escaped
|
2006-03-11 17:13:49 +00:00
|
|
|
|
$headline_hint = trim( $canonized_headline );
|
2006-01-07 09:13:38 +00:00
|
|
|
|
$canonized_headline = Sanitizer::escapeId( $tocline );
|
2005-04-21 06:30:48 +00:00
|
|
|
|
$refers[$headlineCount] = $canonized_headline;
|
2004-04-12 23:59:37 +00:00
|
|
|
|
|
2004-03-21 11:28:44 +00:00
|
|
|
|
# count how many in assoc. array so we can track dupes in anchors
|
2004-03-29 14:48:07 +00:00
|
|
|
|
@$refers[$canonized_headline]++;
|
2004-03-21 11:28:44 +00:00
|
|
|
|
$refcount[$headlineCount]=$refers[$canonized_headline];
|
2004-02-26 13:37:26 +00:00
|
|
|
|
|
2005-01-15 23:21:52 +00:00
|
|
|
|
# Don't number the heading if it is the only one (looks silly)
|
|
|
|
|
|
if( $doNumberHeadings && count( $matches[3] ) > 1) {
|
|
|
|
|
|
# the two are different if the line contains a link
|
|
|
|
|
|
$headline=$numbering . ' ' . $headline;
|
2004-02-26 13:37:26 +00:00
|
|
|
|
}
|
2004-04-12 23:59:37 +00:00
|
|
|
|
|
2004-03-21 11:28:44 +00:00
|
|
|
|
# Create the anchor for linking from the TOC to the section
|
|
|
|
|
|
$anchor = $canonized_headline;
|
|
|
|
|
|
if($refcount[$headlineCount] > 1 ) {
|
2004-06-08 18:11:28 +00:00
|
|
|
|
$anchor .= '_' . $refcount[$headlineCount];
|
2004-03-21 11:28:44 +00:00
|
|
|
|
}
|
2006-05-23 10:01:45 +00:00
|
|
|
|
if( $enoughToc && ( !isset($wgMaxTocLevel) || $toclevel<$wgMaxTocLevel ) ) {
|
2005-01-15 23:21:52 +00:00
|
|
|
|
$toc .= $sk->tocLine($anchor, $tocline, $numbering, $toclevel);
|
2004-02-26 13:37:26 +00:00
|
|
|
|
}
|
2004-09-21 11:54:45 +00:00
|
|
|
|
if( $showEditLink && ( !$istemplate || $templatetitle !== "" ) ) {
|
2004-03-29 14:48:07 +00:00
|
|
|
|
if ( empty( $head[$headlineCount] ) ) {
|
2004-06-08 18:11:28 +00:00
|
|
|
|
$head[$headlineCount] = '';
|
2004-03-29 14:48:07 +00:00
|
|
|
|
}
|
2004-09-21 08:31:25 +00:00
|
|
|
|
if( $istemplate )
|
|
|
|
|
|
$head[$headlineCount] .= $sk->editSectionLinkForOther($templatetitle, $templatesection);
|
|
|
|
|
|
else
|
2006-03-04 03:24:33 +00:00
|
|
|
|
$head[$headlineCount] .= $sk->editSectionLink($this->mTitle, $sectionCount+1, $headline_hint);
|
2004-02-26 13:37:26 +00:00
|
|
|
|
}
|
2004-04-12 23:59:37 +00:00
|
|
|
|
|
2004-04-04 01:45:02 +00:00
|
|
|
|
# give headline the correct <h#> tag
|
2004-08-22 17:24:50 +00:00
|
|
|
|
@$head[$headlineCount] .= "<a name=\"$anchor\"></a><h".$level.$matches[2][$headlineCount] .$headline.'</h'.$level.'>';
|
2004-04-12 23:59:37 +00:00
|
|
|
|
|
2004-03-21 11:28:44 +00:00
|
|
|
|
$headlineCount++;
|
2004-09-21 04:33:51 +00:00
|
|
|
|
if( !$istemplate )
|
|
|
|
|
|
$sectionCount++;
|
2004-04-12 23:59:37 +00:00
|
|
|
|
}
|
2004-02-26 13:37:26 +00:00
|
|
|
|
|
2006-05-23 10:01:45 +00:00
|
|
|
|
if( $enoughToc ) {
|
2006-04-25 19:43:46 +00:00
|
|
|
|
if( $toclevel<$wgMaxTocLevel ) {
|
|
|
|
|
|
$toc .= $sk->tocUnindent( $toclevel - 1 );
|
|
|
|
|
|
}
|
2005-01-15 23:21:52 +00:00
|
|
|
|
$toc = $sk->tocList( $toc );
|
2004-02-26 13:37:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2004-03-21 11:28:44 +00:00
|
|
|
|
# split up and insert constructed headlines
|
2004-04-12 23:59:37 +00:00
|
|
|
|
|
2004-06-08 18:11:28 +00:00
|
|
|
|
$blocks = preg_split( '/<H[1-6].*?' . '>.*?<\/H[1-6]>/i', $text );
|
2004-03-21 11:28:44 +00:00
|
|
|
|
$i = 0;
|
2004-02-26 13:37:26 +00:00
|
|
|
|
|
2004-03-21 11:28:44 +00:00
|
|
|
|
foreach( $blocks as $block ) {
|
2004-03-29 14:48:07 +00:00
|
|
|
|
if( $showEditLink && $headlineCount > 0 && $i == 0 && $block != "\n" ) {
|
2004-08-16 15:23:46 +00:00
|
|
|
|
# This is the [edit] link that appears for the top block of text when
|
2004-02-26 13:37:26 +00:00
|
|
|
|
# section editing is enabled
|
2004-04-11 16:46:06 +00:00
|
|
|
|
|
|
|
|
|
|
# Disabled because it broke block formatting
|
|
|
|
|
|
# For example, a bullet point in the top line
|
|
|
|
|
|
# $full .= $sk->editSectionLink(0);
|
2004-02-26 13:37:26 +00:00
|
|
|
|
}
|
2004-03-21 11:28:44 +00:00
|
|
|
|
$full .= $block;
|
2006-05-23 10:01:45 +00:00
|
|
|
|
if( $enoughToc && !$i && $isMain && !$this->mForceTocPosition ) {
|
2006-05-23 07:19:01 +00:00
|
|
|
|
# Top anchor now in skin
|
2004-04-07 16:12:18 +00:00
|
|
|
|
$full = $full.$toc;
|
2004-02-26 13:37:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2004-03-08 02:50:04 +00:00
|
|
|
|
if( !empty( $head[$i] ) ) {
|
|
|
|
|
|
$full .= $head[$i];
|
|
|
|
|
|
}
|
2004-02-26 13:37:26 +00:00
|
|
|
|
$i++;
|
|
|
|
|
|
}
|
2006-05-23 07:19:01 +00:00
|
|
|
|
if( $this->mForceTocPosition ) {
|
|
|
|
|
|
return str_replace( '<!--MWTOC-->', $toc, $full );
|
2004-06-29 23:59:30 +00:00
|
|
|
|
} else {
|
|
|
|
|
|
return $full;
|
|
|
|
|
|
}
|
2004-02-26 13:37:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2004-09-21 05:49:12 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* Transform wiki markup when saving a page by doing \r\n -> \n
|
|
|
|
|
|
* conversion, substitting signatures, {{subst:}} templates, etc.
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param string $text the text to transform
|
|
|
|
|
|
* @param Title &$title the Title object for the current article
|
|
|
|
|
|
* @param User &$user the User object describing the current user
|
|
|
|
|
|
* @param ParserOptions $options parsing options
|
|
|
|
|
|
* @param bool $clearState whether to clear the parser state first
|
|
|
|
|
|
* @return string the altered wiki markup
|
2006-04-19 15:46:24 +00:00
|
|
|
|
* @public
|
2004-09-21 05:49:12 +00:00
|
|
|
|
*/
|
2004-06-12 06:15:09 +00:00
|
|
|
|
function preSaveTransform( $text, &$title, &$user, $options, $clearState = true ) {
|
2004-03-06 01:49:16 +00:00
|
|
|
|
$this->mOptions = $options;
|
2004-03-27 22:47:25 +00:00
|
|
|
|
$this->mTitle =& $title;
|
2006-08-14 07:10:31 +00:00
|
|
|
|
$this->setOutputType( OT_WIKI );
|
2004-04-12 23:59:37 +00:00
|
|
|
|
|
2004-03-06 01:49:16 +00:00
|
|
|
|
if ( $clearState ) {
|
2004-03-08 09:09:35 +00:00
|
|
|
|
$this->clearState();
|
2004-03-06 01:49:16 +00:00
|
|
|
|
}
|
2004-04-12 23:59:37 +00:00
|
|
|
|
|
2004-03-06 01:49:16 +00:00
|
|
|
|
$stripState = false;
|
2004-04-09 16:22:12 +00:00
|
|
|
|
$pairs = array(
|
|
|
|
|
|
"\r\n" => "\n",
|
2005-04-21 06:30:48 +00:00
|
|
|
|
);
|
2004-11-20 11:28:37 +00:00
|
|
|
|
$text = str_replace( array_keys( $pairs ), array_values( $pairs ), $text );
|
2006-06-13 10:11:12 +00:00
|
|
|
|
$text = $this->strip( $text, $stripState, true, array( 'gallery' ) );
|
2006-04-29 02:20:30 +00:00
|
|
|
|
$text = $this->pstPass2( $text, $stripState, $user );
|
2004-03-06 01:49:16 +00:00
|
|
|
|
$text = $this->unstrip( $text, $stripState );
|
2004-06-02 12:29:15 +00:00
|
|
|
|
$text = $this->unstripNoWiki( $text, $stripState );
|
2004-03-06 01:49:16 +00:00
|
|
|
|
return $text;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2004-09-21 05:49:12 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* Pre-save transform helper function
|
2006-04-19 15:46:24 +00:00
|
|
|
|
* @private
|
2004-09-21 05:49:12 +00:00
|
|
|
|
*/
|
2006-04-29 02:20:30 +00:00
|
|
|
|
function pstPass2( $text, &$stripState, &$user ) {
|
2005-04-21 06:30:48 +00:00
|
|
|
|
global $wgContLang, $wgLocaltimezone;
|
2004-03-20 15:03:26 +00:00
|
|
|
|
|
2005-04-07 18:14:31 +00:00
|
|
|
|
/* Note: This is the timestamp saved as hardcoded wikitext to
|
|
|
|
|
|
* the database, we use $wgContLang here in order to give
|
2006-04-29 02:20:30 +00:00
|
|
|
|
* everyone the same signature and use the default one rather
|
|
|
|
|
|
* than the one selected in each user's preferences.
|
2005-04-07 18:14:31 +00:00
|
|
|
|
*/
|
2005-11-15 00:38:39 +00:00
|
|
|
|
if ( isset( $wgLocaltimezone ) ) {
|
|
|
|
|
|
$oldtz = getenv( 'TZ' );
|
|
|
|
|
|
putenv( 'TZ='.$wgLocaltimezone );
|
|
|
|
|
|
}
|
2005-07-03 02:08:12 +00:00
|
|
|
|
$d = $wgContLang->timeanddate( date( 'YmdHis' ), false, false) .
|
2004-06-08 18:11:28 +00:00
|
|
|
|
' (' . date( 'T' ) . ')';
|
2004-11-20 11:28:37 +00:00
|
|
|
|
if ( isset( $wgLocaltimezone ) ) {
|
2005-04-21 06:30:48 +00:00
|
|
|
|
putenv( 'TZ='.$oldtz );
|
2004-11-20 11:28:37 +00:00
|
|
|
|
}
|
2004-03-06 01:49:16 +00:00
|
|
|
|
|
2006-01-07 23:37:40 +00:00
|
|
|
|
# Variable replacement
|
|
|
|
|
|
# Because mOutputType is OT_WIKI, this will only process {{subst:xxx}} type tags
|
|
|
|
|
|
$text = $this->replaceVariables( $text );
|
2006-07-11 17:40:11 +00:00
|
|
|
|
|
2006-04-29 02:20:30 +00:00
|
|
|
|
# Strip out <nowiki> etc. added via replaceVariables
|
2006-06-13 10:11:12 +00:00
|
|
|
|
$text = $this->strip( $text, $stripState, false, array( 'gallery' ) );
|
2006-07-11 17:40:11 +00:00
|
|
|
|
|
2006-01-12 15:42:38 +00:00
|
|
|
|
# Signatures
|
|
|
|
|
|
$sigText = $this->getUserSig( $user );
|
2006-03-11 17:13:49 +00:00
|
|
|
|
$text = strtr( $text, array(
|
2006-01-12 15:42:38 +00:00
|
|
|
|
'~~~~~' => $d,
|
|
|
|
|
|
'~~~~' => "$sigText $d",
|
|
|
|
|
|
'~~~' => $sigText
|
|
|
|
|
|
) );
|
2006-01-07 23:37:40 +00:00
|
|
|
|
|
2004-03-06 01:49:16 +00:00
|
|
|
|
# Context links: [[|name]] and [[name (context)|]]
|
|
|
|
|
|
#
|
2005-12-05 07:44:14 +00:00
|
|
|
|
global $wgLegalTitleChars;
|
|
|
|
|
|
$tc = "[$wgLegalTitleChars]";
|
2006-01-07 13:31:29 +00:00
|
|
|
|
|
2004-03-06 01:49:16 +00:00
|
|
|
|
$namespacechar = '[ _0-9A-Za-z\x80-\xff]'; # Namespaces can use non-ascii!
|
2006-07-26 19:33:13 +00:00
|
|
|
|
$conpat = "/^{$tc}+?( \\({$tc}+\\)|)$/";
|
2004-03-06 01:49:16 +00:00
|
|
|
|
|
2006-07-26 18:20:12 +00:00
|
|
|
|
$p1 = "/\[\[(:?$namespacechar+:|:|)({$tc}+?)( \\({$tc}+\\)|)\\|]]/"; # [[ns:page (context)|]]
|
2006-07-26 18:09:04 +00:00
|
|
|
|
$p2 = "/\[\[\\|({$tc}+)]]/"; # [[|page]]
|
2004-03-06 01:49:16 +00:00
|
|
|
|
|
2006-07-26 18:09:04 +00:00
|
|
|
|
$text = preg_replace( $p1, '[[\\1\\2\\3|\\2]]', $text );
|
|
|
|
|
|
|
|
|
|
|
|
$t = $this->mTitle->getText();
|
2006-07-26 18:20:12 +00:00
|
|
|
|
if ( preg_match( $conpat, $t, $m ) && '' != $m[1] ) {
|
2006-07-26 19:33:13 +00:00
|
|
|
|
$text = preg_replace( $p2, "[[\\1{$m[1]}|\\1]]", $text );
|
2004-03-06 01:49:16 +00:00
|
|
|
|
} else {
|
2006-07-26 19:33:13 +00:00
|
|
|
|
# if $m[1] is empty, don't bother duplicating the title
|
2006-07-26 18:09:04 +00:00
|
|
|
|
$text = preg_replace( $p2, '[[\\1]]', $text );
|
2004-03-06 01:49:16 +00:00
|
|
|
|
}
|
2004-04-12 23:59:37 +00:00
|
|
|
|
|
2004-03-06 01:49:16 +00:00
|
|
|
|
# Trim trailing whitespace
|
2006-07-14 16:08:16 +00:00
|
|
|
|
# __END__ tag allows for trailing
|
2004-03-06 01:49:16 +00:00
|
|
|
|
# whitespace to be deliberately included
|
|
|
|
|
|
$text = rtrim( $text );
|
2006-07-14 15:39:23 +00:00
|
|
|
|
$mw =& MagicWord::get( 'end' );
|
2004-03-06 01:49:16 +00:00
|
|
|
|
$mw->matchAndRemove( $text );
|
|
|
|
|
|
|
|
|
|
|
|
return $text;
|
|
|
|
|
|
}
|
2006-01-07 13:31:29 +00:00
|
|
|
|
|
2005-11-15 00:38:39 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* Fetch the user's signature text, if any, and normalize to
|
|
|
|
|
|
* validated, ready-to-insert wikitext.
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param User $user
|
|
|
|
|
|
* @return string
|
2006-04-19 15:46:24 +00:00
|
|
|
|
* @private
|
2005-11-15 00:38:39 +00:00
|
|
|
|
*/
|
|
|
|
|
|
function getUserSig( &$user ) {
|
2006-01-07 23:09:21 +00:00
|
|
|
|
$username = $user->getName();
|
2006-01-08 03:39:26 +00:00
|
|
|
|
$nickname = $user->getOption( 'nickname' );
|
|
|
|
|
|
$nickname = $nickname === '' ? $username : $nickname;
|
2006-07-11 17:40:11 +00:00
|
|
|
|
|
2006-01-08 03:39:26 +00:00
|
|
|
|
if( $user->getBoolOption( 'fancysig' ) !== false ) {
|
2006-01-07 23:09:21 +00:00
|
|
|
|
# Sig. might contain markup; validate this
|
2006-01-08 03:09:31 +00:00
|
|
|
|
if( $this->validateSig( $nickname ) !== false ) {
|
2006-01-07 23:09:21 +00:00
|
|
|
|
# Validated; clean up (if needed) and return it
|
2006-04-30 20:09:44 +00:00
|
|
|
|
return $this->cleanSig( $nickname, true );
|
2005-11-15 00:38:39 +00:00
|
|
|
|
} else {
|
2006-01-07 23:09:21 +00:00
|
|
|
|
# Failed to validate; fall back to the default
|
|
|
|
|
|
$nickname = $username;
|
2006-01-08 03:09:31 +00:00
|
|
|
|
wfDebug( "Parser::getUserSig: $username has bad XML tags in signature.\n" );
|
2005-11-15 00:38:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2006-01-07 13:31:29 +00:00
|
|
|
|
|
2006-06-23 19:50:55 +00:00
|
|
|
|
// Make sure nickname doesnt get a sig in a sig
|
|
|
|
|
|
$nickname = $this->cleanSigInSig( $nickname );
|
|
|
|
|
|
|
2006-01-07 23:09:21 +00:00
|
|
|
|
# If we're still here, make it a link to the user page
|
|
|
|
|
|
$userpage = $user->getUserPage();
|
|
|
|
|
|
return( '[[' . $userpage->getPrefixedText() . '|' . wfEscapeWikiText( $nickname ) . ']]' );
|
2005-11-15 00:38:39 +00:00
|
|
|
|
}
|
2006-01-07 13:31:29 +00:00
|
|
|
|
|
2005-11-15 00:38:39 +00:00
|
|
|
|
/**
|
2006-01-07 23:09:21 +00:00
|
|
|
|
* Check that the user's signature contains no bad XML
|
2005-11-15 00:38:39 +00:00
|
|
|
|
*
|
|
|
|
|
|
* @param string $text
|
|
|
|
|
|
* @return mixed An expanded string, or false if invalid.
|
|
|
|
|
|
*/
|
|
|
|
|
|
function validateSig( $text ) {
|
2006-01-07 23:09:21 +00:00
|
|
|
|
return( wfIsWellFormedXmlFragment( $text ) ? $text : false );
|
2005-11-15 00:38:39 +00:00
|
|
|
|
}
|
2006-07-11 17:40:11 +00:00
|
|
|
|
|
2006-01-07 23:09:21 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* Clean up signature text
|
|
|
|
|
|
*
|
2006-06-23 19:50:55 +00:00
|
|
|
|
* 1) Strip ~~~, ~~~~ and ~~~~~ out of signatures @see cleanSigInSig
|
2006-01-13 09:47:09 +00:00
|
|
|
|
* 2) Substitute all transclusions
|
2006-01-07 23:09:21 +00:00
|
|
|
|
*
|
|
|
|
|
|
* @param string $text
|
2006-04-30 20:09:44 +00:00
|
|
|
|
* @param $parsing Whether we're cleaning (preferences save) or parsing
|
2006-01-13 09:47:09 +00:00
|
|
|
|
* @return string Signature text
|
2006-01-07 23:09:21 +00:00
|
|
|
|
*/
|
2006-04-30 20:09:44 +00:00
|
|
|
|
function cleanSig( $text, $parsing = false ) {
|
|
|
|
|
|
global $wgTitle;
|
|
|
|
|
|
$this->startExternalParse( $wgTitle, new ParserOptions(), $parsing ? OT_WIKI : OT_MSG );
|
2006-07-11 17:40:11 +00:00
|
|
|
|
|
2006-07-14 15:39:23 +00:00
|
|
|
|
$substWord = MagicWord::get( 'subst' );
|
2006-01-13 09:47:09 +00:00
|
|
|
|
$substRegex = '/\{\{(?!(?:' . $substWord->getBaseRegex() . '))/x' . $substWord->getRegexCase();
|
|
|
|
|
|
$substText = '{{' . $substWord->getSynonym( 0 );
|
|
|
|
|
|
|
|
|
|
|
|
$text = preg_replace( $substRegex, $substText, $text );
|
2006-06-23 21:54:31 +00:00
|
|
|
|
$text = $this->cleanSigInSig( $text );
|
2006-01-12 22:38:55 +00:00
|
|
|
|
$text = $this->replaceVariables( $text );
|
2006-07-11 17:40:11 +00:00
|
|
|
|
|
|
|
|
|
|
$this->clearState();
|
2006-01-08 05:29:58 +00:00
|
|
|
|
return $text;
|
2006-01-07 23:09:21 +00:00
|
|
|
|
}
|
2006-06-23 19:50:55 +00:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Strip ~~~, ~~~~ and ~~~~~ out of signatures
|
|
|
|
|
|
* @param string $text
|
|
|
|
|
|
* @return string Signature text with /~{3,5}/ removed
|
|
|
|
|
|
*/
|
|
|
|
|
|
function cleanSigInSig( $text ) {
|
|
|
|
|
|
$text = preg_replace( '/~{3,5}/', '', $text );
|
|
|
|
|
|
return $text;
|
|
|
|
|
|
}
|
2006-07-11 17:40:11 +00:00
|
|
|
|
|
2004-09-21 05:49:12 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* Set up some variables which are usually set up in parse()
|
|
|
|
|
|
* so that an external function can call some class members with confidence
|
2006-04-19 15:46:24 +00:00
|
|
|
|
* @public
|
2004-09-21 05:49:12 +00:00
|
|
|
|
*/
|
2004-06-12 06:15:09 +00:00
|
|
|
|
function startExternalParse( &$title, $options, $outputType, $clearState = true ) {
|
2004-03-27 22:47:25 +00:00
|
|
|
|
$this->mTitle =& $title;
|
|
|
|
|
|
$this->mOptions = $options;
|
2006-08-14 07:10:31 +00:00
|
|
|
|
$this->setOutputType( $outputType );
|
2004-03-27 22:47:25 +00:00
|
|
|
|
if ( $clearState ) {
|
|
|
|
|
|
$this->clearState();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2004-04-05 10:38:40 +00:00
|
|
|
|
|
2004-09-21 05:49:12 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* Transform a MediaWiki message by replacing magic variables.
|
2005-07-03 07:15:53 +00:00
|
|
|
|
*
|
2004-09-21 05:49:12 +00:00
|
|
|
|
* @param string $text the text to transform
|
|
|
|
|
|
* @param ParserOptions $options options
|
|
|
|
|
|
* @return string the text with variables substituted
|
2006-04-19 15:46:24 +00:00
|
|
|
|
* @public
|
2004-09-21 05:49:12 +00:00
|
|
|
|
*/
|
2004-04-05 10:38:40 +00:00
|
|
|
|
function transformMsg( $text, $options ) {
|
|
|
|
|
|
global $wgTitle;
|
|
|
|
|
|
static $executing = false;
|
2004-04-12 23:59:37 +00:00
|
|
|
|
|
2006-01-14 03:08:04 +00:00
|
|
|
|
$fname = "Parser::transformMsg";
|
|
|
|
|
|
|
2004-04-05 10:38:40 +00:00
|
|
|
|
# Guard against infinite recursion
|
|
|
|
|
|
if ( $executing ) {
|
|
|
|
|
|
return $text;
|
|
|
|
|
|
}
|
|
|
|
|
|
$executing = true;
|
|
|
|
|
|
|
2006-01-14 03:08:04 +00:00
|
|
|
|
wfProfileIn($fname);
|
|
|
|
|
|
|
2004-04-05 10:38:40 +00:00
|
|
|
|
$this->mTitle = $wgTitle;
|
|
|
|
|
|
$this->mOptions = $options;
|
2006-08-14 07:10:31 +00:00
|
|
|
|
$this->setOutputType( OT_MSG );
|
2004-04-05 10:38:40 +00:00
|
|
|
|
$this->clearState();
|
|
|
|
|
|
$text = $this->replaceVariables( $text );
|
2004-04-12 23:59:37 +00:00
|
|
|
|
|
2004-04-05 10:38:40 +00:00
|
|
|
|
$executing = false;
|
2006-01-14 03:08:04 +00:00
|
|
|
|
wfProfileOut($fname);
|
2004-04-05 10:38:40 +00:00
|
|
|
|
return $text;
|
|
|
|
|
|
}
|
2004-06-09 12:15:42 +00:00
|
|
|
|
|
2004-09-21 05:49:12 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* Create an HTML-style tag, e.g. <yourtag>special text</yourtag>
|
2006-02-28 05:18:36 +00:00
|
|
|
|
* The callback should have the following form:
|
|
|
|
|
|
* function myParserHook( $text, $params, &$parser ) { ... }
|
|
|
|
|
|
*
|
|
|
|
|
|
* Transform and return $text. Use $parser for any required context, e.g. use
|
|
|
|
|
|
* $parser->getTitle() and $parser->getOptions() not $wgTitle or $wgOut->mParserOptions
|
2005-11-26 23:04:05 +00:00
|
|
|
|
*
|
2006-04-19 15:46:24 +00:00
|
|
|
|
* @public
|
2005-11-26 23:04:05 +00:00
|
|
|
|
*
|
|
|
|
|
|
* @param mixed $tag The tag to use, e.g. 'hook' for <hook>
|
2005-11-27 02:33:20 +00:00
|
|
|
|
* @param mixed $callback The callback function (and object) to use for the tag
|
2005-11-26 23:04:05 +00:00
|
|
|
|
*
|
|
|
|
|
|
* @return The old value of the mTagHooks array associated with the hook
|
2004-09-21 05:49:12 +00:00
|
|
|
|
*/
|
2005-11-27 02:33:20 +00:00
|
|
|
|
function setHook( $tag, $callback ) {
|
2006-06-01 06:41:32 +00:00
|
|
|
|
$tag = strtolower( $tag );
|
2004-06-12 06:15:09 +00:00
|
|
|
|
$oldVal = @$this->mTagHooks[$tag];
|
|
|
|
|
|
$this->mTagHooks[$tag] = $callback;
|
2006-01-07 13:31:29 +00:00
|
|
|
|
|
2004-06-09 12:15:42 +00:00
|
|
|
|
return $oldVal;
|
|
|
|
|
|
}
|
2004-10-15 17:39:10 +00:00
|
|
|
|
|
2006-04-05 09:40:25 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* Create a function, e.g. {{sum:1|2|3}}
|
|
|
|
|
|
* The callback function should have the form:
|
|
|
|
|
|
* function myParserFunction( &$parser, $arg1, $arg2, $arg3 ) { ... }
|
|
|
|
|
|
*
|
|
|
|
|
|
* The callback may either return the text result of the function, or an array with the text
|
|
|
|
|
|
* in element 0, and a number of flags in the other elements. The names of the flags are
|
|
|
|
|
|
* specified in the keys. Valid flags are:
|
|
|
|
|
|
* found The text returned is valid, stop processing the template. This
|
|
|
|
|
|
* is on by default.
|
|
|
|
|
|
* nowiki Wiki markup in the return value should be escaped
|
|
|
|
|
|
* noparse Unsafe HTML tags should not be stripped, etc.
|
|
|
|
|
|
* noargs Don't replace triple-brace arguments in the return value
|
|
|
|
|
|
* isHTML The returned text is HTML, armour it against wikitext transformation
|
|
|
|
|
|
*
|
2006-04-19 15:46:24 +00:00
|
|
|
|
* @public
|
2006-04-05 09:40:25 +00:00
|
|
|
|
*
|
2006-08-04 17:59:59 +00:00
|
|
|
|
* @param string $id The magic word ID
|
2006-04-05 09:40:25 +00:00
|
|
|
|
* @param mixed $callback The callback function (and object) to use
|
2006-07-03 11:07:00 +00:00
|
|
|
|
* @param integer $flags a combination of the following flags:
|
|
|
|
|
|
* SFH_NO_HASH No leading hash, i.e. {{plural:...}} instead of {{#if:...}}
|
2006-04-05 09:40:25 +00:00
|
|
|
|
*
|
|
|
|
|
|
* @return The old callback function for this name, if any
|
|
|
|
|
|
*/
|
2006-07-03 11:07:00 +00:00
|
|
|
|
function setFunctionHook( $id, $callback, $flags = 0 ) {
|
2006-06-25 21:24:14 +00:00
|
|
|
|
$oldVal = @$this->mFunctionHooks[$id];
|
|
|
|
|
|
$this->mFunctionHooks[$id] = $callback;
|
2006-07-03 11:07:00 +00:00
|
|
|
|
|
2006-07-03 03:29:57 +00:00
|
|
|
|
# Add to function cache
|
2006-07-14 16:08:16 +00:00
|
|
|
|
$mw = MagicWord::get( $id );
|
|
|
|
|
|
if ( !$mw ) {
|
|
|
|
|
|
throw new MWException( 'The calling convention to Parser::setFunctionHook() has changed, ' .
|
|
|
|
|
|
'it is now required to pass a MagicWord ID as the first parameter.' );
|
2006-07-03 11:07:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2006-07-14 16:08:16 +00:00
|
|
|
|
$synonyms = $mw->getSynonyms();
|
|
|
|
|
|
$sensitive = intval( $mw->isCaseSensitive() );
|
|
|
|
|
|
|
2006-07-03 11:07:00 +00:00
|
|
|
|
foreach ( $synonyms as $syn ) {
|
|
|
|
|
|
# Case
|
|
|
|
|
|
if ( !$sensitive ) {
|
|
|
|
|
|
$syn = strtolower( $syn );
|
|
|
|
|
|
}
|
|
|
|
|
|
# Add leading hash
|
|
|
|
|
|
if ( !( $flags & SFH_NO_HASH ) ) {
|
|
|
|
|
|
$syn = '#' . $syn;
|
|
|
|
|
|
}
|
|
|
|
|
|
# Remove trailing colon
|
|
|
|
|
|
if ( substr( $syn, -1, 1 ) == ':' ) {
|
|
|
|
|
|
$syn = substr( $syn, 0, -1 );
|
|
|
|
|
|
}
|
|
|
|
|
|
$this->mFunctionSynonyms[$sensitive][$syn] = $id;
|
2006-07-02 17:43:32 +00:00
|
|
|
|
}
|
2006-07-03 03:29:57 +00:00
|
|
|
|
return $oldVal;
|
2006-07-02 17:43:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2004-10-15 17:39:10 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* Replace <!--LINK--> link placeholders with actual links, in the buffer
|
|
|
|
|
|
* Placeholders created in Skin::makeLinkObj()
|
|
|
|
|
|
* Returns an array of links found, indexed by PDBK:
|
|
|
|
|
|
* 0 - broken
|
|
|
|
|
|
* 1 - normal link
|
|
|
|
|
|
* 2 - stub
|
|
|
|
|
|
* $options is a bit field, RLH_FOR_UPDATE to select for update
|
|
|
|
|
|
*/
|
|
|
|
|
|
function replaceLinkHolders( &$text, $options = 0 ) {
|
2006-01-05 02:05:53 +00:00
|
|
|
|
global $wgUser;
|
2005-04-27 07:48:14 +00:00
|
|
|
|
global $wgOutputReplace;
|
2004-10-15 17:39:10 +00:00
|
|
|
|
|
|
|
|
|
|
$fname = 'Parser::replaceLinkHolders';
|
|
|
|
|
|
wfProfileIn( $fname );
|
|
|
|
|
|
|
|
|
|
|
|
$pdbks = array();
|
|
|
|
|
|
$colours = array();
|
2006-01-05 02:05:53 +00:00
|
|
|
|
$sk =& $this->mOptions->getSkin();
|
|
|
|
|
|
$linkCache =& LinkCache::singleton();
|
2005-07-03 07:15:53 +00:00
|
|
|
|
|
2005-04-27 07:48:14 +00:00
|
|
|
|
if ( !empty( $this->mLinkHolders['namespaces'] ) ) {
|
2004-10-15 17:39:10 +00:00
|
|
|
|
wfProfileIn( $fname.'-check' );
|
|
|
|
|
|
$dbr =& wfGetDB( DB_SLAVE );
|
2004-12-19 08:00:50 +00:00
|
|
|
|
$page = $dbr->tableName( 'page' );
|
2004-10-15 17:39:10 +00:00
|
|
|
|
$threshold = $wgUser->getOption('stubthreshold');
|
2005-07-03 07:15:53 +00:00
|
|
|
|
|
2004-10-15 17:39:10 +00:00
|
|
|
|
# Sort by namespace
|
2005-04-27 07:48:14 +00:00
|
|
|
|
asort( $this->mLinkHolders['namespaces'] );
|
2005-07-03 07:15:53 +00:00
|
|
|
|
|
2004-10-15 17:39:10 +00:00
|
|
|
|
# Generate query
|
|
|
|
|
|
$query = false;
|
2005-12-30 09:33:11 +00:00
|
|
|
|
foreach ( $this->mLinkHolders['namespaces'] as $key => $ns ) {
|
2004-10-15 17:39:10 +00:00
|
|
|
|
# Make title object
|
2005-04-27 07:48:14 +00:00
|
|
|
|
$title = $this->mLinkHolders['titles'][$key];
|
2004-10-15 17:39:10 +00:00
|
|
|
|
|
|
|
|
|
|
# Skip invalid entries.
|
|
|
|
|
|
# Result will be ugly, but prevents crash.
|
|
|
|
|
|
if ( is_null( $title ) ) {
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
$pdbk = $pdbks[$key] = $title->getPrefixedDBkey();
|
|
|
|
|
|
|
2005-12-30 09:33:11 +00:00
|
|
|
|
# Check if it's a static known link, e.g. interwiki
|
|
|
|
|
|
if ( $title->isAlwaysKnown() ) {
|
|
|
|
|
|
$colours[$pdbk] = 1;
|
2006-01-05 02:05:53 +00:00
|
|
|
|
} elseif ( ( $id = $linkCache->getGoodLinkID( $pdbk ) ) != 0 ) {
|
2004-10-15 17:39:10 +00:00
|
|
|
|
$colours[$pdbk] = 1;
|
2005-12-30 11:10:51 +00:00
|
|
|
|
$this->mOutput->addLink( $title, $id );
|
2006-01-05 02:05:53 +00:00
|
|
|
|
} elseif ( $linkCache->isBadLink( $pdbk ) ) {
|
2004-10-15 17:39:10 +00:00
|
|
|
|
$colours[$pdbk] = 0;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
# Not in the link cache, add it to the query
|
|
|
|
|
|
if ( !isset( $current ) ) {
|
2005-12-30 09:33:11 +00:00
|
|
|
|
$current = $ns;
|
2004-12-19 08:00:50 +00:00
|
|
|
|
$query = "SELECT page_id, page_namespace, page_title";
|
2004-10-15 17:39:10 +00:00
|
|
|
|
if ( $threshold > 0 ) {
|
2005-03-12 11:51:02 +00:00
|
|
|
|
$query .= ', page_len, page_is_redirect';
|
2004-12-19 08:00:50 +00:00
|
|
|
|
}
|
2005-12-30 09:33:11 +00:00
|
|
|
|
$query .= " FROM $page WHERE (page_namespace=$ns AND page_title IN(";
|
|
|
|
|
|
} elseif ( $current != $ns ) {
|
|
|
|
|
|
$current = $ns;
|
|
|
|
|
|
$query .= ")) OR (page_namespace=$ns AND page_title IN(";
|
2004-10-15 17:39:10 +00:00
|
|
|
|
} else {
|
|
|
|
|
|
$query .= ', ';
|
|
|
|
|
|
}
|
2005-07-03 07:15:53 +00:00
|
|
|
|
|
2005-04-27 07:48:14 +00:00
|
|
|
|
$query .= $dbr->addQuotes( $this->mLinkHolders['dbkeys'][$key] );
|
2004-10-15 17:39:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if ( $query ) {
|
|
|
|
|
|
$query .= '))';
|
|
|
|
|
|
if ( $options & RLH_FOR_UPDATE ) {
|
|
|
|
|
|
$query .= ' FOR UPDATE';
|
|
|
|
|
|
}
|
2005-07-03 07:15:53 +00:00
|
|
|
|
|
2004-10-15 17:39:10 +00:00
|
|
|
|
$res = $dbr->query( $query, $fname );
|
2005-07-03 07:15:53 +00:00
|
|
|
|
|
2004-10-15 17:39:10 +00:00
|
|
|
|
# Fetch data and form into an associative array
|
|
|
|
|
|
# non-existent = broken
|
|
|
|
|
|
# 1 = known
|
|
|
|
|
|
# 2 = stub
|
|
|
|
|
|
while ( $s = $dbr->fetchObject($res) ) {
|
2004-12-19 08:00:50 +00:00
|
|
|
|
$title = Title::makeTitle( $s->page_namespace, $s->page_title );
|
2004-10-15 17:39:10 +00:00
|
|
|
|
$pdbk = $title->getPrefixedDBkey();
|
2006-01-05 02:05:53 +00:00
|
|
|
|
$linkCache->addGoodLinkObj( $s->page_id, $title );
|
2005-12-30 11:10:51 +00:00
|
|
|
|
$this->mOutput->addLink( $title, $s->page_id );
|
2005-07-03 07:15:53 +00:00
|
|
|
|
|
2004-10-15 17:39:10 +00:00
|
|
|
|
if ( $threshold > 0 ) {
|
2004-12-19 08:00:50 +00:00
|
|
|
|
$size = $s->page_len;
|
2005-02-21 06:07:52 +00:00
|
|
|
|
if ( $s->page_is_redirect || $s->page_namespace != 0 || $size >= $threshold ) {
|
2004-10-15 17:39:10 +00:00
|
|
|
|
$colours[$pdbk] = 1;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
$colours[$pdbk] = 2;
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
$colours[$pdbk] = 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
wfProfileOut( $fname.'-check' );
|
2005-07-03 07:15:53 +00:00
|
|
|
|
|
2004-10-15 17:39:10 +00:00
|
|
|
|
# Construct search and replace arrays
|
|
|
|
|
|
wfProfileIn( $fname.'-construct' );
|
2005-04-27 07:48:14 +00:00
|
|
|
|
$wgOutputReplace = array();
|
|
|
|
|
|
foreach ( $this->mLinkHolders['namespaces'] as $key => $ns ) {
|
2004-10-15 17:39:10 +00:00
|
|
|
|
$pdbk = $pdbks[$key];
|
2005-04-27 07:48:14 +00:00
|
|
|
|
$searchkey = "<!--LINK $key-->";
|
|
|
|
|
|
$title = $this->mLinkHolders['titles'][$key];
|
2004-10-15 17:39:10 +00:00
|
|
|
|
if ( empty( $colours[$pdbk] ) ) {
|
2006-01-05 02:05:53 +00:00
|
|
|
|
$linkCache->addBadLinkObj( $title );
|
2004-10-15 17:39:10 +00:00
|
|
|
|
$colours[$pdbk] = 0;
|
2005-12-30 11:10:51 +00:00
|
|
|
|
$this->mOutput->addLink( $title, 0 );
|
2005-04-27 07:48:14 +00:00
|
|
|
|
$wgOutputReplace[$searchkey] = $sk->makeBrokenLinkObj( $title,
|
|
|
|
|
|
$this->mLinkHolders['texts'][$key],
|
|
|
|
|
|
$this->mLinkHolders['queries'][$key] );
|
2004-10-15 17:39:10 +00:00
|
|
|
|
} elseif ( $colours[$pdbk] == 1 ) {
|
2005-04-27 07:48:14 +00:00
|
|
|
|
$wgOutputReplace[$searchkey] = $sk->makeKnownLinkObj( $title,
|
|
|
|
|
|
$this->mLinkHolders['texts'][$key],
|
|
|
|
|
|
$this->mLinkHolders['queries'][$key] );
|
2004-10-15 17:39:10 +00:00
|
|
|
|
} elseif ( $colours[$pdbk] == 2 ) {
|
2005-04-27 07:48:14 +00:00
|
|
|
|
$wgOutputReplace[$searchkey] = $sk->makeStubLinkObj( $title,
|
|
|
|
|
|
$this->mLinkHolders['texts'][$key],
|
|
|
|
|
|
$this->mLinkHolders['queries'][$key] );
|
2004-10-15 17:39:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
wfProfileOut( $fname.'-construct' );
|
|
|
|
|
|
|
|
|
|
|
|
# Do the thing
|
|
|
|
|
|
wfProfileIn( $fname.'-replace' );
|
2005-07-03 07:15:53 +00:00
|
|
|
|
|
2004-10-15 17:39:10 +00:00
|
|
|
|
$text = preg_replace_callback(
|
|
|
|
|
|
'/(<!--LINK .*?-->)/',
|
2005-04-27 07:48:14 +00:00
|
|
|
|
"wfOutputReplaceMatches",
|
2004-10-15 17:39:10 +00:00
|
|
|
|
$text);
|
2005-04-27 07:48:14 +00:00
|
|
|
|
|
2004-10-15 17:39:10 +00:00
|
|
|
|
wfProfileOut( $fname.'-replace' );
|
2004-11-13 14:24:42 +00:00
|
|
|
|
}
|
2004-10-15 17:39:10 +00:00
|
|
|
|
|
2005-04-27 07:48:14 +00:00
|
|
|
|
# Now process interwiki link holders
|
|
|
|
|
|
# This is quite a bit simpler than internal links
|
2005-06-03 05:46:24 +00:00
|
|
|
|
if ( !empty( $this->mInterwikiLinkHolders['texts'] ) ) {
|
2004-10-15 17:39:10 +00:00
|
|
|
|
wfProfileIn( $fname.'-interwiki' );
|
2005-04-27 07:48:14 +00:00
|
|
|
|
# Make interwiki link HTML
|
|
|
|
|
|
$wgOutputReplace = array();
|
2005-06-03 05:46:24 +00:00
|
|
|
|
foreach( $this->mInterwikiLinkHolders['texts'] as $key => $link ) {
|
|
|
|
|
|
$title = $this->mInterwikiLinkHolders['titles'][$key];
|
|
|
|
|
|
$wgOutputReplace[$key] = $sk->makeLinkObj( $title, $link );
|
2005-04-27 07:48:14 +00:00
|
|
|
|
}
|
2005-07-03 07:15:53 +00:00
|
|
|
|
|
2004-10-15 17:39:10 +00:00
|
|
|
|
$text = preg_replace_callback(
|
|
|
|
|
|
'/<!--IWLINK (.*?)-->/',
|
2005-04-27 07:48:14 +00:00
|
|
|
|
"wfOutputReplaceMatches",
|
2004-11-20 11:28:37 +00:00
|
|
|
|
$text );
|
2004-10-15 17:39:10 +00:00
|
|
|
|
wfProfileOut( $fname.'-interwiki' );
|
|
|
|
|
|
}
|
2005-07-03 07:15:53 +00:00
|
|
|
|
|
2004-10-15 17:39:10 +00:00
|
|
|
|
wfProfileOut( $fname );
|
|
|
|
|
|
return $colours;
|
|
|
|
|
|
}
|
2005-07-03 07:15:53 +00:00
|
|
|
|
|
2005-05-31 08:49:03 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* Replace <!--LINK--> link placeholders with plain text of links
|
|
|
|
|
|
* (not HTML-formatted).
|
|
|
|
|
|
* @param string $text
|
|
|
|
|
|
* @return string
|
|
|
|
|
|
*/
|
|
|
|
|
|
function replaceLinkHoldersText( $text ) {
|
|
|
|
|
|
$fname = 'Parser::replaceLinkHoldersText';
|
|
|
|
|
|
wfProfileIn( $fname );
|
|
|
|
|
|
|
|
|
|
|
|
$text = preg_replace_callback(
|
|
|
|
|
|
'/<!--(LINK|IWLINK) (.*?)-->/',
|
|
|
|
|
|
array( &$this, 'replaceLinkHoldersTextCallback' ),
|
|
|
|
|
|
$text );
|
2005-07-03 07:15:53 +00:00
|
|
|
|
|
2005-05-31 08:49:03 +00:00
|
|
|
|
wfProfileOut( $fname );
|
|
|
|
|
|
return $text;
|
|
|
|
|
|
}
|
2005-07-03 07:15:53 +00:00
|
|
|
|
|
2005-05-31 08:49:03 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* @param array $matches
|
|
|
|
|
|
* @return string
|
2006-04-19 15:46:24 +00:00
|
|
|
|
* @private
|
2005-05-31 08:49:03 +00:00
|
|
|
|
*/
|
|
|
|
|
|
function replaceLinkHoldersTextCallback( $matches ) {
|
|
|
|
|
|
$type = $matches[1];
|
|
|
|
|
|
$key = $matches[2];
|
|
|
|
|
|
if( $type == 'LINK' ) {
|
|
|
|
|
|
if( isset( $this->mLinkHolders['texts'][$key] ) ) {
|
|
|
|
|
|
return $this->mLinkHolders['texts'][$key];
|
|
|
|
|
|
}
|
|
|
|
|
|
} elseif( $type == 'IWLINK' ) {
|
2005-06-03 05:46:24 +00:00
|
|
|
|
if( isset( $this->mInterwikiLinkHolders['texts'][$key] ) ) {
|
|
|
|
|
|
return $this->mInterwikiLinkHolders['texts'][$key];
|
2005-05-31 08:49:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return $matches[0];
|
|
|
|
|
|
}
|
2004-11-20 11:28:37 +00:00
|
|
|
|
|
2006-06-06 22:56:38 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* Tag hook handler for 'pre'.
|
|
|
|
|
|
*/
|
|
|
|
|
|
function renderPreTag( $text, $attribs, $parser ) {
|
|
|
|
|
|
// Backwards-compatibility hack
|
|
|
|
|
|
$content = preg_replace( '!<nowiki>(.*?)</nowiki>!is', '\\1', $text );
|
2006-07-11 17:40:11 +00:00
|
|
|
|
|
2006-06-06 22:56:38 +00:00
|
|
|
|
$attribs = Sanitizer::validateTagAttributes( $attribs, 'pre' );
|
|
|
|
|
|
return wfOpenElement( 'pre', $attribs ) .
|
|
|
|
|
|
wfEscapeHTMLTagsOnly( $content ) .
|
|
|
|
|
|
'</pre>';
|
|
|
|
|
|
}
|
2006-07-11 17:40:11 +00:00
|
|
|
|
|
2004-11-13 12:04:31 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* Renders an image gallery from a text with one line per image.
|
|
|
|
|
|
* text labels may be given by using |-style alternative text. E.g.
|
|
|
|
|
|
* Image:one.jpg|The number "1"
|
|
|
|
|
|
* Image:tree.jpg|A tree
|
|
|
|
|
|
* given as text will return the HTML of a gallery with two images,
|
|
|
|
|
|
* labeled 'The number "1"' and
|
|
|
|
|
|
* 'A tree'.
|
|
|
|
|
|
*/
|
2006-06-24 00:12:34 +00:00
|
|
|
|
function renderImageGallery( $text, $params ) {
|
2004-11-13 12:04:31 +00:00
|
|
|
|
$ig = new ImageGallery();
|
|
|
|
|
|
$ig->setShowBytes( false );
|
|
|
|
|
|
$ig->setShowFilename( false );
|
2006-05-16 19:15:58 +00:00
|
|
|
|
$ig->setParsing();
|
2006-06-24 00:12:34 +00:00
|
|
|
|
$ig->useSkin( $this->mOptions->getSkin() );
|
2004-11-20 11:28:37 +00:00
|
|
|
|
|
2006-06-24 00:12:34 +00:00
|
|
|
|
if( isset( $params['caption'] ) )
|
2006-06-24 00:27:16 +00:00
|
|
|
|
$ig->setCaption( $params['caption'] );
|
2006-07-11 17:40:11 +00:00
|
|
|
|
|
2006-06-24 00:12:34 +00:00
|
|
|
|
$lines = explode( "\n", $text );
|
2004-11-13 12:04:31 +00:00
|
|
|
|
foreach ( $lines as $line ) {
|
2004-11-20 11:28:37 +00:00
|
|
|
|
# match lines like these:
|
|
|
|
|
|
# Image:someimage.jpg|This is some image
|
2004-11-13 12:04:31 +00:00
|
|
|
|
preg_match( "/^([^|]+)(\\|(.*))?$/", $line, $matches );
|
|
|
|
|
|
# Skip empty lines
|
|
|
|
|
|
if ( count( $matches ) == 0 ) {
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
2006-07-11 14:03:17 +00:00
|
|
|
|
$tp = Title::newFromText( $matches[1] );
|
|
|
|
|
|
$nt =& $tp;
|
2004-12-15 09:07:21 +00:00
|
|
|
|
if( is_null( $nt ) ) {
|
|
|
|
|
|
# Bogus title. Ignore these so we don't bomb out later.
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
2004-11-13 12:04:31 +00:00
|
|
|
|
if ( isset( $matches[3] ) ) {
|
|
|
|
|
|
$label = $matches[3];
|
|
|
|
|
|
} else {
|
|
|
|
|
|
$label = '';
|
|
|
|
|
|
}
|
2005-07-03 07:15:53 +00:00
|
|
|
|
|
2006-06-01 21:22:05 +00:00
|
|
|
|
$pout = $this->parse( $label,
|
|
|
|
|
|
$this->mTitle,
|
|
|
|
|
|
$this->mOptions,
|
|
|
|
|
|
false, // Strip whitespace...?
|
|
|
|
|
|
false // Don't clear state!
|
|
|
|
|
|
);
|
2006-01-07 00:44:28 +00:00
|
|
|
|
$html = $pout->getText();
|
2005-07-03 07:15:53 +00:00
|
|
|
|
|
2005-04-10 18:29:30 +00:00
|
|
|
|
$ig->add( new Image( $nt ), $html );
|
2006-05-09 18:01:15 +00:00
|
|
|
|
|
|
|
|
|
|
# Only add real images (bug #5586)
|
|
|
|
|
|
if ( $nt->getNamespace() == NS_IMAGE ) {
|
|
|
|
|
|
$this->mOutput->addImage( $nt->getDBkey() );
|
|
|
|
|
|
}
|
2004-11-13 12:04:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
return $ig->toHTML();
|
|
|
|
|
|
}
|
2005-04-27 07:48:14 +00:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Parse image options text and use it to make an image
|
|
|
|
|
|
*/
|
|
|
|
|
|
function makeImage( &$nt, $options ) {
|
2006-03-07 01:10:39 +00:00
|
|
|
|
global $wgUseImageResize;
|
2005-07-03 07:15:53 +00:00
|
|
|
|
|
2005-04-27 07:48:14 +00:00
|
|
|
|
$align = '';
|
|
|
|
|
|
|
|
|
|
|
|
# Check if the options text is of the form "options|alt text"
|
|
|
|
|
|
# Options are:
|
|
|
|
|
|
# * thumbnail make a thumbnail with enlarge-icon and caption, alignment depends on lang
|
|
|
|
|
|
# * left no resizing, just left align. label is used for alt= only
|
|
|
|
|
|
# * right same, but right aligned
|
|
|
|
|
|
# * none same, but not aligned
|
|
|
|
|
|
# * ___px scale to ___ pixels width, no aligning. e.g. use in taxobox
|
|
|
|
|
|
# * center center the image
|
|
|
|
|
|
# * framed Keep original image size, no magnify-button.
|
|
|
|
|
|
|
|
|
|
|
|
$part = explode( '|', $options);
|
|
|
|
|
|
|
2006-07-14 15:39:23 +00:00
|
|
|
|
$mwThumb =& MagicWord::get( 'img_thumbnail' );
|
|
|
|
|
|
$mwManualThumb =& MagicWord::get( 'img_manualthumb' );
|
|
|
|
|
|
$mwLeft =& MagicWord::get( 'img_left' );
|
|
|
|
|
|
$mwRight =& MagicWord::get( 'img_right' );
|
|
|
|
|
|
$mwNone =& MagicWord::get( 'img_none' );
|
|
|
|
|
|
$mwWidth =& MagicWord::get( 'img_width' );
|
|
|
|
|
|
$mwCenter =& MagicWord::get( 'img_center' );
|
|
|
|
|
|
$mwFramed =& MagicWord::get( 'img_framed' );
|
2005-04-27 07:48:14 +00:00
|
|
|
|
$caption = '';
|
|
|
|
|
|
|
|
|
|
|
|
$width = $height = $framed = $thumb = false;
|
2005-06-27 01:35:22 +00:00
|
|
|
|
$manual_thumb = '' ;
|
2005-04-27 07:48:14 +00:00
|
|
|
|
|
|
|
|
|
|
foreach( $part as $key => $val ) {
|
|
|
|
|
|
if ( $wgUseImageResize && ! is_null( $mwThumb->matchVariableStartToEnd($val) ) ) {
|
|
|
|
|
|
$thumb=true;
|
2005-08-20 13:27:21 +00:00
|
|
|
|
} elseif ( ! is_null( $match = $mwManualThumb->matchVariableStartToEnd($val) ) ) {
|
2005-04-27 07:48:14 +00:00
|
|
|
|
# use manually specified thumbnail
|
|
|
|
|
|
$thumb=true;
|
2005-08-20 13:27:21 +00:00
|
|
|
|
$manual_thumb = $match;
|
2005-04-27 07:48:14 +00:00
|
|
|
|
} elseif ( ! is_null( $mwRight->matchVariableStartToEnd($val) ) ) {
|
|
|
|
|
|
# remember to set an alignment, don't render immediately
|
|
|
|
|
|
$align = 'right';
|
|
|
|
|
|
} elseif ( ! is_null( $mwLeft->matchVariableStartToEnd($val) ) ) {
|
|
|
|
|
|
# remember to set an alignment, don't render immediately
|
|
|
|
|
|
$align = 'left';
|
|
|
|
|
|
} elseif ( ! is_null( $mwCenter->matchVariableStartToEnd($val) ) ) {
|
|
|
|
|
|
# remember to set an alignment, don't render immediately
|
|
|
|
|
|
$align = 'center';
|
|
|
|
|
|
} elseif ( ! is_null( $mwNone->matchVariableStartToEnd($val) ) ) {
|
|
|
|
|
|
# remember to set an alignment, don't render immediately
|
|
|
|
|
|
$align = 'none';
|
|
|
|
|
|
} elseif ( $wgUseImageResize && ! is_null( $match = $mwWidth->matchVariableStartToEnd($val) ) ) {
|
2006-07-14 16:08:16 +00:00
|
|
|
|
wfDebug( "img_width match: $match\n" );
|
2005-04-27 07:48:14 +00:00
|
|
|
|
# $match is the image width in pixels
|
|
|
|
|
|
if ( preg_match( '/^([0-9]*)x([0-9]*)$/', $match, $m ) ) {
|
|
|
|
|
|
$width = intval( $m[1] );
|
|
|
|
|
|
$height = intval( $m[2] );
|
|
|
|
|
|
} else {
|
|
|
|
|
|
$width = intval($match);
|
|
|
|
|
|
}
|
|
|
|
|
|
} elseif ( ! is_null( $mwFramed->matchVariableStartToEnd($val) ) ) {
|
|
|
|
|
|
$framed=true;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
$caption = $val;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
# Strip bad stuff out of the alt text
|
2005-05-31 08:49:03 +00:00
|
|
|
|
$alt = $this->replaceLinkHoldersText( $caption );
|
2006-03-24 16:48:10 +00:00
|
|
|
|
|
|
|
|
|
|
# make sure there are no placeholders in thumbnail attributes
|
|
|
|
|
|
# that are later expanded to html- so expand them now and
|
|
|
|
|
|
# remove the tags
|
|
|
|
|
|
$alt = $this->unstrip($alt, $this->mStripState);
|
2005-04-27 07:48:14 +00:00
|
|
|
|
$alt = Sanitizer::stripAllTags( $alt );
|
|
|
|
|
|
|
|
|
|
|
|
# Linker does the rest
|
|
|
|
|
|
$sk =& $this->mOptions->getSkin();
|
2006-08-13 23:42:38 +00:00
|
|
|
|
return $sk->makeImageLinkObj( $nt, $caption, $alt, $align, $width, $height, $framed, $thumb, $manual_thumb );
|
2005-04-27 07:48:14 +00:00
|
|
|
|
}
|
2005-08-07 12:09:46 +00:00
|
|
|
|
|
|
|
|
|
|
/**
|
2006-01-07 13:09:30 +00:00
|
|
|
|
* Set a flag in the output object indicating that the content is dynamic and
|
2005-08-07 12:09:46 +00:00
|
|
|
|
* shouldn't be cached.
|
|
|
|
|
|
*/
|
|
|
|
|
|
function disableCache() {
|
2006-05-13 17:40:59 +00:00
|
|
|
|
wfDebug( "Parser output marked as uncacheable.\n" );
|
2005-08-07 12:09:46 +00:00
|
|
|
|
$this->mOutput->mCacheTime = -1;
|
|
|
|
|
|
}
|
2006-01-07 13:31:29 +00:00
|
|
|
|
|
2006-03-11 17:13:49 +00:00
|
|
|
|
/**#@+
|
2005-08-23 21:49:48 +00:00
|
|
|
|
* Callback from the Sanitizer for expanding items found in HTML attribute
|
|
|
|
|
|
* values, so they can be safely tested and escaped.
|
|
|
|
|
|
* @param string $text
|
|
|
|
|
|
* @param array $args
|
|
|
|
|
|
* @return string
|
2006-04-19 15:46:24 +00:00
|
|
|
|
* @private
|
2005-08-23 21:49:48 +00:00
|
|
|
|
*/
|
|
|
|
|
|
function attributeStripCallback( &$text, $args ) {
|
|
|
|
|
|
$text = $this->replaceVariables( $text, $args );
|
2005-08-29 23:34:37 +00:00
|
|
|
|
$text = $this->unstripForHTML( $text );
|
|
|
|
|
|
return $text;
|
|
|
|
|
|
}
|
2006-01-07 13:31:29 +00:00
|
|
|
|
|
2005-08-29 23:34:37 +00:00
|
|
|
|
function unstripForHTML( $text ) {
|
2005-08-23 21:49:48 +00:00
|
|
|
|
$text = $this->unstrip( $text, $this->mStripState );
|
|
|
|
|
|
$text = $this->unstripNoWiki( $text, $this->mStripState );
|
|
|
|
|
|
return $text;
|
|
|
|
|
|
}
|
2006-01-08 15:13:37 +00:00
|
|
|
|
/**#@-*/
|
2005-12-19 01:02:29 +00:00
|
|
|
|
|
2006-01-08 15:13:37 +00:00
|
|
|
|
/**#@+
|
|
|
|
|
|
* Accessor/mutator
|
|
|
|
|
|
*/
|
2005-12-19 01:02:29 +00:00
|
|
|
|
function Title( $x = NULL ) { return wfSetVar( $this->mTitle, $x ); }
|
|
|
|
|
|
function Options( $x = NULL ) { return wfSetVar( $this->mOptions, $x ); }
|
|
|
|
|
|
function OutputType( $x = NULL ) { return wfSetVar( $this->mOutputType, $x ); }
|
2006-01-08 15:13:37 +00:00
|
|
|
|
/**#@-*/
|
|
|
|
|
|
|
|
|
|
|
|
/**#@+
|
|
|
|
|
|
* Accessor
|
|
|
|
|
|
*/
|
|
|
|
|
|
function getTags() { return array_keys( $this->mTagHooks ); }
|
|
|
|
|
|
/**#@-*/
|
2006-06-06 00:51:34 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Break wikitext input into sections, and either pull or replace
|
|
|
|
|
|
* some particular section's text.
|
|
|
|
|
|
*
|
|
|
|
|
|
* External callers should use the getSection and replaceSection methods.
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param $text Page wikitext
|
|
|
|
|
|
* @param $section Numbered section. 0 pulls the text before the first
|
|
|
|
|
|
* heading; other numbers will pull the given section
|
|
|
|
|
|
* along with its lower-level subsections.
|
|
|
|
|
|
* @param $mode One of "get" or "replace"
|
|
|
|
|
|
* @param $newtext Replacement text for section data.
|
|
|
|
|
|
* @return string for "get", the extracted section text.
|
|
|
|
|
|
* for "replace", the whole page with the section replaced.
|
|
|
|
|
|
*/
|
|
|
|
|
|
private function extractSections( $text, $section, $mode, $newtext='' ) {
|
|
|
|
|
|
# strip NOWIKI etc. to avoid confusion (true-parameter causes HTML
|
|
|
|
|
|
# comments to be stripped as well)
|
|
|
|
|
|
$striparray = array();
|
2006-07-11 17:40:11 +00:00
|
|
|
|
|
2006-06-06 00:51:34 +00:00
|
|
|
|
$oldOutputType = $this->mOutputType;
|
|
|
|
|
|
$oldOptions = $this->mOptions;
|
|
|
|
|
|
$this->mOptions = new ParserOptions();
|
2006-08-14 07:10:31 +00:00
|
|
|
|
$this->setOutputType( OT_WIKI );
|
2006-07-11 17:40:11 +00:00
|
|
|
|
|
2006-06-06 00:51:34 +00:00
|
|
|
|
$striptext = $this->strip( $text, $striparray, true );
|
2006-07-11 17:40:11 +00:00
|
|
|
|
|
2006-08-14 07:10:31 +00:00
|
|
|
|
$this->setOutputType( $oldOutputType );
|
2006-06-06 00:51:34 +00:00
|
|
|
|
$this->mOptions = $oldOptions;
|
|
|
|
|
|
|
|
|
|
|
|
# now that we can be sure that no pseudo-sections are in the source,
|
|
|
|
|
|
# split it up by section
|
|
|
|
|
|
$uniq = preg_quote( $this->uniqPrefix(), '/' );
|
|
|
|
|
|
$comment = "(?:$uniq-!--.*?QINU)";
|
|
|
|
|
|
$secs = preg_split(
|
|
|
|
|
|
/*
|
|
|
|
|
|
"/
|
|
|
|
|
|
^(
|
|
|
|
|
|
(?:$comment|<\/?noinclude>)* # Initial comments will be stripped
|
|
|
|
|
|
(?:
|
|
|
|
|
|
(=+) # Should this be limited to 6?
|
|
|
|
|
|
.+? # Section title...
|
|
|
|
|
|
\\2 # Ending = count must match start
|
|
|
|
|
|
|
|
|
|
|
|
|
^
|
|
|
|
|
|
<h([1-6])\b.*?>
|
|
|
|
|
|
.*?
|
|
|
|
|
|
<\/h\\3\s*>
|
|
|
|
|
|
)
|
|
|
|
|
|
(?:$comment|<\/?noinclude>|\s+)* # Trailing whitespace ok
|
|
|
|
|
|
)$
|
|
|
|
|
|
/mix",
|
|
|
|
|
|
*/
|
|
|
|
|
|
"/
|
|
|
|
|
|
(
|
|
|
|
|
|
^
|
|
|
|
|
|
(?:$comment|<\/?noinclude>)* # Initial comments will be stripped
|
|
|
|
|
|
(=+) # Should this be limited to 6?
|
|
|
|
|
|
.+? # Section title...
|
|
|
|
|
|
\\2 # Ending = count must match start
|
2006-06-21 23:13:05 +00:00
|
|
|
|
(?:$comment|<\/?noinclude>|[ \\t]+)* # Trailing whitespace ok
|
2006-06-06 00:51:34 +00:00
|
|
|
|
$
|
|
|
|
|
|
|
|
|
|
|
|
|
<h([1-6])\b.*?>
|
|
|
|
|
|
.*?
|
|
|
|
|
|
<\/h\\3\s*>
|
|
|
|
|
|
)
|
|
|
|
|
|
/mix",
|
|
|
|
|
|
$striptext, -1,
|
|
|
|
|
|
PREG_SPLIT_DELIM_CAPTURE);
|
2006-07-11 17:40:11 +00:00
|
|
|
|
|
2006-06-06 00:51:34 +00:00
|
|
|
|
if( $mode == "get" ) {
|
|
|
|
|
|
if( $section == 0 ) {
|
|
|
|
|
|
// "Section 0" returns the content before any other section.
|
|
|
|
|
|
$rv = $secs[0];
|
|
|
|
|
|
} else {
|
|
|
|
|
|
$rv = "";
|
|
|
|
|
|
}
|
|
|
|
|
|
} elseif( $mode == "replace" ) {
|
|
|
|
|
|
if( $section == 0 ) {
|
|
|
|
|
|
$rv = $newtext . "\n\n";
|
|
|
|
|
|
$remainder = true;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
$rv = $secs[0];
|
|
|
|
|
|
$remainder = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
$count = 0;
|
|
|
|
|
|
$sectionLevel = 0;
|
|
|
|
|
|
for( $index = 1; $index < count( $secs ); ) {
|
|
|
|
|
|
$headerLine = $secs[$index++];
|
|
|
|
|
|
if( $secs[$index] ) {
|
|
|
|
|
|
// A wiki header
|
|
|
|
|
|
$headerLevel = strlen( $secs[$index++] );
|
|
|
|
|
|
} else {
|
|
|
|
|
|
// An HTML header
|
|
|
|
|
|
$index++;
|
|
|
|
|
|
$headerLevel = intval( $secs[$index++] );
|
|
|
|
|
|
}
|
|
|
|
|
|
$content = $secs[$index++];
|
|
|
|
|
|
|
|
|
|
|
|
$count++;
|
|
|
|
|
|
if( $mode == "get" ) {
|
|
|
|
|
|
if( $count == $section ) {
|
|
|
|
|
|
$rv = $headerLine . $content;
|
|
|
|
|
|
$sectionLevel = $headerLevel;
|
|
|
|
|
|
} elseif( $count > $section ) {
|
|
|
|
|
|
if( $sectionLevel && $headerLevel > $sectionLevel ) {
|
|
|
|
|
|
$rv .= $headerLine . $content;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
// Broke out to a higher-level section
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
} elseif( $mode == "replace" ) {
|
|
|
|
|
|
if( $count < $section ) {
|
|
|
|
|
|
$rv .= $headerLine . $content;
|
|
|
|
|
|
} elseif( $count == $section ) {
|
|
|
|
|
|
$rv .= $newtext . "\n\n";
|
|
|
|
|
|
$sectionLevel = $headerLevel;
|
|
|
|
|
|
} elseif( $count > $section ) {
|
|
|
|
|
|
if( $headerLevel <= $sectionLevel ) {
|
|
|
|
|
|
// Passed the section's sub-parts.
|
|
|
|
|
|
$remainder = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
if( $remainder ) {
|
|
|
|
|
|
$rv .= $headerLine . $content;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
# reinsert stripped tags
|
|
|
|
|
|
$rv = $this->unstrip( $rv, $striparray );
|
|
|
|
|
|
$rv = $this->unstripNoWiki( $rv, $striparray );
|
|
|
|
|
|
$rv = trim( $rv );
|
|
|
|
|
|
return $rv;
|
|
|
|
|
|
}
|
2006-07-11 17:40:11 +00:00
|
|
|
|
|
2006-06-06 00:51:34 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* This function returns the text of a section, specified by a number ($section).
|
|
|
|
|
|
* A section is text under a heading like == Heading == or \<h1\>Heading\</h1\>, or
|
|
|
|
|
|
* the first section before any such heading (section 0).
|
|
|
|
|
|
*
|
|
|
|
|
|
* If a section contains subsections, these are also returned.
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param $text String: text to look in
|
|
|
|
|
|
* @param $section Integer: section number
|
|
|
|
|
|
* @return string text of the requested section
|
|
|
|
|
|
*/
|
|
|
|
|
|
function getSection( $text, $section ) {
|
|
|
|
|
|
return $this->extractSections( $text, $section, "get" );
|
|
|
|
|
|
}
|
2006-07-11 17:40:11 +00:00
|
|
|
|
|
2006-06-06 00:51:34 +00:00
|
|
|
|
function replaceSection( $oldtext, $section, $text ) {
|
|
|
|
|
|
return $this->extractSections( $oldtext, $section, "replace", $text );
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2004-02-26 13:37:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* @todo document
|
2004-09-03 23:00:01 +00:00
|
|
|
|
* @package MediaWiki
|
2004-09-02 23:28:24 +00:00
|
|
|
|
*/
|
2004-02-26 13:37:26 +00:00
|
|
|
|
class ParserOutput
|
|
|
|
|
|
{
|
2006-05-11 22:40:38 +00:00
|
|
|
|
var $mText, # The output text
|
2006-05-11 19:10:41 +00:00
|
|
|
|
$mLanguageLinks, # List of the full text of language links, in the order they appear
|
2006-05-11 22:40:38 +00:00
|
|
|
|
$mCategories, # Map of category names to sort keys
|
|
|
|
|
|
$mContainsOldMagic, # Boolean variable indicating if the input contained variables like {{CURRENTDAY}}
|
|
|
|
|
|
$mCacheTime, # Time when this object was generated, or -1 for uncacheable. Used in ParserCache.
|
|
|
|
|
|
$mVersion, # Compatibility check
|
|
|
|
|
|
$mTitleText, # title text of the chosen language variant
|
2006-05-11 19:10:41 +00:00
|
|
|
|
$mLinks, # 2-D map of NS/DBK to ID for the links in the document. ID=zero for broken.
|
|
|
|
|
|
$mTemplates, # 2-D map of NS/DBK to ID for the template references. ID=zero for broken.
|
2006-05-11 22:40:38 +00:00
|
|
|
|
$mImages, # DB keys of the images used, in the array key only
|
|
|
|
|
|
$mExternalLinks, # External link URLs, in the key only
|
2006-05-11 20:24:28 +00:00
|
|
|
|
$mHTMLtitle, # Display HTML title
|
2006-05-11 22:40:38 +00:00
|
|
|
|
$mSubtitle, # Additional subtitle
|
2006-06-13 11:37:09 +00:00
|
|
|
|
$mNewSection, # Show a new section link?
|
|
|
|
|
|
$mNoGallery; # No gallery on category page? (__NOGALLERY__)
|
2004-02-26 13:37:26 +00:00
|
|
|
|
|
2004-08-22 17:24:50 +00:00
|
|
|
|
function ParserOutput( $text = '', $languageLinks = array(), $categoryLinks = array(),
|
2005-04-07 23:04:08 +00:00
|
|
|
|
$containsOldMagic = false, $titletext = '' )
|
2004-02-26 13:37:26 +00:00
|
|
|
|
{
|
|
|
|
|
|
$this->mText = $text;
|
|
|
|
|
|
$this->mLanguageLinks = $languageLinks;
|
2005-12-30 09:33:11 +00:00
|
|
|
|
$this->mCategories = $categoryLinks;
|
2004-02-26 13:37:26 +00:00
|
|
|
|
$this->mContainsOldMagic = $containsOldMagic;
|
2004-08-22 17:24:50 +00:00
|
|
|
|
$this->mCacheTime = '';
|
2004-11-25 22:02:30 +00:00
|
|
|
|
$this->mVersion = MW_PARSER_VERSION;
|
2005-04-07 23:04:08 +00:00
|
|
|
|
$this->mTitleText = $titletext;
|
2005-12-30 09:33:11 +00:00
|
|
|
|
$this->mLinks = array();
|
|
|
|
|
|
$this->mTemplates = array();
|
|
|
|
|
|
$this->mImages = array();
|
2006-01-26 13:29:14 +00:00
|
|
|
|
$this->mExternalLinks = array();
|
2006-04-18 08:28:01 +00:00
|
|
|
|
$this->mHTMLtitle = "" ;
|
|
|
|
|
|
$this->mSubtitle = "" ;
|
2006-05-01 20:35:08 +00:00
|
|
|
|
$this->mNewSection = false;
|
2006-06-13 11:37:09 +00:00
|
|
|
|
$this->mNoGallery = false;
|
2004-02-26 13:37:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2004-11-20 11:28:37 +00:00
|
|
|
|
function getText() { return $this->mText; }
|
2006-04-11 14:56:04 +00:00
|
|
|
|
function &getLanguageLinks() { return $this->mLanguageLinks; }
|
2005-12-30 09:33:11 +00:00
|
|
|
|
function getCategoryLinks() { return array_keys( $this->mCategories ); }
|
|
|
|
|
|
function &getCategories() { return $this->mCategories; }
|
2004-11-20 11:28:37 +00:00
|
|
|
|
function getCacheTime() { return $this->mCacheTime; }
|
2005-04-07 23:04:08 +00:00
|
|
|
|
function getTitleText() { return $this->mTitleText; }
|
2005-12-30 09:33:11 +00:00
|
|
|
|
function &getLinks() { return $this->mLinks; }
|
|
|
|
|
|
function &getTemplates() { return $this->mTemplates; }
|
|
|
|
|
|
function &getImages() { return $this->mImages; }
|
2006-01-26 13:29:14 +00:00
|
|
|
|
function &getExternalLinks() { return $this->mExternalLinks; }
|
2006-06-13 11:37:09 +00:00
|
|
|
|
function getNoGallery() { return $this->mNoGallery; }
|
2006-07-24 05:25:12 +00:00
|
|
|
|
function getSubtitle() { return $this->mSubtitle; }
|
2005-12-30 09:33:11 +00:00
|
|
|
|
|
2004-11-20 11:28:37 +00:00
|
|
|
|
function containsOldMagic() { return $this->mContainsOldMagic; }
|
|
|
|
|
|
function setText( $text ) { return wfSetVar( $this->mText, $text ); }
|
|
|
|
|
|
function setLanguageLinks( $ll ) { return wfSetVar( $this->mLanguageLinks, $ll ); }
|
2005-12-30 09:33:11 +00:00
|
|
|
|
function setCategoryLinks( $cl ) { return wfSetVar( $this->mCategories, $cl ); }
|
2004-02-26 13:37:26 +00:00
|
|
|
|
function setContainsOldMagic( $com ) { return wfSetVar( $this->mContainsOldMagic, $com ); }
|
2004-11-20 11:28:37 +00:00
|
|
|
|
function setCacheTime( $t ) { return wfSetVar( $this->mCacheTime, $t ); }
|
2006-07-24 05:25:12 +00:00
|
|
|
|
function setTitleText( $t ) { return wfSetVar($this->mTitleText, $t); }
|
|
|
|
|
|
function setSubtitle( $st ) { return wfSetVar( $this->mSubtitle, $st ); }
|
2005-04-07 23:04:08 +00:00
|
|
|
|
|
2005-12-30 09:33:11 +00:00
|
|
|
|
function addCategory( $c, $sort ) { $this->mCategories[$c] = $sort; }
|
|
|
|
|
|
function addImage( $name ) { $this->mImages[$name] = 1; }
|
|
|
|
|
|
function addLanguageLink( $t ) { $this->mLanguageLinks[] = $t; }
|
2006-01-26 13:29:14 +00:00
|
|
|
|
function addExternalLink( $url ) { $this->mExternalLinks[$url] = 1; }
|
2006-05-01 20:35:08 +00:00
|
|
|
|
|
|
|
|
|
|
function setNewSection( $value ) {
|
|
|
|
|
|
$this->mNewSection = (bool)$value;
|
|
|
|
|
|
}
|
|
|
|
|
|
function getNewSection() {
|
|
|
|
|
|
return (bool)$this->mNewSection;
|
|
|
|
|
|
}
|
2005-12-30 09:33:11 +00:00
|
|
|
|
|
2006-08-18 05:00:16 +00:00
|
|
|
|
function addLink( $title, $id = null ) {
|
2005-12-30 11:10:51 +00:00
|
|
|
|
$ns = $title->getNamespace();
|
|
|
|
|
|
$dbk = $title->getDBkey();
|
2005-12-30 09:33:11 +00:00
|
|
|
|
if ( !isset( $this->mLinks[$ns] ) ) {
|
|
|
|
|
|
$this->mLinks[$ns] = array();
|
|
|
|
|
|
}
|
2006-08-18 05:00:16 +00:00
|
|
|
|
if ( is_null( $id ) ) {
|
|
|
|
|
|
$id = $title->getArticleID();
|
|
|
|
|
|
}
|
2006-01-07 13:09:30 +00:00
|
|
|
|
$this->mLinks[$ns][$dbk] = $id;
|
2005-12-30 09:33:11 +00:00
|
|
|
|
}
|
2004-03-20 15:03:26 +00:00
|
|
|
|
|
2005-12-30 11:10:51 +00:00
|
|
|
|
function addTemplate( $title, $id ) {
|
|
|
|
|
|
$ns = $title->getNamespace();
|
2006-01-07 13:31:29 +00:00
|
|
|
|
$dbk = $title->getDBkey();
|
2005-12-30 09:33:11 +00:00
|
|
|
|
if ( !isset( $this->mTemplates[$ns] ) ) {
|
|
|
|
|
|
$this->mTemplates[$ns] = array();
|
|
|
|
|
|
}
|
2005-12-30 11:10:51 +00:00
|
|
|
|
$this->mTemplates[$ns][$dbk] = $id;
|
2005-12-30 09:33:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2004-11-25 22:02:30 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* Return true if this cached output object predates the global or
|
|
|
|
|
|
* per-article cache invalidation timestamps, or if it comes from
|
|
|
|
|
|
* an incompatible older version.
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param string $touched the affected article's last touched timestamp
|
|
|
|
|
|
* @return bool
|
2006-04-19 15:46:24 +00:00
|
|
|
|
* @public
|
2004-11-25 22:02:30 +00:00
|
|
|
|
*/
|
|
|
|
|
|
function expired( $touched ) {
|
|
|
|
|
|
global $wgCacheEpoch;
|
2005-05-28 11:09:22 +00:00
|
|
|
|
return $this->getCacheTime() == -1 || // parser says it's uncacheable
|
2005-11-15 12:09:31 +00:00
|
|
|
|
$this->getCacheTime() < $touched ||
|
2004-11-25 22:02:30 +00:00
|
|
|
|
$this->getCacheTime() <= $wgCacheEpoch ||
|
|
|
|
|
|
!isset( $this->mVersion ) ||
|
|
|
|
|
|
version_compare( $this->mVersion, MW_PARSER_VERSION, "lt" );
|
2006-04-11 22:16:10 +00:00
|
|
|
|
}
|
2004-02-26 13:37:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* Set options of the Parser
|
|
|
|
|
|
* @todo document
|
2004-09-03 23:00:01 +00:00
|
|
|
|
* @package MediaWiki
|
2004-09-02 23:28:24 +00:00
|
|
|
|
*/
|
2004-02-29 08:43:29 +00:00
|
|
|
|
class ParserOptions
|
|
|
|
|
|
{
|
|
|
|
|
|
# All variables are private
|
2006-05-11 22:40:38 +00:00
|
|
|
|
var $mUseTeX; # Use texvc to expand <math> tags
|
|
|
|
|
|
var $mUseDynamicDates; # Use DateFormatter to format dates
|
|
|
|
|
|
var $mInterwikiMagic; # Interlanguage links are removed and returned in an array
|
|
|
|
|
|
var $mAllowExternalImages; # Allow external images inline
|
|
|
|
|
|
var $mAllowExternalImagesFrom; # If not, any exception?
|
|
|
|
|
|
var $mSkin; # Reference to the preferred skin
|
|
|
|
|
|
var $mDateFormat; # Date format index
|
|
|
|
|
|
var $mEditSection; # Create "edit section" links
|
|
|
|
|
|
var $mNumberHeadings; # Automatically number headings
|
|
|
|
|
|
var $mAllowSpecialInclusion; # Allow inclusion of special pages
|
|
|
|
|
|
var $mTidy; # Ask for tidy cleanup
|
|
|
|
|
|
var $mInterfaceMessage; # Which lang to call for PLURAL and GRAMMAR
|
2006-08-10 21:28:49 +00:00
|
|
|
|
var $mMaxIncludeSize; # Maximum size of template expansions, in bytes
|
2006-08-15 02:40:20 +00:00
|
|
|
|
var $mRemoveComments; # Remove HTML comments. ONLY APPLIES TO PREPROCESS OPERATIONS
|
2004-02-29 08:43:29 +00:00
|
|
|
|
|
2006-07-02 15:57:59 +00:00
|
|
|
|
var $mUser; # Stored user object, just used to initialise the skin
|
|
|
|
|
|
|
2004-06-12 06:15:09 +00:00
|
|
|
|
function getUseTeX() { return $this->mUseTeX; }
|
|
|
|
|
|
function getUseDynamicDates() { return $this->mUseDynamicDates; }
|
|
|
|
|
|
function getInterwikiMagic() { return $this->mInterwikiMagic; }
|
|
|
|
|
|
function getAllowExternalImages() { return $this->mAllowExternalImages; }
|
2005-10-26 22:13:02 +00:00
|
|
|
|
function getAllowExternalImagesFrom() { return $this->mAllowExternalImagesFrom; }
|
2004-06-12 06:15:09 +00:00
|
|
|
|
function getEditSection() { return $this->mEditSection; }
|
|
|
|
|
|
function getNumberHeadings() { return $this->mNumberHeadings; }
|
2005-05-28 11:09:22 +00:00
|
|
|
|
function getAllowSpecialInclusion() { return $this->mAllowSpecialInclusion; }
|
2006-04-29 13:15:19 +00:00
|
|
|
|
function getTidy() { return $this->mTidy; }
|
|
|
|
|
|
function getInterfaceMessage() { return $this->mInterfaceMessage; }
|
2006-08-10 21:28:49 +00:00
|
|
|
|
function getMaxIncludeSize() { return $this->mMaxIncludeSize; }
|
2006-08-15 02:40:20 +00:00
|
|
|
|
function getRemoveComments() { return $this->mRemoveComments; }
|
2004-06-12 06:15:09 +00:00
|
|
|
|
|
2006-07-02 15:57:59 +00:00
|
|
|
|
function &getSkin() {
|
|
|
|
|
|
if ( !isset( $this->mSkin ) ) {
|
|
|
|
|
|
$this->mSkin = $this->mUser->getSkin();
|
|
|
|
|
|
}
|
|
|
|
|
|
return $this->mSkin;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2006-07-26 07:15:39 +00:00
|
|
|
|
function getDateFormat() {
|
|
|
|
|
|
if ( !isset( $this->mDateFormat ) ) {
|
|
|
|
|
|
$this->mDateFormat = $this->mUser->getDatePreference();
|
|
|
|
|
|
}
|
|
|
|
|
|
return $this->mDateFormat;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2004-06-12 06:15:09 +00:00
|
|
|
|
function setUseTeX( $x ) { return wfSetVar( $this->mUseTeX, $x ); }
|
|
|
|
|
|
function setUseDynamicDates( $x ) { return wfSetVar( $this->mUseDynamicDates, $x ); }
|
|
|
|
|
|
function setInterwikiMagic( $x ) { return wfSetVar( $this->mInterwikiMagic, $x ); }
|
|
|
|
|
|
function setAllowExternalImages( $x ) { return wfSetVar( $this->mAllowExternalImages, $x ); }
|
2005-10-26 22:13:02 +00:00
|
|
|
|
function setAllowExternalImagesFrom( $x ) { return wfSetVar( $this->mAllowExternalImagesFrom, $x ); }
|
2004-06-12 06:15:09 +00:00
|
|
|
|
function setDateFormat( $x ) { return wfSetVar( $this->mDateFormat, $x ); }
|
|
|
|
|
|
function setEditSection( $x ) { return wfSetVar( $this->mEditSection, $x ); }
|
|
|
|
|
|
function setNumberHeadings( $x ) { return wfSetVar( $this->mNumberHeadings, $x ); }
|
2005-05-28 11:09:22 +00:00
|
|
|
|
function setAllowSpecialInclusion( $x ) { return wfSetVar( $this->mAllowSpecialInclusion, $x ); }
|
2006-04-29 13:15:19 +00:00
|
|
|
|
function setTidy( $x ) { return wfSetVar( $this->mTidy, $x); }
|
2004-08-16 15:23:46 +00:00
|
|
|
|
function setSkin( &$x ) { $this->mSkin =& $x; }
|
2006-04-29 13:15:19 +00:00
|
|
|
|
function setInterfaceMessage( $x ) { return wfSetVar( $this->mInterfaceMessage, $x); }
|
2006-08-10 21:28:49 +00:00
|
|
|
|
function setMaxIncludeSize( $x ) { return wfSetVar( $this->mMaxIncludeSize, $x ); }
|
2006-08-15 02:40:20 +00:00
|
|
|
|
function setRemoveComments( $x ) { return wfSetVar( $this->mRemoveComments, $x ); }
|
2004-06-12 06:15:09 +00:00
|
|
|
|
|
2006-07-02 15:57:59 +00:00
|
|
|
|
function ParserOptions( $user = null ) {
|
|
|
|
|
|
$this->initialiseFromUser( $user );
|
2005-05-28 06:59:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2005-01-31 22:59:55 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* Get parser options
|
|
|
|
|
|
* @static
|
|
|
|
|
|
*/
|
2006-07-11 17:46:30 +00:00
|
|
|
|
static function newFromUser( $user ) {
|
2006-07-02 15:57:59 +00:00
|
|
|
|
return new ParserOptions( $user );
|
2004-02-29 08:43:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2005-01-31 22:59:55 +00:00
|
|
|
|
/** Get user options */
|
2006-07-11 17:46:30 +00:00
|
|
|
|
function initialiseFromUser( $userInput ) {
|
2006-03-07 01:10:39 +00:00
|
|
|
|
global $wgUseTeX, $wgUseDynamicDates, $wgInterwikiMagic, $wgAllowExternalImages;
|
2006-08-10 21:28:49 +00:00
|
|
|
|
global $wgAllowExternalImagesFrom, $wgAllowSpecialInclusion, $wgMaxArticleSize;
|
2004-08-22 17:24:50 +00:00
|
|
|
|
$fname = 'ParserOptions::initialiseFromUser';
|
2004-08-19 08:44:13 +00:00
|
|
|
|
wfProfileIn( $fname );
|
2004-02-29 08:43:29 +00:00
|
|
|
|
if ( !$userInput ) {
|
2006-07-02 15:57:59 +00:00
|
|
|
|
global $wgUser;
|
|
|
|
|
|
if ( isset( $wgUser ) ) {
|
|
|
|
|
|
$user = $wgUser;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
$user = new User;
|
|
|
|
|
|
$user->setLoaded( true );
|
|
|
|
|
|
}
|
2004-02-29 08:43:29 +00:00
|
|
|
|
} else {
|
|
|
|
|
|
$user =& $userInput;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2006-07-02 15:57:59 +00:00
|
|
|
|
$this->mUser = $user;
|
|
|
|
|
|
|
2004-02-29 08:43:29 +00:00
|
|
|
|
$this->mUseTeX = $wgUseTeX;
|
|
|
|
|
|
$this->mUseDynamicDates = $wgUseDynamicDates;
|
|
|
|
|
|
$this->mInterwikiMagic = $wgInterwikiMagic;
|
|
|
|
|
|
$this->mAllowExternalImages = $wgAllowExternalImages;
|
2005-10-26 22:13:02 +00:00
|
|
|
|
$this->mAllowExternalImagesFrom = $wgAllowExternalImagesFrom;
|
2006-07-02 15:57:59 +00:00
|
|
|
|
$this->mSkin = null; # Deferred
|
2006-07-26 07:15:39 +00:00
|
|
|
|
$this->mDateFormat = null; # Deferred
|
2006-05-14 21:52:28 +00:00
|
|
|
|
$this->mEditSection = true;
|
2004-06-08 18:11:28 +00:00
|
|
|
|
$this->mNumberHeadings = $user->getOption( 'numberheadings' );
|
2005-05-28 11:09:22 +00:00
|
|
|
|
$this->mAllowSpecialInclusion = $wgAllowSpecialInclusion;
|
2006-01-23 18:37:46 +00:00
|
|
|
|
$this->mTidy = false;
|
2006-04-29 13:15:19 +00:00
|
|
|
|
$this->mInterfaceMessage = false;
|
2006-08-10 21:28:49 +00:00
|
|
|
|
$this->mMaxIncludeSize = $wgMaxArticleSize * 1024;
|
2006-08-15 02:40:20 +00:00
|
|
|
|
$this->mRemoveComments = true;
|
2004-08-19 08:44:13 +00:00
|
|
|
|
wfProfileOut( $fname );
|
2004-02-29 08:43:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2004-02-26 13:37:26 +00:00
|
|
|
|
|
2004-10-15 17:39:10 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* Callback function used by Parser::replaceLinkHolders()
|
|
|
|
|
|
* to substitute link placeholders.
|
|
|
|
|
|
*/
|
2005-04-27 07:48:14 +00:00
|
|
|
|
function &wfOutputReplaceMatches( $matches ) {
|
|
|
|
|
|
global $wgOutputReplace;
|
|
|
|
|
|
return $wgOutputReplace[$matches[1]];
|
2004-10-15 17:39:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* Return the total number of articles
|
|
|
|
|
|
*/
|
2004-08-16 15:23:46 +00:00
|
|
|
|
function wfNumberOfArticles() {
|
2004-08-13 15:55:59 +00:00
|
|
|
|
global $wgNumberOfArticles;
|
|
|
|
|
|
|
|
|
|
|
|
wfLoadSiteStats();
|
|
|
|
|
|
return $wgNumberOfArticles;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2005-06-26 03:23:24 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* Return the number of files
|
|
|
|
|
|
*/
|
|
|
|
|
|
function wfNumberOfFiles() {
|
2006-03-28 05:09:33 +00:00
|
|
|
|
$fname = 'wfNumberOfFiles';
|
2005-07-03 07:15:53 +00:00
|
|
|
|
|
2005-06-26 03:23:24 +00:00
|
|
|
|
wfProfileIn( $fname );
|
|
|
|
|
|
$dbr =& wfGetDB( DB_SLAVE );
|
2006-03-28 05:09:33 +00:00
|
|
|
|
$numImages = $dbr->selectField('site_stats', 'ss_images', array(), $fname );
|
2005-06-26 03:23:24 +00:00
|
|
|
|
wfProfileOut( $fname );
|
2005-07-03 07:15:53 +00:00
|
|
|
|
|
2006-03-28 05:09:33 +00:00
|
|
|
|
return $numImages;
|
2005-06-26 03:23:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2006-04-29 01:58:39 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* Return the number of user accounts
|
|
|
|
|
|
* @return integer
|
|
|
|
|
|
*/
|
|
|
|
|
|
function wfNumberOfUsers() {
|
|
|
|
|
|
wfProfileIn( 'wfNumberOfUsers' );
|
|
|
|
|
|
$dbr =& wfGetDB( DB_SLAVE );
|
|
|
|
|
|
$count = $dbr->selectField( 'site_stats', 'ss_users', array(), 'wfNumberOfUsers' );
|
|
|
|
|
|
wfProfileOut( 'wfNumberOfUsers' );
|
|
|
|
|
|
return (int)$count;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2006-05-13 17:30:42 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* Return the total number of pages
|
|
|
|
|
|
* @return integer
|
|
|
|
|
|
*/
|
|
|
|
|
|
function wfNumberOfPages() {
|
|
|
|
|
|
wfProfileIn( 'wfNumberOfPages' );
|
|
|
|
|
|
$dbr =& wfGetDB( DB_SLAVE );
|
|
|
|
|
|
$count = $dbr->selectField( 'site_stats', 'ss_total_pages', array(), 'wfNumberOfPages' );
|
|
|
|
|
|
wfProfileOut( 'wfNumberOfPages' );
|
|
|
|
|
|
return (int)$count;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2006-06-16 13:58:42 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* Return the total number of admins
|
|
|
|
|
|
*
|
|
|
|
|
|
* @return integer
|
|
|
|
|
|
*/
|
|
|
|
|
|
function wfNumberOfAdmins() {
|
|
|
|
|
|
static $admins = -1;
|
|
|
|
|
|
wfProfileIn( 'wfNumberOfAdmins' );
|
|
|
|
|
|
if( $admins == -1 ) {
|
|
|
|
|
|
$dbr =& wfGetDB( DB_SLAVE );
|
2006-06-17 22:36:12 +00:00
|
|
|
|
$admins = $dbr->selectField( 'user_groups', 'COUNT(*)', array( 'ug_group' => 'sysop' ), 'wfNumberOfAdmins' );
|
2006-06-16 13:58:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
wfProfileOut( 'wfNumberOfAdmins' );
|
|
|
|
|
|
return (int)$admins;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2006-06-12 12:38:41 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* Count the number of pages in a particular namespace
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param $ns Namespace
|
|
|
|
|
|
* @return integer
|
|
|
|
|
|
*/
|
|
|
|
|
|
function wfPagesInNs( $ns ) {
|
|
|
|
|
|
static $pageCount = array();
|
|
|
|
|
|
wfProfileIn( 'wfPagesInNs' );
|
|
|
|
|
|
if( !isset( $pageCount[$ns] ) ) {
|
|
|
|
|
|
$dbr =& wfGetDB( DB_SLAVE );
|
|
|
|
|
|
$pageCount[$ns] = $dbr->selectField( 'page', 'COUNT(*)', array( 'page_namespace' => $ns ), 'wfPagesInNs' );
|
|
|
|
|
|
}
|
|
|
|
|
|
wfProfileOut( 'wfPagesInNs' );
|
|
|
|
|
|
return (int)$pageCount[$ns];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* Get various statistics from the database
|
2006-04-19 15:46:24 +00:00
|
|
|
|
* @private
|
2004-09-02 23:28:24 +00:00
|
|
|
|
*/
|
|
|
|
|
|
function wfLoadSiteStats() {
|
2004-08-13 15:55:59 +00:00
|
|
|
|
global $wgNumberOfArticles, $wgTotalViews, $wgTotalEdits;
|
|
|
|
|
|
$fname = 'wfLoadSiteStats';
|
|
|
|
|
|
|
|
|
|
|
|
if ( -1 != $wgNumberOfArticles ) return;
|
|
|
|
|
|
$dbr =& wfGetDB( DB_SLAVE );
|
2004-10-24 07:10:33 +00:00
|
|
|
|
$s = $dbr->selectRow( 'site_stats',
|
2004-08-13 15:55:59 +00:00
|
|
|
|
array( 'ss_total_views', 'ss_total_edits', 'ss_good_articles' ),
|
|
|
|
|
|
array( 'ss_row_id' => 1 ), $fname
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
if ( $s === false ) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
$wgTotalViews = $s->ss_total_views;
|
|
|
|
|
|
$wgTotalEdits = $s->ss_total_edits;
|
|
|
|
|
|
$wgNumberOfArticles = $s->ss_good_articles;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2005-01-31 22:59:55 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* Escape html tags
|
2005-12-30 09:33:11 +00:00
|
|
|
|
* Basically replacing " > and < with HTML entities ( ", >, <)
|
2005-07-03 07:15:53 +00:00
|
|
|
|
*
|
2006-04-19 15:46:24 +00:00
|
|
|
|
* @param $in String: text that might contain HTML tags.
|
2005-01-31 22:59:55 +00:00
|
|
|
|
* @return string Escaped string
|
|
|
|
|
|
*/
|
2004-08-13 15:55:59 +00:00
|
|
|
|
function wfEscapeHTMLTagsOnly( $in ) {
|
|
|
|
|
|
return str_replace(
|
|
|
|
|
|
array( '"', '>', '<' ),
|
|
|
|
|
|
array( '"', '>', '<' ),
|
|
|
|
|
|
$in );
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2006-01-23 19:05:09 +00:00
|
|
|
|
?>
|