Split out ParserOptions and ParserOutput classes in their own files.
authorAntoine Musso <hashar@users.mediawiki.org>
Sat, 20 Jan 2007 12:50:56 +0000 (12:50 +0000)
committerAntoine Musso <hashar@users.mediawiki.org>
Sat, 20 Jan 2007 12:50:56 +0000 (12:50 +0000)
Made using svn copy so the logs are kept.

RELEASE-NOTES
includes/AutoLoader.php
includes/Parser.php
includes/ParserOptions.php [new file with mode: 0644]
includes/ParserOutput.php [new file with mode: 0644]

index f4ef84e..cab9f66 100644 (file)
@@ -122,6 +122,7 @@ lighter making things easier to read.
 * (bug 8688) Handle underscores/spaces in Special:Blockip and Special:Ipblocklist
   in a consistent manner
 * (bug 8701) Check database lock status when blocking/unblocking users
+* ParserOptions and ParserOutput classes are now in their own files.
 
 == Languages updated ==
 
index 747e9ec..ff89b6c 100644 (file)
@@ -122,8 +122,8 @@ function __autoload($className) {
                'ReverseChronologicalPager' => 'includes/Pager.php',
                'TablePager' => 'includes/Pager.php',
                'Parser' => 'includes/Parser.php',
-               'ParserOutput' => 'includes/Parser.php',
-               'ParserOptions' => 'includes/Parser.php',
+               'ParserOutput' => 'includes/ParserOutput.php',
+               'ParserOptions' => 'includes/ParserOptions.php',
                'ParserCache' => 'includes/ParserCache.php',
                'ProfilerSimple' => 'includes/ProfilerSimple.php',
                'ProfilerSimpleUDP' => 'includes/ProfilerSimpleUDP.php',
index ed4c52e..68470c8 100644 (file)
@@ -4692,238 +4692,6 @@ class Parser
 
 }
 
