* 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
+ * getSection()
+ * Return the content of a section from an article for section editing
+ * replaceSection()
+ * Replaces a section by number inside an article
* getPreloadText()
* Removes <noinclude> sections, and <includeonly> tags.
*
$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;
} else {
$showEditLink = $this->mOptions->getEditSection();
}
+ if ( $showEditLink ) {
+ $editLinkAsToken = $this->mOptions->getEditSectionTokens();
+ if ( $editLinkAsToken ) {
+ $this->mOutput->setEditSectionTokens( "{$this->mUniqPrefix}-editsection-", self::MARKER_SUFFIX );
+ }
+ }
# 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
# give headline the correct <h#> tag
if ( $showEditLink && $sectionIndex !== false ) {
- if ( $isTemplate ) {
- # Put a T flag in the section identifier, to indicate to extractSections()
- # that sections inside <includeonly> should be counted.
- $editlink = $sk->doEditSectionLink( Title::newFromText( $titleText ), "T-$sectionIndex", null, $this->mOptions->getUserLang() );
+ if ( $editLinkAsToken ) {
+ // Output edit section links as markers with styles that can be customized by skins
+ if ( $isTemplate ) {
+ # Put a T flag in the section identifier, to indicate to extractSections()
+ # that sections inside <includeonly> should be counted.
+ $editlinkArgs = array( $titleText, "T-$sectionIndex", null );
+ } else {
+ $editlinkArgs = array( $this->mTitle->getPrefixedText(), $sectionIndex, $headlineHint );
+ }
+ // We use nearly the same structure as uniqPrefix and the marker stuffix (besides there being nothing random)
+ // However the this is output into the parser output itself not replaced early, so we hardcode this in case
+ // the constants change in a different version of MediaWiki, which would break this code.
+ $editlink = "{$this->mUniqPrefix}-editsection-" . serialize($editlinkArgs) . self::MARKER_SUFFIX;
} else {
- $editlink = $sk->doEditSectionLink( $this->mTitle, $sectionIndex, $headlineHint, $this->mOptions->getUserLang() );
+ // Output edit section links directly as markup like we used to
+ if ( $isTemplate ) {
+ # Put a T flag in the section identifier, to indicate to extractSections()
+ # that sections inside <includeonly> should be counted.
+ $editlink = $sk->doEditSectionLink( Title::newFromText( $titleText ), "T-$sectionIndex", null, $this->mOptions->getUserLang() );
+ } else {
+ $editlink = $sk->doEditSectionLink( $this->mTitle, $sectionIndex, $headlineHint, $this->mOptions->getUserLang() );
+ }
}
} else {
$editlink = '';
* @param $clearState Boolean: whether to clear the parser state first
* @return String: the altered wiki markup
*/
- public function preSaveTransform( $text, Title $title, $user, $options, $clearState = true ) {
- $options->resetUsage();
+ public function preSaveTransform( $text, Title $title, User $user, ParserOptions $options, $clearState = true ) {
$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();
return $this->extractSections( $text, $section, "get", $deftext );
}
+ /**
+ * This function returns $oldtext after the content of the section
+ * specified by $section has been replaced with $text.
+ *
+ * @param $text String: former text of the article
+ * @param $section Numeric: section identifier
+ * @param $text String: replacing text
+ * #return String: modified text
+ */
public function replaceSection( $oldtext, $section, $text ) {
return $this->extractSections( $oldtext, $section, "replace", $text );
}
* 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 );