* produces altered wiki markup.
* preprocess()
* removes HTML comments and expands templates
- * cleanSig()
+ * cleanSig() / cleanSigInSig()
* Cleans a signature before saving it to preferences
* extractSections()
* Extracts sections from an article for section editing
$this->firstCallInit();
}
$this->mOutput = new ParserOutput;
+ $this->mOptions->registerWatcher( array( $this->mOutput, 'recordOption' ) );
$this->mAutonumber = 0;
$this->mLastSection = '';
$this->mDTopen = false;
wfProfileIn( __METHOD__ );
wfProfileIn( $fname );
+ $this->mOptions = $options;
if ( $clearState ) {
$this->clearState();
}
- $options->resetUsage();
- $this->mOptions = $options;
$this->setTitle( $title ); # Page title has to be set for the pre-processor
$oldRevisionId = $this->mRevisionId;
*/
function preprocess( $text, $title, $options, $revid = null ) {
wfProfileIn( __METHOD__ );
+ $this->mOptions = $options;
$this->clearState();
$this->setOutputType( self::OT_PREPROCESS );
- $options->resetUsage();
- $this->mOptions = $options;
$this->setTitle( $title );
if ( $revid !== null ) {
$this->mRevisionId = $revid;
*/
public function getPreloadText( $text, $title, $options ) {
# Parser (re)initialisation
+ $this->mOptions = $options;
$this->clearState();
$this->setOutputType( self::OT_PLAIN );
- $options->resetUsage();
- $this->mOptions = $options;
$this->setTitle( $title );
$flags = PPFrame::NO_ARGS | PPFrame::NO_TEMPLATES;
* @return String: the altered wiki markup
*/
public function preSaveTransform( $text, Title $title, $user, $options, $clearState = true ) {
- $options->resetUsage();
$this->mOptions = $options;
$this->setTitle( $title );
$this->setUser( $user );
function cleanSig( $text, $parsing = false ) {
if ( !$parsing ) {
global $wgTitle;
+ $this->mOptions = new ParserOptions;
$this->clearState();
$this->setTitle( $wgTitle );
- $this->mOptions = new ParserOptions;
$this->setOutputType = self::OT_PREPROCESS;
}
*/
private function extractSections( $text, $section, $mode, $newText='' ) {
global $wgTitle;
+ $this->mOptions = new ParserOptions;
$this->clearState();
$this->setTitle( $wgTitle ); # not generally used but removes an ugly failure mode
- $this->mOptions = new ParserOptions;
$this->setOutputType( self::OT_PLAIN );
$outText = '';
$frame = $this->getPreprocessor()->newFrame();
* strip/replaceVariables/unstrip for preprocessor regression testing
*/
function testSrvus( $text, $title, $options, $outputType = self::OT_HTML ) {
+ $this->mOptions = $options;
$this->clearState();
if ( !$title instanceof Title ) {
$title = Title::newFromText( $title );
}
$this->mTitle = $title;
$options->resetUsage();
- $this->mOptions = $options;
$this->setOutputType( $outputType );
$text = $this->replaceVariables( $text );
$text = $this->mStripState->unstripBoth( $text );
$now = wfTimestampNow();
$optionsKey = new CacheTime;
- $optionsKey->mUsedOptions = $popts->usedOptions();
+ $optionsKey->mUsedOptions = $parserOutput->getUsedOptions();
$optionsKey->updateCacheExpiry( $expire );
$optionsKey->setCacheTime( $now );
var $mExtraKey = ''; # Extra key that should be present in the caching key.
- protected $accessedOptions;
+ protected $onAccessCallback = null;
function getUseDynamicDates() { return $this->mUseDynamicDates; }
function getInterwikiMagic() { return $this->mInterwikiMagic; }
function getAllowExternalImages() { return $this->mAllowExternalImages; }
function getAllowExternalImagesFrom() { return $this->mAllowExternalImagesFrom; }
function getEnableImageWhitelist() { return $this->mEnableImageWhitelist; }
- function getEditSection() { $this->accessedOptions['editsection'] = true;
+ function getEditSection() { $this->optionUsed('editsection');
return $this->mEditSection; }
- function getNumberHeadings() { $this->accessedOptions['numberheadings'] = true;
+ function getNumberHeadings() { $this->optionUsed('numberheadings');
return $this->mNumberHeadings; }
function getAllowSpecialInclusion() { return $this->mAllowSpecialInclusion; }
function getTidy() { return $this->mTidy; }
function getEnableLimitReport() { return $this->mEnableLimitReport; }
function getCleanSignatures() { return $this->mCleanSignatures; }
function getExternalLinkTarget() { return $this->mExternalLinkTarget; }
- function getMath() { $this->accessedOptions['math'] = true;
+ function getMath() { $this->optionUsed('math');
return $this->mMath; }
- function getThumbSize() { $this->accessedOptions['thumbsize'] = true;
+ function getThumbSize() { $this->optionUsed('thumbsize');
return $this->mThumbSize; }
function getIsPreview() { return $this->mIsPreview; }
function getIsSectionPreview() { return $this->mIsSectionPreview; }
- function getIsPrintable() { $this->accessedOptions['printable'] = true;
+ function getIsPrintable() { $this->optionUsed('printable');
return $this->mIsPrintable; }
function getUser() { return $this->mUser; }
}
function getDateFormat() {
- $this->accessedOptions['dateformat'] = true;
+ $this->optionUsed('dateformat');
if ( !isset( $this->mDateFormat ) ) {
$this->mDateFormat = $this->mUser->getDatePreference();
}
* producing inconsistent tables (Bug 14404).
*/
function getUserLang() {
- $this->accessedOptions['userlang'] = true;
+ $this->optionUsed('userlang');
return $this->mUserLang;
}
}
/**
- * Returns the options from this ParserOptions which have been used.
+ * Registers a callback for tracking which ParserOptions which are used.
+ * This is a private API with the parser.
*/
- public function usedOptions() {
- return array_keys( $this->accessedOptions );
+ function registerWatcher( $callback ) {
+ $this->onAccessCallback = $callback;
}
/**
- * Resets the memory of options usage.
+ * Called when an option is accessed.
*/
- public function resetUsage() {
- $this->accessedOptions = array();
+ protected function optionUsed( $optionName ) {
+ if ( $this->onAccessCallback ) {
+ call_user_func( $this->onAccessCallback, $optionName );
+ }
}
/**
$mProperties = array(), # Name/value pairs to be cached in the DB
$mTOCHTML = ''; # HTML of the TOC
private $mIndexPolicy = ''; # 'index' or 'noindex'? Any other value will result in no change.
+ private $mAccessedOptions = null; # List of ParserOptions (stored in the keys)
function __construct( $text = '', $languageLinks = array(), $categoryLinks = array(),
$containsOldMagic = false, $titletext = '' )
}
return $this->mProperties;
}
+
+
+ /**
+ * Returns the options from its ParserOptions which have been taken
+ * into account to produce this output or false if not available.
+ * @return mixed Array/false
+ */
+ public function getUsedOptions() {
+ if ( !isset( $this->mAccessedOptions ) ) {
+ return false;
+ }
+ return array_keys( $this->mAccessedOptions );
+ }
+
+ /**
+ * Callback passed by the Parser to the ParserOptions to keep track of which options are used.
+ * @access private
+ */
+ function recordOption( $option ) {
+ $this->mAccessedOptions[$option] = true;
+ }
}