* transformation of that wiki markup it into XHTML output / markup
* (which in turn the browser understands, and can display).
*
- * <pre>
- * There are five main entry points into the Parser class:
- * parse()
+ * There are seven main entry points into the Parser class:
+ *
+ * - Parser::parse()
* produces HTML output
- * preSaveTransform().
+ * - Parser::preSaveTransform().
* produces altered wiki markup.
- * preprocess()
+ * - Parser::preprocess()
* removes HTML comments and expands templates
- * cleanSig() / cleanSigInSig()
+ * - Parser::cleanSig() and Parser::cleanSigInSig()
* Cleans a signature before saving it to preferences
- * getSection()
+ * - Parser::getSection()
* Return the content of a section from an article for section editing
- * replaceSection()
+ * - Parser::replaceSection()
* Replaces a section by number inside an article
- * getPreloadText()
+ * - Parser::getPreloadText()
* Removes <noinclude> sections, and <includeonly> tags.
*
* Globals used:
* object: $wgContLang
*
- * NOT $wgUser or $wgTitle or $wgRequest or $wgLang. Keep them away!
+ * @warning $wgUser or $wgTitle or $wgRequest or $wgLang. Keep them away!
*
- * settings:
- * $wgUseDynamicDates*, $wgInterwikiMagic*,
- * $wgNamespacesWithSubpages, $wgAllowExternalImages*,
- * $wgLocaltimezone, $wgAllowSpecialInclusion*,
- * $wgMaxArticleSize*
+ * @par Settings:
+ * $wgLocaltimezone
+ * $wgNamespacesWithSubpages
*
- * * only within ParserOptions
- * </pre>
+ * @par Settings only within ParserOptions:
+ * $wgAllowExternalImages
+ * $wgAllowSpecialInclusion
+ * $wgInterwikiMagic
+ * $wgMaxArticleSize
+ * $wgUseDynamicDates
*
* @ingroup Parser
*/
# No more strip!
wfRunHooks( 'ParserAfterStrip', array( &$this, &$text, &$this->mStripState ) );
$text = $this->internalParse( $text );
+ wfRunHooks( 'ParserAfterParse', array( &$this, &$text, &$this->mStripState ) );
$text = $this->mStripState->unstripGeneral( $text );
}
/**
- * Process the wikitext for the ?preload= feature. (bug 5210)
+ * Process the wikitext for the "?preload=" feature. (bug 5210)
*
- * <noinclude>, <includeonly> etc. are parsed as for template transclusion,
- * comments, templates, arguments, tags hooks and parser functions are untouched.
+ * "<noinclude>", "<includeonly>" etc. are parsed as for template
+ * transclusion, comments, templates, arguments, tags hooks and parser
+ * functions are untouched.
*
* @param $text String
* @param $title Title
/**
* Get the target language for the content being parsed. This is usually the
* language that the content is in.
+ *
+ * @since 1.19
+ *
+ * @return Language|null
*/
- function getTargetLanguage() {
+ public function getTargetLanguage() {
$target = $this->mOptions->getTargetLanguage();
+
if ( $target !== null ) {
return $target;
} elseif( $this->mOptions->getInterfaceMessage() ) {
return $this->mOptions->getUserLangObj();
} elseif( is_null( $this->mTitle ) ) {
- throw new MWException( __METHOD__.': $this->mTitle is null' );
+ throw new MWException( __METHOD__ . ': $this->mTitle is null' );
}
+
return $this->mTitle->getPageLanguage();
}
* in the text with a random marker and returns the next text. The output
* parameter $matches will be an associative array filled with data in
* the form:
+ *
+ * @code
* 'UNIQ-xxxxx' => array(
* 'element',
* 'tag content',
* array( 'param' => 'x' ),
* '<element param="x">tag content</element>' ) )
+ * @endcode
*
* @param $elements array list of element names. Comments are always extracted.
* @param $text string Source text string.
$text = $this->replaceVariables( $text );
}
+ wfRunHooks( 'InternalParseBeforeSanitize', array( &$this, &$text, &$this->mStripState ) );
$text = Sanitizer::removeHTMLtags( $text, array( &$this, 'attributeStripCallback' ), false, array_keys( $this->mTransparentTagHooks ) );
wfRunHooks( 'InternalParseBeforeLinks', array( &$this, &$text, &$this->mStripState ) );
$subjPage = $this->mTitle->getSubjectPage();
$value = wfEscapeWikiText( $subjPage->getPrefixedUrl() );
break;
+ case 'pageid': // requested in bug 23427
+ $pageid = $this->getTitle()->getArticleId();
+ if( $pageid == 0 ) {
+ # 0 means the page doesn't exist in the database,
+ # which means the user is previewing a new page.
+ # The vary-revision flag must be set, because the magic word
+ # will have a different value once the page is saved.
+ $this->mOutput->setFlag( 'vary-revision' );
+ wfDebug( __METHOD__ . ": {{PAGEID}} used in a new page, setting vary-revision...\n" );
+ }
+ $value = $pageid ? $pageid : null;
+ break;
case 'revisionid':
# Let the edit saving system know we should parse the page
# *after* a revision ID has been assigned.
$value = $pageLang->formatNum( SiteStats::edits() );
break;
case 'numberofviews':
- $value = $pageLang->formatNum( SiteStats::views() );
+ global $wgDisableCounters;
+ $value = !$wgDisableCounters ? $pageLang->formatNum( SiteStats::views() ) : '';
break;
case 'currenttimestamp':
$value = wfTimestamp( TS_MW, $ts );
*
* @param $text String: The text to parse
* @param $flags Integer: bitwise combination of:
- * self::PTD_FOR_INCLUSION Handle <noinclude>/<includeonly> as if the text is being
+ * self::PTD_FOR_INCLUSION Handle "<noinclude>" and "<includeonly>" as if the text is being
* included. Default is to assume a direct page view.
*
* The generated DOM tree must depend only on the input text and the flags.
* Static function to get a template
* Can be overridden via ParserOptions::setTemplateCallback().
*
- * @parma $title Title
+ * @param $title Title
* @param $parser Parser
*
* @return array
# Get the revision
$rev = $id
? Revision::newFromId( $id )
- : Revision::newFromTitle( $title );
+ : Revision::newFromTitle( $title, 0, Revision::READ_NORMAL );
$rev_id = $rev ? $rev->getId() : 0;
# If there is no current revision, there is no page
if ( $id === false && !$rev ) {
* Triple brace replacement -- used for template arguments
* @private
*
- * @param $peice array
+ * @param $piece array
* @param $frame PPFrame
*
* @return array
# Don't number the heading if it is the only one (looks silly)
if ( count( $matches[3] ) > 1 && $this->mOptions->getNumberHeadings() ) {
# the two are different if the line contains a link
- $headline = $numbering . ' ' . $headline;
+ $headline = Html::element( 'span', array( 'class' => 'mw-headline-number' ), $numbering ) . ' ' . $headline;
}
# Create the anchor for linking from the TOC to the section
}
/**
- * Transform wiki markup when saving a page by doing \r\n -> \n
+ * Transform wiki markup when saving a page by doing "\r\n" -> "\n"
* conversion, substitting signatures, {{subst:}} templates, etc.
*
* @param $text String: the text to transform
$p1 = "/\[\[(:?$nc+:|:|)($tc+?)( ?\\($tc+\\))\\|]]/"; # [[ns:page (context)|]]
$p4 = "/\[\[(:?$nc+:|:|)($tc+?)( ?($tc+))\\|]]/"; # [[ns:page(context)|]]
- $p3 = "/\[\[(:?$nc+:|:|)($tc+?)( ?\\($tc+\\)|)(, $tc+|)\\|]]/"; # [[ns:page (context), context|]]
+ $p3 = "/\[\[(:?$nc+:|:|)($tc+?)( ?\\($tc+\\)|)((?:, |,)$tc+|)\\|]]/"; # [[ns:page (context), context|]]
$p2 = "/\[\[\\|($tc+)]]/"; # [[|page]]
# try $p1 first, to turn "[[A, B (C)|]]" into "[[A, B (C)|A, B]]"
}
/**
- * Create an HTML-style tag, e.g. <yourtag>special text</yourtag>
+ * Create an HTML-style tag, e.g. "<yourtag>special text</yourtag>"
* The callback should have the following form:
* function myParserHook( $text, $params, $parser, $frame ) { ... }
*
* this interface, as it is not documented and injudicious use could smash
* private variables.**
*
- * @param $tag Mixed: the tag to use, e.g. 'hook' for <hook>
+ * @param $tag Mixed: the tag to use, e.g. 'hook' for "<hook>"
* @param $callback Mixed: the callback function (and object) to use for the tag
* @return Mixed|null The old value of the mTagHooks array associated with the hook
*/
* @since 1.10
* @todo better document or deprecate this
*
- * @param $tag Mixed: the tag to use, e.g. 'hook' for <hook>
+ * @param $tag Mixed: the tag to use, e.g. 'hook' for "<hook>"
* @param $callback Mixed: the callback function (and object) to use for the tag
* @return Mixed|null The old value of the mTagHooks array associated with the hook
*/
}
/**
- * Create a tag function, e.g. <test>some stuff</test>.
+ * 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.
* @return null
/**
* @todo FIXME: Update documentation. makeLinkObj() is deprecated.
- * Replace <!--LINK--> link placeholders with actual links, in the buffer
+ * Replace "<!--LINK-->" link placeholders with actual links, in the buffer
* Placeholders created in Skin::makeLinkObj()
*
* @param $text string
}
/**
- * Replace <!--LINK--> link placeholders with plain text of links
+ * Replace "<!--LINK-->" link placeholders with plain text of links
* (not HTML-formatted).
*
* @param $text String
# Special case; width and height come in one variable together
if ( $type === 'handler' && $paramName === 'width' ) {
- $m = array();
- # (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 ) ) {
- $width = intval( $m[1] );
- $height = intval( $m[2] );
+ $parsedWidthParam = $this->parseWidthParam( $value );
+ if( isset( $parsedWidthParam['width'] ) ) {
+ $width = $parsedWidthParam['width'];
if ( $handler->validateParam( 'width', $width ) ) {
$params[$type]['width'] = $width;
$validated = true;
}
+ }
+ if( isset( $parsedWidthParam['height'] ) ) {
+ $height = $parsedWidthParam['height'];
if ( $handler->validateParam( 'height', $height ) ) {
$params[$type]['height'] = $height;
$validated = true;
}
- } elseif ( preg_match( '/^[0-9]*\s*(?:px)?\s*$/', $value ) ) {
- $width = intval( $value );
- if ( $handler->validateParam( 'width', $width ) ) {
- $params[$type]['width'] = $width;
- $validated = true;
- }
- } # else no validation -- bug 13436
+ }
+ # else no validation -- bug 13436
} else {
if ( $type === 'handler' ) {
# Validate handler parameter
# Linker does the rest
$time = isset( $options['time'] ) ? $options['time'] : false;
- $ret = Linker::makeImageLink2( $title, $file, $params['frame'], $params['handler'],
+ $ret = Linker::makeImageLink( $this, $title, $file, $params['frame'], $params['handler'],
$time, $descQuery, $this->mOptions->getThumbSize() );
# Give the handler a chance to modify the parser object
*
* @param $text String: Page wikitext
* @param $section String: a section identifier string of the form:
- * <flag1> - <flag2> - ... - <section number>
+ * "<flag1> - <flag2> - ... - <section number>"
*
* Currently the only recognised flag is "T", which means the target section number
* 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
- * enclosed by <includeonly> (bug 6563).
+ * enclosed by "<includeonly>" (bug 6563).
*
* 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
function isValidHalfParsedText( $data ) {
return isset( $data['version'] ) && $data['version'] == self::HALF_PARSED_VERSION;
}
+
+ /**
+ * Parsed a width param of imagelink like 300px or 200x300px
+ *
+ * @param $value String
+ *
+ * @return array
+ * @since 1.20
+ */
+ public function parseWidthParam( $value ) {
+ $parsedWidthParam = array();
+ if( $value === '' ) {
+ return $parsedWidthParam;
+ }
+ $m = array();
+ # (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 ) ) {
+ $width = intval( $m[1] );
+ $height = intval( $m[2] );
+ $parsedWidthParam['width'] = $width;
+ $parsedWidthParam['height'] = $height;
+ } elseif ( preg_match( '/^[0-9]*\s*(?:px)?\s*$/', $value ) ) {
+ $width = intval( $value );
+ $parsedWidthParam['width'] = $width;
+ }
+ return $parsedWidthParam;
+ }
}