2004-02-26 13:37:26 +00:00
|
|
|
|
<?php
|
2004-09-02 23:28:24 +00:00
|
|
|
|
/**
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
|
* @defgroup Parser Parser
|
2007-05-01 23:41:44 +00:00
|
|
|
|
*
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
|
* @file
|
|
|
|
|
|
* @ingroup Parser
|
2004-09-21 05:49:12 +00:00
|
|
|
|
* File for Parser and related classes
|
2004-09-02 23:28:24 +00:00
|
|
|
|
*/
|
|
|
|
|
|
|
2006-06-02 20:54:34 +00:00
|
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
|
/**
|
2008-04-14 07:45:50 +00:00
|
|
|
|
* PHP Parser - Processes wiki markup (which uses a more user-friendly
|
2007-04-04 05:22:37 +00:00
|
|
|
|
* syntax, such as "[[link]]" for making links), and provides a one-way
|
|
|
|
|
|
* transformation of that wiki markup it into XHTML output / markup
|
|
|
|
|
|
* (which in turn the browser understands, and can display).
|
2004-09-21 05:49:12 +00:00
|
|
|
|
*
|
|
|
|
|
|
* <pre>
|
2008-01-19 09:03:45 +00:00
|
|
|
|
* There are five main entry points into the Parser class:
|
2004-09-21 05:49:12 +00:00
|
|
|
|
* parse()
|
|
|
|
|
|
* produces HTML output
|
|
|
|
|
|
* preSaveTransform().
|
|
|
|
|
|
* produces altered wiki markup.
|
2006-10-18 09:19:28 +00:00
|
|
|
|
* preprocess()
|
|
|
|
|
|
* removes HTML comments and expands templates
|
2008-01-19 09:03:45 +00:00
|
|
|
|
* cleanSig()
|
|
|
|
|
|
* Cleans a signature before saving it to preferences
|
|
|
|
|
|
* extractSections()
|
|
|
|
|
|
* Extracts sections from an article for section editing
|
2004-09-21 05:49:12 +00:00
|
|
|
|
*
|
|
|
|
|
|
* 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-10-17 08:49:27 +00:00
|
|
|
|
* $wgLocaltimezone, $wgAllowSpecialInclusion*,
|
2006-08-10 21:28:49 +00:00
|
|
|
|
* $wgMaxArticleSize*
|
2004-09-21 05:49:12 +00:00
|
|
|
|
*
|
|
|
|
|
|
* * only within ParserOptions
|
|
|
|
|
|
* </pre>
|
|
|
|
|
|
*
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
|
* @ingroup Parser
|
2004-09-02 23:28:24 +00:00
|
|
|
|
*/
|
2004-02-26 13:37:26 +00:00
|
|
|
|
class Parser
|
|
|
|
|
|
{
|
2007-11-20 10:55:08 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* Update this version number when the ParserOutput format
|
|
|
|
|
|
* changes in an incompatible way, so the parser cache
|
|
|
|
|
|
* can automatically discard old data.
|
|
|
|
|
|
*/
|
2007-12-28 08:41:45 +00:00
|
|
|
|
const VERSION = '1.6.4';
|
2007-11-20 10:55:08 +00:00
|
|
|
|
|
|
|
|
|
|
# Flags for Parser::setFunctionHook
|
|
|
|
|
|
# Also available as global constants from Defines.php
|
|
|
|
|
|
const SFH_NO_HASH = 1;
|
|
|
|
|
|
const SFH_OBJECT_ARGS = 2;
|
|
|
|
|
|
|
|
|
|
|
|
# Constants needed for external link processing
|
|
|
|
|
|
# Everything except bracket, space, or control characters
|
|
|
|
|
|
const EXT_LINK_URL_CLASS = '[^][<>"\\x00-\\x20\\x7F]';
|
2007-11-20 21:21:39 +00:00
|
|
|
|
const EXT_IMAGE_REGEX = '/^(http:\/\/|https:\/\/)([^][<>"\\x00-\\x20\\x7F]+)
|
|
|
|
|
|
\\/([A-Za-z0-9_.,~%\\-+&;#*?!=()@\\x80-\\xFF]+)\\.((?i)gif|png|jpg|jpeg)$/Sx';
|
2007-11-20 10:55:08 +00:00
|
|
|
|
|
|
|
|
|
|
// State constants for the definition list colon extraction
|
|
|
|
|
|
const COLON_STATE_TEXT = 0;
|
|
|
|
|
|
const COLON_STATE_TAG = 1;
|
|
|
|
|
|
const COLON_STATE_TAGSTART = 2;
|
|
|
|
|
|
const COLON_STATE_CLOSETAG = 3;
|
|
|
|
|
|
const COLON_STATE_TAGSLASH = 4;
|
|
|
|
|
|
const COLON_STATE_COMMENT = 5;
|
|
|
|
|
|
const COLON_STATE_COMMENTDASH = 6;
|
|
|
|
|
|
const COLON_STATE_COMMENTDASHDASH = 7;
|
|
|
|
|
|
|
2008-01-05 12:39:12 +00:00
|
|
|
|
// Flags for preprocessToDom
|
|
|
|
|
|
const PTD_FOR_INCLUSION = 1;
|
2008-01-22 10:47:44 +00:00
|
|
|
|
|
|
|
|
|
|
// Allowed values for $this->mOutputType
|
|
|
|
|
|
// Parameter to startExternalParse().
|
|
|
|
|
|
const OT_HTML = 1;
|
|
|
|
|
|
const OT_WIKI = 2;
|
|
|
|
|
|
const OT_PREPROCESS = 3;
|
|
|
|
|
|
const OT_MSG = 3;
|
2008-03-27 00:00:25 +00:00
|
|
|
|
|
|
|
|
|
|
// Marker Suffix needs to be accessible staticly.
|
|
|
|
|
|
const MARKER_SUFFIX = "-QINU\x7f";
|
|
|
|
|
|
|
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:
|
Basic integrated audio/video support, with Ogg implementation.
* JavaScript video player based loosely on Greg Maxwell's player
* Image page text snippet customisation
* Abstraction of transform parameters in the parser. Introduced Linker::makeImageLink2().
* Made canRender(), mustRender() depend on file, not just on handler. Moved width=0, height=0 checking to ImageHandler::canRender(), since audio streams have width=height=0 but should be rendered.
Also:
* Automatic upgrade for oldimage rows on image page view, allows media handler selection based on oi_*_mime
* oi_*_mime unconditionally referenced, REQUIRES SCHEMA UPGRADE
* Don't destroy file info for missing files on upgrade
* Simple, centralised extension message file handling
* Made MessageCache::loadAllMessages non-static, optimised for repeated-call case due to abuse in User.php
* Support for lightweight parser output hooks, with callback whitelist for security
* Moved Linker::formatSize() to Language, to join the new formatTimePeriod() and formatBitrate()
* Introduced MagicWordArray, regex capture trick requires that magic word IDs DO NOT CONTAIN HYPHENS.
2007-08-15 10:50:09 +00:00
|
|
|
|
var $mTagHooks, $mTransparentTagHooks, $mFunctionHooks, $mFunctionSynonyms, $mVariables,
|
2008-03-27 00:00:25 +00:00
|
|
|
|
$mImageParams, $mImageParamsMagicArray, $mStripList, $mMarkerIndex, $mPreprocessor,
|
2009-07-11 13:03:35 +00:00
|
|
|
|
$mExtLinkBracketedRegex, $mUrlProtocols, $mDefaultStripList, $mVarCache, $mConf,
|
2010-01-15 19:14:23 +00:00
|
|
|
|
$mFunctionTagHooks;
|
2008-01-22 10:10:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
2004-02-29 08:43:29 +00:00
|
|
|
|
# Cleared with clearState():
|
2006-11-21 09:53:45 +00:00
|
|
|
|
var $mOutput, $mAutonumber, $mDTopen, $mStripState;
|
2006-07-03 11:07:00 +00:00
|
|
|
|
var $mIncludeCount, $mArgStack, $mLastSection, $mInPre;
|
2008-08-26 14:37:15 +00:00
|
|
|
|
var $mLinkHolders, $mLinkID;
|
2007-11-20 10:55:08 +00:00
|
|
|
|
var $mIncludeSizes, $mPPNodeCount, $mDefaultSort;
|
2008-01-11 03:25:41 +00:00
|
|
|
|
var $mTplExpandCache; // empty-frame expansion cache
|
2008-02-20 08:53:12 +00:00
|
|
|
|
var $mTplRedirCache, $mTplDomCache, $mHeadings, $mDoubleUnderscores;
|
2008-04-07 22:11:31 +00:00
|
|
|
|
var $mExpensiveFunctionCount; // number of expensive parser function calls
|
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()
|
2006-11-21 09:53:45 +00:00
|
|
|
|
$mRevisionId, // ID to display in {{REVISIONID}} tags
|
|
|
|
|
|
$mRevisionTimestamp, // The timestamp of the specified revision ID
|
2007-01-17 19:48:48 +00:00
|
|
|
|
$mRevIdForTs; // The revision ID which was used to fetch the timestamp
|
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
|
|
|
|
*/
|
2007-11-20 10:55:08 +00:00
|
|
|
|
function __construct( $conf = array() ) {
|
2008-01-24 04:29:56 +00:00
|
|
|
|
$this->mConf = $conf;
|
2004-06-12 06:15:09 +00:00
|
|
|
|
$this->mTagHooks = array();
|
2007-07-15 11:14:53 +00:00
|
|
|
|
$this->mTransparentTagHooks = array();
|
2006-04-05 09:40:25 +00:00
|
|
|
|
$this->mFunctionHooks = array();
|
2009-07-11 13:03:35 +00:00
|
|
|
|
$this->mFunctionTagHooks = array();
|
2006-07-03 11:07:00 +00:00
|
|
|
|
$this->mFunctionSynonyms = array( 0 => array(), 1 => array() );
|
2009-11-07 16:46:34 +00:00
|
|
|
|
$this->mDefaultStripList = $this->mStripList = array( 'nowiki', 'gallery', 'a' );
|
2008-08-26 14:37:15 +00:00
|
|
|
|
$this->mUrlProtocols = wfUrlProtocols();
|
2007-11-20 10:55:08 +00:00
|
|
|
|
$this->mExtLinkBracketedRegex = '/\[(\b(' . wfUrlProtocols() . ')'.
|
|
|
|
|
|
'[^][<>"\\x00-\\x20\\x7F]+) *([^\]\\x0a\\x0d]*?)\]/S';
|
2008-01-24 04:29:56 +00:00
|
|
|
|
$this->mVarCache = array();
|
2008-01-21 16:36:08 +00:00
|
|
|
|
if ( isset( $conf['preprocessorClass'] ) ) {
|
|
|
|
|
|
$this->mPreprocessorClass = $conf['preprocessorClass'];
|
2008-09-04 06:19:27 +00:00
|
|
|
|
} elseif ( extension_loaded( 'domxml' ) ) {
|
|
|
|
|
|
// PECL extension that conflicts with the core DOM extension (bug 13770)
|
|
|
|
|
|
wfDebug( "Warning: you have the obsolete domxml extension for PHP. Please remove it!\n" );
|
|
|
|
|
|
$this->mPreprocessorClass = 'Preprocessor_Hash';
|
2008-08-11 17:24:35 +00:00
|
|
|
|
} elseif ( extension_loaded( 'dom' ) ) {
|
2008-07-07 03:31:00 +00:00
|
|
|
|
$this->mPreprocessorClass = 'Preprocessor_DOM';
|
2008-01-21 16:36:08 +00:00
|
|
|
|
} else {
|
2008-06-10 17:14:36 +00:00
|
|
|
|
$this->mPreprocessorClass = 'Preprocessor_Hash';
|
2008-01-21 16:36:08 +00:00
|
|
|
|
}
|
2008-02-05 08:23:58 +00:00
|
|
|
|
$this->mMarkerIndex = 0;
|
2006-07-03 11:07:00 +00:00
|
|
|
|
$this->mFirstCall = true;
|
2004-02-26 13:37:26 +00:00
|
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
|
2008-08-26 06:48:24 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* Reduce memory usage to reduce the impact of circular references
|
|
|
|
|
|
*/
|
|
|
|
|
|
function __destruct() {
|
2008-08-26 14:37:15 +00:00
|
|
|
|
if ( isset( $this->mLinkHolders ) ) {
|
|
|
|
|
|
$this->mLinkHolders->__destruct();
|
|
|
|
|
|
}
|
2008-08-26 06:48:24 +00:00
|
|
|
|
foreach ( $this as $name => $value ) {
|
|
|
|
|
|
unset( $this->$name );
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
}
|
2008-01-17 08:58:24 +00:00
|
|
|
|
$this->mFirstCall = false;
|
2008-04-14 07:45:50 +00:00
|
|
|
|
|
2006-07-03 11:07:00 +00:00
|
|
|
|
wfProfileIn( __METHOD__ );
|
2007-11-20 10:55:08 +00:00
|
|
|
|
|
2006-07-03 11:07:00 +00:00
|
|
|
|
$this->setHook( 'pre', array( $this, 'renderPreTag' ) );
|
2008-02-20 08:53:12 +00:00
|
|
|
|
CoreParserFunctions::register( $this );
|
2006-07-03 11:07:00 +00:00
|
|
|
|
$this->initialiseVariables();
|
2008-01-17 08:58:24 +00:00
|
|
|
|
|
|
|
|
|
|
wfRunHooks( 'ParserFirstCallInit', array( &$this ) );
|
2006-07-03 11:07:00 +00:00
|
|
|
|
wfProfileOut( __METHOD__ );
|
2006-10-17 08:49:27 +00:00
|
|
|
|
}
|
2006-07-03 11:07:00 +00:00
|
|
|
|
|
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();
|
2006-11-21 09:53:45 +00:00
|
|
|
|
$this->mStripState = new StripState;
|
2007-11-20 10:55:08 +00:00
|
|
|
|
$this->mArgStack = false;
|
2004-06-01 22:19:22 +00:00
|
|
|
|
$this->mInPre = false;
|
2008-08-26 14:37:15 +00:00
|
|
|
|
$this->mLinkHolders = new LinkHolderArray( $this );
|
|
|
|
|
|
$this->mLinkID = 0;
|
2006-11-21 09:53:45 +00:00
|
|
|
|
$this->mRevisionTimestamp = $this->mRevisionId = null;
|
2009-10-02 09:09:18 +00:00
|
|
|
|
$this->mVarCache = array();
|
2007-01-17 19:48:48 +00:00
|
|
|
|
|
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.
|
2007-11-20 10:55:08 +00:00
|
|
|
|
*
|
2008-04-14 07:45:50 +00:00
|
|
|
|
* Must not consist of all title characters, or else it will change
|
2007-11-20 10:55:08 +00:00
|
|
|
|
* the behaviour of <nowiki> in a link.
|
2006-05-26 12:11:54 +00:00
|
|
|
|
*/
|
2010-01-26 11:57:01 +00:00
|
|
|
|
# $this->mUniqPrefix = "\x07UNIQ" . Parser::getRandomString();
|
2008-01-24 04:29:56 +00:00
|
|
|
|
# Changed to \x7f to allow XML double-parsing -- TS
|
2008-08-26 14:37:15 +00:00
|
|
|
|
$this->mUniqPrefix = "\x7fUNIQ" . self::getRandomString();
|
2005-12-24 23:05:18 +00:00
|
|
|
|
|
2008-02-05 08:23:58 +00:00
|
|
|
|
|
2006-02-02 13:42:50 +00:00
|
|
|
|
# Clear these on every parse, bug 4549
|
2007-11-20 10:55:08 +00:00
|
|
|
|
$this->mTplExpandCache = $this->mTplRedirCache = $this->mTplDomCache = array();
|
2006-02-02 13:42:50 +00:00
|
|
|
|
|
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(
|
|
|
|
|
|
'post-expand' => 0,
|
2007-11-20 10:55:08 +00:00
|
|
|
|
'arg' => 0,
|
2006-08-10 21:28:49 +00:00
|
|
|
|
);
|
2007-11-20 10:55:08 +00:00
|
|
|
|
$this->mPPNodeCount = 0;
|
2006-12-29 10:39:35 +00:00
|
|
|
|
$this->mDefaultSort = false;
|
2007-11-20 10:55:08 +00:00
|
|
|
|
$this->mHeadings = array();
|
2008-02-20 08:53:12 +00:00
|
|
|
|
$this->mDoubleUnderscores = array();
|
2008-04-07 22:11:31 +00:00
|
|
|
|
$this->mExpensiveFunctionCount = 0;
|
2006-07-02 17:43:32 +00:00
|
|
|
|
|
2008-01-24 04:29:56 +00:00
|
|
|
|
# Fix cloning
|
|
|
|
|
|
if ( isset( $this->mPreprocessor ) && $this->mPreprocessor->parser !== $this ) {
|
|
|
|
|
|
$this->mPreprocessor = null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
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(
|
2008-01-22 10:47:44 +00:00
|
|
|
|
'html' => $ot == self::OT_HTML,
|
|
|
|
|
|
'wiki' => $ot == self::OT_WIKI,
|
|
|
|
|
|
'pre' => $ot == self::OT_PREPROCESS,
|
2006-08-14 07:10:31 +00:00
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2008-01-16 02:47:31 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* Set the context title
|
|
|
|
|
|
*/
|
|
|
|
|
|
function setTitle( $t ) {
|
2010-01-15 19:14:23 +00:00
|
|
|
|
if ( !$t || $t instanceof FakeTitle ) {
|
|
|
|
|
|
$t = Title::newFromText( 'NO TITLE' );
|
|
|
|
|
|
}
|
2010-01-13 02:41:58 +00:00
|
|
|
|
|
2008-01-16 02:47:31 +00:00
|
|
|
|
if ( strval( $t->getFragment() ) !== '' ) {
|
|
|
|
|
|
# Strip the fragment to avoid various odd effects
|
|
|
|
|
|
$this->mTitle = clone $t;
|
|
|
|
|
|
$this->mTitle->setFragment( '' );
|
|
|
|
|
|
} else {
|
|
|
|
|
|
$this->mTitle = $t;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
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() {
|
2007-12-03 20:38:06 +00:00
|
|
|
|
if( !isset( $this->mUniqPrefix ) ) {
|
2009-12-15 21:26:58 +00:00
|
|
|
|
// @todo Fixme: this is probably *horribly wrong*
|
2007-12-03 20:38:06 +00:00
|
|
|
|
// LanguageConverter seems to want $wgParser's uniqPrefix, however
|
|
|
|
|
|
// if this is called for a parser cache hit, the parser may not
|
|
|
|
|
|
// have ever been initialized in the first place.
|
|
|
|
|
|
// Not really sure what the heck is supposed to be going on here.
|
|
|
|
|
|
return '';
|
|
|
|
|
|
//throw new MWException( "Accessing uninitialized mUniqPrefix" );
|
|
|
|
|
|
}
|
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
|
|
|
|
*
|
2008-08-09 13:31:15 +00:00
|
|
|
|
* @param $text String: text we want to parse
|
|
|
|
|
|
* @param $title A title object
|
|
|
|
|
|
* @param $options ParserOptions
|
|
|
|
|
|
* @param $linestart boolean
|
|
|
|
|
|
* @param $clearState boolean
|
|
|
|
|
|
* @param $revid Int: number to pass in {{REVISIONID}}
|
2004-09-21 05:49:12 +00:00
|
|
|
|
* @return ParserOutput a ParserOutput
|
|
|
|
|
|
*/
|
2008-08-09 13:31:15 +00:00
|
|
|
|
public function parse( $text, Title $title, ParserOptions $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
|
|
|
|
|
2010-01-15 19:14:23 +00:00
|
|
|
|
global $wgUseTidy, $wgAlwaysUseTidy, $wgContLang, $wgDisableLangConversion;
|
2008-08-26 14:37:15 +00:00
|
|
|
|
$fname = __METHOD__.'-' . wfGetCaller();
|
2006-11-12 10:47:10 +00:00
|
|
|
|
wfProfileIn( __METHOD__ );
|
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;
|
2010-01-07 04:13:14 +00:00
|
|
|
|
$this->setTitle( $title ); // Page title has to be set for the pre-processor
|
|
|
|
|
|
|
2006-07-10 18:25:56 +00:00
|
|
|
|
$oldRevisionId = $this->mRevisionId;
|
2006-11-21 09:53:45 +00:00
|
|
|
|
$oldRevisionTimestamp = $this->mRevisionTimestamp;
|
2006-07-10 18:25:56 +00:00
|
|
|
|
if( $revid !== null ) {
|
|
|
|
|
|
$this->mRevisionId = $revid;
|
2006-11-21 09:53:45 +00:00
|
|
|
|
$this->mRevisionTimestamp = null;
|
2006-07-10 18:25:56 +00:00
|
|
|
|
}
|
2008-01-22 10:47:44 +00:00
|
|
|
|
$this->setOutputType( self::OT_HTML );
|
2006-11-21 09:53:45 +00:00
|
|
|
|
wfRunHooks( 'ParserBeforeStrip', array( &$this, &$text, &$this->mStripState ) );
|
2007-11-20 10:55:08 +00:00
|
|
|
|
# No more strip!
|
2006-11-21 09:53:45 +00:00
|
|
|
|
wfRunHooks( 'ParserAfterStrip', array( &$this, &$text, &$this->mStripState ) );
|
2005-04-21 06:30:48 +00:00
|
|
|
|
$text = $this->internalParse( $text );
|
2010-01-07 04:13:14 +00:00
|
|
|
|
|
2006-11-21 09:53:45 +00:00
|
|
|
|
$text = $this->mStripState->unstripGeneral( $text );
|
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
|
2007-06-26 08:56:30 +00:00
|
|
|
|
'/(.) (?=\\?|:|;|!|%|\\302\\273)/' => '\\1 \\2',
|
2005-04-21 01:33:32 +00:00
|
|
|
|
# french spaces, Guillemet-right
|
|
|
|
|
|
'/(\\302\\253) /' => '\\1 ',
|
2010-01-26 11:57:01 +00:00
|
|
|
|
'/ (!\s*important)/' => ' \\1', # Beware of CSS magic word !important, bug #11874.
|
2005-04-21 01:33:32 +00:00
|
|
|
|
);
|
|
|
|
|
|
$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
|
|
|
|
$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
|
|
|
|
|
2010-01-08 08:22:19 +00:00
|
|
|
|
// The position of the convert() call should not be changed. it
|
|
|
|
|
|
// assumes that the links are all replaced and the only thing left
|
|
|
|
|
|
// is the <nowiki> mark.
|
2010-01-15 19:14:23 +00:00
|
|
|
|
if ( !( $wgDisableLangConversion
|
|
|
|
|
|
|| isset( $this->mDoubleUnderscores['nocontentconvert'] )
|
|
|
|
|
|
|| $this->mTitle->isTalkPage()
|
|
|
|
|
|
|| $this->mTitle->isConversionTable() ) ) {
|
2010-01-07 04:13:14 +00:00
|
|
|
|
$text = $wgContLang->convert( $text );
|
|
|
|
|
|
}
|
2005-04-26 20:50:16 +00:00
|
|
|
|
|
2010-01-08 08:22:19 +00:00
|
|
|
|
// A title may have been set in a conversion rule.
|
|
|
|
|
|
// Note that if a user tries to set a title in a conversion
|
|
|
|
|
|
// rule but content conversion was not done, then the parser
|
|
|
|
|
|
// won't pick it up. This is probably expected behavior.
|
|
|
|
|
|
if ( $wgContLang->getConvRuleTitle() ) {
|
2010-01-15 19:14:23 +00:00
|
|
|
|
$this->mOutput->setTitleText( $wgContLang->getConvRuleTitle() );
|
|
|
|
|
|
} elseif ( !( $wgDisableLangConversion
|
|
|
|
|
|
|| isset( $this->mDoubleUnderscores['notitleconvert'] ) ) ) {
|
|
|
|
|
|
$this->mOutput->setTitleText( $wgContLang->convert( $title ) );
|
2010-01-08 08:22:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2006-11-21 09:53:45 +00:00
|
|
|
|
$text = $this->mStripState->unstripNoWiki( $text );
|
2005-07-02 09:15:51 +00:00
|
|
|
|
|
|
|
|
|
|
wfRunHooks( 'ParserBeforeTidy', array( &$this, &$text ) );
|
2005-07-03 07:15:53 +00:00
|
|
|
|
|
2007-07-15 11:14:53 +00:00
|
|
|
|
//!JF Move to its own function
|
|
|
|
|
|
|
|
|
|
|
|
$uniq_prefix = $this->mUniqPrefix;
|
2007-11-20 10:55:08 +00:00
|
|
|
|
$matches = array();
|
2007-07-15 11:14:53 +00:00
|
|
|
|
$elements = array_keys( $this->mTransparentTagHooks );
|
2008-08-26 14:37:15 +00:00
|
|
|
|
$text = self::extractTagsAndParams( $elements, $text, $matches, $uniq_prefix );
|
2007-11-20 10:55:08 +00:00
|
|
|
|
|
|
|
|
|
|
foreach( $matches as $marker => $data ) {
|
|
|
|
|
|
list( $element, $content, $params, $tag ) = $data;
|
|
|
|
|
|
$tagName = strtolower( $element );
|
|
|
|
|
|
if( isset( $this->mTransparentTagHooks[$tagName] ) ) {
|
|
|
|
|
|
$output = call_user_func_array( $this->mTransparentTagHooks[$tagName],
|
|
|
|
|
|
array( $content, $params, $this ) );
|
|
|
|
|
|
} else {
|
2007-07-15 11:14:53 +00:00
|
|
|
|
$output = $tag;
|
|
|
|
|
|
}
|
|
|
|
|
|
$this->mStripState->general->setPair( $marker, $output );
|
|
|
|
|
|
}
|
|
|
|
|
|
$text = $this->mStripState->unstripGeneral( $text );
|
|
|
|
|
|
|
2005-04-21 11:40:58 +00:00
|
|
|
|
$text = Sanitizer::normalizeCharReferences( $text );
|
2006-01-07 13:31:29 +00:00
|
|
|
|
|
2009-01-27 15:20:31 +00:00
|
|
|
|
if ( ( $wgUseTidy && $this->mOptions->mTidy ) || $wgAlwaysUseTidy ) {
|
|
|
|
|
|
$text = MWTidy::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
|
|
|
|
}
|
2008-04-07 22:11:31 +00:00
|
|
|
|
global $wgExpensiveParserFunctionLimit;
|
|
|
|
|
|
if ( $this->mExpensiveFunctionCount > $wgExpensiveParserFunctionLimit ) {
|
2008-05-19 21:33:47 +00:00
|
|
|
|
$this->limitationWarn( 'expensive-parserfunction', $this->mExpensiveFunctionCount, $wgExpensiveParserFunctionLimit );
|
2008-04-07 22:11:31 +00:00
|
|
|
|
}
|
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
|
2007-11-30 14:50:48 +00:00
|
|
|
|
if ( $this->mOptions->getEnableLimitReport() ) {
|
2008-04-07 22:11:31 +00:00
|
|
|
|
global $wgExpensiveParserFunctionLimit;
|
2006-08-10 21:28:49 +00:00
|
|
|
|
$max = $this->mOptions->getMaxIncludeSize();
|
2008-04-07 22:11:31 +00:00
|
|
|
|
$PFreport = "Expensive parser function count: {$this->mExpensiveFunctionCount}/$wgExpensiveParserFunctionLimit\n";
|
2008-04-14 07:45:50 +00:00
|
|
|
|
$limitReport =
|
|
|
|
|
|
"NewPP limit report\n" .
|
2007-11-30 14:50:48 +00:00
|
|
|
|
"Preprocessor node count: {$this->mPPNodeCount}/{$this->mOptions->mMaxPPNodeCount}\n" .
|
|
|
|
|
|
"Post-expand include size: {$this->mIncludeSizes['post-expand']}/$max bytes\n" .
|
2008-04-07 22:11:31 +00:00
|
|
|
|
"Template argument size: {$this->mIncludeSizes['arg']}/$max bytes\n".
|
|
|
|
|
|
$PFreport;
|
2007-11-30 14:50:48 +00:00
|
|
|
|
wfRunHooks( 'ParserLimitReport', array( $this, &$limitReport ) );
|
|
|
|
|
|
$text .= "\n<!-- \n$limitReport-->\n";
|
2006-08-10 21:28:49 +00:00
|
|
|
|
}
|
2004-03-06 01:49:16 +00:00
|
|
|
|
$this->mOutput->setText( $text );
|
2010-01-15 19:14:23 +00:00
|
|
|
|
|
2006-07-10 18:25:56 +00:00
|
|
|
|
$this->mRevisionId = $oldRevisionId;
|
2006-11-21 09:53:45 +00:00
|
|
|
|
$this->mRevisionTimestamp = $oldRevisionTimestamp;
|
2004-03-06 01:49:16 +00:00
|
|
|
|
wfProfileOut( $fname );
|
2006-11-12 10:47:10 +00:00
|
|
|
|
wfProfileOut( __METHOD__ );
|
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.
|
2009-08-30 06:37:10 +00:00
|
|
|
|
*
|
|
|
|
|
|
* If $frame is not provided, then template variables (e.g., {{{1}}}) within $text are not expanded
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param $text String: text extension wants to have parsed
|
|
|
|
|
|
* @param PPFrame $frame: The frame to use for expanding any template variables
|
2006-08-06 14:01:47 +00:00
|
|
|
|
*/
|
2009-08-30 06:37:10 +00:00
|
|
|
|
function recursiveTagParse( $text, $frame=false ) {
|
2006-08-06 14:01:47 +00:00
|
|
|
|
wfProfileIn( __METHOD__ );
|
2006-11-23 08:25:56 +00:00
|
|
|
|
wfRunHooks( 'ParserBeforeStrip', array( &$this, &$text, &$this->mStripState ) );
|
|
|
|
|
|
wfRunHooks( 'ParserAfterStrip', array( &$this, &$text, &$this->mStripState ) );
|
2009-08-30 06:37:10 +00:00
|
|
|
|
$text = $this->internalParse( $text, false, $frame );
|
2006-08-06 14:01:47 +00:00
|
|
|
|
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
|
|
|
|
*/
|
2007-05-31 16:01:26 +00:00
|
|
|
|
function preprocess( $text, $title, $options, $revid = null ) {
|
2006-08-14 07:10:31 +00:00
|
|
|
|
wfProfileIn( __METHOD__ );
|
|
|
|
|
|
$this->clearState();
|
2008-01-22 10:47:44 +00:00
|
|
|
|
$this->setOutputType( self::OT_PREPROCESS );
|
2006-08-14 07:10:31 +00:00
|
|
|
|
$this->mOptions = $options;
|
2008-01-16 02:47:31 +00:00
|
|
|
|
$this->setTitle( $title );
|
2007-05-31 16:01:26 +00:00
|
|
|
|
if( $revid !== null ) {
|
|
|
|
|
|
$this->mRevisionId = $revid;
|
|
|
|
|
|
}
|
2006-11-21 09:53:45 +00:00
|
|
|
|
wfRunHooks( 'ParserBeforeStrip', array( &$this, &$text, &$this->mStripState ) );
|
|
|
|
|
|
wfRunHooks( 'ParserAfterStrip', array( &$this, &$text, &$this->mStripState ) );
|
2007-11-20 10:55:08 +00:00
|
|
|
|
$text = $this->replaceVariables( $text );
|
2006-11-21 09:53:45 +00:00
|
|
|
|
$text = $this->mStripState->unstripBoth( $text );
|
2006-08-14 07:10:31 +00:00
|
|
|
|
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; }
|
2008-05-24 16:57:51 +00:00
|
|
|
|
function getRevisionId() { return $this->mRevisionId; }
|
2008-08-26 14:37:15 +00:00
|
|
|
|
function getOutput() { return $this->mOutput; }
|
|
|
|
|
|
function nextLinkID() { return $this->mLinkID++; }
|
2006-02-28 05:18:36 +00:00
|
|
|
|
|
2006-07-03 11:07:00 +00:00
|
|
|
|
function getFunctionLang() {
|
|
|
|
|
|
global $wgLang, $wgContLang;
|
2008-03-07 14:02:12 +00:00
|
|
|
|
|
|
|
|
|
|
$target = $this->mOptions->getTargetLanguage();
|
|
|
|
|
|
if ( $target !== null ) {
|
|
|
|
|
|
return $target;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
return $this->mOptions->getInterfaceMessage() ? $wgLang : $wgContLang;
|
|
|
|
|
|
}
|
2006-07-03 11:07:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2008-01-21 16:36:08 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* Get a preprocessor object
|
|
|
|
|
|
*/
|
|
|
|
|
|
function getPreprocessor() {
|
|
|
|
|
|
if ( !isset( $this->mPreprocessor ) ) {
|
|
|
|
|
|
$class = $this->mPreprocessorClass;
|
|
|
|
|
|
$this->mPreprocessor = new $class( $this );
|
|
|
|
|
|
}
|
|
|
|
|
|
return $this->mPreprocessor;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
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
|
2008-02-09 21:48:41 +00:00
|
|
|
|
* in the text with a random marker and returns the next text. The output
|
2006-06-01 19:38:14 +00:00
|
|
|
|
* 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
|
|
|
|
*
|
2007-05-19 20:07:01 +00:00
|
|
|
|
* @public
|
2004-09-21 05:49:12 +00:00
|
|
|
|
* @static
|
|
|
|
|
|
*/
|
2008-08-25 04:27:40 +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 );
|
2009-09-07 00:23:04 +00:00
|
|
|
|
$start = "/<($taglist)(\\s+[^>]*?|\\s*?)(\/?" . ">)|<(!--)/i";
|
2004-03-26 17:14:23 +00:00
|
|
|
|
|
2010-01-26 11:57:01 +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
|
|
|
|
|
2008-03-27 00:00:25 +00:00
|
|
|
|
$marker = "$uniq_prefix-$element-" . sprintf('%08X', $n++) . self::MARKER_SUFFIX;
|
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 {
|
2008-08-26 14:37:15 +00:00
|
|
|
|
if( $element === '!--' ) {
|
2006-06-01 19:38:14 +00:00
|
|
|
|
$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-10-17 08:49:27 +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
|
|
|
|
/**
|
2007-11-20 10:55:08 +00:00
|
|
|
|
* Get a list of strippable XML-like elements
|
2004-09-21 05:49:12 +00:00
|
|
|
|
*/
|
2007-11-20 10:55:08 +00:00
|
|
|
|
function getStripList() {
|
2005-06-25 06:24:46 +00:00
|
|
|
|
global $wgRawHtml;
|
2007-11-20 10:55:08 +00:00
|
|
|
|
$elements = $this->mStripList;
|
2005-06-25 06:24:46 +00:00
|
|
|
|
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
|
|
|
|
}
|
2007-11-20 10:55:08 +00:00
|
|
|
|
return $elements;
|
|
|
|
|
|
}
|
2006-10-17 08:49:27 +00:00
|
|
|
|
|
2007-11-20 10:55:08 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* @deprecated use replaceVariables
|
|
|
|
|
|
*/
|
|
|
|
|
|
function strip( $text, $state, $stripcomments = false , $dontstrip = array () ) {
|
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
|
2006-11-21 09:53:45 +00:00
|
|
|
|
* @deprecated use $this->mStripState->unstrip()
|
2004-09-21 05:49:12 +00:00
|
|
|
|
*/
|
2006-10-17 08:49:27 +00:00
|
|
|
|
function unstrip( $text, $state ) {
|
2006-11-21 09:53:45 +00:00
|
|
|
|
return $state->unstripGeneral( $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
|
2006-11-21 09:53:45 +00:00
|
|
|
|
* @deprecated use $this->mStripState->unstrip()
|
2004-09-21 05:49:12 +00:00
|
|
|
|
*/
|
2006-10-17 08:49:27 +00:00
|
|
|
|
function unstripNoWiki( $text, $state ) {
|
2006-11-21 09:53:45 +00:00
|
|
|
|
return $state->unstripNoWiki( $text );
|
|
|
|
|
|
}
|
2006-10-17 08:49:27 +00:00
|
|
|
|
|
2006-11-21 09:53:45 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* @deprecated use $this->mStripState->unstripBoth()
|
|
|
|
|
|
*/
|
|
|
|
|
|
function unstripForHTML( $text ) {
|
|
|
|
|
|
return $this->mStripState->unstripBoth( $text );
|
2004-06-02 12:29:15 +00:00
|
|
|
|
}
|
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
|
|
|
|
*/
|
2007-11-20 10:55:08 +00:00
|
|
|
|
function insertStripItem( $text ) {
|
2008-03-27 00:00:25 +00:00
|
|
|
|
$rnd = "{$this->mUniqPrefix}-item-{$this->mMarkerIndex}-" . self::MARKER_SUFFIX;
|
2008-02-05 08:23:58 +00:00
|
|
|
|
$this->mMarkerIndex++;
|
2007-11-20 10:55:08 +00:00
|
|
|
|
$this->mStripState->general->setPair( $rnd, $text );
|
2004-04-09 15:29:33 +00:00
|
|
|
|
return $rnd;
|
|
|
|
|
|
}
|
2010-01-07 04:13:14 +00:00
|
|
|
|
|
2007-04-23 18:52:51 +00:00
|
|
|
|
/**
|
2009-01-27 15:20:31 +00:00
|
|
|
|
* Interface with html tidy
|
|
|
|
|
|
* @deprecated Use MWTidy::tidy()
|
2007-04-23 18:52:51 +00:00
|
|
|
|
*/
|
2009-01-27 15:20:31 +00:00
|
|
|
|
public static function tidy( $text ) {
|
|
|
|
|
|
wfDeprecated( __METHOD__ );
|
2010-01-07 04:13:14 +00:00
|
|
|
|
return MWTidy::tidy( $text );
|
2007-04-23 18:52:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
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
|
|
|
|
*/
|
2006-12-04 20:08:53 +00:00
|
|
|
|
function doTableStuff ( $text ) {
|
2008-08-26 14:37:15 +00:00
|
|
|
|
wfProfileIn( __METHOD__ );
|
2004-07-12 19:49:20 +00:00
|
|
|
|
|
2008-08-26 14:37:15 +00:00
|
|
|
|
$lines = StringUtils::explode( "\n", $text );
|
|
|
|
|
|
$out = '';
|
2006-12-04 20:08:53 +00:00
|
|
|
|
$td_history = array (); // Is currently a td tag open?
|
|
|
|
|
|
$last_tag_history = array (); // Save history of last lag activated (td, th or caption)
|
|
|
|
|
|
$tr_history = array (); // Is currently a tr tag open?
|
|
|
|
|
|
$tr_attributes = array (); // history of tr attributes
|
|
|
|
|
|
$has_opened_tr = array(); // Did this table open a <tr> element?
|
|
|
|
|
|
$indent_level = 0; // indent level of the table
|
2008-08-26 14:37:15 +00:00
|
|
|
|
|
|
|
|
|
|
foreach ( $lines as $outLine ) {
|
|
|
|
|
|
$line = trim( $outLine );
|
2006-12-04 20:08:53 +00:00
|
|
|
|
|
|
|
|
|
|
if( $line == '' ) { // empty line, go to next line
|
2008-08-26 14:37:15 +00:00
|
|
|
|
$out .= $outLine."\n";
|
2006-12-04 20:08:53 +00:00
|
|
|
|
continue;
|
|
|
|
|
|
}
|
2008-08-26 14:37:15 +00:00
|
|
|
|
$first_character = $line[0];
|
2006-10-17 08:49:27 +00:00
|
|
|
|
$matches = array();
|
2006-12-04 20:08:53 +00:00
|
|
|
|
|
2008-08-26 14:37:15 +00:00
|
|
|
|
if ( preg_match( '/^(:*)\{\|(.*)$/', $line , $matches ) ) {
|
2006-12-04 20:08:53 +00:00
|
|
|
|
// First check if we are starting a new table
|
2004-08-04 16:37:48 +00:00
|
|
|
|
$indent_level = strlen( $matches[1] );
|
2006-01-07 13:31:29 +00:00
|
|
|
|
|
2006-11-21 09:53:45 +00:00
|
|
|
|
$attributes = $this->mStripState->unstripBoth( $matches[2] );
|
2006-12-04 20:08:53 +00:00
|
|
|
|
$attributes = Sanitizer::fixTagAttributes ( $attributes , 'table' );
|
|
|
|
|
|
|
2008-08-26 14:37:15 +00:00
|
|
|
|
$outLine = str_repeat( '<dl><dd>' , $indent_level ) . "<table{$attributes}>";
|
2010-01-18 01:30:29 +00:00
|
|
|
|
array_push( $td_history , false );
|
|
|
|
|
|
array_push( $last_tag_history , '' );
|
|
|
|
|
|
array_push( $tr_history , false );
|
|
|
|
|
|
array_push( $tr_attributes , '' );
|
|
|
|
|
|
array_push( $has_opened_tr , false );
|
2010-01-26 11:57:01 +00:00
|
|
|
|
} elseif ( count ( $td_history ) == 0 ) {
|
2006-12-04 20:08:53 +00:00
|
|
|
|
// Don't do any of the following
|
2008-08-26 14:37:15 +00:00
|
|
|
|
$out .= $outLine."\n";
|
2006-12-04 20:08:53 +00:00
|
|
|
|
continue;
|
2010-01-26 11:57:01 +00:00
|
|
|
|
} elseif ( substr ( $line , 0 , 2 ) === '|}' ) {
|
2006-12-04 20:08:53 +00:00
|
|
|
|
// We are ending a table
|
|
|
|
|
|
$line = '</table>' . substr ( $line , 2 );
|
|
|
|
|
|
$last_tag = array_pop ( $last_tag_history );
|
|
|
|
|
|
|
|
|
|
|
|
if ( !array_pop ( $has_opened_tr ) ) {
|
|
|
|
|
|
$line = "<tr><td></td></tr>{$line}";
|
|
|
|
|
|
}
|
2005-08-29 23:34:37 +00:00
|
|
|
|
|
2006-12-04 20:08:53 +00:00
|
|
|
|
if ( array_pop ( $tr_history ) ) {
|
|
|
|
|
|
$line = "</tr>{$line}";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if ( array_pop ( $td_history ) ) {
|
|
|
|
|
|
$line = "</{$last_tag}>{$line}";
|
|
|
|
|
|
}
|
|
|
|
|
|
array_pop ( $tr_attributes );
|
2008-08-26 14:37:15 +00:00
|
|
|
|
$outLine = $line . str_repeat( '</dd></dl>' , $indent_level );
|
2010-01-26 11:57:01 +00:00
|
|
|
|
} elseif ( substr ( $line , 0 , 2 ) === '|-' ) {
|
2006-12-04 20:08:53 +00:00
|
|
|
|
// Now we have a table row
|
|
|
|
|
|
$line = preg_replace( '#^\|-+#', '', $line );
|
|
|
|
|
|
|
|
|
|
|
|
// Whats after the tag is now only attributes
|
|
|
|
|
|
$attributes = $this->mStripState->unstripBoth( $line );
|
2010-01-18 01:30:29 +00:00
|
|
|
|
$attributes = Sanitizer::fixTagAttributes( $attributes, 'tr' );
|
|
|
|
|
|
array_pop( $tr_attributes );
|
|
|
|
|
|
array_push( $tr_attributes, $attributes );
|
2006-12-04 20:08:53 +00:00
|
|
|
|
|
|
|
|
|
|
$line = '';
|
|
|
|
|
|
$last_tag = array_pop ( $last_tag_history );
|
2006-02-06 15:47:14 +00:00
|
|
|
|
array_pop ( $has_opened_tr );
|
2006-12-04 20:08:53 +00:00
|
|
|
|
array_push ( $has_opened_tr , true );
|
|
|
|
|
|
|
|
|
|
|
|
if ( array_pop ( $tr_history ) ) {
|
|
|
|
|
|
$line = '</tr>';
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if ( array_pop ( $td_history ) ) {
|
|
|
|
|
|
$line = "</{$last_tag}>{$line}";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2008-08-26 14:37:15 +00:00
|
|
|
|
$outLine = $line;
|
2006-12-04 20:08:53 +00:00
|
|
|
|
array_push ( $tr_history , false );
|
|
|
|
|
|
array_push ( $td_history , false );
|
|
|
|
|
|
array_push ( $last_tag_history , '' );
|
2004-07-12 19:49:20 +00:00
|
|
|
|
}
|
2010-01-26 11:57:01 +00:00
|
|
|
|
elseif ( $first_character === '|' || $first_character === '!' || substr ( $line , 0 , 2 ) === '|+' ) {
|
2006-12-04 20:08:53 +00:00
|
|
|
|
// This might be cell elements, td, th or captions
|
2008-08-26 14:37:15 +00:00
|
|
|
|
if ( substr ( $line , 0 , 2 ) === '|+' ) {
|
2006-12-04 20:08:53 +00:00
|
|
|
|
$first_character = '+';
|
|
|
|
|
|
$line = substr ( $line , 1 );
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$line = substr ( $line , 1 );
|
|
|
|
|
|
|
2008-08-26 14:37:15 +00:00
|
|
|
|
if ( $first_character === '!' ) {
|
2006-12-04 20:08:53 +00:00
|
|
|
|
$line = str_replace ( '!!' , '||' , $line );
|
2004-02-29 08:43:29 +00:00
|
|
|
|
}
|
2006-07-11 17:40:11 +00:00
|
|
|
|
|
2006-04-03 08:36:17 +00:00
|
|
|
|
// Split up multiple cells on the same line.
|
2006-12-04 20:08:53 +00:00
|
|
|
|
// FIXME : This can result in improper nesting of tags processed
|
2006-04-03 08:36:17 +00:00
|
|
|
|
// by earlier parser steps, but should avoid splitting up eg
|
|
|
|
|
|
// attribute values containing literal "||".
|
2006-12-04 20:08:53 +00:00
|
|
|
|
$cells = StringUtils::explodeMarkup( '||' , $line );
|
2006-07-11 17:40:11 +00:00
|
|
|
|
|
2008-08-26 14:37:15 +00:00
|
|
|
|
$outLine = '';
|
2004-10-01 21:20:47 +00:00
|
|
|
|
|
2006-12-04 20:08:53 +00:00
|
|
|
|
// Loop through each table cell
|
|
|
|
|
|
foreach ( $cells as $cell )
|
2004-02-29 08:43:29 +00:00
|
|
|
|
{
|
2006-12-04 20:08:53 +00:00
|
|
|
|
$previous = '';
|
2008-08-26 14:37:15 +00:00
|
|
|
|
if ( $first_character !== '+' )
|
2004-02-29 08:43:29 +00:00
|
|
|
|
{
|
2006-12-04 20:08:53 +00:00
|
|
|
|
$tr_after = array_pop ( $tr_attributes );
|
|
|
|
|
|
if ( !array_pop ( $tr_history ) ) {
|
|
|
|
|
|
$previous = "<tr{$tr_after}>\n";
|
|
|
|
|
|
}
|
|
|
|
|
|
array_push ( $tr_history , true );
|
|
|
|
|
|
array_push ( $tr_attributes , '' );
|
2006-02-06 15:47:14 +00:00
|
|
|
|
array_pop ( $has_opened_tr );
|
2006-12-04 20:08:53 +00:00
|
|
|
|
array_push ( $has_opened_tr , true );
|
2004-02-29 08:43:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2006-12-04 20:08:53 +00:00
|
|
|
|
$last_tag = array_pop ( $last_tag_history );
|
|
|
|
|
|
|
|
|
|
|
|
if ( array_pop ( $td_history ) ) {
|
|
|
|
|
|
$previous = "</{$last_tag}>{$previous}";
|
2006-10-17 08:49:27 +00:00
|
|
|
|
}
|
2006-12-04 20:08:53 +00:00
|
|
|
|
|
2008-08-26 14:37:15 +00:00
|
|
|
|
if ( $first_character === '|' ) {
|
2006-12-04 20:08:53 +00:00
|
|
|
|
$last_tag = 'td';
|
2010-01-26 11:57:01 +00:00
|
|
|
|
} elseif ( $first_character === '!' ) {
|
2006-12-04 20:08:53 +00:00
|
|
|
|
$last_tag = 'th';
|
2010-01-26 11:57:01 +00:00
|
|
|
|
} elseif ( $first_character === '+' ) {
|
2006-12-04 20:08:53 +00:00
|
|
|
|
$last_tag = 'caption';
|
|
|
|
|
|
} else {
|
|
|
|
|
|
$last_tag = '';
|
2004-10-01 21:20:47 +00:00
|
|
|
|
}
|
2006-12-04 20:08:53 +00:00
|
|
|
|
|
|
|
|
|
|
array_push ( $last_tag_history , $last_tag );
|
|
|
|
|
|
|
|
|
|
|
|
// A cell could contain both parameters and data
|
|
|
|
|
|
$cell_data = explode ( '|' , $cell , 2 );
|
|
|
|
|
|
|
|
|
|
|
|
// Bug 553: Note that a '|' inside an invalid link should not
|
|
|
|
|
|
// be mistaken as delimiting cell parameters
|
|
|
|
|
|
if ( strpos( $cell_data[0], '[[' ) !== false ) {
|
|
|
|
|
|
$cell = "{$previous}<{$last_tag}>{$cell}";
|
2010-01-26 11:57:01 +00:00
|
|
|
|
} elseif ( count ( $cell_data ) == 1 )
|
2006-12-04 20:08:53 +00:00
|
|
|
|
$cell = "{$previous}<{$last_tag}>{$cell_data[0]}";
|
2005-08-29 23:34:37 +00:00
|
|
|
|
else {
|
2006-12-04 20:08:53 +00:00
|
|
|
|
$attributes = $this->mStripState->unstripBoth( $cell_data[0] );
|
|
|
|
|
|
$attributes = Sanitizer::fixTagAttributes( $attributes , $last_tag );
|
|
|
|
|
|
$cell = "{$previous}<{$last_tag}{$attributes}>{$cell_data[1]}";
|
2005-08-29 23:34:37 +00:00
|
|
|
|
}
|
2006-12-04 20:08:53 +00:00
|
|
|
|
|
2008-08-26 14:37:15 +00:00
|
|
|
|
$outLine .= $cell;
|
2006-12-04 20:08:53 +00:00
|
|
|
|
array_push ( $td_history , true );
|
2004-02-28 05:55:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2008-08-26 14:37:15 +00:00
|
|
|
|
$out .= $outLine . "\n";
|
2004-07-12 19:49:20 +00:00
|
|
|
|
}
|
2004-02-29 08:43:29 +00:00
|
|
|
|
|
2006-12-04 20:08:53 +00:00
|
|
|
|
// Closing open td, tr && table
|
|
|
|
|
|
while ( count ( $td_history ) > 0 )
|
2004-02-29 08:43:29 +00:00
|
|
|
|
{
|
2006-12-04 20:08:53 +00:00
|
|
|
|
if ( array_pop ( $td_history ) ) {
|
2008-08-26 14:37:15 +00:00
|
|
|
|
$out .= "</td>\n";
|
2006-12-04 20:08:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
if ( array_pop ( $tr_history ) ) {
|
2008-08-26 14:37:15 +00:00
|
|
|
|
$out .= "</tr>\n";
|
2006-12-04 20:08:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
if ( !array_pop ( $has_opened_tr ) ) {
|
2008-08-26 14:37:15 +00:00
|
|
|
|
$out .= "<tr><td></td></tr>\n" ;
|
2006-12-04 20:08:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2008-08-26 14:37:15 +00:00
|
|
|
|
$out .= "</table>\n";
|
2006-12-04 20:08:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2008-08-26 14:37:15 +00:00
|
|
|
|
// Remove trailing line-ending (b/c)
|
|
|
|
|
|
if ( substr( $out, -1 ) === "\n" ) {
|
|
|
|
|
|
$out = substr( $out, 0, -1 );
|
|
|
|
|
|
}
|
2006-12-04 20:08:53 +00:00
|
|
|
|
|
|
|
|
|
|
// special case: don't return empty table
|
2008-08-26 14:37:15 +00:00
|
|
|
|
if( $out === "<table>\n<tr><td></td></tr>\n</table>" ) {
|
|
|
|
|
|
$out = '';
|
2004-02-28 05:55:13 +00:00
|
|
|
|
}
|
2004-02-26 13:37:26 +00:00
|
|
|
|
|
2008-08-26 14:37:15 +00:00
|
|
|
|
wfProfileOut( __METHOD__ );
|
2006-12-04 20:08:53 +00:00
|
|
|
|
|
2008-08-26 14:37:15 +00:00
|
|
|
|
return $out;
|
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
|
2008-01-22 10:47:44 +00:00
|
|
|
|
* HTML. Only called for $mOutputType == self::OT_HTML.
|
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
|
|
|
|
*/
|
2009-08-30 06:37:10 +00:00
|
|
|
|
function internalParse( $text, $isMain = true, $frame=false ) {
|
2008-08-26 14:37:15 +00:00
|
|
|
|
wfProfileIn( __METHOD__ );
|
2010-01-07 04:13:14 +00:00
|
|
|
|
|
2009-06-20 18:25:30 +00:00
|
|
|
|
$origText = $text;
|
2004-04-11 16:46:06 +00:00
|
|
|
|
|
2006-08-06 14:01:47 +00:00
|
|
|
|
# Hook to suspend the parser in this state
|
2006-11-23 08:25:56 +00:00
|
|
|
|
if ( !wfRunHooks( 'ParserBeforeInternalParse', array( &$this, &$text, &$this->mStripState ) ) ) {
|
2008-08-26 14:37:15 +00:00
|
|
|
|
wfProfileOut( __METHOD__ );
|
2006-08-06 14:01:47 +00:00
|
|
|
|
return $text ;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2009-08-30 06:37:10 +00:00
|
|
|
|
// if $frame is provided, then use $frame for replacing any variables
|
|
|
|
|
|
if ($frame) {
|
|
|
|
|
|
// use frame depth to infer how include/noinclude tags should be handled
|
|
|
|
|
|
// depth=0 means this is the top-level document; otherwise it's an included document
|
2010-01-07 04:13:14 +00:00
|
|
|
|
if( !$frame->depth )
|
2009-08-30 06:37:10 +00:00
|
|
|
|
$flag = 0;
|
|
|
|
|
|
else
|
|
|
|
|
|
$flag = Parser::PTD_FOR_INCLUSION;
|
|
|
|
|
|
$dom = $this->preprocessToDom( $text, $flag );
|
|
|
|
|
|
$text = $frame->expand( $dom );
|
|
|
|
|
|
}
|
|
|
|
|
|
// if $frame is not provided, then use old-style replaceVariables
|
|
|
|
|
|
else {
|
|
|
|
|
|
$text = $this->replaceVariables( $text );
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2007-11-20 10:55:08 +00:00
|
|
|
|
$text = Sanitizer::removeHTMLtags( $text, array( &$this, 'attributeStripCallback' ), false, array_keys( $this->mTransparentTagHooks ) );
|
2007-04-25 21:23:43 +00:00
|
|
|
|
wfRunHooks( 'InternalParseBeforeLinks', array( &$this, &$text, &$this->mStripState ) );
|
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
|
|
|
|
|
2008-02-20 08:53:12 +00:00
|
|
|
|
$text = $this->doDoubleUnderscore( $text );
|
2010-01-07 04:13:14 +00:00
|
|
|
|
|
2008-08-25 04:27:40 +00:00
|
|
|
|
$text = $this->doHeadings( $text );
|
2009-03-06 02:25:28 +00:00
|
|
|
|
if( $this->mOptions->getUseDynamicDates() ) {
|
2008-04-09 18:23:34 +00:00
|
|
|
|
$df = DateFormatter::getInstance();
|
2005-04-20 15:42:08 +00:00
|
|
|
|
$text = $df->reformat( $this->mOptions->getDateFormat(), $text );
|
2004-02-26 13:37:26 +00:00
|
|
|
|
}
|
2008-08-25 04:27:40 +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
|
2009-03-06 02:25:28 +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 );
|
2009-06-20 18:25:30 +00:00
|
|
|
|
$text = $this->formatHeadings( $text, $origText, $isMain );
|
2004-04-12 16:10:17 +00:00
|
|
|
|
|
2008-08-26 14:37:15 +00:00
|
|
|
|
wfProfileOut( __METHOD__ );
|
2004-02-26 13:37:26 +00:00
|
|
|
|
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.
|
2010-01-07 04:13:14 +00:00
|
|
|
|
*
|
2008-08-26 14:37:15 +00:00
|
|
|
|
* DML
|
2006-04-19 15:46:24 +00:00
|
|
|
|
* @private
|
2004-09-21 05:49:12 +00:00
|
|
|
|
*/
|
2007-11-20 10:55:08 +00:00
|
|
|
|
function doMagicLinks( $text ) {
|
2006-08-06 14:01:47 +00:00
|
|
|
|
wfProfileIn( __METHOD__ );
|
2008-08-26 14:37:15 +00:00
|
|
|
|
$prots = $this->mUrlProtocols;
|
|
|
|
|
|
$urlChar = self::EXT_LINK_URL_CLASS;
|
2006-10-17 08:49:27 +00:00
|
|
|
|
$text = preg_replace_callback(
|
2006-08-06 14:01:47 +00:00
|
|
|
|
'!(?: # Start cases
|
2010-01-07 04:13:14 +00:00
|
|
|
|
(<a.*?</a>) | # m[1]: Skip link text
|
2008-08-26 14:37:15 +00:00
|
|
|
|
(<.*?>) | # m[2]: Skip stuff inside HTML elements' . "
|
|
|
|
|
|
(\\b(?:$prots)$urlChar+) | # m[3]: Free external links" . '
|
|
|
|
|
|
(?:RFC|PMID)\s+([0-9]+) | # m[4]: RFC or PMID, capture number
|
|
|
|
|
|
ISBN\s+(\b # m[5]: ISBN, capture number
|
|
|
|
|
|
(?: 97[89] [\ \-]? )? # optional 13-digit ISBN prefix
|
|
|
|
|
|
(?: [0-9] [\ \-]? ){9} # 9 digits with opt. delimiters
|
|
|
|
|
|
[0-9Xx] # check digit
|
|
|
|
|
|
\b)
|
2006-08-06 14:01:47 +00:00
|
|
|
|
)!x', array( &$this, 'magicLinkCallback' ), $text );
|
|
|
|
|
|
wfProfileOut( __METHOD__ );
|
2006-10-17 08:49:27 +00:00
|
|
|
|
return $text;
|
2006-08-06 14:01:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function magicLinkCallback( $m ) {
|
2009-02-27 17:56:00 +00:00
|
|
|
|
if ( isset( $m[1] ) && $m[1] !== '' ) {
|
2008-08-26 14:37:15 +00:00
|
|
|
|
# Skip anchor
|
|
|
|
|
|
return $m[0];
|
2009-02-27 17:56:00 +00:00
|
|
|
|
} elseif ( isset( $m[2] ) && $m[2] !== '' ) {
|
2006-08-06 14:01:47 +00:00
|
|
|
|
# Skip HTML element
|
|
|
|
|
|
return $m[0];
|
2009-02-27 17:56:00 +00:00
|
|
|
|
} elseif ( isset( $m[3] ) && $m[3] !== '' ) {
|
2008-08-26 14:37:15 +00:00
|
|
|
|
# Free external link
|
|
|
|
|
|
return $this->makeFreeExternalLink( $m[0] );
|
2009-02-27 17:56:00 +00:00
|
|
|
|
} elseif ( isset( $m[4] ) && $m[4] !== '' ) {
|
2008-08-26 14:37:15 +00:00
|
|
|
|
# RFC or PMID
|
2009-08-20 09:13:29 +00:00
|
|
|
|
$CssClass = '';
|
2008-08-26 14:37:15 +00:00
|
|
|
|
if ( substr( $m[0], 0, 3 ) === 'RFC' ) {
|
2006-08-06 14:01:47 +00:00
|
|
|
|
$keyword = 'RFC';
|
|
|
|
|
|
$urlmsg = 'rfcurl';
|
2009-08-20 09:13:29 +00:00
|
|
|
|
$CssClass = 'mw-magiclink-rfc';
|
2008-08-26 14:37:15 +00:00
|
|
|
|
$id = $m[4];
|
|
|
|
|
|
} elseif ( substr( $m[0], 0, 4 ) === 'PMID' ) {
|
2006-08-06 14:01:47 +00:00
|
|
|
|
$keyword = 'PMID';
|
|
|
|
|
|
$urlmsg = 'pubmedurl';
|
2009-08-20 09:13:29 +00:00
|
|
|
|
$CssClass = 'mw-magiclink-pmid';
|
2008-08-26 14:37:15 +00:00
|
|
|
|
$id = $m[4];
|
2006-08-06 14:01:47 +00:00
|
|
|
|
} else {
|
2006-10-17 08:49:27 +00:00
|
|
|
|
throw new MWException( __METHOD__.': unrecognised match type "' .
|
2006-08-06 14:01:47 +00:00
|
|
|
|
substr($m[0], 0, 20 ) . '"' );
|
|
|
|
|
|
}
|
2006-11-08 07:12:03 +00:00
|
|
|
|
$url = wfMsg( $urlmsg, $id);
|
2007-01-22 23:50:42 +00:00
|
|
|
|
$sk = $this->mOptions->getSkin();
|
2009-08-20 09:13:29 +00:00
|
|
|
|
$la = $sk->getExternalLinkAttributes( "external $CssClass" );
|
2008-08-26 14:37:15 +00:00
|
|
|
|
return "<a href=\"{$url}\"{$la}>{$keyword} {$id}</a>";
|
2009-02-27 17:56:00 +00:00
|
|
|
|
} elseif ( isset( $m[5] ) && $m[5] !== '' ) {
|
2008-08-26 14:37:15 +00:00
|
|
|
|
# ISBN
|
|
|
|
|
|
$isbn = $m[5];
|
|
|
|
|
|
$num = strtr( $isbn, array(
|
|
|
|
|
|
'-' => '',
|
|
|
|
|
|
' ' => '',
|
|
|
|
|
|
'x' => 'X',
|
|
|
|
|
|
));
|
|
|
|
|
|
$titleObj = SpecialPage::getTitleFor( 'Booksources', $num );
|
|
|
|
|
|
return'<a href="' .
|
|
|
|
|
|
$titleObj->escapeLocalUrl() .
|
2009-08-20 09:13:29 +00:00
|
|
|
|
"\" class=\"internal mw-magiclink-isbn\">ISBN $isbn</a>";
|
2008-08-26 14:37:15 +00:00
|
|
|
|
} else {
|
|
|
|
|
|
return $m[0];
|
2006-08-06 14:01:47 +00:00
|
|
|
|
}
|
2004-08-04 01:53:29 +00:00
|
|
|
|
}
|
2004-07-12 19:49:20 +00:00
|
|
|
|
|
2008-08-26 14:37:15 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* Make a free external link, given a user-supplied URL
|
|
|
|
|
|
* @return HTML
|
|
|
|
|
|
* @private
|
|
|
|
|
|
*/
|
|
|
|
|
|
function makeFreeExternalLink( $url ) {
|
|
|
|
|
|
global $wgContLang;
|
|
|
|
|
|
wfProfileIn( __METHOD__ );
|
|
|
|
|
|
|
|
|
|
|
|
$sk = $this->mOptions->getSkin();
|
|
|
|
|
|
$trail = '';
|
|
|
|
|
|
|
|
|
|
|
|
# The characters '<' and '>' (which were escaped by
|
|
|
|
|
|
# removeHTMLtags()) should not be included in
|
|
|
|
|
|
# URLs, per RFC 2396.
|
|
|
|
|
|
$m2 = array();
|
|
|
|
|
|
if (preg_match('/&(lt|gt);/', $url, $m2, PREG_OFFSET_CAPTURE)) {
|
|
|
|
|
|
$trail = substr($url, $m2[0][1]) . $trail;
|
|
|
|
|
|
$url = substr($url, 0, $m2[0][1]);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# Move trailing punctuation to $trail
|
|
|
|
|
|
$sep = ',;\.:!?';
|
|
|
|
|
|
# If there is no left bracket, then consider right brackets fair game too
|
|
|
|
|
|
if ( strpos( $url, '(' ) === false ) {
|
|
|
|
|
|
$sep .= ')';
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$numSepChars = strspn( strrev( $url ), $sep );
|
|
|
|
|
|
if ( $numSepChars ) {
|
|
|
|
|
|
$trail = substr( $url, -$numSepChars ) . $trail;
|
|
|
|
|
|
$url = substr( $url, 0, -$numSepChars );
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$url = Sanitizer::cleanUrl( $url );
|
|
|
|
|
|
|
|
|
|
|
|
# Is this an external image?
|
|
|
|
|
|
$text = $this->maybeMakeExternalImage( $url );
|
|
|
|
|
|
if ( $text === false ) {
|
|
|
|
|
|
# Not an image, make a link
|
2010-01-07 04:13:14 +00:00
|
|
|
|
$text = $sk->makeExternalLink( $url, $wgContLang->markNoConversion($url), true, 'free',
|
2009-01-23 18:03:12 +00:00
|
|
|
|
$this->getExternalLinkAttribs( $url ) );
|
2008-08-26 14:37:15 +00:00
|
|
|
|
# Register it in the output object...
|
|
|
|
|
|
# Replace unnecessary URL escape codes with their equivalent characters
|
|
|
|
|
|
$pasteurized = self::replaceUnusualEscapes( $url );
|
|
|
|
|
|
$this->mOutput->addExternalLink( $pasteurized );
|
|
|
|
|
|
}
|
|
|
|
|
|
wfProfileOut( __METHOD__ );
|
|
|
|
|
|
return $text . $trail;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
*/
|
2008-08-25 04:27:40 +00:00
|
|
|
|
function doHeadings( $text ) {
|
2008-08-26 14:37:15 +00:00
|
|
|
|
wfProfileIn( __METHOD__ );
|
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 );
|
2007-11-20 10:55:08 +00:00
|
|
|
|
$text = preg_replace( "/^$h(.+)$h\\s*$/m",
|
|
|
|
|
|
"<h$i>\\1</h$i>", $text );
|
2004-02-26 13:37:26 +00:00
|
|
|
|
}
|
2008-08-26 14:37:15 +00:00
|
|
|
|
wfProfileOut( __METHOD__ );
|
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
|
|
|
|
|
|
*/
|
2008-08-25 04:27:40 +00:00
|
|
|
|
function doAllQuotes( $text ) {
|
2008-08-26 14:37:15 +00:00
|
|
|
|
wfProfileIn( __METHOD__ );
|
2004-06-08 18:11:28 +00:00
|
|
|
|
$outtext = '';
|
2008-08-26 14:37:15 +00:00
|
|
|
|
$lines = StringUtils::explode( "\n", $text );
|
2004-05-26 16:29:04 +00:00
|
|
|
|
foreach ( $lines as $line ) {
|
2008-08-26 14:37:15 +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);
|
2008-08-26 14:37:15 +00:00
|
|
|
|
wfProfileOut( __METHOD__ );
|
2004-06-05 04:51:24 +00:00
|
|
|
|
return $outtext;
|
2004-05-26 16:29:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2004-09-21 05:49:12 +00:00
|
|
|
|
/**
|
2010-01-14 16:18:29 +00:00
|
|
|
|
* Processes bolds and italics on a single line.
|
2004-09-21 05:49:12 +00:00
|
|
|
|
* Helper function for doAllQuotes()
|
|
|
|
|
|
*/
|
2008-08-25 04:27:40 +00:00
|
|
|
|
public function doQuotes( $text ) {
|
2010-01-26 18:55:56 +00:00
|
|
|
|
# Counts the number of occurrences of bold and italics mark-ups.
|
|
|
|
|
|
self::countBoldAndItalic($text, $numbold, $numitalics);
|
2010-01-26 18:55:10 +00:00
|
|
|
|
|
2010-01-26 18:55:56 +00:00
|
|
|
|
if ( ( $numbold == 0 ) && ( $numitalics == 0 ) )
|
2004-08-06 20:47:21 +00:00
|
|
|
|
return $text;
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
# 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
|
|
|
|
{
|
2004-08-07 12:35:59 +00:00
|
|
|
|
|
2010-01-26 18:56:50 +00:00
|
|
|
|
# This algorithm moves the literal quote at the
|
|
|
|
|
|
# right of a single word, at the right of a
|
|
|
|
|
|
# multiletter word or at the right of a space.
|
|
|
|
|
|
# Otherwise, it does nothing.
|
|
|
|
|
|
#
|
|
|
|
|
|
# The original if-based version can be found at
|
|
|
|
|
|
# http://svn.wikimedia.org/viewvc/mediawiki/trunk/phase3/includes/parser/Parser.php?revision=61519&view=markup
|
|
|
|
|
|
#
|
|
|
|
|
|
# Unlike the original one, here we convert the
|
|
|
|
|
|
# texty quotes to ' which shouldn't matter.
|
|
|
|
|
|
|
|
|
|
|
|
$quoteBalancerReplacements = array(
|
|
|
|
|
|
"/(?<= [^ ])'''(?!')/"=>"'''",
|
|
|
|
|
|
"/(?<=[^ '])'''(?!')/"=>"'''",
|
|
|
|
|
|
"/(^|(?<=[^'])) '''(?!')/"=>" '''");
|
|
|
|
|
|
|
|
|
|
|
|
foreach( $quoteBalancerReplacements as $k => $v) {
|
|
|
|
|
|
$text = preg_replace($k, $v, $text, 1, $count);
|
|
|
|
|
|
if ($count != 0)
|
|
|
|
|
|
break;
|
2004-08-06 20:47:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2004-08-07 12:35:59 +00:00
|
|
|
|
|
2010-01-26 18:56:50 +00:00
|
|
|
|
# Split in groups of 2, 3, 5 or 6 apostrophes.
|
|
|
|
|
|
# If there are ever four apostrophes, assume the first is supposed to
|
|
|
|
|
|
# be text, and the remaining three constitute mark-up for bold text.
|
|
|
|
|
|
# If there are more than 6 apostrophes in a row, assume they're all
|
|
|
|
|
|
# text except for the last 6.
|
2010-01-26 18:58:07 +00:00
|
|
|
|
$arr = Stringutils::preg_split( "/('{2,3}(?:''')?)(?!')/", $text, -1, PREG_SPLIT_DELIM_CAPTURE );
|
2010-01-26 18:56:50 +00:00
|
|
|
|
|
|
|
|
|
|
|
2004-08-06 20:47:21 +00:00
|
|
|
|
# Now let's actually convert our apostrophic mush to HTML!
|
2010-01-26 11:57:01 +00:00
|
|
|
|
$output = ''; # Processed text
|
|
|
|
|
|
$buffer = ''; # Content if $state is 'both'
|
|
|
|
|
|
$state = ''; # Flags with the order of open tags: '|b|i|bi|ib|both'
|
2004-08-06 20:47:21 +00:00
|
|
|
|
$i = 0;
|
|
|
|
|
|
foreach ($arr as $r)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (($i % 2) == 0)
|
|
|
|
|
|
{
|
2008-08-26 14:37:15 +00:00
|
|
|
|
if ($state === 'both')
|
2004-08-06 20:47:21 +00:00
|
|
|
|
$buffer .= $r;
|
|
|
|
|
|
else
|
|
|
|
|
|
$output .= $r;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
if (strlen ($r) == 2)
|
|
|
|
|
|
{
|
2008-08-26 14:37:15 +00:00
|
|
|
|
if ($state === 'i')
|
2004-09-11 08:40:26 +00:00
|
|
|
|
{ $output .= '</i>'; $state = ''; }
|
2010-01-26 11:57:01 +00:00
|
|
|
|
elseif ($state === 'bi')
|
2004-09-11 08:40:26 +00:00
|
|
|
|
{ $output .= '</i>'; $state = 'b'; }
|
2010-01-26 11:57:01 +00:00
|
|
|
|
elseif ($state === 'ib')
|
2004-09-11 08:40:26 +00:00
|
|
|
|
{ $output .= '</b></i><b>'; $state = 'b'; }
|
2010-01-26 11:57:01 +00:00
|
|
|
|
elseif ($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
|
|
|
|
}
|
2010-01-26 11:57:01 +00:00
|
|
|
|
elseif (strlen ($r) == 3)
|
2004-08-06 20:47:21 +00:00
|
|
|
|
{
|
2008-08-26 14:37:15 +00:00
|
|
|
|
if ($state === 'b')
|
2004-09-11 08:40:26 +00:00
|
|
|
|
{ $output .= '</b>'; $state = ''; }
|
2010-01-26 11:57:01 +00:00
|
|
|
|
elseif ($state === 'bi')
|
2004-09-11 08:40:26 +00:00
|
|
|
|
{ $output .= '</i></b><i>'; $state = 'i'; }
|
2010-01-26 11:57:01 +00:00
|
|
|
|
elseif ($state === 'ib')
|
2004-09-11 08:40:26 +00:00
|
|
|
|
{ $output .= '</b>'; $state = 'i'; }
|
2010-01-26 11:57:01 +00:00
|
|
|
|
elseif ($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
|
|
|
|
}
|
2010-01-26 11:57:01 +00:00
|
|
|
|
elseif (strlen ($r) == 5)
|
2004-08-06 20:47:21 +00:00
|
|
|
|
{
|
2008-08-26 14:37:15 +00:00
|
|
|
|
if ($state === 'b')
|
2004-09-11 08:40:26 +00:00
|
|
|
|
{ $output .= '</b><i>'; $state = 'i'; }
|
2010-01-26 11:57:01 +00:00
|
|
|
|
elseif ($state === 'i')
|
2004-09-11 08:40:26 +00:00
|
|
|
|
{ $output .= '</i><b>'; $state = 'b'; }
|
2010-01-26 11:57:01 +00:00
|
|
|
|
elseif ($state === 'bi')
|
2004-09-11 08:40:26 +00:00
|
|
|
|
{ $output .= '</i></b>'; $state = ''; }
|
2010-01-26 11:57:01 +00:00
|
|
|
|
elseif ($state === 'ib')
|
2004-09-11 08:40:26 +00:00
|
|
|
|
{ $output .= '</b></i>'; $state = ''; }
|
2010-01-26 11:57:01 +00:00
|
|
|
|
elseif ($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'; }
|
|
|
|
|
|
}
|
2010-01-26 11:57:01 +00:00
|
|
|
|
elseif (strlen ($r) == 6)
|
2010-01-14 16:18:29 +00:00
|
|
|
|
{
|
|
|
|
|
|
if ($state === 'b')
|
|
|
|
|
|
{ $output .= '</b><b>'; $state = 'b'; }
|
2010-01-26 11:57:01 +00:00
|
|
|
|
elseif ($state === 'i')
|
2010-01-14 16:18:29 +00:00
|
|
|
|
{ $output .= '\'</i><b>'; $state = 'b'; }
|
2010-01-26 11:57:01 +00:00
|
|
|
|
elseif ($state === 'bi')
|
2010-01-14 16:18:29 +00:00
|
|
|
|
{ $output .= '\'</i></b>'; $state = ''; }
|
2010-01-26 11:57:01 +00:00
|
|
|
|
elseif ($state === 'ib')
|
2010-01-14 16:18:29 +00:00
|
|
|
|
{ $output .= '\'</b></i>'; $state = ''; }
|
2010-01-26 11:57:01 +00:00
|
|
|
|
elseif ($state === 'both')
|
2010-01-14 16:18:29 +00:00
|
|
|
|
{ $output .= '<i><b>'.$buffer.'</b><b>'; $state = 'ib'; }
|
|
|
|
|
|
else # ($state == '')
|
|
|
|
|
|
{ $buffer = ''; $state = ''; }
|
|
|
|
|
|
}
|
2004-08-06 20:47:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
$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.
|
2008-08-26 14:37:15 +00:00
|
|
|
|
if ($state === 'b' || $state === 'ib')
|
2004-09-11 08:40:26 +00:00
|
|
|
|
$output .= '</b>';
|
2008-08-26 14:37:15 +00:00
|
|
|
|
if ($state === 'i' || $state === 'bi' || $state === 'ib')
|
2004-09-11 08:40:26 +00:00
|
|
|
|
$output .= '</i>';
|
2008-08-26 14:37:15 +00:00
|
|
|
|
if ($state === 'bi')
|
2004-09-11 08:40:26 +00:00
|
|
|
|
$output .= '</b>';
|
2007-03-13 18:09:20 +00:00
|
|
|
|
# There might be lonely ''''', so make sure we have a buffer
|
2008-08-26 14:37:15 +00:00
|
|
|
|
if ($state === 'both' && $buffer)
|
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
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2010-01-26 18:55:56 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* Counts the number of bold and italic items from a line of text.
|
|
|
|
|
|
* Helper function for doQuotes()
|
|
|
|
|
|
*/
|
|
|
|
|
|
private static function countBoldAndItalic($text, &$numBold, &$numItalics) {
|
|
|
|
|
|
$numBold = 0;
|
|
|
|
|
|
$numItalics = 0;
|
|
|
|
|
|
$offset = 0;
|
|
|
|
|
|
|
|
|
|
|
|
do {
|
|
|
|
|
|
$offset = strpos($text, "'", $offset);
|
|
|
|
|
|
if ($offset === false)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
$quoteLen = strspn($text, "'", $offset);
|
|
|
|
|
|
$offset += $quoteLen;
|
|
|
|
|
|
|
|
|
|
|
|
switch ($quoteLen) {
|
|
|
|
|
|
case 0:
|
|
|
|
|
|
case 1:
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
|
|
$numItalics++;
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
|
|
$numBold++;
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case 4:
|
|
|
|
|
|
# If there are ever four apostrophes, assume the first is supposed to
|
|
|
|
|
|
# be text, and the remaining three constitute mark-up for bold text.
|
|
|
|
|
|
$numBold++;
|
|
|
|
|
|
$numItalics++;
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case 5:
|
|
|
|
|
|
$numItalics++;
|
|
|
|
|
|
$numBold++;
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case 6:
|
|
|
|
|
|
default:
|
|
|
|
|
|
# If there are more than 6 apostrophes in a row, assume they're all
|
|
|
|
|
|
# text except for the last 6.
|
|
|
|
|
|
$numBold+=2;
|
|
|
|
|
|
}
|
|
|
|
|
|
} while (true);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2004-09-21 05:49:12 +00:00
|
|
|
|
/**
|
2008-08-26 14:37:15 +00:00
|
|
|
|
* Replace external links (REL)
|
2004-09-21 05:49:12 +00:00
|
|
|
|
*
|
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;
|
2008-08-26 14:37:15 +00:00
|
|
|
|
wfProfileIn( __METHOD__ );
|
2004-08-07 08:54:52 +00:00
|
|
|
|
|
2007-01-22 23:50:42 +00:00
|
|
|
|
$sk = $this->mOptions->getSkin();
|
2006-11-08 07:12:03 +00:00
|
|
|
|
|
2007-11-20 10:55:08 +00:00
|
|
|
|
$bits = preg_split( $this->mExtLinkBracketedRegex, $text, -1, PREG_SPLIT_DELIM_CAPTURE );
|
2008-08-26 14:37:15 +00:00
|
|
|
|
$s = array_shift( $bits );
|
2004-08-07 18:24:12 +00:00
|
|
|
|
|
|
|
|
|
|
$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.
|
2006-10-17 08:49:27 +00:00
|
|
|
|
$m2 = array();
|
2004-10-11 16:57:49 +00:00
|
|
|
|
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
|
2008-08-26 14:37:15 +00:00
|
|
|
|
$linktype = ($text === $url) ? 'free' : 'text';
|
2005-01-15 23:56:26 +00:00
|
|
|
|
|
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 ) {
|
2008-09-28 08:45:03 +00:00
|
|
|
|
$langObj = $this->getFunctionLang();
|
|
|
|
|
|
$text = '[' . $langObj->formatNum( ++$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-10-17 08:49:27 +00:00
|
|
|
|
|
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
|
|
|
|
# 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
|
2009-01-23 18:03:12 +00:00
|
|
|
|
$s .= $sk->makeExternalLink( $url, $text, false, $linktype,
|
|
|
|
|
|
$this->getExternalLinkAttribs( $url ) ) . $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
|
2008-08-26 14:37:15 +00:00
|
|
|
|
$pasteurized = self::replaceUnusualEscapes( $url );
|
2006-03-17 01:02:14 +00:00
|
|
|
|
$this->mOutput->addExternalLink( $pasteurized );
|
2004-08-07 18:24:12 +00:00
|
|
|
|
}
|
2004-08-07 08:54:52 +00:00
|
|
|
|
|
2008-08-26 14:37:15 +00:00
|
|
|
|
wfProfileOut( __METHOD__ );
|
2004-02-26 13:37:26 +00:00
|
|
|
|
return $s;
|
|
|
|
|
|
}
|
2004-08-14 22:38:46 +00:00
|
|
|
|
|
2009-01-23 18:03:12 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* Get an associative array of additional HTML attributes appropriate for a
|
|
|
|
|
|
* particular external link. This currently may include rel => nofollow
|
|
|
|
|
|
* (depending on configuration, namespace, and the URL's domain) and/or a
|
|
|
|
|
|
* target attribute (depending on configuration).
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param string $url Optional URL, to extract the domain from for rel =>
|
|
|
|
|
|
* nofollow if appropriate
|
|
|
|
|
|
* @return array Associative array of HTML attributes
|
|
|
|
|
|
*/
|
|
|
|
|
|
function getExternalLinkAttribs( $url = false ) {
|
2008-09-30 01:00:40 +00:00
|
|
|
|
$attribs = array();
|
|
|
|
|
|
global $wgNoFollowLinks, $wgNoFollowNsExceptions;
|
|
|
|
|
|
$ns = $this->mTitle->getNamespace();
|
|
|
|
|
|
if( $wgNoFollowLinks && !in_array($ns, $wgNoFollowNsExceptions) ) {
|
|
|
|
|
|
$attribs['rel'] = 'nofollow';
|
2009-01-23 18:03:12 +00:00
|
|
|
|
|
|
|
|
|
|
global $wgNoFollowDomainExceptions;
|
|
|
|
|
|
if ( $wgNoFollowDomainExceptions ) {
|
|
|
|
|
|
$bits = wfParseUrl( $url );
|
|
|
|
|
|
if ( is_array( $bits ) && isset( $bits['host'] ) ) {
|
|
|
|
|
|
foreach ( $wgNoFollowDomainExceptions as $domain ) {
|
|
|
|
|
|
if( substr( $bits['host'], -strlen( $domain ) )
|
|
|
|
|
|
== $domain ) {
|
|
|
|
|
|
unset( $attribs['rel'] );
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2008-09-30 01:00:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
if ( $this->mOptions->getExternalLinkTarget() ) {
|
|
|
|
|
|
$attribs['target'] = $this->mOptions->getExternalLinkTarget();
|
|
|
|
|
|
}
|
|
|
|
|
|
return $attribs;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
2007-04-04 05:22:37 +00:00
|
|
|
|
* @todo This can merge genuinely required bits in the path or query string,
|
2006-03-17 01:02:14 +00:00
|
|
|
|
* 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}/',
|
2008-08-26 14:37:15 +00:00
|
|
|
|
array( __CLASS__, 'replaceUnusualEscapesCallback' ), $url );
|
2006-01-26 13:29:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 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
|
2008-09-01 18:49:14 +00:00
|
|
|
|
* option, through the exception, or through the on-wiki whitelist
|
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 ) {
|
2007-01-22 23:50:42 +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;
|
2008-09-01 18:49:14 +00:00
|
|
|
|
# $imagesfrom could be either a single string or an array of strings, parse out the latter
|
|
|
|
|
|
if( $imagesexception && is_array( $imagesfrom ) ) {
|
|
|
|
|
|
$imagematch = false;
|
|
|
|
|
|
foreach( $imagesfrom as $match ) {
|
|
|
|
|
|
if( strpos( $url, $match ) === 0 ) {
|
|
|
|
|
|
$imagematch = true;
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
} elseif( $imagesexception ) {
|
|
|
|
|
|
$imagematch = (strpos( $url, $imagesfrom ) === 0);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
$imagematch = false;
|
|
|
|
|
|
}
|
2006-01-07 13:09:30 +00:00
|
|
|
|
if ( $this->mOptions->getAllowExternalImages()
|
2008-09-01 18:49:14 +00:00
|
|
|
|
|| ( $imagesexception && $imagematch ) ) {
|
2007-11-20 10:55:08 +00:00
|
|
|
|
if ( preg_match( self::EXT_IMAGE_REGEX, $url ) ) {
|
2004-08-07 18:24:12 +00:00
|
|
|
|
# Image found
|
2008-07-02 01:19:00 +00:00
|
|
|
|
$text = $sk->makeExternalImage( $url );
|
2004-08-07 18:24:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2008-09-01 18:49:14 +00:00
|
|
|
|
if( !$text && $this->mOptions->getEnableImageWhitelist()
|
|
|
|
|
|
&& preg_match( self::EXT_IMAGE_REGEX, $url ) ) {
|
|
|
|
|
|
$whitelist = explode( "\n", wfMsgForContent( 'external_image_whitelist' ) );
|
|
|
|
|
|
foreach( $whitelist as $entry ) {
|
|
|
|
|
|
# Sanitize the regex fragment, make it case-insensitive, ignore blank entries/comments
|
|
|
|
|
|
if( strpos( $entry, '#' ) === 0 || $entry === '' )
|
|
|
|
|
|
continue;
|
|
|
|
|
|
if( preg_match( '/' . str_replace( '/', '\\/', $entry ) . '/i', $url ) ) {
|
|
|
|
|
|
# Image matches a whitelist entry
|
|
|
|
|
|
$text = $sk->makeExternalImage( $url );
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
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
|
2008-08-26 14:37:15 +00:00
|
|
|
|
* @return processed text
|
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 replaceInternalLinks( $s ) {
|
2008-08-26 14:37:15 +00:00
|
|
|
|
$this->mLinkHolders->merge( $this->replaceInternalLinks2( $s ) );
|
|
|
|
|
|
return $s;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Process [[ ]] wikilinks (RIL)
|
|
|
|
|
|
* @return LinkHolderArray
|
|
|
|
|
|
*
|
|
|
|
|
|
* @private
|
|
|
|
|
|
*/
|
|
|
|
|
|
function replaceInternalLinks2( &$s ) {
|
2006-01-05 02:05:53 +00:00
|
|
|
|
global $wgContLang;
|
2004-10-23 13:00:33 +00:00
|
|
|
|
|
2008-08-26 14:37:15 +00:00
|
|
|
|
wfProfileIn( __METHOD__ );
|
2004-02-26 13:37:26 +00:00
|
|
|
|
|
2008-08-26 14:37:15 +00:00
|
|
|
|
wfProfileIn( __METHOD__.'-setup' );
|
|
|
|
|
|
static $tc = FALSE, $e1, $e1_img;
|
2004-05-25 14:26:14 +00:00
|
|
|
|
# the % is needed to support urlencoded titles as well
|
2010-01-07 04:13:14 +00:00
|
|
|
|
if ( !$tc ) {
|
2008-08-26 14:37:15 +00:00
|
|
|
|
$tc = Title::legalChars() . '#%';
|
|
|
|
|
|
# Match a link having the form [[namespace:link|alternate]]trail
|
2009-04-28 23:33:28 +00:00
|
|
|
|
$e1 = "/^([{$tc}]+)(?:\\|(.+?))?]](.*)\$/sD";
|
2008-08-26 14:37:15 +00:00
|
|
|
|
# Match cases where there is no "]]", which might still be images
|
|
|
|
|
|
$e1_img = "/^([{$tc}]+)\\|(.*)\$/sD";
|
|
|
|
|
|
}
|
2005-07-03 07:15:53 +00:00
|
|
|
|
|
2007-01-22 23:50:42 +00:00
|
|
|
|
$sk = $this->mOptions->getSkin();
|
2008-08-26 14:37:15 +00:00
|
|
|
|
$holders = new LinkHolderArray( $this );
|
2006-11-08 07:12:03 +00:00
|
|
|
|
|
2010-01-26 11:57:01 +00:00
|
|
|
|
# split the entire text string on occurences of [[
|
2008-08-26 14:37:15 +00:00
|
|
|
|
$a = StringUtils::explode( '[[', ' ' . $s );
|
2010-01-26 11:57:01 +00:00
|
|
|
|
# get the first element (all text up to first [[), and remove the space we added
|
2008-08-26 14:37:15 +00:00
|
|
|
|
$s = $a->current();
|
|
|
|
|
|
$a->next();
|
|
|
|
|
|
$line = $a->current(); # Workaround for broken ArrayIterator::next() that returns "void"
|
2004-05-26 16:29:04 +00:00
|
|
|
|
$s = substr( $s, 1 );
|
|
|
|
|
|
|
2004-09-24 13:14:52 +00:00
|
|
|
|
$useLinkPrefixExtension = $wgContLang->linkPrefixExtension();
|
2007-11-13 09:55:45 +00:00
|
|
|
|
$e2 = null;
|
|
|
|
|
|
if ( $useLinkPrefixExtension ) {
|
|
|
|
|
|
# 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
|
|
|
|
|
|
$e2 = wfMsgForContent( 'linkprefix' );
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2005-02-21 11:28:07 +00:00
|
|
|
|
if( is_null( $this->mTitle ) ) {
|
2008-08-26 14:37:15 +00:00
|
|
|
|
wfProfileOut( __METHOD__.'-setup' );
|
|
|
|
|
|
wfProfileOut( __METHOD__ );
|
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 ) {
|
2006-10-17 08:49:27 +00:00
|
|
|
|
$m = array();
|
2004-06-02 22:54:01 +00:00
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
2007-01-09 20:57:10 +00:00
|
|
|
|
if($wgContLang->hasVariants()) {
|
2006-12-26 12:19:45 +00:00
|
|
|
|
$selflink = $wgContLang->convertLinkToAllVariants($this->mTitle->getPrefixedText());
|
2007-01-09 20:57:10 +00:00
|
|
|
|
} else {
|
2006-12-26 12:19:45 +00:00
|
|
|
|
$selflink = array($this->mTitle->getPrefixedText());
|
2007-01-09 20:57:10 +00:00
|
|
|
|
}
|
2004-11-28 03:29:50 +00:00
|
|
|
|
$useSubpages = $this->areSubpagesAllowed();
|
2008-08-26 14:37:15 +00:00
|
|
|
|
wfProfileOut( __METHOD__.'-setup' );
|
2005-07-03 07:15:53 +00:00
|
|
|
|
|
2004-10-05 03:55:41 +00:00
|
|
|
|
# Loop for each link
|
2008-08-26 14:37:15 +00:00
|
|
|
|
for ( ; $line !== false && $line !== null ; $a->next(), $line = $a->current() ) {
|
|
|
|
|
|
# Check for excessive memory usage
|
|
|
|
|
|
if ( $holders->isBig() ) {
|
|
|
|
|
|
# Too big
|
|
|
|
|
|
# Do the existence check, replace the link holders and clear the array
|
|
|
|
|
|
$holders->replace( $s );
|
|
|
|
|
|
$holders->clear();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2004-06-02 22:54:01 +00:00
|
|
|
|
if ( $useLinkPrefixExtension ) {
|
2008-08-26 14:37:15 +00:00
|
|
|
|
wfProfileIn( __METHOD__.'-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;
|
|
|
|
|
|
}
|
2008-08-26 14:37:15 +00:00
|
|
|
|
wfProfileOut( __METHOD__.'-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
|
|
|
|
|
2008-08-26 14:37:15 +00:00
|
|
|
|
wfProfileIn( __METHOD__."-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:
|
2008-05-05 20:50:40 +00:00
|
|
|
|
# [[Image:Foo.jpg|[http://example.com desc]]] <- having three ] in a row fucks up,
|
2005-04-12 06:07:23 +00:00
|
|
|
|
# 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-10-17 08:49:27 +00:00
|
|
|
|
if( $text !== '' &&
|
|
|
|
|
|
substr( $m[3], 0, 1 ) === ']' &&
|
|
|
|
|
|
strpos($text, '[') !== false
|
|
|
|
|
|
)
|
2006-03-24 16:40:31 +00:00
|
|
|
|
{
|
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 ) {
|
2007-03-30 19:38:11 +00:00
|
|
|
|
$m[1] = urldecode($m[1]);
|
2006-08-06 14:01:47 +00:00
|
|
|
|
}
|
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 ;
|
2008-08-26 14:37:15 +00:00
|
|
|
|
wfProfileOut( __METHOD__."-e1" );
|
2004-10-05 00:21:52 +00:00
|
|
|
|
continue;
|
2004-02-26 13:37:26 +00:00
|
|
|
|
}
|
2008-08-26 14:37:15 +00:00
|
|
|
|
wfProfileOut( __METHOD__."-e1" );
|
|
|
|
|
|
wfProfileIn( __METHOD__."-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.
|
2009-07-03 05:13:58 +00:00
|
|
|
|
if ( preg_match( '/^\b(?:' . wfUrlProtocols() . ')/', $m[1] ) ) {
|
2004-09-24 18:29:01 +00:00
|
|
|
|
$s .= $prefix . '[[' . $line ;
|
2008-08-26 14:37:15 +00:00
|
|
|
|
wfProfileOut( __METHOD__."-misc" );
|
2004-09-24 18:29:01 +00:00
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2004-09-25 20:35:38 +00:00
|
|
|
|
# Make subpage if necessary
|
2009-07-03 05:13:58 +00:00
|
|
|
|
if ( $useSubpages ) {
|
2004-11-28 03:29:50 +00:00
|
|
|
|
$link = $this->maybeDoSubpageLink( $m[1], $text );
|
|
|
|
|
|
} else {
|
|
|
|
|
|
$link = $m[1];
|
|
|
|
|
|
}
|
2004-09-25 20:35:38 +00:00
|
|
|
|
|
2009-07-03 05:13:58 +00:00
|
|
|
|
$noforce = (substr( $m[1], 0, 1 ) !== ':');
|
2004-09-25 20:35:38 +00:00
|
|
|
|
if (!$noforce) {
|
|
|
|
|
|
# Strip off leading ':'
|
2009-07-03 05:13:58 +00:00
|
|
|
|
$link = substr( $link, 1 );
|
2004-09-25 20:35:38 +00:00
|
|
|
|
}
|
2005-07-03 07:15:53 +00:00
|
|
|
|
|
2008-08-26 14:37:15 +00:00
|
|
|
|
wfProfileOut( __METHOD__."-misc" );
|
|
|
|
|
|
wfProfileIn( __METHOD__."-title" );
|
2009-07-03 05:13:58 +00:00
|
|
|
|
$nt = Title::newFromText( $this->mStripState->unstripNoWiki( $link ) );
|
2009-12-11 21:07:27 +00:00
|
|
|
|
if ( $nt === null ) {
|
2004-06-08 18:11:28 +00:00
|
|
|
|
$s .= $prefix . '[[' . $line;
|
2008-08-26 14:37:15 +00:00
|
|
|
|
wfProfileOut( __METHOD__."-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
|
|
|
|
|
2004-05-26 16:29:04 +00:00
|
|
|
|
$ns = $nt->getNamespace();
|
|
|
|
|
|
$iw = $nt->getInterWiki();
|
2008-08-26 14:37:15 +00:00
|
|
|
|
wfProfileOut( __METHOD__."-title" );
|
2006-10-17 08:49:27 +00:00
|
|
|
|
|
2009-07-03 05:13:58 +00:00
|
|
|
|
if ( $might_be_img ) { # if this is actually an invalid link
|
2008-08-26 14:37:15 +00:00
|
|
|
|
wfProfileIn( __METHOD__."-might_be_img" );
|
2010-01-26 11:57:01 +00:00
|
|
|
|
if ( $ns == NS_FILE && $noforce ) { # but might be an image
|
2004-10-05 03:55:41 +00:00
|
|
|
|
$found = false;
|
2008-08-26 14:37:15 +00:00
|
|
|
|
while ( true ) {
|
2010-01-26 11:57:01 +00:00
|
|
|
|
# look at the next 'line' to see if we can close it there
|
2008-08-26 14:37:15 +00:00
|
|
|
|
$a->next();
|
|
|
|
|
|
$next_line = $a->current();
|
|
|
|
|
|
if ( $next_line === false || $next_line === null ) {
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
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 ) {
|
2010-01-26 11:57:01 +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 {
|
2010-01-26 11:57:01 +00:00
|
|
|
|
# if $next_line is invalid too, we need look no further
|
2004-10-05 03:55:41 +00:00
|
|
|
|
$text .= '[[' . $next_line;
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if ( !$found ) {
|
|
|
|
|
|
# we couldn't find the end of this imageLink, so output it raw
|
2010-01-26 11:57:01 +00:00
|
|
|
|
# but don't ignore what might be perfectly normal links in the text we've examined
|
2008-08-26 14:37:15 +00:00
|
|
|
|
$holders->merge( $this->replaceInternalLinks2( $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
|
2008-08-26 14:37:15 +00:00
|
|
|
|
wfProfileOut( __METHOD__."-might_be_img" );
|
2004-10-05 03:55:41 +00:00
|
|
|
|
continue;
|
|
|
|
|
|
}
|
2010-01-26 11:57:01 +00:00
|
|
|
|
} 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
|
2008-08-26 14:37:15 +00:00
|
|
|
|
wfProfileOut( __METHOD__."-might_be_img" );
|
2004-10-05 03:55:41 +00:00
|
|
|
|
continue;
|
|
|
|
|
|
}
|
2008-08-26 14:37:15 +00:00
|
|
|
|
wfProfileOut( __METHOD__."-might_be_img" );
|
2004-10-05 03:55:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2010-01-06 19:59:42 +00:00
|
|
|
|
$wasblank = ( $text == '' );
|
2009-07-03 05:13:58 +00:00
|
|
|
|
if ( $wasblank ) $text = $link;
|
2004-10-05 03:55:41 +00:00
|
|
|
|
|
2004-08-16 20:01:21 +00:00
|
|
|
|
# Link not escaped by : , create the various objects
|
2009-07-03 05:13:58 +00:00
|
|
|
|
if ( $noforce ) {
|
2004-08-16 20:01:21 +00:00
|
|
|
|
|
|
|
|
|
|
# Interwikis
|
2008-08-26 14:37:15 +00:00
|
|
|
|
wfProfileIn( __METHOD__."-interwiki" );
|
2009-07-03 05:13:58 +00:00
|
|
|
|
if ( $iw && $this->mOptions->getInterwikiMagic() && $nottalk && $wgContLang->getLanguageName( $iw ) ) {
|
2005-12-30 09:33:11 +00:00
|
|
|
|
$this->mOutput->addLanguageLink( $nt->getFullText() );
|
2007-02-06 07:45:06 +00:00
|
|
|
|
$s = rtrim($s . $prefix);
|
|
|
|
|
|
$s .= trim($trail, "\n") == '' ? '': $prefix . $trail;
|
2008-08-26 14:37:15 +00:00
|
|
|
|
wfProfileOut( __METHOD__."-interwiki" );
|
2004-05-26 16:29:04 +00:00
|
|
|
|
continue;
|
|
|
|
|
|
}
|
2008-08-26 14:37:15 +00:00
|
|
|
|
wfProfileOut( __METHOD__."-interwiki" );
|
2005-07-03 07:15:53 +00:00
|
|
|
|
|
2008-12-01 17:14:30 +00:00
|
|
|
|
if ( $ns == NS_FILE ) {
|
2008-08-26 14:37:15 +00:00
|
|
|
|
wfProfileIn( __METHOD__."-image" );
|
2006-09-25 01:35:41 +00:00
|
|
|
|
if ( !wfIsBadImage( $nt->getDBkey(), $this->mTitle ) ) {
|
2009-07-03 05:13:58 +00:00
|
|
|
|
if ( $wasblank ) {
|
|
|
|
|
|
# if no parameters were passed, $text
|
|
|
|
|
|
# becomes something like "File:Foo.png",
|
|
|
|
|
|
# which we don't want to pass on to the
|
|
|
|
|
|
# image generator
|
|
|
|
|
|
$text = '';
|
|
|
|
|
|
} else {
|
|
|
|
|
|
# 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);
|
|
|
|
|
|
$holders->merge( $this->replaceInternalLinks2( $text ) );
|
|
|
|
|
|
}
|
2005-04-12 04:03:21 +00:00
|
|
|
|
# cloak any absolute URLs inside the image markup, so replaceExternalLinks() won't touch them
|
2008-08-26 14:37:15 +00:00
|
|
|
|
$s .= $prefix . $this->armorLinks( $this->makeImage( $nt, $text, $holders ) ) . $trail;
|
2005-04-12 04:03:21 +00:00
|
|
|
|
}
|
2008-08-26 14:37:15 +00:00
|
|
|
|
$this->mOutput->addImage( $nt->getDBkey() );
|
|
|
|
|
|
wfProfileOut( __METHOD__."-image" );
|
|
|
|
|
|
continue;
|
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 ) {
|
2008-08-26 14:37:15 +00:00
|
|
|
|
wfProfileIn( __METHOD__."-category" );
|
2009-09-17 00:57:10 +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 ) {
|
2006-12-29 10:39:35 +00:00
|
|
|
|
$sortkey = $this->getDefaultSort();
|
2004-09-07 22:08:01 +00:00
|
|
|
|
} 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.
|
|
|
|
|
|
*/
|
2009-09-17 00:57:10 +00:00
|
|
|
|
$s .= trim($prefix . $trail, "\n") == '' ? '': $prefix . $trail;
|
2005-07-03 07:15:53 +00:00
|
|
|
|
|
2008-08-26 14:37:15 +00:00
|
|
|
|
wfProfileOut( __METHOD__."-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
|
|
|
|
|
2007-01-17 19:29:11 +00:00
|
|
|
|
# Self-link checking
|
2010-01-26 11:57:01 +00:00
|
|
|
|
if( $nt->getFragment() === '' && $ns !== NS_SPECIAL ) {
|
2007-01-17 19:29:11 +00:00
|
|
|
|
if( in_array( $nt->getPrefixedText(), $selflink, true ) ) {
|
|
|
|
|
|
$s .= $prefix . $sk->makeSelfLinkObj( $nt, $text, '', $trail );
|
|
|
|
|
|
continue;
|
2007-01-17 19:48:48 +00:00
|
|
|
|
}
|
2004-04-20 21:08:24 +00:00
|
|
|
|
}
|
2004-03-20 12:10:25 +00:00
|
|
|
|
|
2008-12-13 04:14:40 +00:00
|
|
|
|
# NS_MEDIA is a pseudo-namespace for linking directly to a file
|
|
|
|
|
|
# FIXME: Should do batch file existence checks, see comment below
|
2004-08-07 03:50:46 +00:00
|
|
|
|
if( $ns == NS_MEDIA ) {
|
2009-02-27 23:44:15 +00:00
|
|
|
|
wfProfileIn( __METHOD__."-media" );
|
2008-04-19 21:29:19 +00:00
|
|
|
|
# Give extensions a chance to select the file revision for us
|
|
|
|
|
|
$skip = $time = false;
|
|
|
|
|
|
wfRunHooks( 'BeforeParserMakeImageLinkObj', array( &$this, &$nt, &$skip, &$time ) );
|
|
|
|
|
|
if ( $skip ) {
|
2008-08-01 15:09:57 +00:00
|
|
|
|
$link = $sk->link( $nt );
|
2008-04-19 21:29:19 +00:00
|
|
|
|
} else {
|
|
|
|
|
|
$link = $sk->makeMediaLinkObj( $nt, $text, $time );
|
|
|
|
|
|
}
|
2005-12-21 14:02:20 +00:00
|
|
|
|
# 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() );
|
2009-02-27 23:44:15 +00:00
|
|
|
|
wfProfileOut( __METHOD__."-media" );
|
2004-06-05 02:22:16 +00:00
|
|
|
|
continue;
|
2004-05-26 16:29:04 +00:00
|
|
|
|
}
|
2008-12-13 04:14:40 +00:00
|
|
|
|
|
2009-02-27 23:44:15 +00:00
|
|
|
|
wfProfileIn( __METHOD__."-always_known" );
|
2008-12-13 04:14:40 +00:00
|
|
|
|
# Some titles, such as valid special pages or files in foreign repos, should
|
|
|
|
|
|
# be shown as bluelinks even though they're not included in the page table
|
|
|
|
|
|
#
|
|
|
|
|
|
# FIXME: isAlwaysKnown() can be expensive for file links; we should really do
|
|
|
|
|
|
# batch file existence checks for NS_FILE and NS_MEDIA
|
2008-12-13 21:21:40 +00:00
|
|
|
|
if( $iw == '' && $nt->isAlwaysKnown() ) {
|
2009-01-01 00:05:08 +00:00
|
|
|
|
$this->mOutput->addLink( $nt );
|
2008-12-13 04:14:40 +00:00
|
|
|
|
$s .= $this->makeKnownLinkHolder( $nt, $text, '', $trail, $prefix );
|
|
|
|
|
|
} else {
|
2009-01-01 00:05:08 +00:00
|
|
|
|
# Links will be added to the output link list after checking
|
2008-12-13 04:14:40 +00:00
|
|
|
|
$s .= $holders->makeHolder( $nt, $text, '', $trail, $prefix );
|
|
|
|
|
|
}
|
2009-02-27 23:44:15 +00:00
|
|
|
|
wfProfileOut( __METHOD__."-always_known" );
|
2004-02-28 23:38:08 +00:00
|
|
|
|
}
|
2008-08-26 14:37:15 +00:00
|
|
|
|
wfProfileOut( __METHOD__ );
|
|
|
|
|
|
return $holders;
|
2004-02-26 13:37:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
*
|
2008-08-26 14:37:15 +00:00
|
|
|
|
* @deprecated
|
2005-04-27 07:48:14 +00:00
|
|
|
|
*/
|
|
|
|
|
|
function makeLinkHolder( &$nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
|
2008-08-26 14:37:15 +00:00
|
|
|
|
return $this->mLinkHolders->makeHolder( $nt, $text, $query, $trail, $prefix );
|
2005-04-27 07:48:14 +00:00
|
|
|
|
}
|
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 );
|
2007-01-22 23:50:42 +00:00
|
|
|
|
$sk = $this->mOptions->getSkin();
|
2009-06-07 15:02:12 +00:00
|
|
|
|
// FIXME: use link() instead of deprecated makeKnownLinkObj()
|
2006-11-08 07:12:03 +00:00
|
|
|
|
$link = $sk->makeKnownLinkObj( $nt, $text, $query, $inside, $prefix );
|
2005-12-29 00:31:18 +00:00
|
|
|
|
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.
|
|
|
|
|
|
*
|
2008-08-26 14:37:15 +00:00
|
|
|
|
* Not needed quite as much as it used to be since free links are a bit
|
|
|
|
|
|
* more sensible these days. But bracketed links are still an issue.
|
2005-12-28 22:58:54 +00:00
|
|
|
|
*
|
|
|
|
|
|
* @param string more-or-less HTML
|
|
|
|
|
|
* @return string less-or-more HTML with NOPARSE bits
|
|
|
|
|
|
*/
|
|
|
|
|
|
function armorLinks( $text ) {
|
2006-11-23 08:25:56 +00:00
|
|
|
|
return preg_replace( '/\b(' . wfUrlProtocols() . ')/',
|
2005-12-28 22:58:54 +00:00
|
|
|
|
"{$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
|
2008-05-23 22:00:14 +00:00
|
|
|
|
return MWNamespace::hasSubpages( $this->mTitle->getNamespace() );
|
2004-11-28 03:29:50 +00:00
|
|
|
|
}
|
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) {
|
2009-07-20 02:07:56 +00:00
|
|
|
|
return Linker::normalizeSubpageLink( $this->mTitle, $target, $text );
|
2004-09-25 20:13:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
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 = '';
|
2010-01-26 11:57:01 +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.
|
|
|
|
|
|
#
|
2008-08-25 04:27:40 +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 ) {
|
2010-01-26 11:57:01 +00:00
|
|
|
|
if ( $st1{$i} !== $st2{$i} ) { break; }
|
2004-02-26 13:37:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
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();
|
|
|
|
|
|
|
2008-08-26 14:37:15 +00:00
|
|
|
|
if ( '*' === $char ) { $result .= '<ul><li>'; }
|
2009-06-18 20:51:48 +00:00
|
|
|
|
elseif ( '#' === $char ) { $result .= '<ol><li>'; }
|
|
|
|
|
|
elseif ( ':' === $char ) { $result .= '<dl><dd>'; }
|
|
|
|
|
|
elseif ( ';' === $char ) {
|
2004-06-08 18:11:28 +00:00
|
|
|
|
$result .= '<dl><dt>';
|
2004-02-26 13:37:26 +00:00
|
|
|
|
$this->mDTopen = true;
|
2009-08-27 17:16:15 +00:00
|
|
|
|
}
|
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 ) {
|
2008-08-26 14:37:15 +00:00
|
|
|
|
if ( '*' === $char || '#' === $char ) { return '</li><li>'; }
|
2009-06-18 20:51:48 +00:00
|
|
|
|
elseif ( ':' === $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>'; }
|
2008-08-26 14:37:15 +00:00
|
|
|
|
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 ) {
|
2008-08-26 14:37:15 +00:00
|
|
|
|
if ( '*' === $char ) { $text = '</li></ul>'; }
|
2009-06-18 20:51:48 +00:00
|
|
|
|
elseif ( '#' === $char ) { $text = '</li></ol>'; }
|
|
|
|
|
|
elseif ( ':' === $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
|
|
|
|
/**
|
2008-08-26 14:37:15 +00:00
|
|
|
|
* Make lists from lines starting with ':', '*', '#', etc. (DBL)
|
2004-09-21 05:49:12 +00:00
|
|
|
|
*
|
2009-06-18 20:51:48 +00:00
|
|
|
|
* @param $linestart bool whether or not this is at the start of a line.
|
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 ) {
|
2008-08-26 14:37:15 +00:00
|
|
|
|
wfProfileIn( __METHOD__ );
|
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.
|
|
|
|
|
|
#
|
2008-08-26 14:37:15 +00:00
|
|
|
|
$textLines = StringUtils::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;
|
|
|
|
|
|
|
|
|
|
|
|
foreach ( $textLines as $oLine ) {
|
2008-08-26 14:37:15 +00:00
|
|
|
|
# Fix up $linestart
|
|
|
|
|
|
if ( !$linestart ) {
|
|
|
|
|
|
$output .= $oLine;
|
|
|
|
|
|
$linestart = true;
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
2009-06-18 20:51:48 +00:00
|
|
|
|
// * = ul
|
|
|
|
|
|
// # = ol
|
|
|
|
|
|
// ; = dt
|
|
|
|
|
|
// : = dd
|
2008-08-26 14:37:15 +00:00
|
|
|
|
|
2004-04-29 06:16:21 +00:00
|
|
|
|
$lastPrefixLength = strlen( $lastPrefix );
|
2004-08-16 15:29:17 +00:00
|
|
|
|
$preCloseMatch = preg_match('/<\\/pre/i', $oLine );
|
|
|
|
|
|
$preOpenMatch = preg_match('/<pre/i', $oLine );
|
2009-06-18 20:51:48 +00:00
|
|
|
|
// If not in a <pre> element, scan for and figure out what prefixes are there.
|
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.
|
2009-08-27 17:16:15 +00:00
|
|
|
|
$prefixLength = strspn( $oLine, '*#:;' );
|
2008-08-26 14:37:15 +00:00
|
|
|
|
$prefix = substr( $oLine, 0, $prefixLength );
|
2004-07-12 19:49:20 +00:00
|
|
|
|
|
2004-04-29 06:16:21 +00:00
|
|
|
|
# eh?
|
2009-06-18 20:51:48 +00:00
|
|
|
|
// ; and : are both from definition-lists, so they're equivalent
|
|
|
|
|
|
// for the purposes of determining whether or not we need to open/close
|
|
|
|
|
|
// elements.
|
2008-08-26 14:37:15 +00:00
|
|
|
|
$prefix2 = str_replace( ';', ':', $prefix );
|
2004-04-29 06:16:21 +00:00
|
|
|
|
$t = substr( $oLine, $prefixLength );
|
2008-08-26 14:37:15 +00:00
|
|
|
|
$this->mInPre = (bool)$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;
|
2008-08-26 14:37:15 +00:00
|
|
|
|
$prefix = $prefix2 = '';
|
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
|
2008-08-26 14:37:15 +00:00
|
|
|
|
if( $prefixLength && $lastPrefix === $prefix2 ) {
|
2004-04-29 06:16:21 +00:00
|
|
|
|
# Same as the last item, so no need to deal with nesting or opening stuff
|
2008-08-26 14:37:15 +00:00
|
|
|
|
$output .= $this->nextItem( substr( $prefix, -1 ) );
|
2004-04-29 06:16:21 +00:00
|
|
|
|
$paragraphStack = false;
|
2004-04-16 11:21:51 +00:00
|
|
|
|
|
2008-08-26 14:37:15 +00:00
|
|
|
|
if ( substr( $prefix, -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 = '';
|
2008-08-25 04:27:40 +00:00
|
|
|
|
if ($this->findColonNoLinks($t, $term, $t2) !== false) {
|
2004-09-27 21:01:39 +00:00
|
|
|
|
$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 ) {
|
2009-06-18 20:51:48 +00:00
|
|
|
|
// We need to open or close prefixes, or both.
|
2010-01-07 04:13:14 +00:00
|
|
|
|
|
2004-04-29 06:16:21 +00:00
|
|
|
|
# Either open or close a level...
|
2008-08-26 14:37:15 +00:00
|
|
|
|
$commonPrefixLength = $this->getCommon( $prefix, $lastPrefix );
|
2004-04-29 06:16:21 +00:00
|
|
|
|
$paragraphStack = false;
|
|
|
|
|
|
|
2009-06-18 20:51:48 +00:00
|
|
|
|
// Close all the prefixes which aren't shared.
|
2004-04-29 06:16:21 +00:00
|
|
|
|
while( $commonPrefixLength < $lastPrefixLength ) {
|
2008-08-26 14:37:15 +00:00
|
|
|
|
$output .= $this->closeList( $lastPrefix[$lastPrefixLength-1] );
|
2004-04-29 06:16:21 +00:00
|
|
|
|
--$lastPrefixLength;
|
2004-04-16 11:21:51 +00:00
|
|
|
|
}
|
2010-01-07 04:13:14 +00:00
|
|
|
|
|
2009-06-18 20:51:48 +00:00
|
|
|
|
// Continue the current prefix if appropriate.
|
2004-04-29 06:16:21 +00:00
|
|
|
|
if ( $prefixLength <= $commonPrefixLength && $commonPrefixLength > 0 ) {
|
2008-08-26 14:37:15 +00:00
|
|
|
|
$output .= $this->nextItem( $prefix[$commonPrefixLength-1] );
|
2004-04-16 11:21:51 +00:00
|
|
|
|
}
|
2010-01-07 04:13:14 +00:00
|
|
|
|
|
2009-06-18 20:51:48 +00:00
|
|
|
|
// Open prefixes where appropriate.
|
2004-04-29 06:16:21 +00:00
|
|
|
|
while ( $prefixLength > $commonPrefixLength ) {
|
2008-08-26 14:37:15 +00:00
|
|
|
|
$char = substr( $prefix, $commonPrefixLength, 1 );
|
2004-04-29 06:16:21 +00:00
|
|
|
|
$output .= $this->openList( $char );
|
2004-04-16 11:21:51 +00:00
|
|
|
|
|
2008-08-26 14:37:15 +00:00
|
|
|
|
if ( ';' === $char ) {
|
2004-04-29 06:16:21 +00:00
|
|
|
|
# FIXME: This is dupe of code above
|
2008-08-25 04:27:40 +00:00
|
|
|
|
if ($this->findColonNoLinks($t, $term, $t2) !== false) {
|
2004-09-27 21:01:39 +00:00
|
|
|
|
$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
|
|
|
|
}
|
2008-08-26 14:37:15 +00:00
|
|
|
|
$lastPrefix = $prefix2;
|
2004-02-26 13:37:26 +00:00
|
|
|
|
}
|
2010-01-07 04:13:14 +00:00
|
|
|
|
|
2009-06-18 20:51:48 +00:00
|
|
|
|
// If we have no prefixes, go to paragraph mode.
|
2004-04-29 06:16:21 +00:00
|
|
|
|
if( 0 == $prefixLength ) {
|
2008-08-26 14:37:15 +00:00
|
|
|
|
wfProfileIn( __METHOD__."-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
|
2007-04-13 00:23:49 +00:00
|
|
|
|
$openmatch = preg_match('/(?:<table|<blockquote|<h1|<h2|<h3|<h4|<h5|<h6|<pre|<tr|<p|<ul|<ol|<li|<\\/tr|<\\/td|<\\/th)/iS', $t );
|
2004-04-12 23:59:37 +00:00
|
|
|
|
$closematch = preg_match(
|
2007-04-13 00:23:49 +00:00
|
|
|
|
'/(?:<\\/table|<\\/blockquote|<\\/h1|<\\/h2|<\\/h3|<\\/h4|<\\/h5|<\\/h6|'.
|
2006-12-17 16:51:01 +00:00
|
|
|
|
'<td|<th|<\\/?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;
|
2010-01-26 11:57:01 +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
|
|
|
|
}
|
2010-01-26 11:57:01 +00:00
|
|
|
|
} elseif ( !$inBlockElem && !$this->mInPre ) {
|
|
|
|
|
|
if ( ' ' == substr( $t, 0, 1 ) and ( $this->mLastSection === 'pre' or trim($t) !== '' ) ) {
|
2004-04-10 15:11:14 +00:00
|
|
|
|
// pre
|
2008-08-26 14:37:15 +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
|
2010-01-06 19:59:42 +00:00
|
|
|
|
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 {
|
2008-08-26 14:37:15 +00:00
|
|
|
|
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';
|
2010-01-26 11:57:01 +00:00
|
|
|
|
} elseif ($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
|
|
|
|
}
|
2008-08-26 14:37:15 +00:00
|
|
|
|
wfProfileOut( __METHOD__."-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 ) {
|
2008-08-26 14:37:15 +00:00
|
|
|
|
$output .= $this->closeList( $prefix2[$prefixLength-1] );
|
2004-04-29 06:16:21 +00:00
|
|
|
|
--$prefixLength;
|
2004-02-26 13:37:26 +00:00
|
|
|
|
}
|
2010-01-26 11:57:01 +00:00
|
|
|
|
if ( $this->mLastSection !== '' ) {
|
2004-06-08 18:11:28 +00:00
|
|
|
|
$output .= '</' . $this->mLastSection . '>';
|
|
|
|
|
|
$this->mLastSection = '';
|
2004-02-26 13:37:26 +00:00
|
|
|
|
}
|
2004-04-12 23:59:37 +00:00
|
|
|
|
|
2008-08-26 14:37:15 +00:00
|
|
|
|
wfProfileOut( __METHOD__ );
|
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
|
|
|
|
|
|
*/
|
2008-08-25 04:27:40 +00:00
|
|
|
|
function findColonNoLinks($str, &$before, &$after) {
|
2008-08-26 14:37:15 +00:00
|
|
|
|
wfProfileIn( __METHOD__ );
|
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!
|
2008-08-26 14:37:15 +00:00
|
|
|
|
wfProfileOut( __METHOD__ );
|
2006-06-02 20:54:34 +00:00
|
|
|
|
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 );
|
2008-08-26 14:37:15 +00:00
|
|
|
|
wfProfileOut( __METHOD__ );
|
2006-06-02 20:54:34 +00:00
|
|
|
|
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.
|
2007-11-20 10:55:08 +00:00
|
|
|
|
$state = self::COLON_STATE_TEXT;
|
2006-06-02 20:54:34 +00:00
|
|
|
|
$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)
|
2007-11-20 10:55:08 +00:00
|
|
|
|
case 0: // self::COLON_STATE_TEXT:
|
2006-06-02 20:54:34 +00:00
|
|
|
|
switch( $c ) {
|
|
|
|
|
|
case "<":
|
|
|
|
|
|
// Could be either a <start> tag or an </end> tag
|
2007-11-20 10:55:08 +00:00
|
|
|
|
$state = self::COLON_STATE_TAGSTART;
|
2006-06-02 20:54:34 +00:00
|
|
|
|
break;
|
|
|
|
|
|
case ":":
|
|
|
|
|
|
if( $stack == 0 ) {
|
|
|
|
|
|
// We found it!
|
|
|
|
|
|
$before = substr( $str, 0, $i );
|
|
|
|
|
|
$after = substr( $str, $i + 1 );
|
2008-08-26 14:37:15 +00:00
|
|
|
|
wfProfileOut( __METHOD__ );
|
2006-06-02 20:54:34 +00:00
|
|
|
|
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
|
2008-08-26 14:37:15 +00:00
|
|
|
|
wfProfileOut( __METHOD__ );
|
2006-06-02 23:56:19 +00:00
|
|
|
|
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 );
|
2008-08-26 14:37:15 +00:00
|
|
|
|
wfProfileOut( __METHOD__ );
|
2006-06-02 23:56:19 +00:00
|
|
|
|
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;
|
2007-11-20 10:55:08 +00:00
|
|
|
|
$state = self::COLON_STATE_TAGSTART;
|
2006-06-02 20:54:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
break;
|
2007-11-20 10:55:08 +00:00
|
|
|
|
case 1: // self::COLON_STATE_TAG:
|
2006-06-02 20:54:34 +00:00
|
|
|
|
// In a <tag>
|
|
|
|
|
|
switch( $c ) {
|
|
|
|
|
|
case ">":
|
|
|
|
|
|
$stack++;
|
2007-11-20 10:55:08 +00:00
|
|
|
|
$state = self::COLON_STATE_TEXT;
|
2006-06-02 20:54:34 +00:00
|
|
|
|
break;
|
|
|
|
|
|
case "/":
|
|
|
|
|
|
// Slash may be followed by >?
|
2007-11-20 10:55:08 +00:00
|
|
|
|
$state = self::COLON_STATE_TAGSLASH;
|
2006-06-02 20:54:34 +00:00
|
|
|
|
break;
|
|
|
|
|
|
default:
|
|
|
|
|
|
// ignore
|
|
|
|
|
|
}
|
|
|
|
|
|
break;
|
2007-11-20 10:55:08 +00:00
|
|
|
|
case 2: // self::COLON_STATE_TAGSTART:
|
2006-06-02 20:54:34 +00:00
|
|
|
|
switch( $c ) {
|
|
|
|
|
|
case "/":
|
2007-11-20 10:55:08 +00:00
|
|
|
|
$state = self::COLON_STATE_CLOSETAG;
|
2004-09-27 21:01:39 +00:00
|
|
|
|
break;
|
2006-06-02 20:54:34 +00:00
|
|
|
|
case "!":
|
2007-11-20 10:55:08 +00:00
|
|
|
|
$state = self::COLON_STATE_COMMENT;
|
2006-06-02 20:54:34 +00:00
|
|
|
|
break;
|
|
|
|
|
|
case ">":
|
|
|
|
|
|
// Illegal early close? This shouldn't happen D:
|
2007-11-20 10:55:08 +00:00
|
|
|
|
$state = self::COLON_STATE_TEXT;
|
2006-06-02 20:54:34 +00:00
|
|
|
|
break;
|
|
|
|
|
|
default:
|
2007-11-20 10:55:08 +00:00
|
|
|
|
$state = self::COLON_STATE_TAG;
|
2006-06-02 20:54:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
break;
|
2007-11-20 10:55:08 +00:00
|
|
|
|
case 3: // self::COLON_STATE_CLOSETAG:
|
2006-06-02 20:54:34 +00:00
|
|
|
|
// In a </tag>
|
2008-08-26 14:37:15 +00:00
|
|
|
|
if( $c === ">" ) {
|
2006-06-02 20:54:34 +00:00
|
|
|
|
$stack--;
|
|
|
|
|
|
if( $stack < 0 ) {
|
2008-08-26 14:37:15 +00:00
|
|
|
|
wfDebug( __METHOD__.": Invalid input; too many close tags\n" );
|
|
|
|
|
|
wfProfileOut( __METHOD__ );
|
2006-06-02 20:54:34 +00:00
|
|
|
|
return false;
|
|
|
|
|
|
}
|
2007-11-20 10:55:08 +00:00
|
|
|
|
$state = self::COLON_STATE_TEXT;
|
2006-06-02 20:54:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
break;
|
2007-11-20 10:55:08 +00:00
|
|
|
|
case self::COLON_STATE_TAGSLASH:
|
2008-08-26 14:37:15 +00:00
|
|
|
|
if( $c === ">" ) {
|
2006-06-02 20:54:34 +00:00
|
|
|
|
// Yes, a self-closed tag <blah/>
|
2007-11-20 10:55:08 +00:00
|
|
|
|
$state = self::COLON_STATE_TEXT;
|
2006-06-02 20:54:34 +00:00
|
|
|
|
} else {
|
|
|
|
|
|
// Probably we're jumping the gun, and this is an attribute
|
2007-11-20 10:55:08 +00:00
|
|
|
|
$state = self::COLON_STATE_TAG;
|
2006-06-02 20:54:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
break;
|
2007-11-20 10:55:08 +00:00
|
|
|
|
case 5: // self::COLON_STATE_COMMENT:
|
2008-08-26 14:37:15 +00:00
|
|
|
|
if( $c === "-" ) {
|
2007-11-20 10:55:08 +00:00
|
|
|
|
$state = self::COLON_STATE_COMMENTDASH;
|
2006-06-02 20:54:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
break;
|
2007-11-20 10:55:08 +00:00
|
|
|
|
case self::COLON_STATE_COMMENTDASH:
|
2008-08-26 14:37:15 +00:00
|
|
|
|
if( $c === "-" ) {
|
2007-11-20 10:55:08 +00:00
|
|
|
|
$state = self::COLON_STATE_COMMENTDASHDASH;
|
2006-06-02 20:54:34 +00:00
|
|
|
|
} else {
|
2007-11-20 10:55:08 +00:00
|
|
|
|
$state = self::COLON_STATE_COMMENT;
|
2006-06-02 20:54:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
break;
|
2007-11-20 10:55:08 +00:00
|
|
|
|
case self::COLON_STATE_COMMENTDASHDASH:
|
2008-08-26 14:37:15 +00:00
|
|
|
|
if( $c === ">" ) {
|
2007-11-20 10:55:08 +00:00
|
|
|
|
$state = self::COLON_STATE_TEXT;
|
2006-06-02 20:54:34 +00:00
|
|
|
|
} else {
|
2007-11-20 10:55:08 +00:00
|
|
|
|
$state = self::COLON_STATE_COMMENT;
|
2004-09-27 21:01:39 +00:00
|
|
|
|
}
|
2006-06-02 20:54:34 +00:00
|
|
|
|
break;
|
|
|
|
|
|
default:
|
2008-08-26 14:37:15 +00:00
|
|
|
|
throw new MWException( "State machine error in " . __METHOD__ );
|
2004-09-27 21:01:39 +00:00
|
|
|
|
}
|
2006-06-02 20:54:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
if( $stack > 0 ) {
|
2008-08-26 14:37:15 +00:00
|
|
|
|
wfDebug( __METHOD__.": Invalid input; not enough close tags (stack $stack, state $state)\n" );
|
2006-06-02 20:54:34 +00:00
|
|
|
|
return false;
|
|
|
|
|
|
}
|
2008-08-26 14:37:15 +00:00
|
|
|
|
wfProfileOut( __METHOD__ );
|
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
|
|
|
|
*/
|
2009-08-30 06:37:10 +00:00
|
|
|
|
function getVariableValue( $index, $frame=false ) {
|
2009-09-26 11:51:37 +00:00
|
|
|
|
global $wgContLang, $wgSitename, $wgServer, $wgServerName;
|
|
|
|
|
|
global $wgScriptPath, $wgStylePath;
|
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.
|
|
|
|
|
|
*/
|
2008-01-24 04:29:56 +00:00
|
|
|
|
if ( wfRunHooks( 'ParserGetVariableValueVarCache', array( &$this, &$this->mVarCache ) ) ) {
|
|
|
|
|
|
if ( isset( $this->mVarCache[$index] ) ) {
|
|
|
|
|
|
return $this->mVarCache[$index];
|
2006-10-17 08:49:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2005-11-26 23:04:05 +00:00
|
|
|
|
|
2008-01-24 04:29:56 +00:00
|
|
|
|
$ts = wfTimestamp( TS_UNIX, $this->mOptions->getTimestamp() );
|
2005-11-26 23:04:05 +00:00
|
|
|
|
wfRunHooks( 'ParserGetVariableValueTs', array( &$this, &$ts ) );
|
2005-07-03 07:15:53 +00:00
|
|
|
|
|
2006-08-23 16:45:49 +00:00
|
|
|
|
# Use the time zone
|
|
|
|
|
|
global $wgLocaltimezone;
|
|
|
|
|
|
if ( isset( $wgLocaltimezone ) ) {
|
2010-01-08 01:48:53 +00:00
|
|
|
|
$oldtz = date_default_timezone_get();
|
|
|
|
|
|
date_default_timezone_set( $wgLocaltimezone );
|
2006-08-23 16:45:49 +00:00
|
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
|
2006-08-23 16:45:49 +00:00
|
|
|
|
$localTimestamp = date( 'YmdHis', $ts );
|
|
|
|
|
|
$localMonth = date( 'm', $ts );
|
2009-05-20 07:14:03 +00:00
|
|
|
|
$localMonth1 = date( 'n', $ts );
|
2006-08-23 16:45:49 +00:00
|
|
|
|
$localMonthName = date( 'n', $ts );
|
|
|
|
|
|
$localDay = date( 'j', $ts );
|
|
|
|
|
|
$localDay2 = date( 'd', $ts );
|
|
|
|
|
|
$localDayOfWeek = date( 'w', $ts );
|
|
|
|
|
|
$localWeek = date( 'W', $ts );
|
|
|
|
|
|
$localYear = date( 'Y', $ts );
|
|
|
|
|
|
$localHour = date( 'H', $ts );
|
|
|
|
|
|
if ( isset( $wgLocaltimezone ) ) {
|
2010-01-08 01:48:53 +00:00
|
|
|
|
date_default_timezone_set( $oldtz );
|
2006-08-23 16:45:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2004-03-20 15:03:26 +00:00
|
|
|
|
switch ( $index ) {
|
2006-07-14 15:39:23 +00:00
|
|
|
|
case 'currentmonth':
|
2009-10-02 09:46:17 +00:00
|
|
|
|
$value = $wgContLang->formatNum( gmdate( 'm', $ts ) );
|
|
|
|
|
|
break;
|
2009-05-20 07:14:03 +00:00
|
|
|
|
case 'currentmonth1':
|
2009-10-02 09:46:17 +00:00
|
|
|
|
$value = $wgContLang->formatNum( gmdate( 'n', $ts ) );
|
|
|
|
|
|
break;
|
2006-07-14 15:39:23 +00:00
|
|
|
|
case 'currentmonthname':
|
2009-10-02 09:46:17 +00:00
|
|
|
|
$value = $wgContLang->getMonthName( gmdate( 'n', $ts ) );
|
|
|
|
|
|
break;
|
2006-07-14 15:39:23 +00:00
|
|
|
|
case 'currentmonthnamegen':
|
2009-10-02 09:46:17 +00:00
|
|
|
|
$value = $wgContLang->getMonthNameGen( gmdate( 'n', $ts ) );
|
|
|
|
|
|
break;
|
2006-07-14 15:39:23 +00:00
|
|
|
|
case 'currentmonthabbrev':
|
2009-10-02 09:46:17 +00:00
|
|
|
|
$value = $wgContLang->getMonthAbbreviation( gmdate( 'n', $ts ) );
|
|
|
|
|
|
break;
|
2006-07-14 15:39:23 +00:00
|
|
|
|
case 'currentday':
|
2009-10-02 09:46:17 +00:00
|
|
|
|
$value = $wgContLang->formatNum( gmdate( 'j', $ts ) );
|
|
|
|
|
|
break;
|
2006-07-14 15:39:23 +00:00
|
|
|
|
case 'currentday2':
|
2009-10-02 09:46:17 +00:00
|
|
|
|
$value = $wgContLang->formatNum( gmdate( 'd', $ts ) );
|
|
|
|
|
|
break;
|
2006-08-23 16:45:49 +00:00
|
|
|
|
case 'localmonth':
|
2009-10-02 09:46:17 +00:00
|
|
|
|
$value = $wgContLang->formatNum( $localMonth );
|
|
|
|
|
|
break;
|
2009-05-20 07:14:03 +00:00
|
|
|
|
case 'localmonth1':
|
2009-10-02 09:46:17 +00:00
|
|
|
|
$value = $wgContLang->formatNum( $localMonth1 );
|
|
|
|
|
|
break;
|
2006-08-23 16:45:49 +00:00
|
|
|
|
case 'localmonthname':
|
2009-10-02 09:46:17 +00:00
|
|
|
|
$value = $wgContLang->getMonthName( $localMonthName );
|
|
|
|
|
|
break;
|
2006-08-23 16:45:49 +00:00
|
|
|
|
case 'localmonthnamegen':
|
2009-10-02 09:46:17 +00:00
|
|
|
|
$value = $wgContLang->getMonthNameGen( $localMonthName );
|
|
|
|
|
|
break;
|
2006-08-23 16:45:49 +00:00
|
|
|
|
case 'localmonthabbrev':
|
2009-10-02 09:46:17 +00:00
|
|
|
|
$value = $wgContLang->getMonthAbbreviation( $localMonthName );
|
|
|
|
|
|
break;
|
2006-08-23 16:45:49 +00:00
|
|
|
|
case 'localday':
|
2009-10-02 09:46:17 +00:00
|
|
|
|
$value = $wgContLang->formatNum( $localDay );
|
|
|
|
|
|
break;
|
2006-08-23 16:45:49 +00:00
|
|
|
|
case 'localday2':
|
2009-10-02 09:46:17 +00:00
|
|
|
|
$value = $wgContLang->formatNum( $localDay2 );
|
|
|
|
|
|
break;
|
2006-07-14 15:39:23 +00:00
|
|
|
|
case 'pagename':
|
2009-10-02 09:46:17 +00:00
|
|
|
|
$value = wfEscapeWikiText( $this->mTitle->getText() );
|
|
|
|
|
|
break;
|
2006-07-14 15:39:23 +00:00
|
|
|
|
case 'pagenamee':
|
2009-10-02 09:46:17 +00:00
|
|
|
|
$value = $this->mTitle->getPartialURL();
|
|
|
|
|
|
break;
|
2006-07-14 15:39:23 +00:00
|
|
|
|
case 'fullpagename':
|
2009-10-02 09:46:17 +00:00
|
|
|
|
$value = wfEscapeWikiText( $this->mTitle->getPrefixedText() );
|
|
|
|
|
|
break;
|
2006-07-14 15:39:23 +00:00
|
|
|
|
case 'fullpagenamee':
|
2009-10-02 09:46:17 +00:00
|
|
|
|
$value = $this->mTitle->getPrefixedURL();
|
|
|
|
|
|
break;
|
2006-07-14 15:39:23 +00:00
|
|
|
|
case 'subpagename':
|
2009-10-02 09:46:17 +00:00
|
|
|
|
$value = wfEscapeWikiText( $this->mTitle->getSubpageText() );
|
|
|
|
|
|
break;
|
2006-07-14 15:39:23 +00:00
|
|
|
|
case 'subpagenamee':
|
2009-10-02 09:46:17 +00:00
|
|
|
|
$value = $this->mTitle->getSubpageUrlForm();
|
|
|
|
|
|
break;
|
2006-07-14 15:39:23 +00:00
|
|
|
|
case 'basepagename':
|
2009-10-02 09:46:17 +00:00
|
|
|
|
$value = wfEscapeWikiText( $this->mTitle->getBaseText() );
|
|
|
|
|
|
break;
|
2006-07-14 15:39:23 +00:00
|
|
|
|
case 'basepagenamee':
|
2009-10-02 09:46:17 +00:00
|
|
|
|
$value = wfUrlEncode( str_replace( ' ', '_', $this->mTitle->getBaseText() ) );
|
|
|
|
|
|
break;
|
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();
|
2009-10-02 09:46:17 +00:00
|
|
|
|
$value = wfEscapeWikiText( $talkPage->getPrefixedText() );
|
2006-04-12 15:38:17 +00:00
|
|
|
|
} else {
|
2009-10-02 09:46:17 +00:00
|
|
|
|
$value = '';
|
2006-04-12 15:38:17 +00:00
|
|
|
|
}
|
2009-10-02 09:46:17 +00:00
|
|
|
|
break;
|
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();
|
2009-10-02 09:46:17 +00:00
|
|
|
|
$value = $talkPage->getPrefixedUrl();
|
2006-04-12 15:38:17 +00:00
|
|
|
|
} else {
|
2009-10-02 09:46:17 +00:00
|
|
|
|
$value = '';
|
2006-04-12 15:38:17 +00:00
|
|
|
|
}
|
2009-10-02 09:46:17 +00:00
|
|
|
|
break;
|
2006-07-14 15:39:23 +00:00
|
|
|
|
case 'subjectpagename':
|
2006-04-12 15:38:17 +00:00
|
|
|
|
$subjPage = $this->mTitle->getSubjectPage();
|
2009-10-02 09:46:17 +00:00
|
|
|
|
$value = wfEscapeWikiText( $subjPage->getPrefixedText() );
|
|
|
|
|
|
break;
|
2006-07-14 15:39:23 +00:00
|
|
|
|
case 'subjectpagenamee':
|
2006-04-12 15:38:17 +00:00
|
|
|
|
$subjPage = $this->mTitle->getSubjectPage();
|
2009-10-02 09:46:17 +00:00
|
|
|
|
$value = $subjPage->getPrefixedUrl();
|
|
|
|
|
|
break;
|
2006-07-14 15:39:23 +00:00
|
|
|
|
case 'revisionid':
|
2007-11-15 02:54:28 +00:00
|
|
|
|
// Let the edit saving system know we should parse the page
|
|
|
|
|
|
// *after* a revision ID has been assigned.
|
|
|
|
|
|
$this->mOutput->setFlag( 'vary-revision' );
|
|
|
|
|
|
wfDebug( __METHOD__ . ": {{REVISIONID}} used, setting vary-revision...\n" );
|
2009-10-02 09:46:17 +00:00
|
|
|
|
$value = $this->mRevisionId;
|
|
|
|
|
|
break;
|
2006-09-26 17:20:36 +00:00
|
|
|
|
case 'revisionday':
|
2008-01-06 03:17:09 +00:00
|
|
|
|
// Let the edit saving system know we should parse the page
|
|
|
|
|
|
// *after* a revision ID has been assigned. This is for null edits.
|
|
|
|
|
|
$this->mOutput->setFlag( 'vary-revision' );
|
|
|
|
|
|
wfDebug( __METHOD__ . ": {{REVISIONDAY}} used, setting vary-revision...\n" );
|
2009-10-02 09:46:17 +00:00
|
|
|
|
$value = intval( substr( $this->getRevisionTimestamp(), 6, 2 ) );
|
|
|
|
|
|
break;
|
2006-09-26 17:20:36 +00:00
|
|
|
|
case 'revisionday2':
|
2008-01-06 03:17:09 +00:00
|
|
|
|
// Let the edit saving system know we should parse the page
|
|
|
|
|
|
// *after* a revision ID has been assigned. This is for null edits.
|
|
|
|
|
|
$this->mOutput->setFlag( 'vary-revision' );
|
|
|
|
|
|
wfDebug( __METHOD__ . ": {{REVISIONDAY2}} used, setting vary-revision...\n" );
|
2009-10-02 09:46:17 +00:00
|
|
|
|
$value = substr( $this->getRevisionTimestamp(), 6, 2 );
|
|
|
|
|
|
break;
|
2006-09-26 17:20:36 +00:00
|
|
|
|
case 'revisionmonth':
|
2008-01-06 03:17:09 +00:00
|
|
|
|
// Let the edit saving system know we should parse the page
|
|
|
|
|
|
// *after* a revision ID has been assigned. This is for null edits.
|
|
|
|
|
|
$this->mOutput->setFlag( 'vary-revision' );
|
|
|
|
|
|
wfDebug( __METHOD__ . ": {{REVISIONMONTH}} used, setting vary-revision...\n" );
|
2009-10-02 09:46:17 +00:00
|
|
|
|
$value = intval( substr( $this->getRevisionTimestamp(), 4, 2 ) );
|
|
|
|
|
|
break;
|
2006-09-26 17:20:36 +00:00
|
|
|
|
case 'revisionyear':
|
2008-01-06 03:17:09 +00:00
|
|
|
|
// Let the edit saving system know we should parse the page
|
|
|
|
|
|
// *after* a revision ID has been assigned. This is for null edits.
|
|
|
|
|
|
$this->mOutput->setFlag( 'vary-revision' );
|
|
|
|
|
|
wfDebug( __METHOD__ . ": {{REVISIONYEAR}} used, setting vary-revision...\n" );
|
2009-10-02 09:46:17 +00:00
|
|
|
|
$value = substr( $this->getRevisionTimestamp(), 0, 4 );
|
|
|
|
|
|
break;
|
2006-09-26 17:20:36 +00:00
|
|
|
|
case 'revisiontimestamp':
|
2008-01-06 03:17:09 +00:00
|
|
|
|
// Let the edit saving system know we should parse the page
|
|
|
|
|
|
// *after* a revision ID has been assigned. This is for null edits.
|
|
|
|
|
|
$this->mOutput->setFlag( 'vary-revision' );
|
|
|
|
|
|
wfDebug( __METHOD__ . ": {{REVISIONTIMESTAMP}} used, setting vary-revision...\n" );
|
2009-10-02 09:46:17 +00:00
|
|
|
|
$value = $this->getRevisionTimestamp();
|
|
|
|
|
|
break;
|
2009-03-07 23:01:59 +00:00
|
|
|
|
case 'revisionuser':
|
|
|
|
|
|
// Let the edit saving system know we should parse the page
|
|
|
|
|
|
// *after* a revision ID has been assigned. This is for null edits.
|
|
|
|
|
|
$this->mOutput->setFlag( 'vary-revision' );
|
|
|
|
|
|
wfDebug( __METHOD__ . ": {{REVISIONUSER}} used, setting vary-revision...\n" );
|
2009-10-02 09:46:17 +00:00
|
|
|
|
$value = $this->getRevisionUser();
|
|
|
|
|
|
break;
|
2006-07-14 15:39:23 +00:00
|
|
|
|
case 'namespace':
|
2009-10-02 09:46:17 +00:00
|
|
|
|
$value = str_replace('_',' ',$wgContLang->getNsText( $this->mTitle->getNamespace() ) );
|
|
|
|
|
|
break;
|
2006-07-14 15:39:23 +00:00
|
|
|
|
case 'namespacee':
|
2009-10-02 09:46:17 +00:00
|
|
|
|
$value = wfUrlencode( $wgContLang->getNsText( $this->mTitle->getNamespace() ) );
|
|
|
|
|
|
break;
|
2006-07-14 15:39:23 +00:00
|
|
|
|
case 'talkspace':
|
2009-10-02 09:46:17 +00:00
|
|
|
|
$value = $this->mTitle->canTalk() ? str_replace('_',' ',$this->mTitle->getTalkNsText()) : '';
|
|
|
|
|
|
break;
|
2006-07-14 15:39:23 +00:00
|
|
|
|
case 'talkspacee':
|
2009-10-02 09:46:17 +00:00
|
|
|
|
$value = $this->mTitle->canTalk() ? wfUrlencode( $this->mTitle->getTalkNsText() ) : '';
|
|
|
|
|
|
break;
|
2006-07-14 15:39:23 +00:00
|
|
|
|
case 'subjectspace':
|
2009-10-02 09:46:17 +00:00
|
|
|
|
$value = $this->mTitle->getSubjectNsText();
|
|
|
|
|
|
break;
|
2006-07-14 15:39:23 +00:00
|
|
|
|
case 'subjectspacee':
|
2009-10-02 09:46:17 +00:00
|
|
|
|
$value = ( wfUrlencode( $this->mTitle->getSubjectNsText() ) );
|
|
|
|
|
|
break;
|
2006-07-14 15:39:23 +00:00
|
|
|
|
case 'currentdayname':
|
2009-10-02 09:46:17 +00:00
|
|
|
|
$value = $wgContLang->getWeekdayName( gmdate( 'w', $ts ) + 1 );
|
|
|
|
|
|
break;
|
2006-07-14 15:39:23 +00:00
|
|
|
|
case 'currentyear':
|
2009-10-02 09:46:17 +00:00
|
|
|
|
$value = $wgContLang->formatNum( gmdate( 'Y', $ts ), true );
|
|
|
|
|
|
break;
|
2006-07-14 15:39:23 +00:00
|
|
|
|
case 'currenttime':
|
2009-10-02 09:46:17 +00:00
|
|
|
|
$value = $wgContLang->time( wfTimestamp( TS_MW, $ts ), false, false );
|
|
|
|
|
|
break;
|
2006-08-14 22:43:50 +00:00
|
|
|
|
case 'currenthour':
|
2009-10-02 09:46:17 +00:00
|
|
|
|
$value = $wgContLang->formatNum( gmdate( 'H', $ts ), true );
|
|
|
|
|
|
break;
|
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
|
2009-10-02 09:46:17 +00:00
|
|
|
|
$value = $wgContLang->formatNum( (int)gmdate( 'W', $ts ) );
|
|
|
|
|
|
break;
|
2006-07-14 15:39:23 +00:00
|
|
|
|
case 'currentdow':
|
2009-10-02 09:46:17 +00:00
|
|
|
|
$value = $wgContLang->formatNum( gmdate( 'w', $ts ) );
|
|
|
|
|
|
break;
|
2006-08-23 16:45:49 +00:00
|
|
|
|
case 'localdayname':
|
2009-10-02 09:46:17 +00:00
|
|
|
|
$value = $wgContLang->getWeekdayName( $localDayOfWeek + 1 );
|
|
|
|
|
|
break;
|
2006-08-23 16:45:49 +00:00
|
|
|
|
case 'localyear':
|
2009-10-02 09:46:17 +00:00
|
|
|
|
$value = $wgContLang->formatNum( $localYear, true );
|
|
|
|
|
|
break;
|
2006-08-23 16:45:49 +00:00
|
|
|
|
case 'localtime':
|
2009-10-02 09:46:17 +00:00
|
|
|
|
$value = $wgContLang->time( $localTimestamp, false, false );
|
|
|
|
|
|
break;
|
2006-08-23 16:45:49 +00:00
|
|
|
|
case 'localhour':
|
2009-10-02 09:46:17 +00:00
|
|
|
|
$value = $wgContLang->formatNum( $localHour, true );
|
|
|
|
|
|
break;
|
2006-08-23 16:45:49 +00:00
|
|
|
|
case 'localweek':
|
|
|
|
|
|
// @bug 4594 PHP5 has it zero padded, PHP4 does not, cast to
|
|
|
|
|
|
// int to remove the padding
|
2009-10-02 09:46:17 +00:00
|
|
|
|
$value = $wgContLang->formatNum( (int)$localWeek );
|
|
|
|
|
|
break;
|
2006-08-23 16:45:49 +00:00
|
|
|
|
case 'localdow':
|
2009-10-02 09:46:17 +00:00
|
|
|
|
$value = $wgContLang->formatNum( $localDayOfWeek );
|
|
|
|
|
|
break;
|
2006-07-14 15:39:23 +00:00
|
|
|
|
case 'numberofarticles':
|
2009-10-02 09:46:17 +00:00
|
|
|
|
$value = $wgContLang->formatNum( SiteStats::articles() );
|
|
|
|
|
|
break;
|
2006-07-14 15:39:23 +00:00
|
|
|
|
case 'numberoffiles':
|
2009-10-02 09:46:17 +00:00
|
|
|
|
$value = $wgContLang->formatNum( SiteStats::images() );
|
|
|
|
|
|
break;
|
2006-07-14 15:39:23 +00:00
|
|
|
|
case 'numberofusers':
|
2009-10-02 09:46:17 +00:00
|
|
|
|
$value = $wgContLang->formatNum( SiteStats::users() );
|
|
|
|
|
|
break;
|
2009-02-17 23:05:04 +00:00
|
|
|
|
case 'numberofactiveusers':
|
2009-10-02 09:46:17 +00:00
|
|
|
|
$value = $wgContLang->formatNum( SiteStats::activeUsers() );
|
|
|
|
|
|
break;
|
2006-07-14 15:39:23 +00:00
|
|
|
|
case 'numberofpages':
|
2009-10-02 09:46:17 +00:00
|
|
|
|
$value = $wgContLang->formatNum( SiteStats::pages() );
|
|
|
|
|
|
break;
|
2006-07-14 15:39:23 +00:00
|
|
|
|
case 'numberofadmins':
|
2009-10-02 09:46:17 +00:00
|
|
|
|
$value = $wgContLang->formatNum( SiteStats::numberingroup('sysop') );
|
|
|
|
|
|
break;
|
2007-04-17 09:23:31 +00:00
|
|
|
|
case 'numberofedits':
|
2009-10-02 09:46:17 +00:00
|
|
|
|
$value = $wgContLang->formatNum( SiteStats::edits() );
|
|
|
|
|
|
break;
|
2008-10-19 04:11:02 +00:00
|
|
|
|
case 'numberofviews':
|
2009-10-02 09:46:17 +00:00
|
|
|
|
$value = $wgContLang->formatNum( SiteStats::views() );
|
|
|
|
|
|
break;
|
2006-07-14 15:39:23 +00:00
|
|
|
|
case 'currenttimestamp':
|
2009-10-02 09:46:17 +00:00
|
|
|
|
$value = wfTimestamp( TS_MW, $ts );
|
|
|
|
|
|
break;
|
2006-08-23 16:45:49 +00:00
|
|
|
|
case 'localtimestamp':
|
2009-10-02 09:46:17 +00:00
|
|
|
|
$value = $localTimestamp;
|
|
|
|
|
|
break;
|
2006-07-14 15:39:23 +00:00
|
|
|
|
case 'currentversion':
|
2009-10-02 09:46:17 +00:00
|
|
|
|
$value = SpecialVersion::getVersion();
|
|
|
|
|
|
break;
|
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;
|
2009-12-16 12:02:41 +00:00
|
|
|
|
case 'stylepath':
|
|
|
|
|
|
return $wgStylePath;
|
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':
|
2007-04-27 15:12:22 +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;
|
2009-08-30 06:37:10 +00:00
|
|
|
|
if ( wfRunHooks( 'ParserGetVariableValueSwitch', array( &$this, &$this->mVarCache, &$index, &$ret, &$frame ) ) )
|
2005-11-25 06:53:20 +00:00
|
|
|
|
return $ret;
|
|
|
|
|
|
else
|
|
|
|
|
|
return null;
|
2004-03-20 15:03:26 +00:00
|
|
|
|
}
|
2009-10-02 09:46:17 +00:00
|
|
|
|
|
2010-01-07 04:13:14 +00:00
|
|
|
|
if ( $index )
|
2009-10-02 09:46:17 +00:00
|
|
|
|
$this->mVarCache[$index] = $value;
|
|
|
|
|
|
|
|
|
|
|
|
return $value;
|
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() {
|
2008-08-26 14:37:15 +00:00
|
|
|
|
wfProfileIn( __METHOD__ );
|
2006-07-14 16:36:35 +00:00
|
|
|
|
$variableIDs = MagicWord::getVariableIDs();
|
2006-07-03 11:07:00 +00:00
|
|
|
|
|
2007-11-20 10:55:08 +00:00
|
|
|
|
$this->mVariables = new MagicWordArray( $variableIDs );
|
2008-08-26 14:37:15 +00:00
|
|
|
|
wfProfileOut( __METHOD__ );
|
2004-03-20 15:03:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2005-10-19 06:24:30 +00:00
|
|
|
|
/**
|
2008-01-05 12:39:12 +00:00
|
|
|
|
* Preprocess some wikitext and return the document tree.
|
2008-09-15 06:37:57 +00:00
|
|
|
|
* This is the ghost of replace_variables().
|
2005-10-19 06:24:30 +00:00
|
|
|
|
*
|
|
|
|
|
|
* @param string $text The text to parse
|
2008-01-05 12:39:12 +00:00
|
|
|
|
* @param integer flags Bitwise combination of:
|
2008-04-14 07:45:50 +00:00
|
|
|
|
* self::PTD_FOR_INCLUSION Handle <noinclude>/<includeonly> as if the text is being
|
|
|
|
|
|
* included. Default is to assume a direct page view.
|
2008-01-05 12:39:12 +00:00
|
|
|
|
*
|
2008-01-19 09:03:45 +00:00
|
|
|
|
* The generated DOM tree must depend only on the input text and the flags.
|
2008-04-14 07:45:50 +00:00
|
|
|
|
* The DOM tree must be the same in OT_HTML and OT_WIKI mode, to avoid a regression of bug 4899.
|
2008-01-05 12:39:12 +00:00
|
|
|
|
*
|
2008-04-14 07:45:50 +00:00
|
|
|
|
* Any flag added to the $flags parameter here, or any other parameter liable to cause a
|
|
|
|
|
|
* change in the DOM tree for a given text, must be passed through the section identifier
|
|
|
|
|
|
* in the section edit link and thus back to extractSections().
|
2008-01-05 12:39:12 +00:00
|
|
|
|
*
|
2008-04-14 07:45:50 +00:00
|
|
|
|
* The output of this function is currently only cached in process memory, but a persistent
|
|
|
|
|
|
* cache may be implemented at a later date which takes further advantage of these strict
|
2008-01-05 12:39:12 +00:00
|
|
|
|
* dependency requirements.
|
|
|
|
|
|
*
|
2006-04-19 15:46:24 +00:00
|
|
|
|
* @private
|
2005-10-19 06:24:30 +00:00
|
|
|
|
*/
|
2008-09-15 06:37:57 +00:00
|
|
|
|
function preprocessToDom ( $text, $flags = 0 ) {
|
2008-01-21 16:36:08 +00:00
|
|
|
|
$dom = $this->getPreprocessor()->preprocessToObj( $text, $flags );
|
2007-11-20 10:55:08 +00:00
|
|
|
|
return $dom;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2008-04-14 07:45:50 +00:00
|
|
|
|
/*
|
2007-11-20 10:55:08 +00:00
|
|
|
|
* Return a three-element array: leading whitespace, string contents, trailing whitespace
|
|
|
|
|
|
*/
|
|
|
|
|
|
public static function splitWhitespace( $s ) {
|
|
|
|
|
|
$ltrimmed = ltrim( $s );
|
|
|
|
|
|
$w1 = substr( $s, 0, strlen( $s ) - strlen( $ltrimmed ) );
|
|
|
|
|
|
$trimmed = rtrim( $ltrimmed );
|
|
|
|
|
|
$diff = strlen( $ltrimmed ) - strlen( $trimmed );
|
|
|
|
|
|
if ( $diff > 0 ) {
|
|
|
|
|
|
$w2 = substr( $ltrimmed, -$diff );
|
|
|
|
|
|
} else {
|
|
|
|
|
|
$w2 = '';
|
|
|
|
|
|
}
|
|
|
|
|
|
return array( $w1, $trimmed, $w2 );
|
2005-10-19 06:24:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
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:
|
2008-01-22 10:47:44 +00:00
|
|
|
|
* self::OT_WIKI: only {{subst:}} templates
|
|
|
|
|
|
* self::OT_PREPROCESS: templates but not extension tags
|
|
|
|
|
|
* self::OT_HTML: all templates and extension tags
|
2005-07-03 07:15:53 +00:00
|
|
|
|
*
|
2004-09-21 05:49:12 +00:00
|
|
|
|
* @param string $tex The text to transform
|
2010-01-07 04:13:14 +00:00
|
|
|
|
* @param PPFrame $frame Object describing the arguments passed to the template.
|
2008-06-26 13:05:40 +00:00
|
|
|
|
* Arguments may also be provided as an associative array, as was the usual case before MW1.12.
|
|
|
|
|
|
* Providing arguments this way may be useful for extensions wishing to perform variable replacement explicitly.
|
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
|
|
|
|
*/
|
2007-11-20 10:55:08 +00:00
|
|
|
|
function replaceVariables( $text, $frame = false, $argsOnly = false ) {
|
2009-03-02 02:06:01 +00:00
|
|
|
|
# Is there any text? Also, Prevent too big inclusions!
|
|
|
|
|
|
if ( strlen( $text ) < 1 || strlen( $text ) > $this->mOptions->getMaxIncludeSize() ) {
|
2004-11-21 14:07:24 +00:00
|
|
|
|
return $text;
|
|
|
|
|
|
}
|
2008-08-26 14:37:15 +00:00
|
|
|
|
wfProfileIn( __METHOD__ );
|
2004-04-12 23:59:37 +00:00
|
|
|
|
|
2007-11-20 10:55:08 +00:00
|
|
|
|
if ( $frame === false ) {
|
2008-01-21 16:36:08 +00:00
|
|
|
|
$frame = $this->getPreprocessor()->newFrame();
|
2007-11-20 10:55:08 +00:00
|
|
|
|
} elseif ( !( $frame instanceof PPFrame ) ) {
|
2008-06-26 13:05:40 +00:00
|
|
|
|
wfDebug( __METHOD__." called using plain parameters instead of a PPFrame instance. Creating custom frame.\n" );
|
|
|
|
|
|
$frame = $this->getPreprocessor()->newCustomFrame($frame);
|
2004-05-23 03:39:24 +00:00
|
|
|
|
}
|
2004-04-12 23:59:37 +00:00
|
|
|
|
|
2007-11-20 10:55:08 +00:00
|
|
|
|
$dom = $this->preprocessToDom( $text );
|
|
|
|
|
|
$flags = $argsOnly ? PPFrame::NO_TEMPLATES : 0;
|
2007-12-01 07:13:31 +00:00
|
|
|
|
$text = $frame->expand( $dom, $flags );
|
2006-07-11 17:40:11 +00:00
|
|
|
|
|
2008-08-26 14:37:15 +00:00
|
|
|
|
wfProfileOut( __METHOD__ );
|
2004-09-21 23:30:46 +00:00
|
|
|
|
return $text;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2006-12-11 23:50:41 +00:00
|
|
|
|
/// Clean up argument array - refactored in 1.9 so parserfunctions can use it, too.
|
|
|
|
|
|
static function createAssocArgs( $args ) {
|
|
|
|
|
|
$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;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2007-01-17 19:48:48 +00:00
|
|
|
|
|
2006-12-11 23:50:41 +00:00
|
|
|
|
return $assocArgs;
|
|
|
|
|
|
}
|
2007-01-17 19:48:48 +00:00
|
|
|
|
|
2008-05-19 21:33:47 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* Warn the user when a parser limitation is reached
|
|
|
|
|
|
* Will warn at most once the user per limitation type
|
|
|
|
|
|
*
|
2008-05-20 05:23:38 +00:00
|
|
|
|
* @param string $limitationType, should be one of:
|
|
|
|
|
|
* 'expensive-parserfunction' (corresponding messages: 'expensive-parserfunction-warning', 'expensive-parserfunction-category')
|
|
|
|
|
|
* 'post-expand-template-argument' (corresponding messages: 'post-expand-template-argument-warning', 'post-expand-template-argument-category')
|
|
|
|
|
|
* 'post-expand-template-inclusion' (corresponding messages: 'post-expand-template-inclusion-warning', 'post-expand-template-inclusion-category')
|
2008-05-19 21:33:47 +00:00
|
|
|
|
* @params int $current, $max When an explicit limit has been
|
|
|
|
|
|
* exceeded, provide the values (optional)
|
|
|
|
|
|
*/
|
|
|
|
|
|
function limitationWarn( $limitationType, $current=null, $max=null) {
|
|
|
|
|
|
//does no harm if $current and $max are present but are unnecessary for the message
|
2010-01-07 04:13:14 +00:00
|
|
|
|
$warning = wfMsgExt( "$limitationType-warning", array( 'parsemag', 'escape' ), $current, $max );
|
2008-05-19 21:33:47 +00:00
|
|
|
|
$this->mOutput->addWarning( $warning );
|
2009-10-11 12:52:08 +00:00
|
|
|
|
$this->addTrackingCategory( "$limitationType-category" );
|
2008-05-19 21:33:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
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['title']: the title, i.e. the part before the |
|
|
|
|
|
|
* $piece['parts']: the parameter array
|
2008-01-21 16:36:08 +00:00
|
|
|
|
* $piece['lineStart']: whether the brace was at the start of a line
|
2007-11-20 10:55:08 +00:00
|
|
|
|
* @param PPFrame The current frame, contains template arguments
|
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
|
|
|
|
*/
|
2007-11-20 10:55:08 +00:00
|
|
|
|
function braceSubstitution( $piece, $frame ) {
|
2009-02-25 21:54:11 +00:00
|
|
|
|
global $wgContLang, $wgNonincludableNamespaces;
|
2008-08-26 14:37:15 +00:00
|
|
|
|
wfProfileIn( __METHOD__ );
|
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
|
|
|
|
|
|
$isHTML = false; # $text is HTML, armour it against wikitext transformation
|
|
|
|
|
|
$forceRawInterwiki = false; # Force interwiki transclusion to be done in raw mode not rendered
|
2008-01-21 16:36:08 +00:00
|
|
|
|
$isChildObj = false; # $text is a DOM node needing expansion in a child frame
|
|
|
|
|
|
$isLocalObj = false; # $text is a DOM node needing expansion in the current frame
|
2004-07-12 19:49:20 +00:00
|
|
|
|
|
2006-02-01 04:41:53 +00:00
|
|
|
|
# Title object, where $text came from
|
2009-12-11 21:07:27 +00:00
|
|
|
|
$title = null;
|
2004-04-12 23:59:37 +00:00
|
|
|
|
|
2008-04-14 07:45:50 +00:00
|
|
|
|
# $part1 is the bit before the first |, and must contain only title characters.
|
|
|
|
|
|
# Various prefixes will be stripped from it later.
|
2007-11-20 10:55:08 +00:00
|
|
|
|
$titleWithSpaces = $frame->expand( $piece['title'] );
|
|
|
|
|
|
$part1 = trim( $titleWithSpaces );
|
|
|
|
|
|
$titleText = false;
|
2004-09-25 05:16:38 +00:00
|
|
|
|
|
2007-11-20 10:55:08 +00:00
|
|
|
|
# Original title text preserved for various purposes
|
|
|
|
|
|
$originalTitle = $part1;
|
2006-10-17 08:49:27 +00:00
|
|
|
|
|
2007-11-20 10:55:08 +00:00
|
|
|
|
# $args is a list of argument nodes, starting from index 0, not including $part1
|
2005-10-19 06:24:30 +00:00
|
|
|
|
$args = (null == $piece['parts']) ? array() : $piece['parts'];
|
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 ) {
|
2008-04-09 18:23:34 +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
|
2008-01-21 16:36:08 +00:00
|
|
|
|
$text = $frame->virtualBracketedImplode( '{{', '|', '}}', $titleWithSpaces, $args );
|
|
|
|
|
|
$isLocalObj = true;
|
2007-11-20 10:55:08 +00:00
|
|
|
|
$found = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# Variables
|
2008-01-21 16:36:08 +00:00
|
|
|
|
if ( !$found && $args->getLength() == 0 ) {
|
2007-11-20 10:55:08 +00:00
|
|
|
|
$id = $this->mVariables->matchStartToEnd( $part1 );
|
|
|
|
|
|
if ( $id !== false ) {
|
2009-08-30 06:37:10 +00:00
|
|
|
|
$text = $this->getVariableValue( $id, $frame );
|
2008-01-09 20:47:46 +00:00
|
|
|
|
if (MagicWord::getCacheTTL($id)>-1)
|
|
|
|
|
|
$this->mOutput->mContainsOldMagic = true;
|
2004-03-20 15:03:26 +00:00
|
|
|
|
$found = true;
|
|
|
|
|
|
}
|
2004-02-26 13:37:26 +00:00
|
|
|
|
}
|
2004-04-12 23:59:37 +00:00
|
|
|
|
|
2006-09-30 04:53:36 +00:00
|
|
|
|
# MSG, MSGNW and RAW
|
2004-03-20 15:03:26 +00:00
|
|
|
|
if ( !$found ) {
|
|
|
|
|
|
# Check for MSGNW:
|
2008-04-09 18:23:34 +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:
|
2008-04-09 18:23:34 +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-10-17 08:49:27 +00:00
|
|
|
|
|
2006-02-01 04:41:53 +00:00
|
|
|
|
# Check for RAW:
|
2008-04-09 18:23:34 +00:00
|
|
|
|
$mwRaw = MagicWord::get( 'raw' );
|
2006-02-01 04:41:53 +00:00
|
|
|
|
if ( $mwRaw->matchStartAndRemove( $part1 ) ) {
|
|
|
|
|
|
$forceRawInterwiki = 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' );
|
2006-10-17 08:49:27 +00:00
|
|
|
|
|
2006-07-03 11:07:00 +00:00
|
|
|
|
$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
|
2009-08-26 15:47:03 +00:00
|
|
|
|
$function = $wgContLang->lc( $function );
|
2006-07-03 11:07:00 +00:00
|
|
|
|
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 ) {
|
2007-11-20 10:55:08 +00:00
|
|
|
|
list( $callback, $flags ) = $this->mFunctionHooks[$function];
|
|
|
|
|
|
$initialArgs = array( &$this );
|
|
|
|
|
|
$funcArgs = array( trim( substr( $part1, $colonPos + 1 ) ) );
|
|
|
|
|
|
if ( $flags & SFH_OBJECT_ARGS ) {
|
|
|
|
|
|
# Add a frame parameter, and pass the arguments as an array
|
|
|
|
|
|
$allArgs = $initialArgs;
|
|
|
|
|
|
$allArgs[] = $frame;
|
2008-01-21 16:36:08 +00:00
|
|
|
|
for ( $i = 0; $i < $args->getLength(); $i++ ) {
|
|
|
|
|
|
$funcArgs[] = $args->item( $i );
|
2007-11-20 10:55:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
$allArgs[] = $funcArgs;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
# Convert arguments to plain text
|
2008-01-21 16:36:08 +00:00
|
|
|
|
for ( $i = 0; $i < $args->getLength(); $i++ ) {
|
|
|
|
|
|
$funcArgs[] = trim( $frame->expand( $args->item( $i ) ) );
|
2007-11-20 10:55:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
$allArgs = array_merge( $initialArgs, $funcArgs );
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2008-01-25 07:43:23 +00:00
|
|
|
|
# Workaround for PHP bug 35229 and similar
|
|
|
|
|
|
if ( !is_callable( $callback ) ) {
|
2009-04-05 01:10:52 +00:00
|
|
|
|
wfProfileOut( __METHOD__ . '-pfunc' );
|
|
|
|
|
|
wfProfileOut( __METHOD__ );
|
2008-09-21 07:18:24 +00:00
|
|
|
|
throw new MWException( "Tag hook for $function is not callable\n" );
|
2008-01-25 07:43:23 +00:00
|
|
|
|
}
|
2007-11-20 10:55:08 +00:00
|
|
|
|
$result = call_user_func_array( $callback, $allArgs );
|
2006-04-05 09:40:25 +00:00
|
|
|
|
$found = true;
|
2008-05-10 18:31:05 +00:00
|
|
|
|
$noparse = true;
|
|
|
|
|
|
$preprocessFlags = 0;
|
2010-01-07 04:13:14 +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] ) ) {
|
2007-11-20 10:55:08 +00:00
|
|
|
|
$text = $result[0];
|
2006-07-03 11:07:00 +00:00
|
|
|
|
unset( $result[0] );
|
|
|
|
|
|
}
|
2006-04-05 09:40:25 +00:00
|
|
|
|
|
|
|
|
|
|
// Extract flags into the local scope
|
2008-01-03 05:37:32 +00:00
|
|
|
|
// This allows callers to set flags such as nowiki, found, etc.
|
2006-04-05 09:40:25 +00:00
|
|
|
|
extract( $result );
|
|
|
|
|
|
} else {
|
2007-11-20 10:55:08 +00:00
|
|
|
|
$text = $result;
|
2006-04-05 09:40:25 +00:00
|
|
|
|
}
|
2008-05-10 18:31:05 +00:00
|
|
|
|
if ( !$noparse ) {
|
|
|
|
|
|
$text = $this->preprocessToDom( $text, $preprocessFlags );
|
|
|
|
|
|
$isChildObj = true;
|
|
|
|
|
|
}
|
2006-04-05 09:40:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2006-07-11 17:40:11 +00:00
|
|
|
|
wfProfileOut( __METHOD__ . '-pfunc' );
|
2006-04-05 09:40:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2007-11-20 10:55:08 +00:00
|
|
|
|
# Finish mangling title and then check for loops.
|
|
|
|
|
|
# Set $title to a Title object and $titleText to the PDBK
|
2004-03-20 15:03:26 +00:00
|
|
|
|
if ( !$found ) {
|
2004-09-25 20:13:14 +00:00
|
|
|
|
$ns = NS_TEMPLATE;
|
2007-11-20 10:55:08 +00:00
|
|
|
|
# Split the title into page and subpage
|
2006-03-24 16:44:52 +00:00
|
|
|
|
$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 );
|
2007-11-20 10:55:08 +00:00
|
|
|
|
if ( $title ) {
|
2006-08-17 22:20:06 +00:00
|
|
|
|
$titleText = $title->getPrefixedText();
|
2006-06-17 08:55:44 +00:00
|
|
|
|
# Check for language variants if the template is not found
|
2006-12-11 23:33:27 +00:00
|
|
|
|
if($wgContLang->hasVariants() && $title->getArticleID() == 0){
|
2008-08-25 18:06:54 +00:00
|
|
|
|
$wgContLang->findVariantLink( $part1, $title, true );
|
2006-06-17 08:55:44 +00:00
|
|
|
|
}
|
2008-01-11 03:25:41 +00:00
|
|
|
|
# Do recursion depth check
|
|
|
|
|
|
$limit = $this->mOptions->getMaxTemplateDepth();
|
|
|
|
|
|
if ( $frame->depth >= $limit ) {
|
|
|
|
|
|
$found = true;
|
2008-11-12 21:00:59 +00:00
|
|
|
|
$text = '<span class="error">' . wfMsgForContent( 'parser-template-recursion-depth-warning', $limit ) . '</span>';
|
2008-01-11 03:25:41 +00:00
|
|
|
|
}
|
2007-11-20 10:55:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2006-06-17 08:55:44 +00:00
|
|
|
|
|
2007-11-20 10:55:08 +00:00
|
|
|
|
# Load from database
|
|
|
|
|
|
if ( !$found && $title ) {
|
|
|
|
|
|
wfProfileIn( __METHOD__ . '-loadtpl' );
|
|
|
|
|
|
if ( !$title->isExternal() ) {
|
|
|
|
|
|
if ( $title->getNamespace() == NS_SPECIAL && $this->mOptions->getAllowSpecialInclusion() && $this->ot['html'] ) {
|
|
|
|
|
|
$text = SpecialPage::capturePath( $title );
|
|
|
|
|
|
if ( is_string( $text ) ) {
|
2006-01-31 03:44:08 +00:00
|
|
|
|
$found = true;
|
2007-11-20 10:55:08 +00:00
|
|
|
|
$isHTML = true;
|
|
|
|
|
|
$this->disableCache();
|
|
|
|
|
|
}
|
2010-01-26 11:57:01 +00:00
|
|
|
|
} elseif ( $wgNonincludableNamespaces && in_array( $title->getNamespace(), $wgNonincludableNamespaces ) ) {
|
2007-11-20 10:55:08 +00:00
|
|
|
|
$found = false; //access denied
|
2008-08-26 14:37:15 +00:00
|
|
|
|
wfDebug( __METHOD__.": template inclusion denied for " . $title->getPrefixedDBkey() );
|
2007-11-20 10:55:08 +00:00
|
|
|
|
} else {
|
|
|
|
|
|
list( $text, $title ) = $this->getTemplateDom( $title );
|
|
|
|
|
|
if ( $text !== false ) {
|
|
|
|
|
|
$found = true;
|
2008-01-21 16:36:08 +00:00
|
|
|
|
$isChildObj = true;
|
2006-01-31 03:44:08 +00:00
|
|
|
|
}
|
2005-02-05 07:14:25 +00:00
|
|
|
|
}
|
2006-07-11 17:40:11 +00:00
|
|
|
|
|
2007-11-20 10:55:08 +00:00
|
|
|
|
# If the title is valid but undisplayable, make a link to it
|
|
|
|
|
|
if ( !$found && ( $this->ot['html'] || $this->ot['pre'] ) ) {
|
|
|
|
|
|
$text = "[[:$titleText]]";
|
|
|
|
|
|
$found = true;
|
2006-02-01 04:41:53 +00:00
|
|
|
|
}
|
2007-11-20 10:55:08 +00:00
|
|
|
|
} elseif ( $title->isTrans() ) {
|
|
|
|
|
|
// Interwiki transclusion
|
|
|
|
|
|
if ( $this->ot['html'] && !$forceRawInterwiki ) {
|
|
|
|
|
|
$text = $this->interwikiTransclude( $title, 'render' );
|
|
|
|
|
|
$isHTML = true;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
$text = $this->interwikiTransclude( $title, 'raw' );
|
2008-01-03 05:37:32 +00:00
|
|
|
|
// Preprocess it like a template
|
2008-01-05 12:39:12 +00:00
|
|
|
|
$text = $this->preprocessToDom( $text, self::PTD_FOR_INCLUSION );
|
2008-01-21 16:36:08 +00:00
|
|
|
|
$isChildObj = true;
|
2007-11-20 10:55:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
$found = true;
|
2004-03-20 15:03:26 +00:00
|
|
|
|
}
|
2009-04-05 15:01:25 +00:00
|
|
|
|
|
|
|
|
|
|
# Do infinite loop check
|
|
|
|
|
|
# This has to be done after redirect resolution to avoid infinite loops via redirects
|
|
|
|
|
|
if ( !$frame->loopCheck( $title ) ) {
|
|
|
|
|
|
$found = true;
|
|
|
|
|
|
$text = '<span class="error">' . wfMsgForContent( 'parser-template-loop-warning', $titleText ) . '</span>';
|
|
|
|
|
|
wfDebug( __METHOD__.": template loop broken at '$titleText'\n" );
|
|
|
|
|
|
}
|
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
|
|
|
|
|
2008-01-03 05:37:32 +00:00
|
|
|
|
# If we haven't found text to substitute by now, we're done
|
|
|
|
|
|
# Recover the source wikitext and return it
|
|
|
|
|
|
if ( !$found ) {
|
2008-01-21 16:36:08 +00:00
|
|
|
|
$text = $frame->virtualBracketedImplode( '{{', '|', '}}', $titleWithSpaces, $args );
|
2008-08-26 14:37:15 +00:00
|
|
|
|
wfProfileOut( __METHOD__ );
|
2008-01-21 16:36:08 +00:00
|
|
|
|
return array( 'object' => $text );
|
2008-01-03 05:37:32 +00:00
|
|
|
|
}
|
2004-04-12 23:59:37 +00:00
|
|
|
|
|
2008-01-03 05:37:32 +00:00
|
|
|
|
# Expand DOM-style return values in a child frame
|
2008-01-21 16:36:08 +00:00
|
|
|
|
if ( $isChildObj ) {
|
2008-01-03 05:37:32 +00:00
|
|
|
|
# Clean up argument array
|
|
|
|
|
|
$newFrame = $frame->newChild( $args, $title );
|
2007-11-20 10:55:08 +00:00
|
|
|
|
|
2008-01-24 04:29:56 +00:00
|
|
|
|
if ( $nowiki ) {
|
|
|
|
|
|
$text = $newFrame->expand( $text, PPFrame::RECOVER_ORIG );
|
|
|
|
|
|
} elseif ( $titleText !== false && $newFrame->isEmpty() ) {
|
2008-01-03 05:37:32 +00:00
|
|
|
|
# Expansion is eligible for the empty-frame cache
|
|
|
|
|
|
if ( isset( $this->mTplExpandCache[$titleText] ) ) {
|
|
|
|
|
|
$text = $this->mTplExpandCache[$titleText];
|
2007-11-20 10:55:08 +00:00
|
|
|
|
} else {
|
2008-01-03 05:37:32 +00:00
|
|
|
|
$text = $newFrame->expand( $text );
|
|
|
|
|
|
$this->mTplExpandCache[$titleText] = $text;
|
2007-11-20 10:55:08 +00:00
|
|
|
|
}
|
2008-01-03 05:37:32 +00:00
|
|
|
|
} else {
|
2008-01-11 03:25:41 +00:00
|
|
|
|
# Uncached expansion
|
2008-01-03 05:37:32 +00:00
|
|
|
|
$text = $newFrame->expand( $text );
|
2004-09-25 16:06:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2008-01-24 04:29:56 +00:00
|
|
|
|
if ( $isLocalObj && $nowiki ) {
|
|
|
|
|
|
$text = $frame->expand( $text, PPFrame::RECOVER_ORIG );
|
|
|
|
|
|
$isLocalObj = false;
|
|
|
|
|
|
}
|
2007-11-20 10:55:08 +00:00
|
|
|
|
|
2008-01-03 05:37:32 +00:00
|
|
|
|
# Replace raw HTML by a placeholder
|
|
|
|
|
|
# Add a blank line preceding, to prevent it from mucking up
|
|
|
|
|
|
# immediately preceding headings
|
|
|
|
|
|
if ( $isHTML ) {
|
|
|
|
|
|
$text = "\n\n" . $this->insertStripItem( $text );
|
|
|
|
|
|
}
|
|
|
|
|
|
# Escape nowiki-style return values
|
|
|
|
|
|
elseif ( $nowiki && ( $this->ot['html'] || $this->ot['pre'] ) ) {
|
|
|
|
|
|
$text = wfEscapeWikiText( $text );
|
|
|
|
|
|
}
|
|
|
|
|
|
# Bug 529: if the template begins with a table or block-level
|
|
|
|
|
|
# element, it should be treated as beginning a new line.
|
|
|
|
|
|
# This behaviour is somewhat controversial.
|
2008-01-21 16:36:08 +00:00
|
|
|
|
elseif ( is_string( $text ) && !$piece['lineStart'] && preg_match('/^(?:{\\||:|;|#|\*)/', $text)) /*}*/{
|
2008-01-03 05:37:32 +00:00
|
|
|
|
$text = "\n" . $text;
|
|
|
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
|
2008-01-21 16:36:08 +00:00
|
|
|
|
if ( is_string( $text ) && !$this->incrementIncludeSize( 'post-expand', strlen( $text ) ) ) {
|
2006-08-10 21:28:49 +00:00
|
|
|
|
# Error, oversize inclusion
|
2008-04-14 07:45:50 +00:00
|
|
|
|
$text = "[[$originalTitle]]" .
|
2007-11-20 10:55:08 +00:00
|
|
|
|
$this->insertStripItem( '<!-- WARNING: template omitted, post-expand include size too large -->' );
|
2008-05-19 21:33:47 +00:00
|
|
|
|
$this->limitationWarn( 'post-expand-template-inclusion' );
|
2006-08-10 21:28:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2008-01-21 16:36:08 +00:00
|
|
|
|
if ( $isLocalObj ) {
|
|
|
|
|
|
$ret = array( 'object' => $text );
|
|
|
|
|
|
} else {
|
|
|
|
|
|
$ret = array( 'text' => $text );
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2008-08-26 14:37:15 +00:00
|
|
|
|
wfProfileOut( __METHOD__ );
|
2008-01-21 16:36:08 +00:00
|
|
|
|
return $ret;
|
2004-02-26 13:37:26 +00:00
|
|
|
|
}
|
2006-01-07 13:31:29 +00:00
|
|
|
|
|
2007-11-20 10:55:08 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* Get the semi-parsed DOM representation of a template with a given title,
|
|
|
|
|
|
* and its redirect destination title. Cached.
|
|
|
|
|
|
*/
|
|
|
|
|
|
function getTemplateDom( $title ) {
|
2007-11-21 23:07:36 +00:00
|
|
|
|
$cacheTitle = $title;
|
2007-11-20 10:55:08 +00:00
|
|
|
|
$titleText = $title->getPrefixedDBkey();
|
2008-04-14 07:45:50 +00:00
|
|
|
|
|
2007-11-20 10:55:08 +00:00
|
|
|
|
if ( isset( $this->mTplRedirCache[$titleText] ) ) {
|
|
|
|
|
|
list( $ns, $dbk ) = $this->mTplRedirCache[$titleText];
|
|
|
|
|
|
$title = Title::makeTitle( $ns, $dbk );
|
|
|
|
|
|
$titleText = $title->getPrefixedDBkey();
|
|
|
|
|
|
}
|
|
|
|
|
|
if ( isset( $this->mTplDomCache[$titleText] ) ) {
|
|
|
|
|
|
return array( $this->mTplDomCache[$titleText], $title );
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Cache miss, go to the database
|
|
|
|
|
|
list( $text, $title ) = $this->fetchTemplateAndTitle( $title );
|
|
|
|
|
|
|
|
|
|
|
|
if ( $text === false ) {
|
|
|
|
|
|
$this->mTplDomCache[$titleText] = false;
|
|
|
|
|
|
return array( false, $title );
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2008-01-05 12:39:12 +00:00
|
|
|
|
$dom = $this->preprocessToDom( $text, self::PTD_FOR_INCLUSION );
|
2007-11-21 23:07:36 +00:00
|
|
|
|
$this->mTplDomCache[ $titleText ] = $dom;
|
|
|
|
|
|
|
|
|
|
|
|
if (! $title->equals($cacheTitle)) {
|
2008-04-14 07:45:50 +00:00
|
|
|
|
$this->mTplRedirCache[$cacheTitle->getPrefixedDBkey()] =
|
2007-11-21 23:07:36 +00:00
|
|
|
|
array( $title->getNamespace(),$cdb = $title->getDBkey() );
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2007-11-20 10:55:08 +00:00
|
|
|
|
return array( $dom, $title );
|
|
|
|
|
|
}
|
|
|
|
|
|
|
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
|
|
|
|
*/
|
2007-11-20 10:55:08 +00:00
|
|
|
|
function fetchTemplateAndTitle( $title ) {
|
|
|
|
|
|
$templateCb = $this->mOptions->getTemplateCallback();
|
2008-06-06 20:28:34 +00:00
|
|
|
|
$stuff = call_user_func( $templateCb, $title, $this );
|
2007-11-20 10:55:08 +00:00
|
|
|
|
$text = $stuff['text'];
|
|
|
|
|
|
$finalTitle = isset( $stuff['finalTitle'] ) ? $stuff['finalTitle'] : $title;
|
|
|
|
|
|
if ( isset( $stuff['deps'] ) ) {
|
|
|
|
|
|
foreach ( $stuff['deps'] as $dep ) {
|
|
|
|
|
|
$this->mOutput->addTemplate( $dep['title'], $dep['page_id'], $dep['rev_id'] );
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return array($text,$finalTitle);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function fetchTemplate( $title ) {
|
|
|
|
|
|
$rv = $this->fetchTemplateAndTitle($title);
|
|
|
|
|
|
return $rv[0];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Static function to get a template
|
|
|
|
|
|
* Can be overridden via ParserOptions::setTemplateCallback().
|
|
|
|
|
|
*/
|
2008-06-06 20:28:34 +00:00
|
|
|
|
static function statelessFetchTemplate( $title, $parser=false ) {
|
2007-05-31 16:01:26 +00:00
|
|
|
|
$text = $skip = false;
|
2007-05-01 22:42:41 +00:00
|
|
|
|
$finalTitle = $title;
|
2007-11-20 10:55:08 +00:00
|
|
|
|
$deps = array();
|
2008-04-14 07:45:50 +00:00
|
|
|
|
|
2006-01-11 02:19:41 +00:00
|
|
|
|
// Loop to fetch the article, with up to 1 redirect
|
|
|
|
|
|
for ( $i = 0; $i < 2 && is_object( $title ); $i++ ) {
|
2007-05-31 16:01:26 +00:00
|
|
|
|
# Give extensions a chance to select the revision instead
|
|
|
|
|
|
$id = false; // Assume current
|
2008-06-06 20:28:34 +00:00
|
|
|
|
wfRunHooks( 'BeforeParserFetchTemplateAndtitle', array( $parser, &$title, &$skip, &$id ) );
|
2008-04-14 07:45:50 +00:00
|
|
|
|
|
2007-05-31 16:01:26 +00:00
|
|
|
|
if( $skip ) {
|
|
|
|
|
|
$text = false;
|
2007-11-20 10:55:08 +00:00
|
|
|
|
$deps[] = array(
|
|
|
|
|
|
'title' => $title,
|
|
|
|
|
|
'page_id' => $title->getArticleID(),
|
|
|
|
|
|
'rev_id' => null );
|
2007-05-31 16:01:26 +00:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
$rev = $id ? Revision::newFromId( $id ) : Revision::newFromTitle( $title );
|
|
|
|
|
|
$rev_id = $rev ? $rev->getId() : 0;
|
2008-05-13 16:06:31 +00:00
|
|
|
|
// If there is no current revision, there is no page
|
|
|
|
|
|
if( $id === false && !$rev ) {
|
|
|
|
|
|
$linkCache = LinkCache::singleton();
|
|
|
|
|
|
$linkCache->addBadLinkObj( $title );
|
|
|
|
|
|
}
|
2007-11-20 10:55:08 +00:00
|
|
|
|
|
2008-04-14 07:45:50 +00:00
|
|
|
|
$deps[] = array(
|
|
|
|
|
|
'title' => $title,
|
|
|
|
|
|
'page_id' => $title->getArticleID(),
|
2007-11-20 10:55:08 +00:00
|
|
|
|
'rev_id' => $rev_id );
|
|
|
|
|
|
|
2007-05-31 16:01:26 +00:00
|
|
|
|
if( $rev ) {
|
2007-01-07 12:30:46 +00:00
|
|
|
|
$text = $rev->getText();
|
|
|
|
|
|
} elseif( $title->getNamespace() == NS_MEDIAWIKI ) {
|
2008-09-28 10:51:58 +00:00
|
|
|
|
global $wgContLang;
|
|
|
|
|
|
$message = $wgContLang->lcfirst( $title->getText() );
|
2007-01-07 12:30:46 +00:00
|
|
|
|
$text = wfMsgForContentNoTrans( $message );
|
|
|
|
|
|
if( wfEmptyMsg( $message, $text ) ) {
|
|
|
|
|
|
$text = false;
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
2006-01-11 02:19:41 +00:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
if ( $text === false ) {
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
// Redirect?
|
2007-05-01 22:42:41 +00:00
|
|
|
|
$finalTitle = $title;
|
2006-01-11 02:19:41 +00:00
|
|
|
|
$title = Title::newFromRedirect( $text );
|
|
|
|
|
|
}
|
2007-11-20 10:55:08 +00:00
|
|
|
|
return array(
|
|
|
|
|
|
'text' => $text,
|
|
|
|
|
|
'finalTitle' => $finalTitle,
|
|
|
|
|
|
'deps' => $deps );
|
2006-01-11 02:19:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
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 ) {
|
2006-12-31 03:04:49 +00:00
|
|
|
|
global $wgEnableScaryTranscluding;
|
2005-07-03 07:15:53 +00:00
|
|
|
|
|
|
|
|
|
|
if (!$wgEnableScaryTranscluding)
|
|
|
|
|
|
return wfMsg('scarytranscludedisabled');
|
|
|
|
|
|
|
2006-12-31 03:04:49 +00:00
|
|
|
|
$url = $title->getFullUrl( "action=$action" );
|
2007-01-17 19:48:48 +00:00
|
|
|
|
|
2005-07-03 07:48:04 +00:00
|
|
|
|
if (strlen($url) > 255)
|
|
|
|
|
|
return wfMsg('scarytranscludetoolong');
|
2008-09-10 23:02:48 +00:00
|
|
|
|
return $this->fetchScaryTemplateMaybeFromCache($url);
|
2005-07-03 07:15:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2008-08-25 04:27:40 +00:00
|
|
|
|
function fetchScaryTemplateMaybeFromCache($url) {
|
2006-01-31 03:44:08 +00:00
|
|
|
|
global $wgTranscludeCacheExpiry;
|
2007-01-22 23:50:42 +00:00
|
|
|
|
$dbr = wfGetDB(DB_SLAVE);
|
2009-12-09 02:26:50 +00:00
|
|
|
|
$tsCond = $dbr->timestamp( time() - $wgTranscludeCacheExpiry );
|
2005-07-03 07:15:53 +00:00
|
|
|
|
$obj = $dbr->selectRow('transcache', array('tc_time', 'tc_contents'),
|
2009-12-09 02:26:50 +00:00
|
|
|
|
array('tc_url' => $url, "tc_time >= " . $dbr->addQuotes( $tsCond ) ) );
|
2005-07-03 07:15:53 +00:00
|
|
|
|
if ($obj) {
|
2009-12-09 02:26:50 +00:00
|
|
|
|
return $obj->tc_contents;
|
2005-07-03 07:15:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
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
|
|
|
|
|
2007-01-22 23:50:42 +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,
|
2009-12-08 02:01:26 +00:00
|
|
|
|
'tc_time' => $dbw->timestamp( time() ),
|
2005-07-03 07:15:53 +00:00
|
|
|
|
'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
|
|
|
|
*/
|
2007-11-20 10:55:08 +00:00
|
|
|
|
function argSubstitution( $piece, $frame ) {
|
|
|
|
|
|
wfProfileIn( __METHOD__ );
|
2004-05-23 03:39:24 +00:00
|
|
|
|
|
2007-11-20 10:55:08 +00:00
|
|
|
|
$error = false;
|
|
|
|
|
|
$parts = $piece['parts'];
|
2008-01-13 09:23:58 +00:00
|
|
|
|
$nameWithSpaces = $frame->expand( $piece['title'] );
|
|
|
|
|
|
$argName = trim( $nameWithSpaces );
|
2008-01-21 16:36:08 +00:00
|
|
|
|
$object = false;
|
2008-01-13 12:47:38 +00:00
|
|
|
|
$text = $frame->getArgument( $argName );
|
2008-04-14 07:45:50 +00:00
|
|
|
|
if ( $text === false && $parts->getLength() > 0
|
|
|
|
|
|
&& (
|
|
|
|
|
|
$this->ot['html']
|
|
|
|
|
|
|| $this->ot['pre']
|
2008-01-30 02:52:14 +00:00
|
|
|
|
|| ( $this->ot['wiki'] && $frame->isTemplate() )
|
|
|
|
|
|
)
|
|
|
|
|
|
) {
|
2008-01-13 06:40:14 +00:00
|
|
|
|
# No match in frame, use the supplied default
|
2008-01-21 16:36:08 +00:00
|
|
|
|
$object = $parts->item( 0 )->getChildren();
|
2004-05-23 03:39:24 +00:00
|
|
|
|
}
|
2006-08-10 21:28:49 +00:00
|
|
|
|
if ( !$this->incrementIncludeSize( 'arg', strlen( $text ) ) ) {
|
2007-11-20 10:55:08 +00:00
|
|
|
|
$error = '<!-- WARNING: argument omitted, expansion size too large -->';
|
2008-05-19 21:33:47 +00:00
|
|
|
|
$this->limitationWarn( 'post-expand-template-argument' );
|
2006-08-10 21:28:49 +00:00
|
|
|
|
}
|
2004-07-12 19:49:20 +00:00
|
|
|
|
|
2008-01-21 16:36:08 +00:00
|
|
|
|
if ( $text === false && $object === false ) {
|
2008-01-13 06:40:14 +00:00
|
|
|
|
# No match anywhere
|
2008-01-21 16:36:08 +00:00
|
|
|
|
$object = $frame->virtualBracketedImplode( '{{{', '|', '}}}', $nameWithSpaces, $parts );
|
2007-11-20 10:55:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
if ( $error !== false ) {
|
|
|
|
|
|
$text .= $error;
|
|
|
|
|
|
}
|
2008-01-21 16:36:08 +00:00
|
|
|
|
if ( $object !== false ) {
|
|
|
|
|
|
$ret = array( 'object' => $object );
|
|
|
|
|
|
} else {
|
|
|
|
|
|
$ret = array( 'text' => $text );
|
|
|
|
|
|
}
|
2007-11-20 10:55:08 +00:00
|
|
|
|
|
|
|
|
|
|
wfProfileOut( __METHOD__ );
|
2008-01-21 16:36:08 +00:00
|
|
|
|
return $ret;
|
2004-05-23 03:39:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2007-11-20 10:55:08 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* Return the text to be used for a given extension tag.
|
|
|
|
|
|
* This is the ghost of strip().
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param array $params Associative array of parameters:
|
2008-01-21 16:36:08 +00:00
|
|
|
|
* name PPNode for the tag name
|
|
|
|
|
|
* attr PPNode for unparsed text where tag attributes are thought to be
|
2008-01-09 07:13:54 +00:00
|
|
|
|
* attributes Optional associative array of parsed attributes
|
2007-11-20 10:55:08 +00:00
|
|
|
|
* inner Contents of extension element
|
|
|
|
|
|
* noClose Original text did not have a close tag
|
|
|
|
|
|
* @param PPFrame $frame
|
|
|
|
|
|
*/
|
|
|
|
|
|
function extensionSubstitution( $params, $frame ) {
|
|
|
|
|
|
global $wgRawHtml, $wgContLang;
|
|
|
|
|
|
|
|
|
|
|
|
$name = $frame->expand( $params['name'] );
|
2008-01-09 07:13:54 +00:00
|
|
|
|
$attrText = !isset( $params['attr'] ) ? null : $frame->expand( $params['attr'] );
|
|
|
|
|
|
$content = !isset( $params['inner'] ) ? null : $frame->expand( $params['inner'] );
|
2007-11-20 10:55:08 +00:00
|
|
|
|
|
2008-03-27 00:00:25 +00:00
|
|
|
|
$marker = "{$this->mUniqPrefix}-$name-" . sprintf('%08X', $this->mMarkerIndex++) . self::MARKER_SUFFIX;
|
2008-04-14 07:45:50 +00:00
|
|
|
|
|
2009-07-11 13:03:35 +00:00
|
|
|
|
$isFunctionTag = isset( $this->mFunctionTagHooks[strtolower($name)] ) &&
|
|
|
|
|
|
( $this->ot['html'] || $this->ot['pre'] );
|
|
|
|
|
|
if ( $this->ot['html'] || $isFunctionTag ) {
|
2007-11-20 10:55:08 +00:00
|
|
|
|
$name = strtolower( $name );
|
2008-01-09 07:13:54 +00:00
|
|
|
|
$attributes = Sanitizer::decodeTagAttributes( $attrText );
|
|
|
|
|
|
if ( isset( $params['attributes'] ) ) {
|
|
|
|
|
|
$attributes = $attributes + $params['attributes'];
|
|
|
|
|
|
}
|
2007-11-20 10:55:08 +00:00
|
|
|
|
switch ( $name ) {
|
|
|
|
|
|
case 'html':
|
|
|
|
|
|
if( $wgRawHtml ) {
|
|
|
|
|
|
$output = $content;
|
|
|
|
|
|
break;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
throw new MWException( '<html> extension tag encountered unexpectedly' );
|
|
|
|
|
|
}
|
|
|
|
|
|
case 'nowiki':
|
2009-01-17 05:01:43 +00:00
|
|
|
|
$content = strtr($content, array('-{' => '-{', '}-' => '}-'));
|
2007-11-20 10:55:08 +00:00
|
|
|
|
$output = Xml::escapeTagsOnly( $content );
|
|
|
|
|
|
break;
|
2009-10-22 22:07:05 +00:00
|
|
|
|
case 'gallery':
|
|
|
|
|
|
$output = $this->renderImageGallery( $content, $attributes );
|
|
|
|
|
|
break;
|
2009-11-07 16:46:34 +00:00
|
|
|
|
case 'a':
|
|
|
|
|
|
$output = $this->renderHyperlink( $content, $attributes, $frame );
|
|
|
|
|
|
break;
|
2007-11-20 10:55:08 +00:00
|
|
|
|
case 'math':
|
2009-10-22 11:40:38 +00:00
|
|
|
|
if ( $this->mOptions->getUseTeX() ) {
|
|
|
|
|
|
$output = $wgContLang->armourMath(
|
|
|
|
|
|
MathRenderer::renderMath( $content, $attributes ) );
|
2009-10-25 13:37:15 +00:00
|
|
|
|
break;
|
2009-10-22 11:40:38 +00:00
|
|
|
|
}
|
2009-10-22 22:07:05 +00:00
|
|
|
|
/* else let a tag hook handle it (bug 21222) */
|
2007-11-20 10:55:08 +00:00
|
|
|
|
default:
|
|
|
|
|
|
if( isset( $this->mTagHooks[$name] ) ) {
|
2008-01-25 07:43:23 +00:00
|
|
|
|
# Workaround for PHP bug 35229 and similar
|
|
|
|
|
|
if ( !is_callable( $this->mTagHooks[$name] ) ) {
|
|
|
|
|
|
throw new MWException( "Tag hook for $name is not callable\n" );
|
|
|
|
|
|
}
|
2007-11-20 10:55:08 +00:00
|
|
|
|
$output = call_user_func_array( $this->mTagHooks[$name],
|
2010-01-19 15:32:49 +00:00
|
|
|
|
array( $content, $attributes, $this, $frame ) );
|
2009-07-11 13:03:35 +00:00
|
|
|
|
} elseif( isset( $this->mFunctionTagHooks[$name] ) ) {
|
|
|
|
|
|
list( $callback, $flags ) = $this->mFunctionTagHooks[$name];
|
|
|
|
|
|
if( !is_callable( $callback ) )
|
|
|
|
|
|
throw new MWException( "Tag hook for $name is not callable\n" );
|
|
|
|
|
|
|
|
|
|
|
|
$output = call_user_func_array( $callback,
|
|
|
|
|
|
array( &$this, $frame, $content, $attributes ) );
|
2007-11-20 10:55:08 +00:00
|
|
|
|
} else {
|
2008-05-06 02:01:24 +00:00
|
|
|
|
$output = '<span class="error">Invalid tag extension name: ' .
|
|
|
|
|
|
htmlspecialchars( $name ) . '</span>';
|
2007-11-20 10:55:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
2008-01-19 09:03:45 +00:00
|
|
|
|
if ( is_null( $attrText ) ) {
|
|
|
|
|
|
$attrText = '';
|
|
|
|
|
|
}
|
|
|
|
|
|
if ( isset( $params['attributes'] ) ) {
|
|
|
|
|
|
foreach ( $params['attributes'] as $attrName => $attrValue ) {
|
|
|
|
|
|
$attrText .= ' ' . htmlspecialchars( $attrName ) . '="' .
|
|
|
|
|
|
htmlspecialchars( $attrValue ) . '"';
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2007-12-17 15:07:25 +00:00
|
|
|
|
if ( $content === null ) {
|
|
|
|
|
|
$output = "<$name$attrText/>";
|
2007-11-20 10:55:08 +00:00
|
|
|
|
} else {
|
2007-12-17 15:07:25 +00:00
|
|
|
|
$close = is_null( $params['close'] ) ? '' : $frame->expand( $params['close'] );
|
|
|
|
|
|
$output = "<$name$attrText>$content$close";
|
2007-11-20 10:55:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2009-07-11 13:03:35 +00:00
|
|
|
|
if( $isFunctionTag ) {
|
|
|
|
|
|
return $output;
|
|
|
|
|
|
} elseif ( $name === 'html' || $name === 'nowiki' ) {
|
2007-11-20 10:55:08 +00:00
|
|
|
|
$this->mStripState->nowiki->setPair( $marker, $output );
|
|
|
|
|
|
} else {
|
|
|
|
|
|
$this->mStripState->general->setPair( $marker, $output );
|
|
|
|
|
|
}
|
|
|
|
|
|
return $marker;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
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 ) {
|
2007-11-20 10:55:08 +00:00
|
|
|
|
if ( $this->mIncludeSizes[$type] + $size > $this->mOptions->getMaxIncludeSize( $type ) ) {
|
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
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2008-04-18 14:34:38 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* Increment the expensive function count
|
|
|
|
|
|
*
|
|
|
|
|
|
* @return boolean False if the limit has been exceeded
|
|
|
|
|
|
*/
|
|
|
|
|
|
function incrementExpensiveFunctionCount() {
|
|
|
|
|
|
global $wgExpensiveParserFunctionLimit;
|
|
|
|
|
|
$this->mExpensiveFunctionCount++;
|
|
|
|
|
|
if($this->mExpensiveFunctionCount <= $wgExpensiveParserFunctionLimit) {
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2006-06-13 11:37:09 +00:00
|
|
|
|
/**
|
2008-02-20 08:53:12 +00:00
|
|
|
|
* Strip double-underscore items like __NOGALLERY__ and __NOTOC__
|
|
|
|
|
|
* Fills $this->mDoubleUnderscores, returns the modified text
|
2006-06-13 11:37:09 +00:00
|
|
|
|
*/
|
2008-02-20 08:53:12 +00:00
|
|
|
|
function doDoubleUnderscore( $text ) {
|
2009-03-06 02:25:28 +00:00
|
|
|
|
wfProfileIn( __METHOD__ );
|
2010-01-07 04:13:14 +00:00
|
|
|
|
|
2008-02-20 08:53:12 +00:00
|
|
|
|
// The position of __TOC__ needs to be recorded
|
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 );
|
|
|
|
|
|
}
|
2008-02-20 08:53:12 +00:00
|
|
|
|
|
|
|
|
|
|
// Now match and remove the rest of them
|
|
|
|
|
|
$mwa = MagicWord::getDoubleUnderscoreArray();
|
|
|
|
|
|
$this->mDoubleUnderscores = $mwa->matchAndRemove( $text );
|
|
|
|
|
|
|
|
|
|
|
|
if ( isset( $this->mDoubleUnderscores['nogallery'] ) ) {
|
|
|
|
|
|
$this->mOutput->mNoGallery = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
if ( isset( $this->mDoubleUnderscores['notoc'] ) && !$this->mForceTocPosition ) {
|
|
|
|
|
|
$this->mShowToc = false;
|
|
|
|
|
|
}
|
2008-02-29 00:55:45 +00:00
|
|
|
|
if ( isset( $this->mDoubleUnderscores['hiddencat'] ) && $this->mTitle->getNamespace() == NS_CATEGORY ) {
|
2008-02-20 08:53:12 +00:00
|
|
|
|
$this->mOutput->setProperty( 'hiddencat', 'y' );
|
2009-09-28 17:55:00 +00:00
|
|
|
|
$this->addTrackingCategory( 'hidden-category-category' );
|
2008-02-20 08:53:12 +00:00
|
|
|
|
}
|
2008-07-24 18:10:35 +00:00
|
|
|
|
# (bug 8068) Allow control over whether robots index a page.
|
|
|
|
|
|
#
|
|
|
|
|
|
# FIXME (bug 14899): __INDEX__ always overrides __NOINDEX__ here! This
|
|
|
|
|
|
# is not desirable, the last one on the page should win.
|
2009-09-28 17:55:00 +00:00
|
|
|
|
if( isset( $this->mDoubleUnderscores['noindex'] ) && $this->mTitle->canUseNoindex() ) {
|
2008-07-23 19:49:46 +00:00
|
|
|
|
$this->mOutput->setIndexPolicy( 'noindex' );
|
2009-09-28 17:55:00 +00:00
|
|
|
|
$this->addTrackingCategory( 'noindex-category' );
|
|
|
|
|
|
}
|
|
|
|
|
|
if( isset( $this->mDoubleUnderscores['index'] ) && $this->mTitle->canUseNoindex() ){
|
2008-07-23 19:49:46 +00:00
|
|
|
|
$this->mOutput->setIndexPolicy( 'index' );
|
2009-09-28 17:55:00 +00:00
|
|
|
|
$this->addTrackingCategory( 'index-category' );
|
2008-07-23 19:49:46 +00:00
|
|
|
|
}
|
2010-01-07 04:13:14 +00:00
|
|
|
|
|
2009-03-06 02:25:28 +00:00
|
|
|
|
wfProfileOut( __METHOD__ );
|
2006-05-23 07:19:01 +00:00
|
|
|
|
return $text;
|
2010-01-07 04:13:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2009-09-28 17:55:00 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* Add a tracking category, getting the title from a system message,
|
|
|
|
|
|
* or print a debug message if the title is invalid.
|
|
|
|
|
|
* @param $msg String message key
|
|
|
|
|
|
* @return Bool whether the addition was successful
|
|
|
|
|
|
*/
|
|
|
|
|
|
protected function addTrackingCategory( $msg ){
|
2009-10-11 12:52:08 +00:00
|
|
|
|
$cat = wfMsgForContent( $msg );
|
2010-01-07 04:13:14 +00:00
|
|
|
|
|
2009-10-11 12:52:08 +00:00
|
|
|
|
# Allow tracking categories to be disabled by setting them to "-"
|
|
|
|
|
|
if( $cat === '-' ) return false;
|
2010-01-07 04:13:14 +00:00
|
|
|
|
|
2009-10-11 12:52:08 +00:00
|
|
|
|
$containerCategory = Title::makeTitleSafe( NS_CATEGORY, $cat );
|
2009-09-28 17:55:00 +00:00
|
|
|
|
if ( $containerCategory ) {
|
|
|
|
|
|
$this->mOutput->addCategory( $containerCategory->getDBkey(), $this->getDefaultSort() );
|
|
|
|
|
|
return true;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
wfDebug( __METHOD__.": [[MediaWiki:$msg]] is not a valid title!\n" );
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
2006-05-23 07:19:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2004-09-21 05:49:12 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* This function accomplishes several tasks:
|
|
|
|
|
|
* 1) Auto-number headings if that option is enabled
|
2007-10-12 07:11:09 +00:00
|
|
|
|
* 2) Add an [edit] link to sections for users who have enabled the option and can edit the page
|
2004-09-21 05:49:12 +00:00
|
|
|
|
* 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
|
2009-06-20 18:25:30 +00:00
|
|
|
|
* @param string $origText Original, untouched wikitext
|
2005-01-31 22:59:55 +00:00
|
|
|
|
* @param boolean $isMain
|
2006-04-19 15:46:24 +00:00
|
|
|
|
* @private
|
2004-09-21 05:49:12 +00:00
|
|
|
|
*/
|
2009-06-20 18:25:30 +00:00
|
|
|
|
function formatHeadings( $text, $origText, $isMain=true ) {
|
2009-05-19 15:12:05 +00:00
|
|
|
|
global $wgMaxTocLevel, $wgContLang, $wgEnforceHtmlIds;
|
2004-07-12 19:49:20 +00:00
|
|
|
|
|
2004-03-21 11:28:44 +00:00
|
|
|
|
$doNumberHeadings = $this->mOptions->getNumberHeadings();
|
2008-10-06 00:45:18 +00:00
|
|
|
|
$showEditLink = $this->mOptions->getEditSection();
|
|
|
|
|
|
|
|
|
|
|
|
// Do not call quickUserCan unless necessary
|
|
|
|
|
|
if( $showEditLink && !$this->mTitle->quickUserCan( 'edit' ) ) {
|
Revert r38196, r38204 -- "(bugs 6089, 13079) Show edit section links for transcluded template if, and only if the user can edit it, made Title::getUserPermissionsErrorsInternal() public so that it can be used in Parser and it can pass the User object from ParserOptions. " & co
Cause regression in 19 parser test cases, looks like messing up the tooltips for section edit links.
19 previously failing test(s) now PASSING! :)
* Bug 6563: Edit link generation for section shown by <includeonly> [Fixed between 29-Jul-2008 22:42:06, 1.14alpha (r38207) and 29-Jul-2008 23:54:51, 1.14alpha (r38207)]
* Bug 6563: Edit link generation for section suppressed by <includeonly> [Fixed between 29-Jul-2008 22:42:06, 1.14alpha (r38207) and 29-Jul-2008 23:54:51, 1.14alpha (r38207)]
* Basic section headings [Fixed between 29-Jul-2008 22:42:06, 1.14alpha (r38207) and 29-Jul-2008 23:54:51, 1.14alpha (r38207)]
* Section headings with TOC [Fixed between 29-Jul-2008 22:42:06, 1.14alpha (r38207) and 29-Jul-2008 23:54:51, 1.14alpha (r38207)]
* Handling of sections up to level 6 and beyond [Fixed between 29-Jul-2008 22:42:06, 1.14alpha (r38207) and 29-Jul-2008 23:54:51, 1.14alpha (r38207)]
* TOC regression (bug 9764) [Fixed between 29-Jul-2008 22:42:06, 1.14alpha (r38207) and 29-Jul-2008 23:54:51, 1.14alpha (r38207)]
* TOC with wgMaxTocLevel=3 (bug 6204) [Fixed between 29-Jul-2008 22:42:06, 1.14alpha (r38207) and 29-Jul-2008 23:54:51, 1.14alpha (r38207)]
* Resolving duplicate section names [Fixed between 29-Jul-2008 22:42:06, 1.14alpha (r38207) and 29-Jul-2008 23:54:51, 1.14alpha (r38207)]
* Resolving duplicate section names with differing case (bug 10721) [Fixed between 29-Jul-2008 22:42:06, 1.14alpha (r38207) and 29-Jul-2008 23:54:51, 1.14alpha (r38207)]
* Template with sections, __NOTOC__ [Fixed between 29-Jul-2008 22:42:06, 1.14alpha (r38207) and 29-Jul-2008 23:54:51, 1.14alpha (r38207)]
* Link inside a section heading [Fixed between 29-Jul-2008 22:42:06, 1.14alpha (r38207) and 29-Jul-2008 23:54:51, 1.14alpha (r38207)]
* TOC regression (bug 12077) [Fixed between 29-Jul-2008 22:42:06, 1.14alpha (r38207) and 29-Jul-2008 23:54:51, 1.14alpha (r38207)]
* Fuzz testing: Parser14 [Fixed between 29-Jul-2008 22:42:06, 1.14alpha (r38207) and 29-Jul-2008 23:54:51, 1.14alpha (r38207)]
* Fuzz testing: Parser14-table [Fixed between 29-Jul-2008 22:42:06, 1.14alpha (r38207) and 29-Jul-2008 23:54:51, 1.14alpha (r38207)]
* Inclusion of !userCanEdit() content [Fixed between 29-Jul-2008 22:42:06, 1.14alpha (r38207) and 29-Jul-2008 23:54:51, 1.14alpha (r38207)]
* Out-of-order TOC heading levels [Fixed between 29-Jul-2008 22:42:06, 1.14alpha (r38207) and 29-Jul-2008 23:54:51, 1.14alpha (r38207)]
* -{}- tags within headlines (within html for parserConvert()) [Fixed between 29-Jul-2008 22:42:06, 1.14alpha (r38207) and 29-Jul-2008 23:54:51, 1.14alpha (r38207)]
* Morwen/13: Unclosed link followed by heading [Fixed between 29-Jul-2008 22:42:06, 1.14alpha (r38207) and 29-Jul-2008 23:54:51, 1.14alpha (r38207)]
* HHP2.2: Heuristics for headings in preprocessor parenthetical structures [Fixed between 29-Jul-2008 22:42:06, 1.14alpha (r38207) and 29-Jul-2008 23:54:51, 1.14alpha (r38207)]
2008-07-29 23:56:30 +00:00
|
|
|
|
$showEditLink = 0;
|
|
|
|
|
|
}
|
2004-02-26 13:37:26 +00:00
|
|
|
|
|
|
|
|
|
|
# Inhibit editsection links if requested in the page
|
2009-03-18 23:27:48 +00:00
|
|
|
|
if ( isset( $this->mDoubleUnderscores['noeditsection'] ) || $this->mOptions->getIsPrintable() ) {
|
2004-03-21 11:28:44 +00:00
|
|
|
|
$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
|
2006-10-17 08:49:27 +00:00
|
|
|
|
$matches = array();
|
2007-01-08 02:11:45 +00:00
|
|
|
|
$numMatches = preg_match_all( '/<H(?P<level>[1-6])(?P<attrib>.*?'.'>)(?P<header>.*?)<\/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__
|
2008-02-20 08:53:12 +00:00
|
|
|
|
if ( isset( $this->mDoubleUnderscores['newsectionlink'] ) ) {
|
2006-05-01 20:35:08 +00:00
|
|
|
|
$this->mOutput->setNewSection( true );
|
2008-02-20 08:53:12 +00:00
|
|
|
|
}
|
2006-05-01 20:35:08 +00:00
|
|
|
|
|
2009-02-19 22:14:59 +00:00
|
|
|
|
# Allow user to remove the "new section"
|
|
|
|
|
|
# link via __NONEWSECTIONLINK__
|
|
|
|
|
|
if ( isset( $this->mDoubleUnderscores['nonewsectionlink'] ) ) {
|
|
|
|
|
|
$this->mOutput->hideNewSection( 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
|
2008-02-20 08:53:12 +00:00
|
|
|
|
if ( isset( $this->mDoubleUnderscores['forcetoc'] ) ) {
|
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
|
|
|
|
|
2006-11-08 07:12:03 +00:00
|
|
|
|
# We need this to perform operations on the HTML
|
2007-01-22 23:50:42 +00:00
|
|
|
|
$sk = $this->mOptions->getSkin();
|
2006-11-08 07:12:03 +00:00
|
|
|
|
|
2004-02-26 13:37:26 +00:00
|
|
|
|
# headline counter
|
2004-03-21 11:28:44 +00:00
|
|
|
|
$headlineCount = 0;
|
2007-04-30 19:51:56 +00:00
|
|
|
|
$numVisible = 0;
|
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;
|
2008-03-27 00:00:25 +00:00
|
|
|
|
$markerRegex = "{$this->mUniqPrefix}-h-(\d+)-" . self::MARKER_SUFFIX;
|
2007-11-20 10:55:08 +00:00
|
|
|
|
$baseTitleText = $this->mTitle->getPrefixedDBkey();
|
2009-06-20 18:25:30 +00:00
|
|
|
|
$oldType = $this->mOutputType;
|
|
|
|
|
|
$this->setOutputType( self::OT_WIKI );
|
|
|
|
|
|
$frame = $this->getPreprocessor()->newFrame();
|
|
|
|
|
|
$root = $this->preprocessToDom( $origText );
|
|
|
|
|
|
$node = $root->getFirstChild();
|
|
|
|
|
|
$byteOffset = 0;
|
2007-12-27 20:14:07 +00:00
|
|
|
|
$tocraw = array();
|
2005-01-15 23:21:52 +00:00
|
|
|
|
|
2004-03-21 11:28:44 +00:00
|
|
|
|
foreach( $matches[3] as $headline ) {
|
2007-11-20 10:55:08 +00:00
|
|
|
|
$isTemplate = false;
|
|
|
|
|
|
$titleText = false;
|
|
|
|
|
|
$sectionIndex = false;
|
2005-01-15 23:21:52 +00:00
|
|
|
|
$numbering = '';
|
2007-11-20 10:55:08 +00:00
|
|
|
|
$markerMatches = array();
|
|
|
|
|
|
if (preg_match("/^$markerRegex/", $headline, $markerMatches)) {
|
|
|
|
|
|
$serial = $markerMatches[1];
|
|
|
|
|
|
list( $titleText, $sectionIndex ) = $this->mHeadings[$serial];
|
2010-01-26 11:57:01 +00:00
|
|
|
|
$isTemplate = ($titleText !== $baseTitleText);
|
2007-11-20 10:55:08 +00:00
|
|
|
|
$headline = preg_replace("/^$markerRegex/", "", $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;
|
2007-05-02 19:09:36 +00:00
|
|
|
|
$prevtoclevel = $toclevel;
|
2004-03-21 11:28:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
$level = $matches[1][$headlineCount];
|
2005-07-03 07:15:53 +00:00
|
|
|
|
|
2009-06-25 11:05:22 +00:00
|
|
|
|
if ( $level > $prevlevel ) {
|
|
|
|
|
|
# Increase TOC level
|
|
|
|
|
|
$toclevel++;
|
|
|
|
|
|
$sublevelCount[$toclevel] = 0;
|
|
|
|
|
|
if( $toclevel<$wgMaxTocLevel ) {
|
|
|
|
|
|
$prevtoclevel = $toclevel;
|
|
|
|
|
|
$toc .= $sk->tocIndent();
|
|
|
|
|
|
$numVisible++;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
elseif ( $level < $prevlevel && $toclevel > 1 ) {
|
|
|
|
|
|
# Decrease TOC level, find level to jump to
|
|
|
|
|
|
|
|
|
|
|
|
for ($i = $toclevel; $i > 0; $i--) {
|
|
|
|
|
|
if ( $levelCount[$i] == $level ) {
|
|
|
|
|
|
# Found last matching level
|
|
|
|
|
|
$toclevel = $i;
|
|
|
|
|
|
break;
|
2005-01-15 23:21:52 +00:00
|
|
|
|
}
|
2009-06-25 11:05:22 +00:00
|
|
|
|
elseif ( $levelCount[$i] < $level ) {
|
|
|
|
|
|
# Found first matching level below current level
|
|
|
|
|
|
$toclevel = $i + 1;
|
|
|
|
|
|
break;
|
2006-04-25 19:43:46 +00:00
|
|
|
|
}
|
2005-01-15 23:21:52 +00:00
|
|
|
|
}
|
2009-06-25 11:05:22 +00:00
|
|
|
|
if( $i == 0 ) $toclevel = 1;
|
|
|
|
|
|
if( $toclevel<$wgMaxTocLevel ) {
|
|
|
|
|
|
if($prevtoclevel < $wgMaxTocLevel) {
|
|
|
|
|
|
# Unindent only if the previous toc level was shown :p
|
|
|
|
|
|
$toc .= $sk->tocUnindent( $prevtoclevel - $toclevel );
|
|
|
|
|
|
$prevtoclevel = $toclevel;
|
|
|
|
|
|
} else {
|
2006-11-08 07:12:03 +00:00
|
|
|
|
$toc .= $sk->tocLineEnd();
|
2006-04-25 19:43:46 +00:00
|
|
|
|
}
|
2005-01-15 23:21:52 +00:00
|
|
|
|
}
|
2009-06-25 11:05:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
else {
|
|
|
|
|
|
# No change in level, end TOC line
|
|
|
|
|
|
if( $toclevel<$wgMaxTocLevel ) {
|
|
|
|
|
|
$toc .= $sk->tocLineEnd();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2005-07-03 07:15:53 +00:00
|
|
|
|
|
2009-06-25 11:05:22 +00:00
|
|
|
|
$levelCount[$toclevel] = $level;
|
2005-01-15 23:21:52 +00:00
|
|
|
|
|
2009-06-25 11:05:22 +00:00
|
|
|
|
# count number of headlines for each level
|
|
|
|
|
|
@$sublevelCount[$toclevel]++;
|
|
|
|
|
|
$dot = 0;
|
|
|
|
|
|
for( $i = 1; $i <= $toclevel; $i++ ) {
|
|
|
|
|
|
if( !empty( $sublevelCount[$i] ) ) {
|
|
|
|
|
|
if( $dot ) {
|
|
|
|
|
|
$numbering .= '.';
|
2004-02-26 13:37:26 +00:00
|
|
|
|
}
|
2009-06-25 11:05:22 +00:00
|
|
|
|
$numbering .= $wgContLang->formatNum( $sublevelCount[$i] );
|
|
|
|
|
|
$dot = 1;
|
2004-02-26 13:37:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2009-01-10 17:16:21 +00:00
|
|
|
|
# The safe 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
|
|
|
|
|
|
$safeHeadline = $this->mStripState->unstripBoth( $headline );
|
|
|
|
|
|
|
|
|
|
|
|
# Remove link placeholders by the link text.
|
|
|
|
|
|
# <!--LINK number-->
|
|
|
|
|
|
# turns into
|
|
|
|
|
|
# link text with suffix
|
|
|
|
|
|
$safeHeadline = $this->replaceLinkHoldersText( $safeHeadline );
|
|
|
|
|
|
|
|
|
|
|
|
# Strip out HTML (other than plain <sup> and <sub>: bug 8393)
|
|
|
|
|
|
$tocline = preg_replace(
|
|
|
|
|
|
array( '#<(?!/?(sup|sub)).*?'.'>#', '#<(/?(sup|sub)).*?'.'>#' ),
|
|
|
|
|
|
array( '', '<$1>'),
|
|
|
|
|
|
$safeHeadline
|
|
|
|
|
|
);
|
|
|
|
|
|
$tocline = trim( $tocline );
|
|
|
|
|
|
|
|
|
|
|
|
# For the anchor, strip out HTML-y stuff period
|
|
|
|
|
|
$safeHeadline = preg_replace( '/<.*?'.'>/', '', $safeHeadline );
|
2009-06-02 19:32:51 +00:00
|
|
|
|
$safeHeadline = preg_replace( '/[ _]+/', ' ', $safeHeadline );
|
2009-01-10 17:16:21 +00:00
|
|
|
|
$safeHeadline = trim( $safeHeadline );
|
|
|
|
|
|
|
|
|
|
|
|
# Save headline for section edit hint before it's escaped
|
|
|
|
|
|
$headlineHint = $safeHeadline;
|
|
|
|
|
|
|
|
|
|
|
|
if ( $wgEnforceHtmlIds ) {
|
|
|
|
|
|
$legacyHeadline = false;
|
|
|
|
|
|
$safeHeadline = Sanitizer::escapeId( $safeHeadline,
|
|
|
|
|
|
'noninitial' );
|
|
|
|
|
|
} else {
|
|
|
|
|
|
# For reverse compatibility, provide an id that's
|
|
|
|
|
|
# HTML4-compatible, like we used to.
|
|
|
|
|
|
#
|
|
|
|
|
|
# It may be worth noting, academically, that it's possible for
|
|
|
|
|
|
# the legacy anchor to conflict with a non-legacy headline
|
|
|
|
|
|
# anchor on the page. In this case likely the "correct" thing
|
|
|
|
|
|
# would be to either drop the legacy anchors or make sure
|
|
|
|
|
|
# they're numbered first. However, this would require people
|
|
|
|
|
|
# to type in section names like "abc_.D7.93.D7.90.D7.A4"
|
|
|
|
|
|
# manually, so let's not bother worrying about it.
|
|
|
|
|
|
$legacyHeadline = Sanitizer::escapeId( $safeHeadline,
|
|
|
|
|
|
'noninitial' );
|
|
|
|
|
|
$safeHeadline = Sanitizer::escapeId( $safeHeadline, 'xml' );
|
|
|
|
|
|
|
|
|
|
|
|
if ( $legacyHeadline == $safeHeadline ) {
|
|
|
|
|
|
# No reason to have both (in fact, we can't)
|
|
|
|
|
|
$legacyHeadline = false;
|
2010-01-26 11:57:01 +00:00
|
|
|
|
} elseif ( $legacyHeadline !== Sanitizer::escapeId(
|
2009-01-10 17:16:21 +00:00
|
|
|
|
$legacyHeadline, 'xml' ) ) {
|
|
|
|
|
|
# The legacy id is invalid XML. We used to allow this, but
|
|
|
|
|
|
# there's no reason to do so anymore. Backward
|
|
|
|
|
|
# compatibility will fail slightly in this case, but it's
|
|
|
|
|
|
# no big deal.
|
|
|
|
|
|
$legacyHeadline = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2009-01-05 15:59:46 +00:00
|
|
|
|
|
|
|
|
|
|
# HTML names must be case-insensitively unique (bug 10721). FIXME:
|
|
|
|
|
|
# Does this apply to Unicode characters? Because we aren't
|
|
|
|
|
|
# handling those here.
|
2009-01-10 17:16:21 +00:00
|
|
|
|
$arrayKey = strtolower( $safeHeadline );
|
|
|
|
|
|
if ( $legacyHeadline === false ) {
|
2009-01-05 15:59:46 +00:00
|
|
|
|
$legacyArrayKey = false;
|
|
|
|
|
|
} else {
|
2009-01-10 17:16:21 +00:00
|
|
|
|
$legacyArrayKey = strtolower( $legacyHeadline );
|
2009-01-05 15:59:46 +00:00
|
|
|
|
}
|
2008-03-13 18:30:50 +00:00
|
|
|
|
|
2004-03-21 11:28:44 +00:00
|
|
|
|
# count how many in assoc. array so we can track dupes in anchors
|
2009-01-05 15:59:46 +00:00
|
|
|
|
if ( isset( $refers[$arrayKey] ) ) {
|
|
|
|
|
|
$refers[$arrayKey]++;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
$refers[$arrayKey] = 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
if ( isset( $refers[$legacyArrayKey] ) ) {
|
|
|
|
|
|
$refers[$legacyArrayKey]++;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
$refers[$legacyArrayKey] = 1;
|
|
|
|
|
|
}
|
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
|
2009-01-10 17:16:21 +00:00
|
|
|
|
$anchor = $safeHeadline;
|
|
|
|
|
|
$legacyAnchor = $legacyHeadline;
|
2009-01-05 15:59:46 +00:00
|
|
|
|
if ( $refers[$arrayKey] > 1 ) {
|
|
|
|
|
|
$anchor .= '_' . $refers[$arrayKey];
|
|
|
|
|
|
}
|
2009-01-10 17:16:21 +00:00
|
|
|
|
if ( $legacyHeadline !== false && $refers[$legacyArrayKey] > 1 ) {
|
2009-01-05 15:59:46 +00:00
|
|
|
|
$legacyAnchor .= '_' . $refers[$legacyArrayKey];
|
2004-03-21 11:28:44 +00:00
|
|
|
|
}
|
2006-05-23 10:01:45 +00:00
|
|
|
|
if( $enoughToc && ( !isset($wgMaxTocLevel) || $toclevel<$wgMaxTocLevel ) ) {
|
2009-06-20 21:47:10 +00:00
|
|
|
|
$toc .= $sk->tocLine($anchor, $tocline,
|
|
|
|
|
|
$numbering, $toclevel, ($isTemplate ? false : $sectionIndex));
|
2004-02-26 13:37:26 +00:00
|
|
|
|
}
|
2010-01-07 04:13:14 +00:00
|
|
|
|
|
2009-06-25 11:05:22 +00:00
|
|
|
|
# Add the section to the section tree
|
|
|
|
|
|
# Find the DOM node for this header
|
|
|
|
|
|
while ( $node && !$isTemplate ) {
|
|
|
|
|
|
if ( $node->getName() === 'h' ) {
|
|
|
|
|
|
$bits = $node->splitHeading();
|
|
|
|
|
|
if ( $bits['i'] == $sectionIndex )
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
2010-01-07 04:13:14 +00:00
|
|
|
|
$byteOffset += mb_strlen( $this->mStripState->unstripBoth(
|
2009-06-25 11:05:22 +00:00
|
|
|
|
$frame->expand( $node, PPFrame::RECOVER_ORIG ) ) );
|
|
|
|
|
|
$node = $node->getNextSibling();
|
|
|
|
|
|
}
|
2010-01-07 04:13:14 +00:00
|
|
|
|
$tocraw[] = array(
|
2009-06-25 11:05:22 +00:00
|
|
|
|
'toclevel' => $toclevel,
|
|
|
|
|
|
'level' => $level,
|
|
|
|
|
|
'line' => $tocline,
|
|
|
|
|
|
'number' => $numbering,
|
|
|
|
|
|
'index' => ($isTemplate ? 'T-' : '' ) . $sectionIndex,
|
|
|
|
|
|
'fromtitle' => $titleText,
|
|
|
|
|
|
'byteoffset' => ( $isTemplate ? null : $byteOffset ),
|
|
|
|
|
|
'anchor' => $anchor,
|
|
|
|
|
|
);
|
2010-01-07 04:13:14 +00:00
|
|
|
|
|
2006-10-18 06:53:19 +00:00
|
|
|
|
# give headline the correct <h#> tag
|
2007-11-20 10:55:08 +00:00
|
|
|
|
if( $showEditLink && $sectionIndex !== false ) {
|
2008-01-05 12:39:12 +00:00
|
|
|
|
if( $isTemplate ) {
|
2008-04-14 07:45:50 +00:00
|
|
|
|
# Put a T flag in the section identifier, to indicate to extractSections()
|
2008-01-05 12:39:12 +00:00
|
|
|
|
# that sections inside <includeonly> should be counted.
|
Revert r38196, r38204 -- "(bugs 6089, 13079) Show edit section links for transcluded template if, and only if the user can edit it, made Title::getUserPermissionsErrorsInternal() public so that it can be used in Parser and it can pass the User object from ParserOptions. " & co
Cause regression in 19 parser test cases, looks like messing up the tooltips for section edit links.
19 previously failing test(s) now PASSING! :)
* Bug 6563: Edit link generation for section shown by <includeonly> [Fixed between 29-Jul-2008 22:42:06, 1.14alpha (r38207) and 29-Jul-2008 23:54:51, 1.14alpha (r38207)]
* Bug 6563: Edit link generation for section suppressed by <includeonly> [Fixed between 29-Jul-2008 22:42:06, 1.14alpha (r38207) and 29-Jul-2008 23:54:51, 1.14alpha (r38207)]
* Basic section headings [Fixed between 29-Jul-2008 22:42:06, 1.14alpha (r38207) and 29-Jul-2008 23:54:51, 1.14alpha (r38207)]
* Section headings with TOC [Fixed between 29-Jul-2008 22:42:06, 1.14alpha (r38207) and 29-Jul-2008 23:54:51, 1.14alpha (r38207)]
* Handling of sections up to level 6 and beyond [Fixed between 29-Jul-2008 22:42:06, 1.14alpha (r38207) and 29-Jul-2008 23:54:51, 1.14alpha (r38207)]
* TOC regression (bug 9764) [Fixed between 29-Jul-2008 22:42:06, 1.14alpha (r38207) and 29-Jul-2008 23:54:51, 1.14alpha (r38207)]
* TOC with wgMaxTocLevel=3 (bug 6204) [Fixed between 29-Jul-2008 22:42:06, 1.14alpha (r38207) and 29-Jul-2008 23:54:51, 1.14alpha (r38207)]
* Resolving duplicate section names [Fixed between 29-Jul-2008 22:42:06, 1.14alpha (r38207) and 29-Jul-2008 23:54:51, 1.14alpha (r38207)]
* Resolving duplicate section names with differing case (bug 10721) [Fixed between 29-Jul-2008 22:42:06, 1.14alpha (r38207) and 29-Jul-2008 23:54:51, 1.14alpha (r38207)]
* Template with sections, __NOTOC__ [Fixed between 29-Jul-2008 22:42:06, 1.14alpha (r38207) and 29-Jul-2008 23:54:51, 1.14alpha (r38207)]
* Link inside a section heading [Fixed between 29-Jul-2008 22:42:06, 1.14alpha (r38207) and 29-Jul-2008 23:54:51, 1.14alpha (r38207)]
* TOC regression (bug 12077) [Fixed between 29-Jul-2008 22:42:06, 1.14alpha (r38207) and 29-Jul-2008 23:54:51, 1.14alpha (r38207)]
* Fuzz testing: Parser14 [Fixed between 29-Jul-2008 22:42:06, 1.14alpha (r38207) and 29-Jul-2008 23:54:51, 1.14alpha (r38207)]
* Fuzz testing: Parser14-table [Fixed between 29-Jul-2008 22:42:06, 1.14alpha (r38207) and 29-Jul-2008 23:54:51, 1.14alpha (r38207)]
* Inclusion of !userCanEdit() content [Fixed between 29-Jul-2008 22:42:06, 1.14alpha (r38207) and 29-Jul-2008 23:54:51, 1.14alpha (r38207)]
* Out-of-order TOC heading levels [Fixed between 29-Jul-2008 22:42:06, 1.14alpha (r38207) and 29-Jul-2008 23:54:51, 1.14alpha (r38207)]
* -{}- tags within headlines (within html for parserConvert()) [Fixed between 29-Jul-2008 22:42:06, 1.14alpha (r38207) and 29-Jul-2008 23:54:51, 1.14alpha (r38207)]
* Morwen/13: Unclosed link followed by heading [Fixed between 29-Jul-2008 22:42:06, 1.14alpha (r38207) and 29-Jul-2008 23:54:51, 1.14alpha (r38207)]
* HHP2.2: Heuristics for headings in preprocessor parenthetical structures [Fixed between 29-Jul-2008 22:42:06, 1.14alpha (r38207) and 29-Jul-2008 23:54:51, 1.14alpha (r38207)]
2008-07-29 23:56:30 +00:00
|
|
|
|
$editlink = $sk->doEditSectionLink(Title::newFromText( $titleText ), "T-$sectionIndex");
|
2008-01-05 12:39:12 +00:00
|
|
|
|
} else {
|
Revert r38196, r38204 -- "(bugs 6089, 13079) Show edit section links for transcluded template if, and only if the user can edit it, made Title::getUserPermissionsErrorsInternal() public so that it can be used in Parser and it can pass the User object from ParserOptions. " & co
Cause regression in 19 parser test cases, looks like messing up the tooltips for section edit links.
19 previously failing test(s) now PASSING! :)
* Bug 6563: Edit link generation for section shown by <includeonly> [Fixed between 29-Jul-2008 22:42:06, 1.14alpha (r38207) and 29-Jul-2008 23:54:51, 1.14alpha (r38207)]
* Bug 6563: Edit link generation for section suppressed by <includeonly> [Fixed between 29-Jul-2008 22:42:06, 1.14alpha (r38207) and 29-Jul-2008 23:54:51, 1.14alpha (r38207)]
* Basic section headings [Fixed between 29-Jul-2008 22:42:06, 1.14alpha (r38207) and 29-Jul-2008 23:54:51, 1.14alpha (r38207)]
* Section headings with TOC [Fixed between 29-Jul-2008 22:42:06, 1.14alpha (r38207) and 29-Jul-2008 23:54:51, 1.14alpha (r38207)]
* Handling of sections up to level 6 and beyond [Fixed between 29-Jul-2008 22:42:06, 1.14alpha (r38207) and 29-Jul-2008 23:54:51, 1.14alpha (r38207)]
* TOC regression (bug 9764) [Fixed between 29-Jul-2008 22:42:06, 1.14alpha (r38207) and 29-Jul-2008 23:54:51, 1.14alpha (r38207)]
* TOC with wgMaxTocLevel=3 (bug 6204) [Fixed between 29-Jul-2008 22:42:06, 1.14alpha (r38207) and 29-Jul-2008 23:54:51, 1.14alpha (r38207)]
* Resolving duplicate section names [Fixed between 29-Jul-2008 22:42:06, 1.14alpha (r38207) and 29-Jul-2008 23:54:51, 1.14alpha (r38207)]
* Resolving duplicate section names with differing case (bug 10721) [Fixed between 29-Jul-2008 22:42:06, 1.14alpha (r38207) and 29-Jul-2008 23:54:51, 1.14alpha (r38207)]
* Template with sections, __NOTOC__ [Fixed between 29-Jul-2008 22:42:06, 1.14alpha (r38207) and 29-Jul-2008 23:54:51, 1.14alpha (r38207)]
* Link inside a section heading [Fixed between 29-Jul-2008 22:42:06, 1.14alpha (r38207) and 29-Jul-2008 23:54:51, 1.14alpha (r38207)]
* TOC regression (bug 12077) [Fixed between 29-Jul-2008 22:42:06, 1.14alpha (r38207) and 29-Jul-2008 23:54:51, 1.14alpha (r38207)]
* Fuzz testing: Parser14 [Fixed between 29-Jul-2008 22:42:06, 1.14alpha (r38207) and 29-Jul-2008 23:54:51, 1.14alpha (r38207)]
* Fuzz testing: Parser14-table [Fixed between 29-Jul-2008 22:42:06, 1.14alpha (r38207) and 29-Jul-2008 23:54:51, 1.14alpha (r38207)]
* Inclusion of !userCanEdit() content [Fixed between 29-Jul-2008 22:42:06, 1.14alpha (r38207) and 29-Jul-2008 23:54:51, 1.14alpha (r38207)]
* Out-of-order TOC heading levels [Fixed between 29-Jul-2008 22:42:06, 1.14alpha (r38207) and 29-Jul-2008 23:54:51, 1.14alpha (r38207)]
* -{}- tags within headlines (within html for parserConvert()) [Fixed between 29-Jul-2008 22:42:06, 1.14alpha (r38207) and 29-Jul-2008 23:54:51, 1.14alpha (r38207)]
* Morwen/13: Unclosed link followed by heading [Fixed between 29-Jul-2008 22:42:06, 1.14alpha (r38207) and 29-Jul-2008 23:54:51, 1.14alpha (r38207)]
* HHP2.2: Heuristics for headings in preprocessor parenthetical structures [Fixed between 29-Jul-2008 22:42:06, 1.14alpha (r38207) and 29-Jul-2008 23:54:51, 1.14alpha (r38207)]
2008-07-29 23:56:30 +00:00
|
|
|
|
$editlink = $sk->doEditSectionLink($this->mTitle, $sectionIndex, $headlineHint);
|
2008-01-05 12:39:12 +00:00
|
|
|
|
}
|
2007-01-08 02:11:45 +00:00
|
|
|
|
} else {
|
|
|
|
|
|
$editlink = '';
|
2004-02-26 13:37:26 +00:00
|
|
|
|
}
|
2009-01-05 15:59:46 +00:00
|
|
|
|
$head[$headlineCount] = $sk->makeHeadline( $level,
|
|
|
|
|
|
$matches['attrib'][$headlineCount], $anchor, $headline,
|
|
|
|
|
|
$editlink, $legacyAnchor );
|
2004-04-12 23:59:37 +00:00
|
|
|
|
|
2004-03-21 11:28:44 +00:00
|
|
|
|
$headlineCount++;
|
2004-04-12 23:59:37 +00:00
|
|
|
|
}
|
2004-02-26 13:37:26 +00:00
|
|
|
|
|
2009-06-20 18:25:30 +00:00
|
|
|
|
$this->setOutputType( $oldType );
|
2007-12-27 20:14:07 +00:00
|
|
|
|
|
2007-04-30 19:51:56 +00:00
|
|
|
|
# Never ever show TOC if no headers
|
|
|
|
|
|
if( $numVisible < 1 ) {
|
|
|
|
|
|
$enoughToc = false;
|
|
|
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
|
2006-05-23 10:01:45 +00:00
|
|
|
|
if( $enoughToc ) {
|
2007-04-30 19:51:56 +00:00
|
|
|
|
if( $prevtoclevel > 0 && $prevtoclevel < $wgMaxTocLevel ) {
|
|
|
|
|
|
$toc .= $sk->tocUnindent( $prevtoclevel - 1 );
|
2006-04-25 19:43:46 +00:00
|
|
|
|
}
|
2006-11-08 07:12:03 +00:00
|
|
|
|
$toc = $sk->tocList( $toc );
|
2009-07-14 13:35:07 +00:00
|
|
|
|
$this->mOutput->setTOCHTML( $toc );
|
2004-02-26 13:37:26 +00:00
|
|
|
|
}
|
2010-01-07 04:13:14 +00:00
|
|
|
|
|
2009-06-21 12:52:24 +00:00
|
|
|
|
if ( $isMain ) {
|
|
|
|
|
|
$this->mOutput->setSections( $tocraw );
|
|
|
|
|
|
}
|
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;
|
2010-01-07 04:13:14 +00:00
|
|
|
|
|
2004-03-21 11:28:44 +00:00
|
|
|
|
foreach( $blocks as $block ) {
|
2008-08-26 14:37:15 +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
|
2006-11-08 07:12:03 +00:00
|
|
|
|
# $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
|
|
|
|
}
|
2010-01-07 04:13:14 +00:00
|
|
|
|
|
2009-06-25 11:05:22 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* Merge $tree2 into $tree1 by replacing the section with index
|
|
|
|
|
|
* $section in $tree1 and its descendants with the sections in $tree2.
|
|
|
|
|
|
* Note that in the returned section tree, only the 'index' and
|
|
|
|
|
|
* 'byteoffset' fields are guaranteed to be correct.
|
|
|
|
|
|
* @param $tree1 array Section tree from ParserOutput::getSectons()
|
|
|
|
|
|
* @param $tree2 array Section tree
|
|
|
|
|
|
* @param $section int Section index
|
|
|
|
|
|
* @param $title Title Title both section trees come from
|
|
|
|
|
|
* @param $len2 int Length of the original wikitext for $tree2
|
|
|
|
|
|
* @return array Merged section tree
|
|
|
|
|
|
*/
|
|
|
|
|
|
public static function mergeSectionTrees( $tree1, $tree2, $section, $title, $len2 ) {
|
|
|
|
|
|
global $wgContLang;
|
|
|
|
|
|
$newTree = array();
|
|
|
|
|
|
$targetLevel = false;
|
|
|
|
|
|
$merged = false;
|
|
|
|
|
|
$lastLevel = 1;
|
|
|
|
|
|
$nextIndex = 1;
|
|
|
|
|
|
$numbering = array( 0 );
|
|
|
|
|
|
$titletext = $title->getPrefixedDBkey();
|
|
|
|
|
|
foreach ( $tree1 as $s ) {
|
2010-01-07 04:13:14 +00:00
|
|
|
|
if ( $targetLevel !== false ) {
|
2009-06-25 11:05:22 +00:00
|
|
|
|
if ( $s['level'] <= $targetLevel )
|
|
|
|
|
|
// We've skipped enough
|
|
|
|
|
|
$targetLevel = false;
|
|
|
|
|
|
else
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
2010-01-26 11:57:01 +00:00
|
|
|
|
if ( $s['index'] !== $section ||
|
|
|
|
|
|
$s['fromtitle'] !== $titletext ) {
|
2009-06-25 11:05:22 +00:00
|
|
|
|
self::incrementNumbering( $numbering,
|
|
|
|
|
|
$s['toclevel'], $lastLevel );
|
2010-01-07 04:13:14 +00:00
|
|
|
|
|
2009-06-25 11:05:22 +00:00
|
|
|
|
// Rewrite index, byteoffset and number
|
|
|
|
|
|
if ( $s['fromtitle'] == $titletext ) {
|
|
|
|
|
|
$s['index'] = $nextIndex++;
|
|
|
|
|
|
if ( $merged )
|
|
|
|
|
|
$s['byteoffset'] += $len2;
|
|
|
|
|
|
}
|
|
|
|
|
|
$s['number'] = implode( '.', array_map(
|
|
|
|
|
|
array( $wgContLang, 'formatnum' ),
|
|
|
|
|
|
$numbering ) );
|
|
|
|
|
|
$lastLevel = $s['toclevel'];
|
|
|
|
|
|
$newTree[] = $s;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
// We're at $section
|
|
|
|
|
|
// Insert sections from $tree2 here
|
|
|
|
|
|
foreach ( $tree2 as $s2 ) {
|
|
|
|
|
|
// Rewrite the fields in $s2
|
|
|
|
|
|
// before inserting it
|
|
|
|
|
|
$s2['toclevel'] += $s['toclevel'] - 1;
|
|
|
|
|
|
$s2['level'] += $s['level'] - 1;
|
|
|
|
|
|
$s2['index'] = $nextIndex++;
|
|
|
|
|
|
$s2['byteoffset'] += $s['byteoffset'];
|
2010-01-07 04:13:14 +00:00
|
|
|
|
|
2009-06-25 11:05:22 +00:00
|
|
|
|
self::incrementNumbering( $numbering,
|
|
|
|
|
|
$s2['toclevel'], $lastLevel );
|
|
|
|
|
|
$s2['number'] = implode( '.', array_map(
|
|
|
|
|
|
array( $wgContLang, 'formatnum' ),
|
|
|
|
|
|
$numbering ) );
|
|
|
|
|
|
$lastLevel = $s2['toclevel'];
|
|
|
|
|
|
$newTree[] = $s2;
|
|
|
|
|
|
}
|
|
|
|
|
|
// Skip all descendants of $section in $tree1
|
|
|
|
|
|
$targetLevel = $s['level'];
|
|
|
|
|
|
$merged = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return $newTree;
|
|
|
|
|
|
}
|
2010-01-07 04:13:14 +00:00
|
|
|
|
|
2009-06-25 11:05:22 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* Increment a section number. Helper function for mergeSectionTrees()
|
|
|
|
|
|
* @param $number array Array representing a section number
|
|
|
|
|
|
* @param $level int Current TOC level (depth)
|
|
|
|
|
|
* @param $lastLevel int Level of previous TOC entry
|
|
|
|
|
|
*/
|
|
|
|
|
|
private static function incrementNumbering( &$number, $level, $lastLevel ) {
|
|
|
|
|
|
if ( $level > $lastLevel )
|
|
|
|
|
|
$number[$level - 1] = 1;
|
2010-01-26 11:57:01 +00:00
|
|
|
|
elseif ( $level < $lastLevel ) {
|
2009-06-25 11:05:22 +00:00
|
|
|
|
foreach ( $number as $key => $unused )
|
|
|
|
|
|
if ( $key >= $level )
|
|
|
|
|
|
unset( $number[$key] );
|
|
|
|
|
|
$number[$level - 1]++;
|
|
|
|
|
|
} else
|
|
|
|
|
|
$number[$level - 1]++;
|
|
|
|
|
|
}
|
2010-01-07 04:13:14 +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
|
2009-04-02 19:16:24 +00:00
|
|
|
|
* @param User $user the User object describing the current user
|
2004-09-21 05:49:12 +00:00
|
|
|
|
* @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
|
|
|
|
*/
|
2009-04-02 19:16:24 +00:00
|
|
|
|
function preSaveTransform( $text, Title $title, $user, $options, $clearState = true ) {
|
2004-03-06 01:49:16 +00:00
|
|
|
|
$this->mOptions = $options;
|
2008-01-16 02:47:31 +00:00
|
|
|
|
$this->setTitle( $title );
|
2008-01-22 10:47:44 +00:00
|
|
|
|
$this->setOutputType( self::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-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 );
|
2007-11-20 10:55:08 +00:00
|
|
|
|
$text = $this->pstPass2( $text, $user );
|
|
|
|
|
|
$text = $this->mStripState->unstripBoth( $text );
|
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
|
|
|
|
*/
|
2007-11-20 10:55:08 +00:00
|
|
|
|
function pstPass2( $text, $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.
|
2008-02-09 20:39:32 +00:00
|
|
|
|
*
|
|
|
|
|
|
* (see also bug 12815)
|
2005-04-07 18:14:31 +00:00
|
|
|
|
*/
|
2008-02-09 20:39:32 +00:00
|
|
|
|
$ts = $this->mOptions->getTimestamp();
|
2005-11-15 00:38:39 +00:00
|
|
|
|
if ( isset( $wgLocaltimezone ) ) {
|
2010-01-08 01:48:53 +00:00
|
|
|
|
$tz = $wgLocaltimezone;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
$tz = date_default_timezone_get();
|
|
|
|
|
|
}
|
2009-01-31 17:34:47 +00:00
|
|
|
|
|
2010-01-08 01:48:53 +00:00
|
|
|
|
$unixts = wfTimestamp( TS_UNIX, $ts );
|
|
|
|
|
|
$oldtz = date_default_timezone_get();
|
|
|
|
|
|
date_default_timezone_set( $tz );
|
|
|
|
|
|
$ts = date( 'YmdHis', $unixts );
|
|
|
|
|
|
$tzMsg = date( 'T', $unixts ); # might vary on DST changeover!
|
2009-01-31 17:34:47 +00:00
|
|
|
|
|
2010-01-08 01:48:53 +00:00
|
|
|
|
/* Allow translation of timezones trough wiki. date() can return
|
|
|
|
|
|
* whatever crap the system uses, localised or not, so we cannot
|
|
|
|
|
|
* ship premade translations.
|
|
|
|
|
|
*/
|
|
|
|
|
|
$key = 'timezone-' . strtolower( trim( $tzMsg ) );
|
|
|
|
|
|
$value = wfMsgForContent( $key );
|
|
|
|
|
|
if ( !wfEmptyMsg( $key, $value ) ) $tzMsg = $value;
|
|
|
|
|
|
|
|
|
|
|
|
date_default_timezone_set( $oldtz );
|
2008-06-25 12:09:32 +00:00
|
|
|
|
|
2010-01-08 01:48:53 +00:00
|
|
|
|
$d = $wgContLang->timeanddate( $ts, false, false ) . " ($tzMsg)";
|
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-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]";
|
2008-05-09 20:02:12 +00:00
|
|
|
|
$nc = '[ _0-9A-Za-z\x80-\xff-]'; # Namespaces can use non-ascii!
|
2006-01-07 13:31:29 +00:00
|
|
|
|
|
2006-10-04 21:32:09 +00:00
|
|
|
|
$p1 = "/\[\[(:?$nc+:|:|)($tc+?)( \\($tc+\\))\\|]]/"; # [[ns:page (context)|]]
|
2008-08-30 13:33:05 +00:00
|
|
|
|
$p4 = "/\[\[(:?$nc+:|:|)($tc+?)(($tc+))\\|]]/"; # [[ns:page(context)|]]
|
2006-10-04 21:32:09 +00:00
|
|
|
|
$p3 = "/\[\[(:?$nc+:|:|)($tc+?)( \\($tc+\\)|)(, $tc+|)\\|]]/"; # [[ns:page (context), context|]]
|
|
|
|
|
|
$p2 = "/\[\[\\|($tc+)]]/"; # [[|page]]
|
2004-03-06 01:49:16 +00:00
|
|
|
|
|
2006-10-04 21:32:09 +00:00
|
|
|
|
# try $p1 first, to turn "[[A, B (C)|]]" into "[[A, B (C)|A, B]]"
|
2006-07-26 18:09:04 +00:00
|
|
|
|
$text = preg_replace( $p1, '[[\\1\\2\\3|\\2]]', $text );
|
2008-08-30 13:33:05 +00:00
|
|
|
|
$text = preg_replace( $p4, '[[\\1\\2\\3|\\2]]', $text );
|
2006-10-04 21:32:09 +00:00
|
|
|
|
$text = preg_replace( $p3, '[[\\1\\2\\3\\4|\\2]]', $text );
|
2006-07-26 18:09:04 +00:00
|
|
|
|
|
|
|
|
|
|
$t = $this->mTitle->getText();
|
2006-10-17 08:49:27 +00:00
|
|
|
|
$m = array();
|
2006-10-04 21:32:09 +00:00
|
|
|
|
if ( preg_match( "/^($nc+:|)$tc+?( \\($tc+\\))$/", $t, $m ) ) {
|
|
|
|
|
|
$text = preg_replace( $p2, "[[$m[1]\\1$m[2]|\\1]]", $text );
|
2010-01-26 11:57:01 +00:00
|
|
|
|
} elseif ( preg_match( "/^($nc+:|)$tc+?(, $tc+|)$/", $t, $m ) && "$m[1]$m[2]" !== '' ) {
|
2006-10-04 21:32:09 +00:00
|
|
|
|
$text = preg_replace( $p2, "[[$m[1]\\1$m[2]|\\1]]", $text );
|
2004-03-06 01:49:16 +00:00
|
|
|
|
} else {
|
2006-10-04 21:32:09 +00:00
|
|
|
|
# if there's no context, 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
|
|
|
|
|
|
$text = rtrim( $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.
|
2009-09-30 10:35:34 +00:00
|
|
|
|
* If you have pre-fetched the nickname or the fancySig option, you can
|
|
|
|
|
|
* specify them here to save a database query.
|
2005-11-15 00:38:39 +00:00
|
|
|
|
*
|
|
|
|
|
|
* @param User $user
|
|
|
|
|
|
* @return string
|
|
|
|
|
|
*/
|
2009-09-30 10:35:34 +00:00
|
|
|
|
function getUserSig( &$user, $nickname = false, $fancySig = null ) {
|
2007-06-13 16:28:19 +00:00
|
|
|
|
global $wgMaxSigChars;
|
2008-04-14 07:45:50 +00:00
|
|
|
|
|
2006-01-07 23:09:21 +00:00
|
|
|
|
$username = $user->getName();
|
2010-01-07 04:13:14 +00:00
|
|
|
|
|
2009-09-30 10:35:34 +00:00
|
|
|
|
// If not given, retrieve from the user object.
|
|
|
|
|
|
if ( $nickname === false )
|
|
|
|
|
|
$nickname = $user->getOption( 'nickname' );
|
2010-01-07 04:13:14 +00:00
|
|
|
|
|
2009-09-30 10:35:34 +00:00
|
|
|
|
if ( is_null( $fancySig ) )
|
|
|
|
|
|
$fancySig = $user->getBoolOption( 'fancysig' );
|
2010-01-07 04:13:14 +00:00
|
|
|
|
|
2009-09-09 17:30:52 +00:00
|
|
|
|
$nickname = $nickname == null ? $username : $nickname;
|
2008-04-14 07:45:50 +00:00
|
|
|
|
|
2007-06-25 15:02:46 +00:00
|
|
|
|
if( mb_strlen( $nickname ) > $wgMaxSigChars ) {
|
2007-06-13 16:28:19 +00:00
|
|
|
|
$nickname = $username;
|
|
|
|
|
|
wfDebug( __METHOD__ . ": $username has overlong signature.\n" );
|
2009-09-30 10:35:34 +00:00
|
|
|
|
} elseif( $fancySig !== false ) {
|
2006-01-07 23:09:21 +00:00
|
|
|
|
# Sig. might contain markup; validate this
|
2008-08-25 04:27:40 +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;
|
2008-08-26 14:37:15 +00:00
|
|
|
|
wfDebug( __METHOD__.": $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
|
2008-08-25 04:27:40 +00:00
|
|
|
|
$nickname = $this->cleanSigInSig( $nickname );
|
2006-06-23 19:50:55 +00:00
|
|
|
|
|
2006-01-07 23:09:21 +00:00
|
|
|
|
# If we're still here, make it a link to the user page
|
2007-11-15 03:30:03 +00:00
|
|
|
|
$userText = wfEscapeWikiText( $username );
|
|
|
|
|
|
$nickText = wfEscapeWikiText( $nickname );
|
2007-11-13 20:32:11 +00:00
|
|
|
|
if ( $user->isAnon() ) {
|
2007-11-23 17:49:08 +00:00
|
|
|
|
return wfMsgExt( 'signature-anon', array( 'content', 'parsemag' ), $userText, $nickText );
|
2007-11-13 20:32:11 +00:00
|
|
|
|
} else {
|
2007-11-23 17:02:25 +00:00
|
|
|
|
return wfMsgExt( 'signature', array( 'content', 'parsemag' ), $userText, $nickText );
|
2007-11-13 20:32:11 +00:00
|
|
|
|
}
|
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.
|
|
|
|
|
|
*/
|
2008-08-25 04:27:40 +00:00
|
|
|
|
function validateSig( $text ) {
|
2008-09-22 17:01:44 +00:00
|
|
|
|
return( Xml::isWellFormedXmlFragment( $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 ) {
|
2007-12-01 06:52:25 +00:00
|
|
|
|
if ( !$parsing ) {
|
|
|
|
|
|
global $wgTitle;
|
2008-01-19 09:03:45 +00:00
|
|
|
|
$this->clearState();
|
|
|
|
|
|
$this->setTitle( $wgTitle );
|
|
|
|
|
|
$this->mOptions = new ParserOptions;
|
2008-01-22 10:47:44 +00:00
|
|
|
|
$this->setOutputType = self::OT_PREPROCESS;
|
2007-12-01 06:52:25 +00:00
|
|
|
|
}
|
2006-07-11 17:40:11 +00:00
|
|
|
|
|
2008-07-31 09:41:28 +00:00
|
|
|
|
# Option to disable this feature
|
|
|
|
|
|
if ( !$this->mOptions->getCleanSignatures() ) {
|
|
|
|
|
|
return $text;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2007-12-01 06:52:25 +00:00
|
|
|
|
# FIXME: regex doesn't respect extension tags or nowiki
|
|
|
|
|
|
# => Move this logic to braceSubstitution()
|
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 );
|
2008-08-25 04:27:40 +00:00
|
|
|
|
$text = $this->cleanSigInSig( $text );
|
2007-12-01 06:52:25 +00:00
|
|
|
|
$dom = $this->preprocessToDom( $text );
|
2008-01-21 16:36:08 +00:00
|
|
|
|
$frame = $this->getPreprocessor()->newFrame();
|
|
|
|
|
|
$text = $frame->expand( $dom );
|
2007-12-01 06:52:25 +00:00
|
|
|
|
|
|
|
|
|
|
if ( !$parsing ) {
|
|
|
|
|
|
$text = $this->mStripState->unstripBoth( $text );
|
|
|
|
|
|
}
|
2006-07-11 17:40:11 +00:00
|
|
|
|
|
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
|
|
|
|
|
|
*/
|
2008-08-25 04:27:40 +00:00
|
|
|
|
function cleanSigInSig( $text ) {
|
2006-06-23 19:50:55 +00:00
|
|
|
|
$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 ) {
|
2008-01-16 02:47:31 +00:00
|
|
|
|
$this->setTitle( $title );
|
2004-03-27 22:47:25 +00:00
|
|
|
|
$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
|
|
|
|
/**
|
2008-01-19 09:03:45 +00:00
|
|
|
|
* Wrapper for preprocess()
|
2007-11-20 10:55:08 +00:00
|
|
|
|
*
|
2008-01-19 09:03:45 +00:00
|
|
|
|
* @param string $text the text to preprocess
|
2004-09-21 05:49:12 +00:00
|
|
|
|
* @param ParserOptions $options options
|
2008-01-19 09:03:45 +00:00
|
|
|
|
* @return string
|
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
|
|
|
|
|
2004-04-05 10:38:40 +00:00
|
|
|
|
# Guard against infinite recursion
|
|
|
|
|
|
if ( $executing ) {
|
|
|
|
|
|
return $text;
|
|
|
|
|
|
}
|
|
|
|
|
|
$executing = true;
|
|
|
|
|
|
|
2008-08-26 14:37:15 +00:00
|
|
|
|
wfProfileIn(__METHOD__);
|
2008-01-19 09:03:45 +00:00
|
|
|
|
$text = $this->preprocess( $text, $wgTitle, $options );
|
2004-04-12 23:59:37 +00:00
|
|
|
|
|
2004-04-05 10:38:40 +00:00
|
|
|
|
$executing = false;
|
2008-08-26 14:37:15 +00:00
|
|
|
|
wfProfileOut(__METHOD__);
|
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 );
|
2006-11-29 05:45:03 +00:00
|
|
|
|
$oldVal = isset( $this->mTagHooks[$tag] ) ? $this->mTagHooks[$tag] : null;
|
2004-06-12 06:15:09 +00:00
|
|
|
|
$this->mTagHooks[$tag] = $callback;
|
2008-03-18 21:45:18 +00:00
|
|
|
|
if( !in_array( $tag, $this->mStripList ) ) {
|
|
|
|
|
|
$this->mStripList[] = $tag;
|
|
|
|
|
|
}
|
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
|
|
|
|
|
2007-07-15 11:14:53 +00:00
|
|
|
|
function setTransparentTagHook( $tag, $callback ) {
|
|
|
|
|
|
$tag = strtolower( $tag );
|
|
|
|
|
|
$oldVal = isset( $this->mTransparentTagHooks[$tag] ) ? $this->mTransparentTagHooks[$tag] : null;
|
|
|
|
|
|
$this->mTransparentTagHooks[$tag] = $callback;
|
|
|
|
|
|
|
|
|
|
|
|
return $oldVal;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2008-01-22 10:10:21 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* Remove all tag hooks
|
|
|
|
|
|
*/
|
|
|
|
|
|
function clearTagHooks() {
|
|
|
|
|
|
$this->mTagHooks = array();
|
|
|
|
|
|
$this->mStripList = $this->mDefaultStripList;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
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 ) { ... }
|
|
|
|
|
|
*
|
2008-07-23 14:51:39 +00:00
|
|
|
|
* Or with SFH_OBJECT_ARGS:
|
|
|
|
|
|
* function myParserFunction( $parser, $frame, $args ) { ... }
|
|
|
|
|
|
*
|
2006-10-17 08:49:27 +00:00
|
|
|
|
* 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
|
2006-04-05 09:40:25 +00:00
|
|
|
|
* specified in the keys. Valid flags are:
|
2006-10-17 08:49:27 +00:00
|
|
|
|
* found The text returned is valid, stop processing the template. This
|
2006-04-05 09:40:25 +00:00
|
|
|
|
* is on by default.
|
|
|
|
|
|
* nowiki Wiki markup in the return value should be escaped
|
|
|
|
|
|
* 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-10-17 08:49:27 +00:00
|
|
|
|
* @param integer $flags a combination of the following flags:
|
2008-07-23 14:51:39 +00:00
|
|
|
|
* SFH_NO_HASH No leading hash, i.e. {{plural:...}} instead of {{#if:...}}
|
|
|
|
|
|
*
|
2010-01-07 04:13:14 +00:00
|
|
|
|
* SFH_OBJECT_ARGS Pass the template arguments as PPNode objects instead of text. This
|
2008-07-23 14:51:39 +00:00
|
|
|
|
* allows for conditional expansion of the parse tree, allowing you to eliminate dead
|
2010-01-07 04:13:14 +00:00
|
|
|
|
* branches and thus speed up parsing. It is also possible to analyse the parse tree of
|
2008-07-23 14:51:39 +00:00
|
|
|
|
* the arguments, and to control the way they are expanded.
|
|
|
|
|
|
*
|
|
|
|
|
|
* The $frame parameter is a PPFrame. This can be used to produce expanded text from the
|
|
|
|
|
|
* arguments, for instance:
|
|
|
|
|
|
* $text = isset( $args[0] ) ? $frame->expand( $args[0] ) : '';
|
|
|
|
|
|
*
|
2010-01-07 04:13:14 +00:00
|
|
|
|
* For technical reasons, $args[0] is pre-expanded and will be a string. This may change in
|
2008-07-23 14:51:39 +00:00
|
|
|
|
* future versions. Please call $frame->expand() on it anyway so that your code keeps
|
|
|
|
|
|
* working if/when this is changed.
|
|
|
|
|
|
*
|
|
|
|
|
|
* If you want whitespace to be trimmed from $args, you need to do it yourself, post-
|
|
|
|
|
|
* expansion.
|
|
|
|
|
|
*
|
2010-01-07 04:13:14 +00:00
|
|
|
|
* Please read the documentation in includes/parser/Preprocessor.php for more information
|
2008-07-23 14:51:39 +00:00
|
|
|
|
* about the methods available in PPFrame and PPNode.
|
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 ) {
|
2009-08-26 15:47:03 +00:00
|
|
|
|
global $wgContLang;
|
|
|
|
|
|
|
2007-11-20 10:55:08 +00:00
|
|
|
|
$oldVal = isset( $this->mFunctionHooks[$id] ) ? $this->mFunctionHooks[$id][0] : null;
|
|
|
|
|
|
$this->mFunctionHooks[$id] = array( $callback, $flags );
|
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 );
|
2006-08-30 07:45:07 +00:00
|
|
|
|
if( !$mw )
|
2008-08-26 14:37:15 +00:00
|
|
|
|
throw new MWException( __METHOD__.'() expecting a magic word identifier.' );
|
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 ) {
|
2009-08-26 15:47:03 +00:00
|
|
|
|
$syn = $wgContLang->lc( $syn );
|
2006-07-03 11:07:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
# Add leading hash
|
|
|
|
|
|
if ( !( $flags & SFH_NO_HASH ) ) {
|
|
|
|
|
|
$syn = '#' . $syn;
|
|
|
|
|
|
}
|
|
|
|
|
|
# Remove trailing colon
|
2008-08-26 14:37:15 +00:00
|
|
|
|
if ( substr( $syn, -1, 1 ) === ':' ) {
|
2006-07-03 11:07:00 +00:00
|
|
|
|
$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
|
|
|
|
}
|
|
|
|
|
|
|
2006-08-30 07:45:07 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* Get all registered function hook identifiers
|
|
|
|
|
|
*
|
|
|
|
|
|
* @return array
|
|
|
|
|
|
*/
|
|
|
|
|
|
function getFunctionHooks() {
|
|
|
|
|
|
return array_keys( $this->mFunctionHooks );
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2009-07-11 13:03:35 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* Create a tag function, e.g. <test>some stuff</test>.
|
|
|
|
|
|
* Unlike tag hooks, tag functions are parsed at preprocessor level.
|
|
|
|
|
|
* Unlike parser functions, their content is not preprocessed.
|
|
|
|
|
|
*/
|
|
|
|
|
|
function setFunctionTagHook( $tag, $callback, $flags ) {
|
|
|
|
|
|
$tag = strtolower( $tag );
|
|
|
|
|
|
$old = isset( $this->mFunctionTagHooks[$tag] ) ?
|
|
|
|
|
|
$this->mFunctionTagHooks[$tag] : null;
|
|
|
|
|
|
$this->mFunctionTagHooks[$tag] = array( $callback, $flags );
|
|
|
|
|
|
|
|
|
|
|
|
if( !in_array( $tag, $this->mStripList ) ) {
|
|
|
|
|
|
$this->mStripList[] = $tag;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return $old;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2004-10-15 17:39:10 +00:00
|
|
|
|
/**
|
2009-06-06 15:45:43 +00:00
|
|
|
|
* FIXME: update documentation. makeLinkObj() is deprecated.
|
2004-10-15 17:39:10 +00:00
|
|
|
|
* Replace <!--LINK--> link placeholders with actual links, in the buffer
|
2006-11-08 07:12:03 +00:00
|
|
|
|
* Placeholders created in Skin::makeLinkObj()
|
2007-11-22 15:54:18 +00:00
|
|
|
|
* Returns an array of link CSS classes, indexed by PDBK.
|
2004-10-15 17:39:10 +00:00
|
|
|
|
*/
|
|
|
|
|
|
function replaceLinkHolders( &$text, $options = 0 ) {
|
2008-08-26 14:37:15 +00:00
|
|
|
|
return $this->mLinkHolders->replace( $text );
|
2004-10-15 17:39:10 +00:00
|
|
|
|
}
|
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 ) {
|
2008-08-26 14:37:15 +00:00
|
|
|
|
return $this->mLinkHolders->replaceText( $text );
|
2005-05-31 08:49:03 +00:00
|
|
|
|
}
|
2004-11-20 11:28:37 +00:00
|
|
|
|
|
2006-06-06 22:56:38 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* Tag hook handler for 'pre'.
|
|
|
|
|
|
*/
|
2008-08-19 20:59:18 +00:00
|
|
|
|
function renderPreTag( $text, $attribs ) {
|
2006-06-06 22:56:38 +00:00
|
|
|
|
// Backwards-compatibility hack
|
2006-11-21 09:53:45 +00:00
|
|
|
|
$content = StringUtils::delimiterReplace( '<nowiki>', '</nowiki>', '$1', $text, 'i' );
|
2006-07-11 17:40:11 +00:00
|
|
|
|
|
2006-06-06 22:56:38 +00:00
|
|
|
|
$attribs = Sanitizer::validateTagAttributes( $attribs, 'pre' );
|
2008-12-14 19:14:21 +00:00
|
|
|
|
return Xml::openElement( 'pre', $attribs ) .
|
2006-11-21 09:53:45 +00:00
|
|
|
|
Xml::escapeTagsOnly( $content ) .
|
2006-06-06 22:56:38 +00:00
|
|
|
|
'</pre>';
|
|
|
|
|
|
}
|
2006-07-11 17:40:11 +00:00
|
|
|
|
|
2009-11-07 16:46:34 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* Tag hook handler for 'a'. Renders a HTML <a> tag, allowing most attributes, filtering href against
|
|
|
|
|
|
* allowed protocols and spam blacklist.
|
|
|
|
|
|
**/
|
|
|
|
|
|
function renderHyperlink( $text, $params, $frame = false ) {
|
|
|
|
|
|
foreach ( $params as $name => $value ) {
|
|
|
|
|
|
$params[ $name ] = $this->replaceVariables( $value, $frame );
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$whitelist = Sanitizer::attributeWhitelist( 'a' );
|
|
|
|
|
|
$params = Sanitizer::validateAttributes( $params, $whitelist );
|
|
|
|
|
|
|
|
|
|
|
|
$content = $this->recursiveTagParse( trim( $text ), $frame );
|
|
|
|
|
|
|
|
|
|
|
|
if ( isset( $params[ 'href' ] ) ) {
|
|
|
|
|
|
$href = $params[ 'href' ];
|
|
|
|
|
|
$this->mOutput->addExternalLink( $href );
|
|
|
|
|
|
unset( $params[ 'href' ] );
|
|
|
|
|
|
} else {
|
|
|
|
|
|
# Non-link <a> tag
|
2010-01-07 04:13:14 +00:00
|
|
|
|
return Xml::openElement( 'a', $params ) . $content . Xml::closeElement( 'a' );
|
2009-11-07 16:46:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$sk = $this->mOptions->getSkin();
|
|
|
|
|
|
$html = $sk->makeExternalLink( $href, $content, false, '', $params );
|
|
|
|
|
|
|
|
|
|
|
|
return $html;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
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();
|
2007-01-20 22:34:05 +00:00
|
|
|
|
$ig->setContextTitle( $this->mTitle );
|
2004-11-13 12:04:31 +00:00
|
|
|
|
$ig->setShowBytes( false );
|
|
|
|
|
|
$ig->setShowFilename( false );
|
2007-08-22 13:40:22 +00:00
|
|
|
|
$ig->setParser( $this );
|
|
|
|
|
|
$ig->setHideBadImages();
|
2007-07-13 17:25:06 +00:00
|
|
|
|
$ig->setAttributes( Sanitizer::validateTagAttributes( $params, 'table' ) );
|
2006-11-08 07:12:03 +00:00
|
|
|
|
$ig->useSkin( $this->mOptions->getSkin() );
|
2007-05-31 16:01:26 +00:00
|
|
|
|
$ig->mRevisionId = $this->mRevisionId;
|
2004-11-20 11:28:37 +00:00
|
|
|
|
|
2007-01-04 19:47:11 +00:00
|
|
|
|
if( isset( $params['caption'] ) ) {
|
|
|
|
|
|
$caption = $params['caption'];
|
|
|
|
|
|
$caption = htmlspecialchars( $caption );
|
|
|
|
|
|
$caption = $this->replaceInternalLinks( $caption );
|
2007-01-05 01:07:04 +00:00
|
|
|
|
$ig->setCaptionHtml( $caption );
|
2007-01-04 19:47:11 +00:00
|
|
|
|
}
|
2007-02-02 03:32:03 +00:00
|
|
|
|
if( isset( $params['perrow'] ) ) {
|
|
|
|
|
|
$ig->setPerRow( $params['perrow'] );
|
|
|
|
|
|
}
|
|
|
|
|
|
if( isset( $params['widths'] ) ) {
|
|
|
|
|
|
$ig->setWidths( $params['widths'] );
|
|
|
|
|
|
}
|
|
|
|
|
|
if( isset( $params['heights'] ) ) {
|
|
|
|
|
|
$ig->setHeights( $params['heights'] );
|
|
|
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
|
2007-05-31 16:01:26 +00:00
|
|
|
|
wfRunHooks( 'BeforeParserrenderImageGallery', array( &$this, &$ig ) );
|
2006-07-11 17:40:11 +00:00
|
|
|
|
|
2008-08-26 14:37:15 +00:00
|
|
|
|
$lines = StringUtils::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
|
2006-10-17 08:49:27 +00:00
|
|
|
|
$matches = array();
|
2004-11-13 12:04:31 +00:00
|
|
|
|
preg_match( "/^([^|]+)(\\|(.*))?$/", $line, $matches );
|
|
|
|
|
|
# Skip empty lines
|
|
|
|
|
|
if ( count( $matches ) == 0 ) {
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
2010-01-07 04:13:14 +00:00
|
|
|
|
|
2008-06-01 18:31:40 +00:00
|
|
|
|
if ( strpos( $matches[0], '%' ) !== false )
|
|
|
|
|
|
$matches[1] = urldecode( $matches[1] );
|
2008-12-01 17:14:30 +00:00
|
|
|
|
$tp = Title::newFromText( $matches[1]/*, NS_FILE*/ );
|
2006-07-11 14:03:17 +00:00
|
|
|
|
$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
|
|
|
|
|
2008-01-14 06:59:20 +00:00
|
|
|
|
$html = $this->recursiveTagParse( trim( $label ) );
|
2005-07-03 07:15:53 +00:00
|
|
|
|
|
2007-05-30 21:02:32 +00:00
|
|
|
|
$ig->add( $nt, $html );
|
2006-05-09 18:01:15 +00:00
|
|
|
|
|
|
|
|
|
|
# Only add real images (bug #5586)
|
2008-12-01 17:14:30 +00:00
|
|
|
|
if ( $nt->getNamespace() == NS_FILE ) {
|
2006-05-09 18:01:15 +00:00
|
|
|
|
$this->mOutput->addImage( $nt->getDBkey() );
|
|
|
|
|
|
}
|
2004-11-13 12:04:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
return $ig->toHTML();
|
|
|
|
|
|
}
|
2005-04-27 07:48:14 +00:00
|
|
|
|
|
Basic integrated audio/video support, with Ogg implementation.
* JavaScript video player based loosely on Greg Maxwell's player
* Image page text snippet customisation
* Abstraction of transform parameters in the parser. Introduced Linker::makeImageLink2().
* Made canRender(), mustRender() depend on file, not just on handler. Moved width=0, height=0 checking to ImageHandler::canRender(), since audio streams have width=height=0 but should be rendered.
Also:
* Automatic upgrade for oldimage rows on image page view, allows media handler selection based on oi_*_mime
* oi_*_mime unconditionally referenced, REQUIRES SCHEMA UPGRADE
* Don't destroy file info for missing files on upgrade
* Simple, centralised extension message file handling
* Made MessageCache::loadAllMessages non-static, optimised for repeated-call case due to abuse in User.php
* Support for lightweight parser output hooks, with callback whitelist for security
* Moved Linker::formatSize() to Language, to join the new formatTimePeriod() and formatBitrate()
* Introduced MagicWordArray, regex capture trick requires that magic word IDs DO NOT CONTAIN HYPHENS.
2007-08-15 10:50:09 +00:00
|
|
|
|
function getImageParams( $handler ) {
|
|
|
|
|
|
if ( $handler ) {
|
|
|
|
|
|
$handlerClass = get_class( $handler );
|
|
|
|
|
|
} else {
|
|
|
|
|
|
$handlerClass = '';
|
|
|
|
|
|
}
|
|
|
|
|
|
if ( !isset( $this->mImageParams[$handlerClass] ) ) {
|
|
|
|
|
|
// Initialise static lists
|
|
|
|
|
|
static $internalParamNames = array(
|
|
|
|
|
|
'horizAlign' => array( 'left', 'right', 'center', 'none' ),
|
2008-04-14 07:45:50 +00:00
|
|
|
|
'vertAlign' => array( 'baseline', 'sub', 'super', 'top', 'text-top', 'middle',
|
Basic integrated audio/video support, with Ogg implementation.
* JavaScript video player based loosely on Greg Maxwell's player
* Image page text snippet customisation
* Abstraction of transform parameters in the parser. Introduced Linker::makeImageLink2().
* Made canRender(), mustRender() depend on file, not just on handler. Moved width=0, height=0 checking to ImageHandler::canRender(), since audio streams have width=height=0 but should be rendered.
Also:
* Automatic upgrade for oldimage rows on image page view, allows media handler selection based on oi_*_mime
* oi_*_mime unconditionally referenced, REQUIRES SCHEMA UPGRADE
* Don't destroy file info for missing files on upgrade
* Simple, centralised extension message file handling
* Made MessageCache::loadAllMessages non-static, optimised for repeated-call case due to abuse in User.php
* Support for lightweight parser output hooks, with callback whitelist for security
* Moved Linker::formatSize() to Language, to join the new formatTimePeriod() and formatBitrate()
* Introduced MagicWordArray, regex capture trick requires that magic word IDs DO NOT CONTAIN HYPHENS.
2007-08-15 10:50:09 +00:00
|
|
|
|
'bottom', 'text-bottom' ),
|
2008-04-14 07:45:50 +00:00
|
|
|
|
'frame' => array( 'thumbnail', 'manualthumb', 'framed', 'frameless',
|
2008-10-08 16:33:36 +00:00
|
|
|
|
'upright', 'border', 'link', 'alt' ),
|
Basic integrated audio/video support, with Ogg implementation.
* JavaScript video player based loosely on Greg Maxwell's player
* Image page text snippet customisation
* Abstraction of transform parameters in the parser. Introduced Linker::makeImageLink2().
* Made canRender(), mustRender() depend on file, not just on handler. Moved width=0, height=0 checking to ImageHandler::canRender(), since audio streams have width=height=0 but should be rendered.
Also:
* Automatic upgrade for oldimage rows on image page view, allows media handler selection based on oi_*_mime
* oi_*_mime unconditionally referenced, REQUIRES SCHEMA UPGRADE
* Don't destroy file info for missing files on upgrade
* Simple, centralised extension message file handling
* Made MessageCache::loadAllMessages non-static, optimised for repeated-call case due to abuse in User.php
* Support for lightweight parser output hooks, with callback whitelist for security
* Moved Linker::formatSize() to Language, to join the new formatTimePeriod() and formatBitrate()
* Introduced MagicWordArray, regex capture trick requires that magic word IDs DO NOT CONTAIN HYPHENS.
2007-08-15 10:50:09 +00:00
|
|
|
|
);
|
|
|
|
|
|
static $internalParamMap;
|
|
|
|
|
|
if ( !$internalParamMap ) {
|
|
|
|
|
|
$internalParamMap = array();
|
|
|
|
|
|
foreach ( $internalParamNames as $type => $names ) {
|
|
|
|
|
|
foreach ( $names as $name ) {
|
|
|
|
|
|
$magicName = str_replace( '-', '_', "img_$name" );
|
|
|
|
|
|
$internalParamMap[$magicName] = array( $type, $name );
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Add handler params
|
|
|
|
|
|
$paramMap = $internalParamMap;
|
|
|
|
|
|
if ( $handler ) {
|
|
|
|
|
|
$handlerParamMap = $handler->getParamMap();
|
|
|
|
|
|
foreach ( $handlerParamMap as $magic => $paramName ) {
|
|
|
|
|
|
$paramMap[$magic] = array( 'handler', $paramName );
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
$this->mImageParams[$handlerClass] = $paramMap;
|
|
|
|
|
|
$this->mImageParamsMagicArray[$handlerClass] = new MagicWordArray( array_keys( $paramMap ) );
|
|
|
|
|
|
}
|
|
|
|
|
|
return array( $this->mImageParams[$handlerClass], $this->mImageParamsMagicArray[$handlerClass] );
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2005-04-27 07:48:14 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* Parse image options text and use it to make an image
|
2008-08-26 14:37:15 +00:00
|
|
|
|
* @param Title $title
|
|
|
|
|
|
* @param string $options
|
|
|
|
|
|
* @param LinkHolderArray $holders
|
2005-04-27 07:48:14 +00:00
|
|
|
|
*/
|
2008-08-26 14:37:15 +00:00
|
|
|
|
function makeImage( $title, $options, $holders = false ) {
|
2005-04-27 07:48:14 +00:00
|
|
|
|
# Check if the options text is of the form "options|alt text"
|
|
|
|
|
|
# Options are:
|
2008-10-08 16:33:36 +00:00
|
|
|
|
# * 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
|
2009-07-03 05:13:58 +00:00
|
|
|
|
# * frame Keep original image size, no magnify-button.
|
|
|
|
|
|
# * framed Same as "frame"
|
2008-10-08 16:33:36 +00:00
|
|
|
|
# * frameless like 'thumb' but without a frame. Keeps user preferences for width
|
|
|
|
|
|
# * upright reduce width for upright images, rounded to full __0 px
|
|
|
|
|
|
# * border draw a 1px border around the image
|
|
|
|
|
|
# * alt Text for HTML alt attribute (defaults to empty)
|
2010-01-07 04:13:14 +00:00
|
|
|
|
# * link Set the target of the image link. Can be external, interwiki, or local
|
2007-02-02 00:44:42 +00:00
|
|
|
|
# vertical-align values (no % or length right now):
|
|
|
|
|
|
# * baseline
|
|
|
|
|
|
# * sub
|
|
|
|
|
|
# * super
|
|
|
|
|
|
# * top
|
|
|
|
|
|
# * text-top
|
|
|
|
|
|
# * middle
|
|
|
|
|
|
# * bottom
|
|
|
|
|
|
# * text-bottom
|
2008-04-14 07:45:50 +00:00
|
|
|
|
|
2008-08-26 14:37:15 +00:00
|
|
|
|
$parts = StringUtils::explode( "|", $options );
|
Basic integrated audio/video support, with Ogg implementation.
* JavaScript video player based loosely on Greg Maxwell's player
* Image page text snippet customisation
* Abstraction of transform parameters in the parser. Introduced Linker::makeImageLink2().
* Made canRender(), mustRender() depend on file, not just on handler. Moved width=0, height=0 checking to ImageHandler::canRender(), since audio streams have width=height=0 but should be rendered.
Also:
* Automatic upgrade for oldimage rows on image page view, allows media handler selection based on oi_*_mime
* oi_*_mime unconditionally referenced, REQUIRES SCHEMA UPGRADE
* Don't destroy file info for missing files on upgrade
* Simple, centralised extension message file handling
* Made MessageCache::loadAllMessages non-static, optimised for repeated-call case due to abuse in User.php
* Support for lightweight parser output hooks, with callback whitelist for security
* Moved Linker::formatSize() to Language, to join the new formatTimePeriod() and formatBitrate()
* Introduced MagicWordArray, regex capture trick requires that magic word IDs DO NOT CONTAIN HYPHENS.
2007-08-15 10:50:09 +00:00
|
|
|
|
$sk = $this->mOptions->getSkin();
|
2005-04-27 07:48:14 +00:00
|
|
|
|
|
Basic integrated audio/video support, with Ogg implementation.
* JavaScript video player based loosely on Greg Maxwell's player
* Image page text snippet customisation
* Abstraction of transform parameters in the parser. Introduced Linker::makeImageLink2().
* Made canRender(), mustRender() depend on file, not just on handler. Moved width=0, height=0 checking to ImageHandler::canRender(), since audio streams have width=height=0 but should be rendered.
Also:
* Automatic upgrade for oldimage rows on image page view, allows media handler selection based on oi_*_mime
* oi_*_mime unconditionally referenced, REQUIRES SCHEMA UPGRADE
* Don't destroy file info for missing files on upgrade
* Simple, centralised extension message file handling
* Made MessageCache::loadAllMessages non-static, optimised for repeated-call case due to abuse in User.php
* Support for lightweight parser output hooks, with callback whitelist for security
* Moved Linker::formatSize() to Language, to join the new formatTimePeriod() and formatBitrate()
* Introduced MagicWordArray, regex capture trick requires that magic word IDs DO NOT CONTAIN HYPHENS.
2007-08-15 10:50:09 +00:00
|
|
|
|
# Give extensions a chance to select the file revision for us
|
2008-05-19 18:55:48 +00:00
|
|
|
|
$skip = $time = $descQuery = false;
|
|
|
|
|
|
wfRunHooks( 'BeforeParserMakeImageLinkObj', array( &$this, &$title, &$skip, &$time, &$descQuery ) );
|
2007-04-20 12:31:36 +00:00
|
|
|
|
|
Basic integrated audio/video support, with Ogg implementation.
* JavaScript video player based loosely on Greg Maxwell's player
* Image page text snippet customisation
* Abstraction of transform parameters in the parser. Introduced Linker::makeImageLink2().
* Made canRender(), mustRender() depend on file, not just on handler. Moved width=0, height=0 checking to ImageHandler::canRender(), since audio streams have width=height=0 but should be rendered.
Also:
* Automatic upgrade for oldimage rows on image page view, allows media handler selection based on oi_*_mime
* oi_*_mime unconditionally referenced, REQUIRES SCHEMA UPGRADE
* Don't destroy file info for missing files on upgrade
* Simple, centralised extension message file handling
* Made MessageCache::loadAllMessages non-static, optimised for repeated-call case due to abuse in User.php
* Support for lightweight parser output hooks, with callback whitelist for security
* Moved Linker::formatSize() to Language, to join the new formatTimePeriod() and formatBitrate()
* Introduced MagicWordArray, regex capture trick requires that magic word IDs DO NOT CONTAIN HYPHENS.
2007-08-15 10:50:09 +00:00
|
|
|
|
if ( $skip ) {
|
2008-08-01 15:09:57 +00:00
|
|
|
|
return $sk->link( $title );
|
2007-02-02 00:44:42 +00:00
|
|
|
|
}
|
2005-04-27 07:48:14 +00:00
|
|
|
|
|
2008-10-10 22:19:55 +00:00
|
|
|
|
# Get the file
|
|
|
|
|
|
$imagename = $title->getDBkey();
|
2009-08-15 09:59:59 +00:00
|
|
|
|
$file = wfFindFile( $title, array( 'time' => $time ) );
|
Basic integrated audio/video support, with Ogg implementation.
* JavaScript video player based loosely on Greg Maxwell's player
* Image page text snippet customisation
* Abstraction of transform parameters in the parser. Introduced Linker::makeImageLink2().
* Made canRender(), mustRender() depend on file, not just on handler. Moved width=0, height=0 checking to ImageHandler::canRender(), since audio streams have width=height=0 but should be rendered.
Also:
* Automatic upgrade for oldimage rows on image page view, allows media handler selection based on oi_*_mime
* oi_*_mime unconditionally referenced, REQUIRES SCHEMA UPGRADE
* Don't destroy file info for missing files on upgrade
* Simple, centralised extension message file handling
* Made MessageCache::loadAllMessages non-static, optimised for repeated-call case due to abuse in User.php
* Support for lightweight parser output hooks, with callback whitelist for security
* Moved Linker::formatSize() to Language, to join the new formatTimePeriod() and formatBitrate()
* Introduced MagicWordArray, regex capture trick requires that magic word IDs DO NOT CONTAIN HYPHENS.
2007-08-15 10:50:09 +00:00
|
|
|
|
# Get parameter map
|
|
|
|
|
|
$handler = $file ? $file->getHandler() : false;
|
2005-04-27 07:48:14 +00:00
|
|
|
|
|
Basic integrated audio/video support, with Ogg implementation.
* JavaScript video player based loosely on Greg Maxwell's player
* Image page text snippet customisation
* Abstraction of transform parameters in the parser. Introduced Linker::makeImageLink2().
* Made canRender(), mustRender() depend on file, not just on handler. Moved width=0, height=0 checking to ImageHandler::canRender(), since audio streams have width=height=0 but should be rendered.
Also:
* Automatic upgrade for oldimage rows on image page view, allows media handler selection based on oi_*_mime
* oi_*_mime unconditionally referenced, REQUIRES SCHEMA UPGRADE
* Don't destroy file info for missing files on upgrade
* Simple, centralised extension message file handling
* Made MessageCache::loadAllMessages non-static, optimised for repeated-call case due to abuse in User.php
* Support for lightweight parser output hooks, with callback whitelist for security
* Moved Linker::formatSize() to Language, to join the new formatTimePeriod() and formatBitrate()
* Introduced MagicWordArray, regex capture trick requires that magic word IDs DO NOT CONTAIN HYPHENS.
2007-08-15 10:50:09 +00:00
|
|
|
|
list( $paramMap, $mwArray ) = $this->getImageParams( $handler );
|
|
|
|
|
|
|
|
|
|
|
|
# Process the input parameters
|
2008-08-08 21:50:37 +00:00
|
|
|
|
$caption = '';
|
2008-04-14 07:45:50 +00:00
|
|
|
|
$params = array( 'frame' => array(), 'handler' => array(),
|
Basic integrated audio/video support, with Ogg implementation.
* JavaScript video player based loosely on Greg Maxwell's player
* Image page text snippet customisation
* Abstraction of transform parameters in the parser. Introduced Linker::makeImageLink2().
* Made canRender(), mustRender() depend on file, not just on handler. Moved width=0, height=0 checking to ImageHandler::canRender(), since audio streams have width=height=0 but should be rendered.
Also:
* Automatic upgrade for oldimage rows on image page view, allows media handler selection based on oi_*_mime
* oi_*_mime unconditionally referenced, REQUIRES SCHEMA UPGRADE
* Don't destroy file info for missing files on upgrade
* Simple, centralised extension message file handling
* Made MessageCache::loadAllMessages non-static, optimised for repeated-call case due to abuse in User.php
* Support for lightweight parser output hooks, with callback whitelist for security
* Moved Linker::formatSize() to Language, to join the new formatTimePeriod() and formatBitrate()
* Introduced MagicWordArray, regex capture trick requires that magic word IDs DO NOT CONTAIN HYPHENS.
2007-08-15 10:50:09 +00:00
|
|
|
|
'horizAlign' => array(), 'vertAlign' => array() );
|
|
|
|
|
|
foreach( $parts as $part ) {
|
2008-08-26 14:37:15 +00:00
|
|
|
|
$part = trim( $part );
|
Basic integrated audio/video support, with Ogg implementation.
* JavaScript video player based loosely on Greg Maxwell's player
* Image page text snippet customisation
* Abstraction of transform parameters in the parser. Introduced Linker::makeImageLink2().
* Made canRender(), mustRender() depend on file, not just on handler. Moved width=0, height=0 checking to ImageHandler::canRender(), since audio streams have width=height=0 but should be rendered.
Also:
* Automatic upgrade for oldimage rows on image page view, allows media handler selection based on oi_*_mime
* oi_*_mime unconditionally referenced, REQUIRES SCHEMA UPGRADE
* Don't destroy file info for missing files on upgrade
* Simple, centralised extension message file handling
* Made MessageCache::loadAllMessages non-static, optimised for repeated-call case due to abuse in User.php
* Support for lightweight parser output hooks, with callback whitelist for security
* Moved Linker::formatSize() to Language, to join the new formatTimePeriod() and formatBitrate()
* Introduced MagicWordArray, regex capture trick requires that magic word IDs DO NOT CONTAIN HYPHENS.
2007-08-15 10:50:09 +00:00
|
|
|
|
list( $magicName, $value ) = $mwArray->matchVariableStartToEnd( $part );
|
2008-03-25 05:17:42 +00:00
|
|
|
|
$validated = false;
|
|
|
|
|
|
if( isset( $paramMap[$magicName] ) ) {
|
Basic integrated audio/video support, with Ogg implementation.
* JavaScript video player based loosely on Greg Maxwell's player
* Image page text snippet customisation
* Abstraction of transform parameters in the parser. Introduced Linker::makeImageLink2().
* Made canRender(), mustRender() depend on file, not just on handler. Moved width=0, height=0 checking to ImageHandler::canRender(), since audio streams have width=height=0 but should be rendered.
Also:
* Automatic upgrade for oldimage rows on image page view, allows media handler selection based on oi_*_mime
* oi_*_mime unconditionally referenced, REQUIRES SCHEMA UPGRADE
* Don't destroy file info for missing files on upgrade
* Simple, centralised extension message file handling
* Made MessageCache::loadAllMessages non-static, optimised for repeated-call case due to abuse in User.php
* Support for lightweight parser output hooks, with callback whitelist for security
* Moved Linker::formatSize() to Language, to join the new formatTimePeriod() and formatBitrate()
* Introduced MagicWordArray, regex capture trick requires that magic word IDs DO NOT CONTAIN HYPHENS.
2007-08-15 10:50:09 +00:00
|
|
|
|
list( $type, $paramName ) = $paramMap[$magicName];
|
2008-03-25 05:17:42 +00:00
|
|
|
|
|
2007-08-25 15:49:36 +00:00
|
|
|
|
// Special case; width and height come in one variable together
|
2008-08-26 14:37:15 +00:00
|
|
|
|
if( $type === 'handler' && $paramName === 'width' ) {
|
2007-08-25 15:49:36 +00:00
|
|
|
|
$m = array();
|
2008-03-27 14:33:02 +00:00
|
|
|
|
# (bug 13500) In both cases (width/height and width only),
|
|
|
|
|
|
# permit trailing "px" for backward compatibility.
|
|
|
|
|
|
if ( preg_match( '/^([0-9]*)x([0-9]*)\s*(?:px)?\s*$/', $value, $m ) ) {
|
2008-03-25 08:23:10 +00:00
|
|
|
|
$width = intval( $m[1] );
|
|
|
|
|
|
$height = intval( $m[2] );
|
|
|
|
|
|
if ( $handler->validateParam( 'width', $width ) ) {
|
|
|
|
|
|
$params[$type]['width'] = $width;
|
|
|
|
|
|
$validated = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
if ( $handler->validateParam( 'height', $height ) ) {
|
|
|
|
|
|
$params[$type]['height'] = $height;
|
|
|
|
|
|
$validated = true;
|
|
|
|
|
|
}
|
2008-03-27 14:33:02 +00:00
|
|
|
|
} elseif ( preg_match( '/^[0-9]*\s*(?:px)?\s*$/', $value ) ) {
|
2008-03-25 08:23:10 +00:00
|
|
|
|
$width = intval( $value );
|
|
|
|
|
|
if ( $handler->validateParam( 'width', $width ) ) {
|
|
|
|
|
|
$params[$type]['width'] = $width;
|
|
|
|
|
|
$validated = true;
|
|
|
|
|
|
}
|
2008-03-25 05:17:42 +00:00
|
|
|
|
} // else no validation -- bug 13436
|
|
|
|
|
|
} else {
|
2008-08-26 14:37:15 +00:00
|
|
|
|
if ( $type === 'handler' ) {
|
2008-03-25 05:17:42 +00:00
|
|
|
|
# Validate handler parameter
|
|
|
|
|
|
$validated = $handler->validateParam( $paramName, $value );
|
|
|
|
|
|
} else {
|
|
|
|
|
|
# Validate internal parameters
|
2008-04-07 23:30:45 +00:00
|
|
|
|
switch( $paramName ) {
|
2008-10-08 16:33:36 +00:00
|
|
|
|
case 'manualthumb':
|
|
|
|
|
|
case 'alt':
|
2009-12-15 21:26:58 +00:00
|
|
|
|
// @todo Fixme: possibly check validity here for
|
2008-10-08 16:33:36 +00:00
|
|
|
|
// manualthumb? downstream behavior seems odd with
|
|
|
|
|
|
// missing manual thumbs.
|
2008-04-07 23:30:45 +00:00
|
|
|
|
$validated = true;
|
2008-10-15 21:20:13 +00:00
|
|
|
|
$value = $this->stripAltText( $value, $holders );
|
2008-04-07 23:30:45 +00:00
|
|
|
|
break;
|
2008-10-07 00:31:26 +00:00
|
|
|
|
case 'link':
|
2008-10-06 05:55:27 +00:00
|
|
|
|
$chars = self::EXT_LINK_URL_CLASS;
|
|
|
|
|
|
$prots = $this->mUrlProtocols;
|
|
|
|
|
|
if ( $value === '' ) {
|
|
|
|
|
|
$paramName = 'no-link';
|
|
|
|
|
|
$value = true;
|
|
|
|
|
|
$validated = true;
|
|
|
|
|
|
} elseif ( preg_match( "/^$prots/", $value ) ) {
|
|
|
|
|
|
if ( preg_match( "/^($prots)$chars+$/", $value, $m ) ) {
|
2008-10-07 00:31:26 +00:00
|
|
|
|
$paramName = 'link-url';
|
2008-10-06 05:55:27 +00:00
|
|
|
|
$this->mOutput->addExternalLink( $value );
|
|
|
|
|
|
$validated = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
2008-10-07 00:31:26 +00:00
|
|
|
|
$linkTitle = Title::newFromText( $value );
|
|
|
|
|
|
if ( $linkTitle ) {
|
|
|
|
|
|
$paramName = 'link-title';
|
|
|
|
|
|
$value = $linkTitle;
|
|
|
|
|
|
$this->mOutput->addLink( $linkTitle );
|
2008-10-06 05:55:27 +00:00
|
|
|
|
$validated = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
break;
|
2008-04-07 23:30:45 +00:00
|
|
|
|
default:
|
|
|
|
|
|
// Most other things appear to be empty or numeric...
|
|
|
|
|
|
$validated = ( $value === false || is_numeric( trim( $value ) ) );
|
|
|
|
|
|
}
|
2008-03-25 05:17:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if ( $validated ) {
|
|
|
|
|
|
$params[$type][$paramName] = $value;
|
2007-08-25 15:49:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2008-03-25 05:17:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
if ( !$validated ) {
|
Basic integrated audio/video support, with Ogg implementation.
* JavaScript video player based loosely on Greg Maxwell's player
* Image page text snippet customisation
* Abstraction of transform parameters in the parser. Introduced Linker::makeImageLink2().
* Made canRender(), mustRender() depend on file, not just on handler. Moved width=0, height=0 checking to ImageHandler::canRender(), since audio streams have width=height=0 but should be rendered.
Also:
* Automatic upgrade for oldimage rows on image page view, allows media handler selection based on oi_*_mime
* oi_*_mime unconditionally referenced, REQUIRES SCHEMA UPGRADE
* Don't destroy file info for missing files on upgrade
* Simple, centralised extension message file handling
* Made MessageCache::loadAllMessages non-static, optimised for repeated-call case due to abuse in User.php
* Support for lightweight parser output hooks, with callback whitelist for security
* Moved Linker::formatSize() to Language, to join the new formatTimePeriod() and formatBitrate()
* Introduced MagicWordArray, regex capture trick requires that magic word IDs DO NOT CONTAIN HYPHENS.
2007-08-15 10:50:09 +00:00
|
|
|
|
$caption = $part;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# Process alignment parameters
|
|
|
|
|
|
if ( $params['horizAlign'] ) {
|
|
|
|
|
|
$params['frame']['align'] = key( $params['horizAlign'] );
|
|
|
|
|
|
}
|
|
|
|
|
|
if ( $params['vertAlign'] ) {
|
|
|
|
|
|
$params['frame']['valign'] = key( $params['vertAlign'] );
|
|
|
|
|
|
}
|
2008-08-08 21:50:37 +00:00
|
|
|
|
|
2008-10-08 16:33:36 +00:00
|
|
|
|
$params['frame']['caption'] = $caption;
|
|
|
|
|
|
|
2009-07-03 05:13:58 +00:00
|
|
|
|
# Will the image be presented in a frame, with the caption below?
|
|
|
|
|
|
$imageIsFramed = isset( $params['frame']['frame'] ) ||
|
|
|
|
|
|
isset( $params['frame']['framed'] ) ||
|
|
|
|
|
|
isset( $params['frame']['thumbnail'] ) ||
|
|
|
|
|
|
isset( $params['frame']['manualthumb'] );
|
2008-10-08 16:33:36 +00:00
|
|
|
|
|
|
|
|
|
|
# In the old days, [[Image:Foo|text...]] would set alt text. Later it
|
|
|
|
|
|
# came to also set the caption, ordinary text after the image -- which
|
|
|
|
|
|
# makes no sense, because that just repeats the text multiple times in
|
|
|
|
|
|
# screen readers. It *also* came to set the title attribute.
|
|
|
|
|
|
#
|
|
|
|
|
|
# Now that we have an alt attribute, we should not set the alt text to
|
|
|
|
|
|
# equal the caption: that's worse than useless, it just repeats the
|
|
|
|
|
|
# text. This is the framed/thumbnail case. If there's no caption, we
|
|
|
|
|
|
# use the unnamed parameter for alt text as well, just for the time be-
|
|
|
|
|
|
# ing, if the unnamed param is set and the alt param is not.
|
|
|
|
|
|
#
|
|
|
|
|
|
# For the future, we need to figure out if we want to tweak this more,
|
|
|
|
|
|
# e.g., introducing a title= parameter for the title; ignoring the un-
|
|
|
|
|
|
# named parameter entirely for images without a caption; adding an ex-
|
|
|
|
|
|
# plicit caption= parameter and preserving the old magic unnamed para-
|
|
|
|
|
|
# meter for BC; ...
|
2009-07-03 05:13:58 +00:00
|
|
|
|
if ( $imageIsFramed ) { # Framed image
|
|
|
|
|
|
if ( $caption === '' && !isset( $params['frame']['alt'] ) ) {
|
|
|
|
|
|
# No caption or alt text, add the filename as the alt text so
|
|
|
|
|
|
# that screen readers at least get some description of the image
|
|
|
|
|
|
$params['frame']['alt'] = $title->getText();
|
|
|
|
|
|
}
|
|
|
|
|
|
# Do not set $params['frame']['title'] because tooltips don't make sense
|
|
|
|
|
|
# for framed images
|
|
|
|
|
|
} else { # Inline image
|
|
|
|
|
|
if ( !isset( $params['frame']['alt'] ) ) {
|
|
|
|
|
|
# No alt text, use the "caption" for the alt text
|
|
|
|
|
|
if ( $caption !== '') {
|
|
|
|
|
|
$params['frame']['alt'] = $this->stripAltText( $caption, $holders );
|
|
|
|
|
|
} else {
|
|
|
|
|
|
# No caption, fall back to using the filename for the
|
|
|
|
|
|
# alt text
|
|
|
|
|
|
$params['frame']['alt'] = $title->getText();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
# Use the "caption" for the tooltip text
|
|
|
|
|
|
$params['frame']['title'] = $this->stripAltText( $caption, $holders );
|
2008-10-08 16:33:36 +00:00
|
|
|
|
}
|
2007-05-31 16:01:26 +00:00
|
|
|
|
|
2008-02-21 10:25:44 +00:00
|
|
|
|
wfRunHooks( 'ParserMakeImageParams', array( $title, $file, &$params ) );
|
|
|
|
|
|
|
2005-04-27 07:48:14 +00:00
|
|
|
|
# Linker does the rest
|
2008-05-19 18:55:48 +00:00
|
|
|
|
$ret = $sk->makeImageLink2( $title, $file, $params['frame'], $params['handler'], $time, $descQuery );
|
Basic integrated audio/video support, with Ogg implementation.
* JavaScript video player based loosely on Greg Maxwell's player
* Image page text snippet customisation
* Abstraction of transform parameters in the parser. Introduced Linker::makeImageLink2().
* Made canRender(), mustRender() depend on file, not just on handler. Moved width=0, height=0 checking to ImageHandler::canRender(), since audio streams have width=height=0 but should be rendered.
Also:
* Automatic upgrade for oldimage rows on image page view, allows media handler selection based on oi_*_mime
* oi_*_mime unconditionally referenced, REQUIRES SCHEMA UPGRADE
* Don't destroy file info for missing files on upgrade
* Simple, centralised extension message file handling
* Made MessageCache::loadAllMessages non-static, optimised for repeated-call case due to abuse in User.php
* Support for lightweight parser output hooks, with callback whitelist for security
* Moved Linker::formatSize() to Language, to join the new formatTimePeriod() and formatBitrate()
* Introduced MagicWordArray, regex capture trick requires that magic word IDs DO NOT CONTAIN HYPHENS.
2007-08-15 10:50:09 +00:00
|
|
|
|
|
|
|
|
|
|
# Give the handler a chance to modify the parser object
|
|
|
|
|
|
if ( $handler ) {
|
|
|
|
|
|
$handler->parserTransformHook( $this, $file );
|
2007-05-31 16:01:26 +00:00
|
|
|
|
}
|
Basic integrated audio/video support, with Ogg implementation.
* JavaScript video player based loosely on Greg Maxwell's player
* Image page text snippet customisation
* Abstraction of transform parameters in the parser. Introduced Linker::makeImageLink2().
* Made canRender(), mustRender() depend on file, not just on handler. Moved width=0, height=0 checking to ImageHandler::canRender(), since audio streams have width=height=0 but should be rendered.
Also:
* Automatic upgrade for oldimage rows on image page view, allows media handler selection based on oi_*_mime
* oi_*_mime unconditionally referenced, REQUIRES SCHEMA UPGRADE
* Don't destroy file info for missing files on upgrade
* Simple, centralised extension message file handling
* Made MessageCache::loadAllMessages non-static, optimised for repeated-call case due to abuse in User.php
* Support for lightweight parser output hooks, with callback whitelist for security
* Moved Linker::formatSize() to Language, to join the new formatTimePeriod() and formatBitrate()
* Introduced MagicWordArray, regex capture trick requires that magic word IDs DO NOT CONTAIN HYPHENS.
2007-08-15 10:50:09 +00:00
|
|
|
|
|
|
|
|
|
|
return $ret;
|
2005-04-27 07:48:14 +00:00
|
|
|
|
}
|
2010-01-07 04:13:14 +00:00
|
|
|
|
|
2008-10-15 21:20:13 +00:00
|
|
|
|
protected function stripAltText( $caption, $holders ) {
|
|
|
|
|
|
# Strip bad stuff out of the title (tooltip). We can't just use
|
|
|
|
|
|
# replaceLinkHoldersText() here, because if this function is called
|
|
|
|
|
|
# from replaceInternalLinks2(), mLinkHolders won't be up-to-date.
|
|
|
|
|
|
if ( $holders ) {
|
|
|
|
|
|
$tooltip = $holders->replaceText( $caption );
|
|
|
|
|
|
} else {
|
|
|
|
|
|
$tooltip = $this->replaceLinkHoldersText( $caption );
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# make sure there are no placeholders in thumbnail attributes
|
|
|
|
|
|
# that are later expanded to html- so expand them now and
|
|
|
|
|
|
# remove the tags
|
|
|
|
|
|
$tooltip = $this->mStripState->unstripBoth( $tooltip );
|
|
|
|
|
|
$tooltip = Sanitizer::stripAllTags( $tooltip );
|
2010-01-07 04:13:14 +00:00
|
|
|
|
|
2008-10-15 21:20:13 +00:00
|
|
|
|
return $tooltip;
|
|
|
|
|
|
}
|
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
|
2007-11-20 10:55:08 +00:00
|
|
|
|
* @param PPFrame $frame
|
2005-08-23 21:49:48 +00:00
|
|
|
|
* @return string
|
2006-04-19 15:46:24 +00:00
|
|
|
|
* @private
|
2005-08-23 21:49:48 +00:00
|
|
|
|
*/
|
2007-11-20 10:55:08 +00:00
|
|
|
|
function attributeStripCallback( &$text, $frame = false ) {
|
|
|
|
|
|
$text = $this->replaceVariables( $text, $frame );
|
2006-11-21 09:53:45 +00:00
|
|
|
|
$text = $this->mStripState->unstripBoth( $text );
|
2005-08-29 23:34:37 +00:00
|
|
|
|
return $text;
|
|
|
|
|
|
}
|
2006-01-07 13:31:29 +00:00
|
|
|
|
|
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
|
|
|
|
|
|
*/
|
2009-12-11 21:07:27 +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
|
|
|
|
|
|
*/
|
2007-07-15 11:14:53 +00:00
|
|
|
|
function getTags() { return array_merge( array_keys($this->mTransparentTagHooks), array_keys( $this->mTagHooks ) ); }
|
2006-01-08 15:13:37 +00:00
|
|
|
|
/**#@-*/
|
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.
|
|
|
|
|
|
*
|
2008-01-05 12:39:12 +00:00
|
|
|
|
* @param string $text Page wikitext
|
|
|
|
|
|
* @param string $section A section identifier string of the form:
|
|
|
|
|
|
* <flag1> - <flag2> - ... - <section number>
|
|
|
|
|
|
*
|
|
|
|
|
|
* Currently the only recognised flag is "T", which means the target section number
|
2008-04-14 07:45:50 +00:00
|
|
|
|
* was derived during a template inclusion parse, in other words this is a template
|
|
|
|
|
|
* section edit link. If no flags are given, it was an ordinary section edit link.
|
|
|
|
|
|
* This flag is required to avoid a section numbering mismatch when a section is
|
2008-01-05 12:39:12 +00:00
|
|
|
|
* enclosed by <includeonly> (bug 6563).
|
|
|
|
|
|
*
|
2008-04-14 07:45:50 +00:00
|
|
|
|
* The section number 0 pulls the text before the first heading; other numbers will
|
|
|
|
|
|
* pull the given section along with its lower-level subsections. If the section is
|
2008-01-05 12:39:12 +00:00
|
|
|
|
* not found, $mode=get will return $newtext, and $mode=replace will return $text.
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param string $mode One of "get" or "replace"
|
|
|
|
|
|
* @param string $newText Replacement text for section data.
|
2006-06-06 00:51:34 +00:00
|
|
|
|
* @return string for "get", the extracted section text.
|
|
|
|
|
|
* for "replace", the whole page with the section replaced.
|
|
|
|
|
|
*/
|
2007-11-20 10:55:08 +00:00
|
|
|
|
private function extractSections( $text, $section, $mode, $newText='' ) {
|
2007-12-17 15:07:25 +00:00
|
|
|
|
global $wgTitle;
|
2007-06-19 16:00:11 +00:00
|
|
|
|
$this->clearState();
|
2008-01-16 02:47:31 +00:00
|
|
|
|
$this->setTitle( $wgTitle ); // not generally used but removes an ugly failure mode
|
2007-11-20 10:55:08 +00:00
|
|
|
|
$this->mOptions = new ParserOptions;
|
2008-01-22 10:47:44 +00:00
|
|
|
|
$this->setOutputType( self::OT_WIKI );
|
2007-11-20 10:55:08 +00:00
|
|
|
|
$outText = '';
|
2008-01-21 16:36:08 +00:00
|
|
|
|
$frame = $this->getPreprocessor()->newFrame();
|
2007-11-20 10:55:08 +00:00
|
|
|
|
|
2008-01-05 12:39:12 +00:00
|
|
|
|
// Process section extraction flags
|
|
|
|
|
|
$flags = 0;
|
|
|
|
|
|
$sectionParts = explode( '-', $section );
|
|
|
|
|
|
$sectionIndex = array_pop( $sectionParts );
|
|
|
|
|
|
foreach ( $sectionParts as $part ) {
|
2008-08-26 14:37:15 +00:00
|
|
|
|
if ( $part === 'T' ) {
|
2008-01-05 12:39:12 +00:00
|
|
|
|
$flags |= self::PTD_FOR_INCLUSION;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2007-11-20 10:55:08 +00:00
|
|
|
|
// Preprocess the text
|
2008-01-21 16:36:08 +00:00
|
|
|
|
$root = $this->preprocessToDom( $text, $flags );
|
2007-11-20 10:55:08 +00:00
|
|
|
|
|
|
|
|
|
|
// <h> nodes indicate section breaks
|
|
|
|
|
|
// They can only occur at the top level, so we can find them by iterating the root's children
|
2008-01-21 16:36:08 +00:00
|
|
|
|
$node = $root->getFirstChild();
|
2007-11-20 10:55:08 +00:00
|
|
|
|
|
|
|
|
|
|
// Find the target section
|
2008-01-05 12:39:12 +00:00
|
|
|
|
if ( $sectionIndex == 0 ) {
|
2007-11-20 10:55:08 +00:00
|
|
|
|
// Section zero doesn't nest, level=big
|
|
|
|
|
|
$targetLevel = 1000;
|
|
|
|
|
|
} else {
|
2008-02-01 01:35:55 +00:00
|
|
|
|
while ( $node ) {
|
2008-08-26 14:37:15 +00:00
|
|
|
|
if ( $node->getName() === 'h' ) {
|
2008-02-01 01:35:55 +00:00
|
|
|
|
$bits = $node->splitHeading();
|
|
|
|
|
|
if ( $bits['i'] == $sectionIndex ) {
|
|
|
|
|
|
$targetLevel = $bits['level'];
|
2007-11-20 10:55:08 +00:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2008-08-26 14:37:15 +00:00
|
|
|
|
if ( $mode === 'replace' ) {
|
2007-12-01 07:13:31 +00:00
|
|
|
|
$outText .= $frame->expand( $node, PPFrame::RECOVER_ORIG );
|
2007-11-20 10:55:08 +00:00
|
|
|
|
}
|
2008-01-21 16:36:08 +00:00
|
|
|
|
$node = $node->getNextSibling();
|
2006-06-06 00:51:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2007-11-20 10:55:08 +00:00
|
|
|
|
|
|
|
|
|
|
if ( !$node ) {
|
|
|
|
|
|
// Not found
|
2008-08-26 14:37:15 +00:00
|
|
|
|
if ( $mode === 'get' ) {
|
2007-11-20 10:55:08 +00:00
|
|
|
|
return $newText;
|
2006-06-06 00:51:34 +00:00
|
|
|
|
} else {
|
2007-11-20 10:55:08 +00:00
|
|
|
|
return $text;
|
2006-06-06 00:51:34 +00:00
|
|
|
|
}
|
2007-11-20 10:55:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Find the end of the section, including nested sections
|
|
|
|
|
|
do {
|
2008-08-26 14:37:15 +00:00
|
|
|
|
if ( $node->getName() === 'h' ) {
|
2008-01-21 16:36:08 +00:00
|
|
|
|
$bits = $node->splitHeading();
|
|
|
|
|
|
$curLevel = $bits['level'];
|
2010-01-26 11:57:01 +00:00
|
|
|
|
if ( $bits['i'] !== $sectionIndex && $curLevel <= $targetLevel ) {
|
2007-11-20 10:55:08 +00:00
|
|
|
|
break;
|
2006-06-06 00:51:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2008-08-26 14:37:15 +00:00
|
|
|
|
if ( $mode === 'get' ) {
|
2007-12-01 07:13:31 +00:00
|
|
|
|
$outText .= $frame->expand( $node, PPFrame::RECOVER_ORIG );
|
2007-11-20 10:55:08 +00:00
|
|
|
|
}
|
2008-01-21 16:36:08 +00:00
|
|
|
|
$node = $node->getNextSibling();
|
2007-11-20 10:55:08 +00:00
|
|
|
|
} while ( $node );
|
2008-04-14 07:45:50 +00:00
|
|
|
|
|
2007-11-20 10:55:08 +00:00
|
|
|
|
// Write out the remainder (in replace mode only)
|
2008-08-26 14:37:15 +00:00
|
|
|
|
if ( $mode === 'replace' ) {
|
2007-11-20 10:55:08 +00:00
|
|
|
|
// Output the replacement text
|
2008-04-14 07:45:50 +00:00
|
|
|
|
// Add two newlines on -- trailing whitespace in $newText is conventionally
|
2007-11-20 10:55:08 +00:00
|
|
|
|
// stripped by the editor, so we need both newlines to restore the paragraph gap
|
2009-02-01 18:58:18 +00:00
|
|
|
|
// Only add trailing whitespace if there is newText
|
2010-01-26 11:57:01 +00:00
|
|
|
|
if($newText !== "") {
|
2009-02-01 18:58:18 +00:00
|
|
|
|
$outText .= $newText . "\n\n";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2007-11-20 10:55:08 +00:00
|
|
|
|
while ( $node ) {
|
2007-12-01 07:13:31 +00:00
|
|
|
|
$outText .= $frame->expand( $node, PPFrame::RECOVER_ORIG );
|
2008-01-21 16:36:08 +00:00
|
|
|
|
$node = $node->getNextSibling();
|
2007-11-20 10:55:08 +00:00
|
|
|
|
}
|
2006-06-06 00:51:34 +00:00
|
|
|
|
}
|
2007-03-14 18:20:21 +00:00
|
|
|
|
|
2007-11-20 10:55:08 +00:00
|
|
|
|
if ( is_string( $outText ) ) {
|
|
|
|
|
|
// Re-insert stripped tags
|
2008-04-14 20:39:00 +00:00
|
|
|
|
$outText = rtrim( $this->mStripState->unstripBoth( $outText ) );
|
2007-11-20 10:55:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return $outText;
|
2006-06-06 00:51:34 +00:00
|
|
|
|
}
|
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.
|
|
|
|
|
|
*
|
2008-01-05 12:39:12 +00:00
|
|
|
|
* @param string $text text to look in
|
|
|
|
|
|
* @param string $section section identifier
|
|
|
|
|
|
* @param string $deftext default to return if section is not found
|
2006-06-06 00:51:34 +00:00
|
|
|
|
* @return string text of the requested section
|
|
|
|
|
|
*/
|
2007-03-14 18:20:21 +00:00
|
|
|
|
public function getSection( $text, $section, $deftext='' ) {
|
|
|
|
|
|
return $this->extractSections( $text, $section, "get", $deftext );
|
2006-06-06 00:51:34 +00:00
|
|
|
|
}
|
2006-07-11 17:40:11 +00:00
|
|
|
|
|
2007-02-28 17:25:41 +00:00
|
|
|
|
public function replaceSection( $oldtext, $section, $text ) {
|
2006-06-06 00:51:34 +00:00
|
|
|
|
return $this->extractSections( $oldtext, $section, "replace", $text );
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2006-11-21 09:53:45 +00:00
|
|
|
|
/**
|
2007-01-17 19:48:48 +00:00
|
|
|
|
* Get the timestamp associated with the current revision, adjusted for
|
2006-12-02 23:56:25 +00:00
|
|
|
|
* the default server-local timestamp
|
2006-11-21 09:53:45 +00:00
|
|
|
|
*/
|
|
|
|
|
|
function getRevisionTimestamp() {
|
|
|
|
|
|
if ( is_null( $this->mRevisionTimestamp ) ) {
|
|
|
|
|
|
wfProfileIn( __METHOD__ );
|
|
|
|
|
|
global $wgContLang;
|
2007-01-22 23:50:42 +00:00
|
|
|
|
$dbr = wfGetDB( DB_SLAVE );
|
2006-11-21 09:53:45 +00:00
|
|
|
|
$timestamp = $dbr->selectField( 'revision', 'rev_timestamp',
|
2006-11-27 03:15:38 +00:00
|
|
|
|
array( 'rev_id' => $this->mRevisionId ), __METHOD__ );
|
2007-01-17 19:48:48 +00:00
|
|
|
|
|
2006-12-02 23:56:25 +00:00
|
|
|
|
// Normalize timestamp to internal MW format for timezone processing.
|
|
|
|
|
|
// This has the added side-effect of replacing a null value with
|
|
|
|
|
|
// the current time, which gives us more sensible behavior for
|
|
|
|
|
|
// previews.
|
|
|
|
|
|
$timestamp = wfTimestamp( TS_MW, $timestamp );
|
2007-01-17 19:48:48 +00:00
|
|
|
|
|
2006-12-02 23:56:25 +00:00
|
|
|
|
// The cryptic '' timezone parameter tells to use the site-default
|
|
|
|
|
|
// timezone offset instead of the user settings.
|
|
|
|
|
|
//
|
|
|
|
|
|
// Since this value will be saved into the parser cache, served
|
|
|
|
|
|
// to other users, and potentially even used inside links and such,
|
|
|
|
|
|
// it needs to be consistent for all visitors.
|
|
|
|
|
|
$this->mRevisionTimestamp = $wgContLang->userAdjust( $timestamp, '' );
|
2007-01-17 19:48:48 +00:00
|
|
|
|
|
2006-11-21 09:53:45 +00:00
|
|
|
|
wfProfileOut( __METHOD__ );
|
|
|
|
|
|
}
|
|
|
|
|
|
return $this->mRevisionTimestamp;
|
|
|
|
|
|
}
|
2007-01-17 19:48:48 +00:00
|
|
|
|
|
2009-03-07 23:01:59 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* Get the name of the user that edited the last revision
|
|
|
|
|
|
*/
|
|
|
|
|
|
function getRevisionUser() {
|
|
|
|
|
|
// if this template is subst: the revision id will be blank,
|
|
|
|
|
|
// so just use the current user's name
|
|
|
|
|
|
if( $this->mRevisionId ) {
|
2009-03-09 08:52:04 +00:00
|
|
|
|
$revision = Revision::newFromId( $this->mRevisionId );
|
|
|
|
|
|
$revuser = $revision->getUserText();
|
2009-03-07 23:01:59 +00:00
|
|
|
|
} else {
|
|
|
|
|
|
global $wgUser;
|
|
|
|
|
|
$revuser = $wgUser->getName();
|
|
|
|
|
|
}
|
|
|
|
|
|
return $revuser;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2006-12-29 10:39:35 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* Mutator for $mDefaultSort
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param $sort New value
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function setDefaultSort( $sort ) {
|
|
|
|
|
|
$this->mDefaultSort = $sort;
|
|
|
|
|
|
}
|
2007-01-17 19:48:48 +00:00
|
|
|
|
|
2006-12-29 10:39:35 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* Accessor for $mDefaultSort
|
|
|
|
|
|
* Will use the title/prefixed title if none is set
|
|
|
|
|
|
*
|
|
|
|
|
|
* @return string
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function getDefaultSort() {
|
2008-08-09 11:19:18 +00:00
|
|
|
|
global $wgCategoryPrefixedDefaultSortkey;
|
2006-12-29 10:39:35 +00:00
|
|
|
|
if( $this->mDefaultSort !== false ) {
|
|
|
|
|
|
return $this->mDefaultSort;
|
2008-08-09 11:19:18 +00:00
|
|
|
|
} elseif ($this->mTitle->getNamespace() == NS_CATEGORY ||
|
|
|
|
|
|
!$wgCategoryPrefixedDefaultSortkey) {
|
|
|
|
|
|
return $this->mTitle->getText();
|
2006-12-29 10:39:35 +00:00
|
|
|
|
} else {
|
2008-08-09 11:19:18 +00:00
|
|
|
|
return $this->mTitle->getPrefixedText();
|
2006-12-29 10:39:35 +00:00
|
|
|
|
}
|
2007-09-08 02:08:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2008-11-02 14:21:04 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* Accessor for $mDefaultSort
|
|
|
|
|
|
* Unlike getDefaultSort(), will return false if none is set
|
|
|
|
|
|
*
|
|
|
|
|
|
* @return string or false
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function getCustomDefaultSort() {
|
|
|
|
|
|
return $this->mDefaultSort;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2007-09-08 02:08:08 +00:00
|
|
|
|
/**
|
2008-04-14 07:45:50 +00:00
|
|
|
|
* Try to guess the section anchor name based on a wikitext fragment
|
|
|
|
|
|
* presumably extracted from a heading, for example "Header" from
|
2007-09-08 02:08:08 +00:00
|
|
|
|
* "== Header ==".
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function guessSectionNameFromWikiText( $text ) {
|
2009-01-10 17:16:21 +00:00
|
|
|
|
# Strip out wikitext links(they break the anchor)
|
2007-09-08 02:08:08 +00:00
|
|
|
|
$text = $this->stripSectionName( $text );
|
2009-01-10 17:16:21 +00:00
|
|
|
|
$headline = Sanitizer::decodeCharReferences( $text );
|
|
|
|
|
|
# strip out HTML
|
|
|
|
|
|
$headline = StringUtils::delimiterReplace( '<', '>', '', $headline );
|
|
|
|
|
|
$headline = trim( $headline );
|
|
|
|
|
|
$sectionanchor = '#' . urlencode( str_replace( ' ', '_', $headline ) );
|
|
|
|
|
|
$replacearray = array(
|
|
|
|
|
|
'%3A' => ':',
|
|
|
|
|
|
'%' => '.'
|
|
|
|
|
|
);
|
|
|
|
|
|
return str_replace(
|
|
|
|
|
|
array_keys( $replacearray ),
|
|
|
|
|
|
array_values( $replacearray ),
|
|
|
|
|
|
$sectionanchor );
|
2007-09-08 02:08:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Strips a text string of wikitext for use in a section anchor
|
2008-04-14 07:45:50 +00:00
|
|
|
|
*
|
2007-09-08 02:08:08 +00:00
|
|
|
|
* Accepts a text string and then removes all wikitext from the
|
|
|
|
|
|
* string and leaves only the resultant text (i.e. the result of
|
|
|
|
|
|
* [[User:WikiSysop|Sysop]] would be "Sysop" and the result of
|
|
|
|
|
|
* [[User:WikiSysop]] would be "User:WikiSysop") - this is intended
|
|
|
|
|
|
* to create valid section anchors by mimicing the output of the
|
|
|
|
|
|
* parser when headings are parsed.
|
2008-04-14 07:45:50 +00:00
|
|
|
|
*
|
2007-09-08 02:08:08 +00:00
|
|
|
|
* @param $text string Text string to be stripped of wikitext
|
|
|
|
|
|
* for use in a Section anchor
|
|
|
|
|
|
* @return Filtered text string
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function stripSectionName( $text ) {
|
|
|
|
|
|
# Strip internal link markup
|
|
|
|
|
|
$text = preg_replace('/\[\[:?([^[|]+)\|([^[]+)\]\]/','$2',$text);
|
|
|
|
|
|
$text = preg_replace('/\[\[:?([^[]+)\|?\]\]/','$1',$text);
|
2008-04-14 07:45:50 +00:00
|
|
|
|
|
2007-09-08 02:08:08 +00:00
|
|
|
|
# Strip external link markup (FIXME: Not Tolerant to blank link text
|
|
|
|
|
|
# I.E. [http://www.mediawiki.org] will render as [1] or something depending
|
|
|
|
|
|
# on how many empty links there are on the page - need to figure that out.
|
|
|
|
|
|
$text = preg_replace('/\[(?:' . wfUrlProtocols() . ')([^ ]+?) ([^[]+)\]/','$2',$text);
|
2008-04-14 07:45:50 +00:00
|
|
|
|
|
2007-09-08 02:08:08 +00:00
|
|
|
|
# Parse wikitext quotes (italics & bold)
|
|
|
|
|
|
$text = $this->doQuotes($text);
|
2008-04-14 07:45:50 +00:00
|
|
|
|
|
2007-09-08 02:08:08 +00:00
|
|
|
|
# Strip HTML tags
|
|
|
|
|
|
$text = StringUtils::delimiterReplace( '<', '>', '', $text );
|
|
|
|
|
|
return $text;
|
2006-12-29 10:39:35 +00:00
|
|
|
|
}
|
2007-11-20 10:55:08 +00:00
|
|
|
|
|
2008-01-21 16:36:08 +00:00
|
|
|
|
function srvus( $text ) {
|
|
|
|
|
|
return $this->testSrvus( $text, $this->mOutputType );
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2007-11-20 10:55:08 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* strip/replaceVariables/unstrip for preprocessor regression testing
|
|
|
|
|
|
*/
|
2008-01-22 10:47:44 +00:00
|
|
|
|
function testSrvus( $text, $title, $options, $outputType = self::OT_HTML ) {
|
2008-01-21 16:36:08 +00:00
|
|
|
|
$this->clearState();
|
2008-01-24 04:29:56 +00:00
|
|
|
|
if ( ! ( $title instanceof Title ) ) {
|
|
|
|
|
|
$title = Title::newFromText( $title );
|
|
|
|
|
|
}
|
2008-01-21 16:36:08 +00:00
|
|
|
|
$this->mTitle = $title;
|
|
|
|
|
|
$this->mOptions = $options;
|
|
|
|
|
|
$this->setOutputType( $outputType );
|
2007-11-20 10:55:08 +00:00
|
|
|
|
$text = $this->replaceVariables( $text );
|
|
|
|
|
|
$text = $this->mStripState->unstripBoth( $text );
|
2007-12-17 15:07:25 +00:00
|
|
|
|
$text = Sanitizer::removeHTMLtags( $text );
|
2007-11-20 10:55:08 +00:00
|
|
|
|
return $text;
|
|
|
|
|
|
}
|
2008-01-21 16:36:08 +00:00
|
|
|
|
|
|
|
|
|
|
function testPst( $text, $title, $options ) {
|
|
|
|
|
|
global $wgUser;
|
2008-01-24 04:29:56 +00:00
|
|
|
|
if ( ! ( $title instanceof Title ) ) {
|
|
|
|
|
|
$title = Title::newFromText( $title );
|
|
|
|
|
|
}
|
2008-01-21 16:36:08 +00:00
|
|
|
|
return $this->preSaveTransform( $text, $title, $wgUser, $options );
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function testPreprocess( $text, $title, $options ) {
|
2008-01-24 04:29:56 +00:00
|
|
|
|
if ( ! ( $title instanceof Title ) ) {
|
|
|
|
|
|
$title = Title::newFromText( $title );
|
|
|
|
|
|
}
|
2008-01-22 10:47:44 +00:00
|
|
|
|
return $this->testSrvus( $text, $title, $options, self::OT_PREPROCESS );
|
2008-01-21 16:36:08 +00:00
|
|
|
|
}
|
2008-01-24 09:07:47 +00:00
|
|
|
|
|
|
|
|
|
|
function markerSkipCallback( $s, $callback ) {
|
|
|
|
|
|
$i = 0;
|
|
|
|
|
|
$out = '';
|
|
|
|
|
|
while ( $i < strlen( $s ) ) {
|
|
|
|
|
|
$markerStart = strpos( $s, $this->mUniqPrefix, $i );
|
|
|
|
|
|
if ( $markerStart === false ) {
|
|
|
|
|
|
$out .= call_user_func( $callback, substr( $s, $i ) );
|
|
|
|
|
|
break;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
$out .= call_user_func( $callback, substr( $s, $i, $markerStart - $i ) );
|
2008-03-27 00:00:25 +00:00
|
|
|
|
$markerEnd = strpos( $s, self::MARKER_SUFFIX, $markerStart );
|
2008-01-24 09:07:47 +00:00
|
|
|
|
if ( $markerEnd === false ) {
|
|
|
|
|
|
$out .= substr( $s, $markerStart );
|
|
|
|
|
|
break;
|
|
|
|
|
|
} else {
|
2008-03-27 00:00:25 +00:00
|
|
|
|
$markerEnd += strlen( self::MARKER_SUFFIX );
|
2008-01-24 09:07:47 +00:00
|
|
|
|
$out .= substr( $s, $markerStart, $markerEnd - $markerStart );
|
|
|
|
|
|
$i = $markerEnd;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return $out;
|
|
|
|
|
|
}
|
2009-02-03 04:58:08 +00:00
|
|
|
|
|
|
|
|
|
|
function serialiseHalfParsedText( $text ) {
|
|
|
|
|
|
$data = array();
|
|
|
|
|
|
$data['text'] = $text;
|
|
|
|
|
|
|
|
|
|
|
|
// First, find all strip markers, and store their
|
|
|
|
|
|
// data in an array.
|
|
|
|
|
|
$stripState = new StripState;
|
|
|
|
|
|
$pos = 0;
|
|
|
|
|
|
while( ( $start_pos = strpos( $text, $this->mUniqPrefix, $pos ) ) && ( $end_pos = strpos( $text, self::MARKER_SUFFIX, $pos ) ) ) {
|
|
|
|
|
|
$end_pos += strlen( self::MARKER_SUFFIX );
|
|
|
|
|
|
$marker = substr( $text, $start_pos, $end_pos-$start_pos );
|
|
|
|
|
|
|
|
|
|
|
|
if ( !empty( $this->mStripState->general->data[$marker] ) ) {
|
|
|
|
|
|
$replaceArray = $stripState->general;
|
|
|
|
|
|
$stripText = $this->mStripState->general->data[$marker];
|
|
|
|
|
|
} elseif ( !empty( $this->mStripState->nowiki->data[$marker] ) ) {
|
|
|
|
|
|
$replaceArray = $stripState->nowiki;
|
|
|
|
|
|
$stripText = $this->mStripState->nowiki->data[$marker];
|
|
|
|
|
|
} else {
|
|
|
|
|
|
throw new MWException( "Hanging strip marker: '$marker'." );
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$replaceArray->setPair( $marker, $stripText );
|
|
|
|
|
|
$pos = $end_pos;
|
|
|
|
|
|
}
|
|
|
|
|
|
$data['stripstate'] = $stripState;
|
|
|
|
|
|
|
|
|
|
|
|
// Now, find all of our links, and store THEIR
|
|
|
|
|
|
// data in an array! :)
|
|
|
|
|
|
$links = array( 'internal' => array(), 'interwiki' => array() );
|
|
|
|
|
|
$pos = 0;
|
|
|
|
|
|
|
|
|
|
|
|
// Internal links
|
|
|
|
|
|
while( ( $start_pos = strpos( $text, '<!--LINK ', $pos ) ) ) {
|
|
|
|
|
|
list( $ns, $trail ) = explode( ':', substr( $text, $start_pos + strlen( '<!--LINK ' ) ), 2 );
|
|
|
|
|
|
|
|
|
|
|
|
$ns = trim($ns);
|
|
|
|
|
|
if (empty( $links['internal'][$ns] )) {
|
|
|
|
|
|
$links['internal'][$ns] = array();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$key = trim( substr( $trail, 0, strpos( $trail, '-->' ) ) );
|
|
|
|
|
|
$links['internal'][$ns][] = $this->mLinkHolders->internals[$ns][$key];
|
|
|
|
|
|
$pos = $start_pos + strlen( "<!--LINK $ns:$key-->" );
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$pos = 0;
|
|
|
|
|
|
|
|
|
|
|
|
// Interwiki links
|
|
|
|
|
|
while( ( $start_pos = strpos( $text, '<!--IWLINK ', $pos ) ) ) {
|
|
|
|
|
|
$data = substr( $text, $start_pos );
|
|
|
|
|
|
$key = trim( substr( $data, 0, strpos( $data, '-->' ) ) );
|
|
|
|
|
|
$links['interwiki'][] = $this->mLinkHolders->interwiki[$key];
|
|
|
|
|
|
$pos = $start_pos + strlen( "<!--IWLINK $key-->" );
|
|
|
|
|
|
}
|
2010-01-07 04:13:14 +00:00
|
|
|
|
|
2009-02-03 04:58:08 +00:00
|
|
|
|
$data['linkholder'] = $links;
|
|
|
|
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function unserialiseHalfParsedText( $data, $intPrefix = null /* Unique identifying prefix */ ) {
|
|
|
|
|
|
if (!$intPrefix)
|
|
|
|
|
|
$intPrefix = $this->getRandomString();
|
2010-01-07 04:13:14 +00:00
|
|
|
|
|
2009-02-03 04:58:08 +00:00
|
|
|
|
// First, extract the strip state.
|
|
|
|
|
|
$stripState = $data['stripstate'];
|
|
|
|
|
|
$this->mStripState->general->merge( $stripState->general );
|
|
|
|
|
|
$this->mStripState->nowiki->merge( $stripState->nowiki );
|
|
|
|
|
|
|
|
|
|
|
|
// Now, extract the text, and renumber links
|
|
|
|
|
|
$text = $data['text'];
|
|
|
|
|
|
$links = $data['linkholder'];
|
|
|
|
|
|
|
|
|
|
|
|
// Internal...
|
|
|
|
|
|
foreach( $links['internal'] as $ns => $nsLinks ) {
|
|
|
|
|
|
foreach( $nsLinks as $key => $entry ) {
|
|
|
|
|
|
$newKey = $intPrefix . '-' . $key;
|
|
|
|
|
|
$this->mLinkHolders->internals[$ns][$newKey] = $entry;
|
|
|
|
|
|
|
|
|
|
|
|
$text = str_replace( "<!--LINK $ns:$key-->", "<!--LINK $ns:$newKey-->", $text );
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Interwiki...
|
|
|
|
|
|
foreach( $links['interwiki'] as $key => $entry ) {
|
|
|
|
|
|
$newKey = "$intPrefix-$key";
|
|
|
|
|
|
$this->mLinkHolders->interwikis[$newKey] = $entry;
|
|
|
|
|
|
|
|
|
|
|
|
$text = str_replace( "<!--IWLINK $key-->", "<!--IWLINK $newKey-->", $text );
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Should be good to go.
|
|
|
|
|
|
return $text;
|
|
|
|
|
|
}
|
2004-02-26 13:37:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2007-04-04 05:22:37 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* @todo document, briefly.
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
|
* @ingroup Parser
|
2007-04-04 05:22:37 +00:00
|
|
|
|
*/
|
2006-11-21 09:53:45 +00:00
|
|
|
|
class StripState {
|
|
|
|
|
|
var $general, $nowiki;
|
2006-05-13 17:30:42 +00:00
|
|
|
|
|
2006-11-21 09:53:45 +00:00
|
|
|
|
function __construct() {
|
|
|
|
|
|
$this->general = new ReplacementArray;
|
|
|
|
|
|
$this->nowiki = new ReplacementArray;
|
2006-06-16 13:58:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2006-11-21 09:53:45 +00:00
|
|
|
|
function unstripGeneral( $text ) {
|
|
|
|
|
|
wfProfileIn( __METHOD__ );
|
2007-11-20 10:55:08 +00:00
|
|
|
|
do {
|
|
|
|
|
|
$oldText = $text;
|
|
|
|
|
|
$text = $this->general->replace( $text );
|
2008-08-26 14:37:15 +00:00
|
|
|
|
} while ( $text !== $oldText );
|
2006-11-21 09:53:45 +00:00
|
|
|
|
wfProfileOut( __METHOD__ );
|
|
|
|
|
|
return $text;
|
2006-06-12 12:38:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2006-11-21 09:53:45 +00:00
|
|
|
|
function unstripNoWiki( $text ) {
|
|
|
|
|
|
wfProfileIn( __METHOD__ );
|
2007-11-20 10:55:08 +00:00
|
|
|
|
do {
|
|
|
|
|
|
$oldText = $text;
|
|
|
|
|
|
$text = $this->nowiki->replace( $text );
|
2008-08-26 14:37:15 +00:00
|
|
|
|
} while ( $text !== $oldText );
|
2006-11-21 09:53:45 +00:00
|
|
|
|
wfProfileOut( __METHOD__ );
|
|
|
|
|
|
return $text;
|
2004-08-13 15:55:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2006-11-21 09:53:45 +00:00
|
|
|
|
function unstripBoth( $text ) {
|
|
|
|
|
|
wfProfileIn( __METHOD__ );
|
2007-11-20 10:55:08 +00:00
|
|
|
|
do {
|
|
|
|
|
|
$oldText = $text;
|
|
|
|
|
|
$text = $this->general->replace( $text );
|
|
|
|
|
|
$text = $this->nowiki->replace( $text );
|
2008-08-26 14:37:15 +00:00
|
|
|
|
} while ( $text !== $oldText );
|
2006-11-21 09:53:45 +00:00
|
|
|
|
wfProfileOut( __METHOD__ );
|
|
|
|
|
|
return $text;
|
|
|
|
|
|
}
|
2004-08-13 15:55:59 +00:00
|
|
|
|
}
|
2007-11-20 10:55:08 +00:00
|
|
|
|
|
2008-01-17 04:02:57 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* @todo document, briefly.
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
|
* @ingroup Parser
|
2008-01-17 04:02:57 +00:00
|
|
|
|
*/
|
|
|
|
|
|
class OnlyIncludeReplacer {
|
|
|
|
|
|
var $output = '';
|
|
|
|
|
|
|
2008-04-14 07:45:50 +00:00
|
|
|
|
function replace( $matches ) {
|
2008-08-26 14:37:15 +00:00
|
|
|
|
if ( substr( $matches[1], -1 ) === "\n" ) {
|
2008-01-17 04:02:57 +00:00
|
|
|
|
$this->output .= substr( $matches[1], 0, -1 );
|
|
|
|
|
|
} else {
|
|
|
|
|
|
$this->output .= $matches[1];
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|