From: Daniel Kinzler Date: Mon, 5 Mar 2012 17:09:41 +0000 (+0000) Subject: replacing deprecated getText, etc X-Git-Tag: 1.31.0-rc.0~22097^2^2~300 X-Git-Url: http://git.cyclocoop.org/%7B%24admin_url%7Dmes_infos.php?a=commitdiff_plain;h=bdbe861d3472ca62e39b9c1553e92661cbb9d4ff;p=lhc%2Fweb%2Fwiklou.git replacing deprecated getText, etc --- diff --git a/includes/Article.php b/includes/Article.php index 895619ff5b..906f06fdfc 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -37,7 +37,7 @@ class Article extends Page { */ public $mParserOptions; - var $mContent; // !< #FIXME: use Content object! + var $mContent; // !< #BC cruft var $mContentObject; // !< var $mContentLoaded = false; // !< var $mOldId; // !< @@ -192,7 +192,7 @@ class Article extends Page { * @return Return the text of this revision * @deprecated in 1.20; use getContentObject() instead */ - public function getContent() { #FIXME: deprecated! replace usage! use content object! + public function getContent() { wfDeprecated( __METHOD__, '1.20' ); $content = $this->getContentObject(); return ContentHandler::getContentText( $content ); @@ -226,7 +226,7 @@ class Article extends Page { } wfProfileOut( __METHOD__ ); - return new WikitextContent( $text, $this->getTitle() ); + return ContentHandler::makeContent( $text, $this->getTitle() ); } else { $this->fetchContentObject(); wfProfileOut( __METHOD__ ); @@ -312,7 +312,7 @@ class Article extends Page { * @return mixed string containing article contents, or false if null * @deprecated in 1.20, use getContentObject() instead */ - function fetchContent() { #BC cruft! #FIXME: deprecated, replace usage + protected function fetchContent() { #BC cruft! wfDeprecated( __METHOD__, '1.20' ); if ( $this->mContentLoaded && $this->mContent ) { @@ -338,7 +338,7 @@ class Article extends Page { * * @return Content object containing article contents, or null */ - function fetchContentObject() { + protected function fetchContentObject() { if ( $this->mContentLoaded ) { return $this->mContentObject; } @@ -423,7 +423,7 @@ class Article extends Page { * @return Revision|null */ public function getRevisionFetched() { - $this->fetchContent(); + $this->fetchContentObject(); return $this->mRevision; } @@ -582,7 +582,7 @@ class Article extends Page { break; case 3: # This will set $this->mRevision if needed - $this->fetchContent(); + $this->fetchContentObject(); # Are we looking at an old revision if ( $oldid && $this->mRevision ) { @@ -603,7 +603,7 @@ class Article extends Page { # Pages containing custom CSS or JavaScript get special treatment if ( $this->getTitle()->isCssOrJsPage() || $this->getTitle()->isCssJsSubpage() ) { - #FIXME: use Content object instead! + #FIXME: use ContentHandler for specialized actions insetad. wfDebug( __METHOD__ . ": showing CSS/JS source\n" ); $this->showCssOrJsPage(); $outputDone = true; @@ -611,14 +611,14 @@ class Article extends Page { # Allow extensions do their own custom view for certain pages $outputDone = true; } else { - $text = $this->getContent(); - $rt = Title::newFromRedirectArray( $text ); + $content = $this->getContentObject(); + $rt = $content->getRedirectChain(); if ( $rt ) { wfDebug( __METHOD__ . ": showing redirect=no page\n" ); # Viewing a redirect page (e.g. with parameter redirect=no) $wgOut->addHTML( $this->viewRedirect( $rt ) ); # Parse just to get categories, displaytitle, etc. - $this->mParserOutput = $wgParser->parse( $text, $this->getTitle(), $parserOptions ); + $this->mParserOutput = $content->getParserOutput( $parserOptions ); $wgOut->addParserOutputNoText( $this->mParserOutput ); $outputDone = true; } @@ -629,7 +629,7 @@ class Article extends Page { wfDebug( __METHOD__ . ": doing uncached parse\n" ); $poolArticleView = new PoolWorkArticleView( $this, $parserOptions, - $this->getRevIdFetched(), $useParserCache, $this->getContent() ); + $this->getRevIdFetched(), $useParserCache, $this->getContentObject() ); if ( !$poolArticleView->execute() ) { $error = $poolArticleView->getError(); @@ -741,24 +741,18 @@ class Article extends Page { * This is hooked by SyntaxHighlight_GeSHi to do syntax highlighting of these * page views. */ - protected function showCssOrJsPage() { #FIXME: deprecate, keep for BC + protected function showCssOrJsPage() { #FIXME: move this to handler! global $wgOut; $dir = $this->getContext()->getLanguage()->getDir(); $lang = $this->getContext()->getLanguage()->getCode(); $wgOut->wrapWikiMsg( "
\n$1\n
", - 'clearyourcache' ); #FIXME: get this from handler + 'clearyourcache' ); #FIXME: do this in handler // Give hooks a chance to customise the output if ( wfRunHooks( 'ShowRawCssJs', array( $this->mContent, $this->getTitle(), $wgOut ) ) ) { - #FIXME: use content object instead - // Wrap the whole lot in a
 and don't parse