-/**
- * @todo document
- * @package MediaWiki
- */
-class ParserOutput
-{
-       var $mText,             # The output text
-               $mLanguageLinks,    # List of the full text of language links, in the order they appear
-               $mCategories,       # Map of category names to sort keys
-               $mContainsOldMagic, # Boolean variable indicating if the input contained variables like {{CURRENTDAY}}
-               $mCacheTime,        # Time when this object was generated, or -1 for uncacheable. Used in ParserCache.
-               $mVersion,          # Compatibility check
-               $mTitleText,        # title text of the chosen language variant
-               $mLinks,            # 2-D map of NS/DBK to ID for the links in the document. ID=zero for broken.
-               $mTemplates,        # 2-D map of NS/DBK to ID for the template references. ID=zero for broken.
-               $mImages,           # DB keys of the images used, in the array key only
-               $mExternalLinks,    # External link URLs, in the key only
-               $mHTMLtitle,            # Display HTML title
-               $mSubtitle,                     # Additional subtitle
-               $mNewSection,           # Show a new section link?
-               $mNoGallery;            # No gallery on category page? (__NOGALLERY__)
-
-       function ParserOutput( $text = '', $languageLinks = array(), $categoryLinks = array(),
-               $containsOldMagic = false, $titletext = '' )
-       {
-               $this->mText = $text;
-               $this->mLanguageLinks = $languageLinks;
-               $this->mCategories = $categoryLinks;
-               $this->mContainsOldMagic = $containsOldMagic;
-               $this->mCacheTime = '';
-               $this->mVersion = MW_PARSER_VERSION;
-               $this->mTitleText = $titletext;
-               $this->mLinks = array();
-               $this->mTemplates = array();
-               $this->mImages = array();
-               $this->mExternalLinks = array();
-               $this->mHTMLtitle = "" ;
-               $this->mSubtitle = "" ;
-               $this->mNewSection = false;
-               $this->mNoGallery = false;
-       }
-
-       function getText()                   { return $this->mText; }
-       function &getLanguageLinks()          { return $this->mLanguageLinks; }
-       function getCategoryLinks()          { return array_keys( $this->mCategories ); }
-       function &getCategories()            { return $this->mCategories; }
-       function getCacheTime()              { return $this->mCacheTime; }
-       function getTitleText()              { return $this->mTitleText; }
-       function &getLinks()                 { return $this->mLinks; }
-       function &getTemplates()             { return $this->mTemplates; }
-       function &getImages()                { return $this->mImages; }
-       function &getExternalLinks()         { return $this->mExternalLinks; }
-       function getNoGallery()              { return $this->mNoGallery; }
-       function getSubtitle()               { return $this->mSubtitle; }
-
-       function containsOldMagic()          { return $this->mContainsOldMagic; }
-       function setText( $text )            { return wfSetVar( $this->mText, $text ); }
-       function setLanguageLinks( $ll )     { return wfSetVar( $this->mLanguageLinks, $ll ); }
-       function setCategoryLinks( $cl )     { return wfSetVar( $this->mCategories, $cl ); }
-       function setContainsOldMagic( $com ) { return wfSetVar( $this->mContainsOldMagic, $com ); }
-       function setCacheTime( $t )          { return wfSetVar( $this->mCacheTime, $t ); }
-       function setTitleText( $t )          { return wfSetVar($this->mTitleText, $t); }
-       function setSubtitle( $st )          { return wfSetVar( $this->mSubtitle, $st ); }
-
-       function addCategory( $c, $sort )    { $this->mCategories[$c] = $sort; }
-       function addImage( $name )           { $this->mImages[$name] = 1; }
-       function addLanguageLink( $t )       { $this->mLanguageLinks[] = $t; }
-       function addExternalLink( $url )     { $this->mExternalLinks[$url] = 1; }
-
-       function setNewSection( $value ) {
-               $this->mNewSection = (bool)$value;
-       }
-       function getNewSection() {
-               return (bool)$this->mNewSection;
-       }
-
-       function addLink( $title, $id = null ) {
-               $ns = $title->getNamespace();
-               $dbk = $title->getDBkey();
-               if ( !isset( $this->mLinks[$ns] ) ) {
-                       $this->mLinks[$ns] = array();
-               }
-               if ( is_null( $id ) ) {
-                       $id = $title->getArticleID();
-               }
-               $this->mLinks[$ns][$dbk] = $id;
-       }
-
-       function addTemplate( $title, $id ) {
-               $ns = $title->getNamespace();
-               $dbk = $title->getDBkey();
-               if ( !isset( $this->mTemplates[$ns] ) ) {
-                       $this->mTemplates[$ns] = array();
-               }
-               $this->mTemplates[$ns][$dbk] = $id;
-       }
-
-       /**
-        * Return true if this cached output object predates the global or
-        * per-article cache invalidation timestamps, or if it comes from
-        * an incompatible older version.
-        *
-        * @param string $touched the affected article's last touched timestamp
-        * @return bool
-        * @public
-        */
-       function expired( $touched ) {
-               global $wgCacheEpoch;
-               return $this->getCacheTime() == -1 || // parser says it's uncacheable
-                      $this->getCacheTime() < $touched ||
-                      $this->getCacheTime() <= $wgCacheEpoch ||
-                      !isset( $this->mVersion ) ||
-                      version_compare( $this->mVersion, MW_PARSER_VERSION, "lt" );
-       }
-}
-
-/**
- * Set options of the Parser
- * @todo document
- * @package MediaWiki
- */
-class ParserOptions
-{
-       # All variables are supposed to be private in theory, although in practise this is not the case.
-       var $mUseTeX;                    # Use texvc to expand <math> tags
-       var $mUseDynamicDates;           # Use DateFormatter to format dates
-       var $mInterwikiMagic;            # Interlanguage links are removed and returned in an array
-       var $mAllowExternalImages;       # Allow external images inline
-       var $mAllowExternalImagesFrom;   # If not, any exception?
-       var $mSkin;                      # Reference to the preferred skin
-       var $mDateFormat;                # Date format index
-       var $mEditSection;               # Create "edit section" links
-       var $mNumberHeadings;            # Automatically number headings
-       var $mAllowSpecialInclusion;     # Allow inclusion of special pages
-       var $mTidy;                      # Ask for tidy cleanup
-       var $mInterfaceMessage;          # Which lang to call for PLURAL and GRAMMAR
-       var $mMaxIncludeSize;            # Maximum size of template expansions, in bytes
-       var $mRemoveComments;            # Remove HTML comments. ONLY APPLIES TO PREPROCESS OPERATIONS
-
-       var $mUser;                      # Stored user object, just used to initialise the skin
-
-       function getUseTeX()                        { return $this->mUseTeX; }
-       function getUseDynamicDates()               { return $this->mUseDynamicDates; }
-       function getInterwikiMagic()                { return $this->mInterwikiMagic; }
-       function getAllowExternalImages()           { return $this->mAllowExternalImages; }
-       function getAllowExternalImagesFrom()       { return $this->mAllowExternalImagesFrom; }
-       function getEditSection()                   { return $this->mEditSection; }
-       function getNumberHeadings()                { return $this->mNumberHeadings; }
-       function getAllowSpecialInclusion()         { return $this->mAllowSpecialInclusion; }
-       function getTidy()                          { return $this->mTidy; }
-       function getInterfaceMessage()              { return $this->mInterfaceMessage; }
-       function getMaxIncludeSize()                { return $this->mMaxIncludeSize; }
-       function getRemoveComments()                { return $this->mRemoveComments; }
-
-       function &getSkin() {
-               if ( !isset( $this->mSkin ) ) {
-                       $this->mSkin = $this->mUser->getSkin();
-               }
-               return $this->mSkin;
-       }
-
-       function getDateFormat() {
-               if ( !isset( $this->mDateFormat ) ) {
-                       $this->mDateFormat = $this->mUser->getDatePreference();
-               }
-               return $this->mDateFormat;
-       }
-
-       function setUseTeX( $x )                    { return wfSetVar( $this->mUseTeX, $x ); }
-       function setUseDynamicDates( $x )           { return wfSetVar( $this->mUseDynamicDates, $x ); }
-       function setInterwikiMagic( $x )            { return wfSetVar( $this->mInterwikiMagic, $x ); }
-       function setAllowExternalImages( $x )       { return wfSetVar( $this->mAllowExternalImages, $x ); }
-       function setAllowExternalImagesFrom( $x )   { return wfSetVar( $this->mAllowExternalImagesFrom, $x ); }
-       function setDateFormat( $x )                { return wfSetVar( $this->mDateFormat, $x ); }
-       function setEditSection( $x )               { return wfSetVar( $this->mEditSection, $x ); }
-       function setNumberHeadings( $x )            { return wfSetVar( $this->mNumberHeadings, $x ); }
-       function setAllowSpecialInclusion( $x )     { return wfSetVar( $this->mAllowSpecialInclusion, $x ); }
-       function setTidy( $x )                      { return wfSetVar( $this->mTidy, $x); }
-       function setSkin( $x )                      { $this->mSkin = $x; }
-       function setInterfaceMessage( $x )          { return wfSetVar( $this->mInterfaceMessage, $x); }
-       function setMaxIncludeSize( $x )            { return wfSetVar( $this->mMaxIncludeSize, $x ); }
-       function setRemoveComments( $x )            { return wfSetVar( $this->mRemoveComments, $x ); }
-
-       function ParserOptions( $user = null ) {
-               $this->initialiseFromUser( $user );
-       }
-
-       /**
-        * Get parser options
-        * @static
-        */
-       static function newFromUser( $user ) {
-               return new ParserOptions( $user );
-       }
-
-       /** Get user options */
-       function initialiseFromUser( $userInput ) {
-               global $wgUseTeX, $wgUseDynamicDates, $wgInterwikiMagic, $wgAllowExternalImages;
-               global $wgAllowExternalImagesFrom, $wgAllowSpecialInclusion, $wgMaxArticleSize;
-               $fname = 'ParserOptions::initialiseFromUser';
-               wfProfileIn( $fname );
-               if ( !$userInput ) {
-                       global $wgUser;
-                       if ( isset( $wgUser ) ) {
-                               $user = $wgUser;
-                       } else {
-                               $user = new User;
-                       }
-               } else {
-                       $user =& $userInput;
-               }
-
-               $this->mUser = $user;
-
-               $this->mUseTeX = $wgUseTeX;
-               $this->mUseDynamicDates = $wgUseDynamicDates;
-               $this->mInterwikiMagic = $wgInterwikiMagic;
-               $this->mAllowExternalImages = $wgAllowExternalImages;
-               $this->mAllowExternalImagesFrom = $wgAllowExternalImagesFrom;
-               $this->mSkin = null; # Deferred
-               $this->mDateFormat = null; # Deferred
-               $this->mEditSection = true;
-               $this->mNumberHeadings = $user->getOption( 'numberheadings' );
-               $this->mAllowSpecialInclusion = $wgAllowSpecialInclusion;
-               $this->mTidy = false;
-               $this->mInterfaceMessage = false;
-               $this->mMaxIncludeSize = $wgMaxArticleSize * 1024;
-               $this->mRemoveComments = true;
-               wfProfileOut( $fname );
-       }
-}
-
 class OnlyIncludeReplacer {
        var $output = '';
 
diff --git a/includes/ParserOptions.php b/includes/ParserOptions.php
new file mode 100644 (file)
index 0000000..efa3606
--- /dev/null
@@ -0,0 +1,119 @@
+<?php
+
+/**
+ * Set options of the Parser
+ * @todo document
+ * @package MediaWiki
+ */
+class ParserOptions
+{
+       # All variables are supposed to be private in theory, although in practise this is not the case.
+       var $mUseTeX;                    # Use texvc to expand <math> tags
+       var $mUseDynamicDates;           # Use DateFormatter to format dates
+       var $mInterwikiMagic;            # Interlanguage links are removed and returned in an array
+       var $mAllowExternalImages;       # Allow external images inline
+       var $mAllowExternalImagesFrom;   # If not, any exception?
+       var $mSkin;                      # Reference to the preferred skin
+       var $mDateFormat;                # Date format index
+       var $mEditSection;               # Create "edit section" links
+       var $mNumberHeadings;            # Automatically number headings
+       var $mAllowSpecialInclusion;     # Allow inclusion of special pages
+       var $mTidy;                      # Ask for tidy cleanup
+       var $mInterfaceMessage;          # Which lang to call for PLURAL and GRAMMAR
+       var $mMaxIncludeSize;            # Maximum size of template expansions, in bytes
+       var $mRemoveComments;            # Remove HTML comments. ONLY APPLIES TO PREPROCESS OPERATIONS
+
+       var $mUser;                      # Stored user object, just used to initialise the skin
+
+       function getUseTeX()                        { return $this->mUseTeX; }
+       function getUseDynamicDates()               { return $this->mUseDynamicDates; }
+       function getInterwikiMagic()                { return $this->mInterwikiMagic; }
+       function getAllowExternalImages()           { return $this->mAllowExternalImages; }
+       function getAllowExternalImagesFrom()       { return $this->mAllowExternalImagesFrom; }
+       function getEditSection()                   { return $this->mEditSection; }
+       function getNumberHeadings()                { return $this->mNumberHeadings; }
+       function getAllowSpecialInclusion()         { return $this->mAllowSpecialInclusion; }
+       function getTidy()                          { return $this->mTidy; }
+       function getInterfaceMessage()              { return $this->mInterfaceMessage; }
+       function getMaxIncludeSize()                { return $this->mMaxIncludeSize; }
+       function getRemoveComments()                { return $this->mRemoveComments; }
+
+       function &getSkin() {
+               if ( !isset( $this->mSkin ) ) {
+                       $this->mSkin = $this->mUser->getSkin();
+               }
+               return $this->mSkin;
+       }
+
+       function getDateFormat() {
+               if ( !isset( $this->mDateFormat ) ) {
+                       $this->mDateFormat = $this->mUser->getDatePreference();
+               }
+               return $this->mDateFormat;
+       }
+
+       function setUseTeX( $x )                    { return wfSetVar( $this->mUseTeX, $x ); }
+       function setUseDynamicDates( $x )           { return wfSetVar( $this->mUseDynamicDates, $x ); }
+       function setInterwikiMagic( $x )            { return wfSetVar( $this->mInterwikiMagic, $x ); }
+       function setAllowExternalImages( $x )       { return wfSetVar( $this->mAllowExternalImages, $x ); }
+       function setAllowExternalImagesFrom( $x )   { return wfSetVar( $this->mAllowExternalImagesFrom, $x ); }
+       function setDateFormat( $x )                { return wfSetVar( $this->mDateFormat, $x ); }
+       function setEditSection( $x )               { return wfSetVar( $this->mEditSection, $x ); }
+       function setNumberHeadings( $x )            { return wfSetVar( $this->mNumberHeadings, $x ); }
+       function setAllowSpecialInclusion( $x )     { return wfSetVar( $this->mAllowSpecialInclusion, $x ); }
+       function setTidy( $x )                      { return wfSetVar( $this->mTidy, $x); }
+       function setSkin( $x )                      { $this->mSkin = $x; }
+       function setInterfaceMessage( $x )          { return wfSetVar( $this->mInterfaceMessage, $x); }
+       function setMaxIncludeSize( $x )            { return wfSetVar( $this->mMaxIncludeSize, $x ); }
+       function setRemoveComments( $x )            { return wfSetVar( $this->mRemoveComments, $x ); }
+
+       function ParserOptions( $user = null ) {
+               $this->initialiseFromUser( $user );
+       }
+
+       /**
+        * Get parser options
+        * @static
+        */
+       static function newFromUser( $user ) {
+               return new ParserOptions( $user );
+       }
+
+       /** Get user options */
+       function initialiseFromUser( $userInput ) {
+               global $wgUseTeX, $wgUseDynamicDates, $wgInterwikiMagic, $wgAllowExternalImages;
+               global $wgAllowExternalImagesFrom, $wgAllowSpecialInclusion, $wgMaxArticleSize;
+               $fname = 'ParserOptions::initialiseFromUser';
+               wfProfileIn( $fname );
+               if ( !$userInput ) {
+                       global $wgUser;
+                       if ( isset( $wgUser ) ) {
+                               $user = $wgUser;
+                       } else {
+                               $user = new User;
+                       }
+               } else {
+                       $user =& $userInput;
+               }
+
+               $this->mUser = $user;
+
+               $this->mUseTeX = $wgUseTeX;
+               $this->mUseDynamicDates = $wgUseDynamicDates;
+               $this->mInterwikiMagic = $wgInterwikiMagic;
+               $this->mAllowExternalImages = $wgAllowExternalImages;
+               $this->mAllowExternalImagesFrom = $wgAllowExternalImagesFrom;
+               $this->mSkin = null; # Deferred
+               $this->mDateFormat = null; # Deferred
+               $this->mEditSection = true;
+               $this->mNumberHeadings = $user->getOption( 'numberheadings' );
+               $this->mAllowSpecialInclusion = $wgAllowSpecialInclusion;
+               $this->mTidy = false;
+               $this->mInterfaceMessage = false;
+               $this->mMaxIncludeSize = $wgMaxArticleSize * 1024;
+               $this->mRemoveComments = true;
+               wfProfileOut( $fname );
+       }
+}
+
+?>
diff --git a/includes/ParserOutput.php b/includes/ParserOutput.php
new file mode 100644 (file)
index 0000000..df7bb58
--- /dev/null
@@ -0,0 +1,118 @@
+<?php
+/**
+ * @todo document
+ * @package MediaWiki
+ */
+class ParserOutput
+{
+       var $mText,             # The output text
+               $mLanguageLinks,    # List of the full text of language links, in the order they appear
+               $mCategories,       # Map of category names to sort keys
+               $mContainsOldMagic, # Boolean variable indicating if the input contained variables like {{CURRENTDAY}}
+               $mCacheTime,        # Time when this object was generated, or -1 for uncacheable. Used in ParserCache.
+               $mVersion,          # Compatibility check
+               $mTitleText,        # title text of the chosen language variant
+               $mLinks,            # 2-D map of NS/DBK to ID for the links in the document. ID=zero for broken.
+               $mTemplates,        # 2-D map of NS/DBK to ID for the template references. ID=zero for broken.
+               $mImages,           # DB keys of the images used, in the array key only
+               $mExternalLinks,    # External link URLs, in the key only
+               $mHTMLtitle,            # Display HTML title
+               $mSubtitle,                     # Additional subtitle
+               $mNewSection,           # Show a new section link?
+               $mNoGallery;            # No gallery on category page? (__NOGALLERY__)
+
+       function ParserOutput( $text = '', $languageLinks = array(), $categoryLinks = array(),
+               $containsOldMagic = false, $titletext = '' )
+       {
+               $this->mText = $text;
+               $this->mLanguageLinks = $languageLinks;
+               $this->mCategories = $categoryLinks;
+               $this->mContainsOldMagic = $containsOldMagic;
+               $this->mCacheTime = '';
+               $this->mVersion = MW_PARSER_VERSION;
+               $this->mTitleText = $titletext;
+               $this->mLinks = array();
+               $this->mTemplates = array();
+               $this->mImages = array();
+               $this->mExternalLinks = array();
+               $this->mHTMLtitle = "" ;
+               $this->mSubtitle = "" ;
+               $this->mNewSection = false;
+               $this->mNoGallery = false;
+       }
+
+       function getText()                   { return $this->mText; }
+       function &getLanguageLinks()          { return $this->mLanguageLinks; }
+       function getCategoryLinks()          { return array_keys( $this->mCategories ); }
+       function &getCategories()            { return $this->mCategories; }
+       function getCacheTime()              { return $this->mCacheTime; }
+       function getTitleText()              { return $this->mTitleText; }
+       function &getLinks()                 { return $this->mLinks; }
+       function &getTemplates()             { return $this->mTemplates; }
+       function &getImages()                { return $this->mImages; }
+       function &getExternalLinks()         { return $this->mExternalLinks; }
+       function getNoGallery()              { return $this->mNoGallery; }
+       function getSubtitle()               { return $this->mSubtitle; }
+
+       function containsOldMagic()          { return $this->mContainsOldMagic; }
+       function setText( $text )            { return wfSetVar( $this->mText, $text ); }
+       function setLanguageLinks( $ll )     { return wfSetVar( $this->mLanguageLinks, $ll ); }
+       function setCategoryLinks( $cl )     { return wfSetVar( $this->mCategories, $cl ); }
+       function setContainsOldMagic( $com ) { return wfSetVar( $this->mContainsOldMagic, $com ); }
+       function setCacheTime( $t )          { return wfSetVar( $this->mCacheTime, $t ); }
+       function setTitleText( $t )          { return wfSetVar($this->mTitleText, $t); }
+       function setSubtitle( $st )          { return wfSetVar( $this->mSubtitle, $st ); }
+
+       function addCategory( $c, $sort )    { $this->mCategories[$c] = $sort; }
+       function addImage( $name )           { $this->mImages[$name] = 1; }
+       function addLanguageLink( $t )       { $this->mLanguageLinks[] = $t; }
+       function addExternalLink( $url )     { $this->mExternalLinks[$url] = 1; }
+
+       function setNewSection( $value ) {
+               $this->mNewSection = (bool)$value;
+       }
+       function getNewSection() {
+               return (bool)$this->mNewSection;
+       }
+
+       function addLink( $title, $id = null ) {
+               $ns = $title->getNamespace();
+               $dbk = $title->getDBkey();
+               if ( !isset( $this->mLinks[$ns] ) ) {
+                       $this->mLinks[$ns] = array();
+               }
+               if ( is_null( $id ) ) {
+                       $id = $title->getArticleID();
+               }
+               $this->mLinks[$ns][$dbk] = $id;
+       }
+
+       function addTemplate( $title, $id ) {
+               $ns = $title->getNamespace();
+               $dbk = $title->getDBkey();
+               if ( !isset( $this->mTemplates[$ns] ) ) {
+                       $this->mTemplates[$ns] = array();
+               }
+               $this->mTemplates[$ns][$dbk] = $id;
+       }
+
+       /**
+        * Return true if this cached output object predates the global or
+        * per-article cache invalidation timestamps, or if it comes from
+        * an incompatible older version.
+        *
+        * @param string $touched the affected article's last touched timestamp
+        * @return bool
+        * @public
+        */
+       function expired( $touched ) {
+               global $wgCacheEpoch;
+               return $this->getCacheTime() == -1 || // parser says it's uncacheable
+                      $this->getCacheTime() < $touched ||
+                      $this->getCacheTime() <= $wgCacheEpoch ||
+                      !isset( $this->mVersion ) ||
+                      version_compare( $this->mVersion, MW_PARSER_VERSION, "lt" );
+       }
+}
+
+?>