-			$m = array();
-			preg_match( '!\.(css|js)$!u', $this->getTitle()->getText(), $m );
-			$wgOut->addHTML( "
\n" );
-			$wgOut->addHTML( htmlspecialchars( $this->mContent ) );
-			$wgOut->addHTML( "\n
\n" ); + $wgOut->addHTML( $this->mContentObject->getHTML() ); } } diff --git a/includes/Content.php b/includes/Content.php index 1a445c669e..a8a0ba6462 100644 --- a/includes/Content.php +++ b/includes/Content.php @@ -6,7 +6,7 @@ */ abstract class Content { - public function __construct( Title $title, $revId, $modelName ) { + public function __construct( Title $title, $revId, $modelName ) { #FIXME: really need revId? annoying! #FIXME: really $title? or just when parsing, every time? $this->mModelName = $modelName; $this->mTitle = $title; $this->mRevId = $revId; @@ -43,6 +43,14 @@ abstract class Content { return $update; } + public function getRedirectChain() { + return null; + } + + public function getSection( $section ) { #FIXME: should this return text? or a Content object? or what?? + return null; + } + #XXX: is the native model for wikitext a string or the parser output? parse early or parse late? } @@ -90,6 +98,11 @@ class TextContent extends Content { return $text; } + public function getRedirectChain() { + #XXX: really do this for all text, or just in WikitextContent + $text = $this->getRawData(); + return Title::newFromRedirectArray( $text ); + } } class WikitextContent extends TextContent { @@ -121,11 +134,18 @@ class WikitextContent extends TextContent { $options = $this->getDefaultParserOptions(); } - $po = $wgParser->parse( $this->mText, $this->getTitle(), $options ); + $po = $wgParser->parse( $this->mText, $this->getTitle(), $options, true, true, $this->mRevId ); return $po; } + public function getSection( $section ) { + global $wgParser; + + $text = $this->getRawData(); + return $wgParser->getSection( $text, $section, false ); + } + } class MessageContent extends TextContent { diff --git a/includes/ContentHandler.php b/includes/ContentHandler.php index 025c740c27..f586c94db9 100644 --- a/includes/ContentHandler.php +++ b/includes/ContentHandler.php @@ -25,6 +25,13 @@ abstract class ContentHandler { return null; } + public static function makeContent( $text, Title $title, $format = null, $revId = null ) { + $handler = ContentHandler::getForTitle( $title ); + + #FIXME: pass revid? + return $handler->unserialize( $text, $title, $format ); + } + public static function getDefaultModelFor( Title $title ) { global $wgNamespaceContentModels; @@ -130,33 +137,15 @@ abstract class ContentHandler { return $this->mSupportedFormats[0]; } - public abstract function serialize( $obj, $format = null ); + public abstract function serialize( $obj, Title $title, $format = null ); # for wikitext, do nothing (in the future: serialise ast/dom) # for wikidata: serialize arrays to json - public abstract function unserialize( $blob, $format = null ); + public abstract function unserialize( $blob, Title $title, $format = null ); #FIXME: ...and revId? # for wikitext, do nothing (in the future: parse into ast/dom) # for wikidata: serialize arrays to json - public function getSearchText( $obj ) { - # for wikitext, return wikitext - # for wikidata, return pseudo-wikitext composed of property values (or some such) - $text = $this->serialize( $obj ); - return $text; # return the default serialization. - } - - public function getWikitextForTransclusion( $obj ) { - # for wikitext, return text - # for wikidata, return false, or some generated wikitext - $text = $this->serialize( $obj ); - return '
' . $text . '
'; # return a pre-formatted block containing the default serialization. - } - - public abstract function render( $obj, Title $title, ParserOptions $options, $revid = null ); - # returns a ParserOutput instance! - # are parser options, generic?! - public abstract function doPreSaveTransform( $title, $obj ); # TODO: getPreloadText() diff --git a/includes/EditPage.php b/includes/EditPage.php index 0f32c702b6..3425bb5902 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -864,7 +864,9 @@ class EditPage { if ( $revision === null ) { return ''; } - return $this->mArticle->getContent(); + + $content = $this->mArticle->getContentObject(); + return $content->getRawData(); # this editor is for editing the raw text. so use the raw text. } /** @@ -900,7 +902,7 @@ class EditPage { * @param $preload String: representing the title to preload from. * @return String */ - protected function getPreloadedText( $preload ) { + protected function getPreloadedText( $preload ) { #FIXME: change to getPreloadedContent() global $wgUser, $wgParser; if ( !empty( $this->mPreloadText ) ) { @@ -928,7 +930,7 @@ class EditPage { } $parserOptions = ParserOptions::newFromUser( $wgUser ); - return $wgParser->getPreloadText( $page->getRawText(), $title, $parserOptions ); + return $wgParser->getPreloadText( $page->getRawText(), $title, $parserOptions ); #FIXME: create Content::getPreloadCopy } /** diff --git a/includes/ImagePage.php b/includes/ImagePage.php index e1cc6e75f2..cd086c73d7 100644 --- a/includes/ImagePage.php +++ b/includes/ImagePage.php @@ -245,20 +245,20 @@ class ImagePage extends Article { return $r; } - /** - * Overloading Article's getContent method. - * - * Omit noarticletext if sharedupload; text will be fetched from the - * shared upload server if possible. - * @return string - */ - public function getContent() { - $this->loadFile(); - if ( $this->mPage->getFile() && !$this->mPage->getFile()->isLocal() && 0 == $this->getID() ) { - return ''; - } - return parent::getContent(); - } + /** + * Overloading Article's getContentObject method. + * + * Omit noarticletext if sharedupload; text will be fetched from the + * shared upload server if possible. + * @return string + */ + public function getContentObject() { + $this->loadFile(); + if ( $this->mPage->getFile() && !$this->mPage->getFile()->isLocal() && 0 == $this->getID() ) { + return null; + } + return parent::getContentObject(); + } protected function openShowImage() { global $wgOut, $wgUser, $wgImageLimits, $wgRequest, diff --git a/includes/Revision.php b/includes/Revision.php index 9bc9469a92..b40cd71dab 100644 --- a/includes/Revision.php +++ b/includes/Revision.php @@ -496,7 +496,7 @@ class Revision { $this->mCurrent = false; # If we still have no length, see it we have the text to figure it out if ( !$this->mSize ) { - $this->mSize = is_null( $this->mText ) ? null : strlen( $this->mText ); + $this->mSize = is_null( $this->mText ) ? null : strlen( $this->mText ); #FIXME: do strlen in Content object } # Same for sha1 if ( $this->mSha1 === null ) { @@ -779,7 +779,7 @@ class Revision { * @return String * @deprectaed in 1.20, use getContent() instead */ - public function getText( $audience = self::FOR_PUBLIC, User $user = null ) { #FIXME: deprecated, replace usage! + public function getText( $audience = self::FOR_PUBLIC, User $user = null ) { #FIXME: deprecated, replace usage! #FIXME: used a LOT! wfDeprecated( __METHOD__, '1.20' ); $content = $this->getContent(); diff --git a/includes/WikiPage.php b/includes/WikiPage.php index e68a697ad7..e5462b54d7 100644 --- a/includes/WikiPage.php +++ b/includes/WikiPage.php @@ -429,6 +429,11 @@ class WikiPage extends Page { return $this->getText( Revision::RAW ); } + protected function getRawData() { + $content = $this->getContent( Revision::RAW ); + return $content->getRawData(); + } + /** * @return string MW timestamp of last article revision */ @@ -542,7 +547,7 @@ class WikiPage extends Page { * if false, the current database state will be used * @return Boolean */ - public function isCountable( $editInfo = false ) { + public function isCountable( $editInfo = false ) { #FIXME: move this to Content object global $wgArticleCountMethod; if ( !$this->mTitle->isContentPage() ) { @@ -620,7 +625,7 @@ class WikiPage extends Page { */ public function insertRedirect() { // recurse through to only get the final target - $retval = Title::newFromRedirectRecurse( $this->getRawText() ); + $retval = Title::newFromRedirectRecurse( $this->getRawText() ); #FIXME: move this to Content object if ( !$retval ) { return null; } @@ -904,7 +909,7 @@ class WikiPage extends Page { if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) { if ( $this->mTitle->exists() ) { - $text = $this->getRawText(); + $text = $this->getRawData(); } else { $text = false; } @@ -1093,7 +1098,7 @@ class WikiPage extends Page { * @param $undoafter Revision Must be an earlier revision than $undo * @return mixed string on success, false on failure */ - public function getUndoText( Revision $undo, Revision $undoafter = null ) { + public function getUndoText( Revision $undo, Revision $undoafter = null ) { #FIXME: move undo logic to ContentHandler $cur_text = $this->getRawText(); if ( $cur_text === false ) { return false; // no page @@ -1122,7 +1127,7 @@ class WikiPage extends Page { * @param $edittime String: revision timestamp or null to use the current revision * @return string Complete article text, or null if error */ - public function replaceSection( $section, $text, $sectionTitle = '', $edittime = null ) { + public function replaceSection( $section, $text, $sectionTitle = '', $edittime = null ) { #FIXME: move to Content object! wfProfileIn( __METHOD__ ); if ( strval( $section ) == '' ) { @@ -1233,7 +1238,7 @@ class WikiPage extends Page { * * Compatibility note: this function previously returned a boolean value indicating success/failure */ - public function doEdit( $text, $summary, $flags = 0, $baseRevId = false, $user = null ) { + public function doEdit( $text, $summary, $flags = 0, $baseRevId = false, $user = null ) { #FIXME: change $text to $content global $wgUser, $wgDBtransactions, $wgUseAutomaticEditSummaries; # Low-level sanity check @@ -1268,7 +1273,7 @@ class WikiPage extends Page { $isminor = ( $flags & EDIT_MINOR ) && $user->isAllowed( 'minoredit' ); $bot = $flags & EDIT_FORCE_BOT; - $oldtext = $this->getRawText(); // current revision + $oldtext = $this->getRawData(); // current revision $oldsize = strlen( $oldtext ); $oldid = $this->getLatest(); $oldIsRedirect = $this->isRedirect(); @@ -1276,7 +1281,7 @@ class WikiPage extends Page { # Provide autosummaries if one is not provided and autosummaries are enabled. if ( $wgUseAutomaticEditSummaries && $flags & EDIT_AUTOSUMMARY && $summary == '' ) { - $summary = self::getAutosummary( $oldtext, $text, $flags ); + $summary = self::getAutosummary( $oldtext, $text, $flags ); #FIXME: auto-summary from ContentHandler } $editInfo = $this->prepareTextForEdit( $text, null, $user ); @@ -1309,7 +1314,7 @@ class WikiPage extends Page { 'page' => $this->getId(), 'comment' => $summary, 'minor_edit' => $isminor, - 'text' => $text, #FIXME: set content instead, leavfe serialization to revision?! + 'text' => $text, #FIXME: set content instead, leave serialization to revision?! 'parent_id' => $oldid, 'user' => $user->getId(), 'user_text' => $user->getName(), @@ -1512,7 +1517,7 @@ class WikiPage extends Page { $edit->pst = $wgParser->preSaveTransform( $text, $this->mTitle, $user, $popts ); $edit->popts = $this->makeParserOptions( 'canonical' ); $edit->output = $wgParser->parse( $edit->pst, $this->mTitle, $edit->popts, true, true, $revid ); - $edit->oldText = $this->getRawText(); + $edit->oldText = $this->getRawText(); #FIXME: $oldcontent instead?! $this->mPreparedEdit = $edit; @@ -2820,14 +2825,18 @@ class PoolWorkArticleView extends PoolCounterWork { * @param $revid Integer: ID of the revision being parsed * @param $useParserCache Boolean: whether to use the parser cache * @param $parserOptions parserOptions to use for the parse operation - * @param $text String: text to parse or null to load it + * @param $content Content|String: content to parse or null to load it; may also be given as a wikitext string, for BC */ - function __construct( Page $page, ParserOptions $parserOptions, $revid, $useParserCache, $text = null ) { + function __construct( Page $page, ParserOptions $parserOptions, $revid, $useParserCache, $content = null ) { + if ( is_string($content) ) { #BC: old style call + $content = ContentHandler::makeContent( $content, $page->getTitle(), null, $this->revid ); #FIXME: format? from revision? + } + $this->page = $page; $this->revid = $revid; $this->cacheable = $useParserCache; $this->parserOptions = $parserOptions; - $this->text = $text; + $this->content = $content; $this->cacheKey = ParserCache::singleton()->getKey( $page, $parserOptions ); parent::__construct( 'ArticleView', $this->cacheKey . ':revid:' . $revid ); } @@ -2867,21 +2876,20 @@ class PoolWorkArticleView extends PoolCounterWork { $isCurrent = $this->revid === $this->page->getLatest(); - if ( $this->text !== null ) { - $text = $this->text; + if ( $this->content !== null ) { + $content = $this->content; } elseif ( $isCurrent ) { - $text = $this->page->getRawText(); + $content = $this->page->getContent( Revision::RAW ); #XXX: why use RAW audience here, and PUBLIC (default) below? } else { $rev = Revision::newFromTitle( $this->page->getTitle(), $this->revid ); if ( $rev === null ) { return false; } - $text = $rev->getText(); + $content = $rev->getContent(); #XXX: why use PUBLIC audience here (default), and RAW above? } $time = - wfTime(); - $this->parserOutput = $wgParser->parse( $text, $this->page->getTitle(), - $this->parserOptions, true, true, $this->revid ); + $this->parserOutput = $content->getParserOutput( $this->parserOptions ); $time += wfTime(); # Timing hack diff --git a/includes/api/ApiEditPage.php b/includes/api/ApiEditPage.php index 9ed6d08da7..cd07e30dd1 100644 --- a/includes/api/ApiEditPage.php +++ b/includes/api/ApiEditPage.php @@ -108,21 +108,22 @@ class ApiEditPage extends ApiBase { // We do want getContent()'s behavior for non-existent // MediaWiki: pages, though if ( $articleObj->getID() == 0 && $titleObj->getNamespace() != NS_MEDIAWIKI ) { - $content = ''; + $content = null; + $text = ''; } else { - $content = $articleObj->getContent(); + $content = $articleObj->getContentObject(); + $text = $content->getRawData(); } if ( !is_null( $params['section'] ) ) { // Process the content for section edits - global $wgParser; $section = intval( $params['section'] ); - $content = $wgParser->getSection( $content, $section, false ); - if ( $content === false ) { + $text = $content->getSection( $section, false ); + if ( $text === false || $text === null ) { $this->dieUsage( "There is no section {$section}.", 'nosuchsection' ); } } - $params['text'] = $params['prependtext'] . $content . $params['appendtext']; + $params['text'] = $params['prependtext'] . $text . $params['appendtext']; $toMD5 = $params['prependtext'] . $params['appendtext']; } diff --git a/includes/api/ApiParse.php b/includes/api/ApiParse.php index 893491b9c4..7824c355e8 100644 --- a/includes/api/ApiParse.php +++ b/includes/api/ApiParse.php @@ -320,7 +320,7 @@ class ApiParse extends ApiBase { if ( $this->section !== false ) { $this->text = $this->getSectionText( $page->getRawText(), !is_null( $pageId ) - ? 'page id ' . $pageId : $titleObj->getText() ); + ? 'page id ' . $pageId : $titleObj->getText() ); #FIXME: get section... // Not cached (save or load) return $wgParser->parse( $this->text, $titleObj, $popts ); @@ -329,7 +329,8 @@ class ApiParse extends ApiBase { // getParserOutput will save to Parser cache if able $pout = $page->getParserOutput( $popts ); if ( $getWikitext ) { - $this->text = $page->getRawText(); + $this->content = $page->getContent( Revision::RAW ); #FIXME: use $this->content everywhere + $this->text = $this->content->getRawData(); #FIXME: change $this->text to $this->data?! } return $pout; } diff --git a/includes/api/ApiPurge.php b/includes/api/ApiPurge.php index 9e9320fb6c..c43c03277e 100644 --- a/includes/api/ApiPurge.php +++ b/includes/api/ApiPurge.php @@ -90,7 +90,7 @@ class ApiPurge extends ApiBase { $popts = ParserOptions::newFromContext( $this->getContext() ); $p_result = $wgParser->parse( $page->getRawText(), $title, $popts, - true, true, $page->getLatest() ); + true, true, $page->getLatest() ); #FIXME: content! # Update the links tables $u = new LinksUpdate( $title, $p_result ); diff --git a/includes/resourceloader/ResourceLoaderWikiModule.php b/includes/resourceloader/ResourceLoaderWikiModule.php index b13753119f..f93330c82b 100644 --- a/includes/resourceloader/ResourceLoaderWikiModule.php +++ b/includes/resourceloader/ResourceLoaderWikiModule.php @@ -80,7 +80,7 @@ abstract class ResourceLoaderWikiModule extends ResourceLoaderModule { if ( !$revision ) { return null; } - return $revision->getRawText(); + return $revision->getRawText(); #FIXME: get raw data from content object after checking the type; } /* Methods */ diff --git a/maintenance/populateRevisionLength.php b/maintenance/populateRevisionLength.php index 6626cbc1c5..cec91fb029 100644 --- a/maintenance/populateRevisionLength.php +++ b/maintenance/populateRevisionLength.php @@ -67,7 +67,7 @@ class PopulateRevisionLength extends LoggedUpdateMaintenance { # Go through and update rev_len from these rows. foreach ( $res as $row ) { $rev = new Revision( $row ); - $text = $rev->getRawText(); + $text = $rev->getRawText(); #FIXME: go via Content object; #FIXME: get size via Content object if ( !is_string( $text ) ) { # This should not happen, but sometimes does (bug 20757) $this->output( "Text of revision {$row->rev_id} unavailable!\n" );