r79455 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r79454‎ | r79455 | r79456 >
Date:23:01, 1 January 2011
Author:reedy
Status:resolved (Comments)
Tags:
Comment:
Allow section to work with oldid when oldid == currentrevid (worked with older id)
Modified paths:
  • /trunk/phase3/includes/api/ApiParse.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/api/ApiParse.php
@@ -96,9 +96,9 @@
9797 // If for some reason the "oldid" is actually the current revision, it may be cached
9898 if ( $titleObj->getLatestRevID() === intval( $oldid ) ) {
9999 $articleObj = new Article( $titleObj );
100 - $wgTitle = $titleObj;
101100
102 - $p_result = $articleObj->getParserOutput();
 101+ $p_result = $this->getParsedSectionOrText( $articleObj, $titleObj, $pageid ) ;
 102+
103103 } else {
104104 $text = $rev->getText( Revision::FOR_THIS_USER );
105105
@@ -147,15 +147,7 @@
148148 $oldid = $articleObj->getRevIdFetched();
149149 }
150150
151 - if ( $this->section !== false ) {
152 - $text = $this->getSectionText( $text, !is_null ( $pageid )
153 - ? 'page id ' . $pageid : $titleObj->getText() );
154 -
155 - $p_result = $wgParser->parse( $text, $titleObj, $popts );
156 - } else {
157 - // Try the parser cache first
158 - $p_result = $articleObj->getParserOutput();
159 - }
 151+ $p_result = $this->getParsedSectionOrText( $articleObj, $titleObj, $pageid ) ;
160152 }
161153 } else {
162154 $titleObj = Title::newFromText( $title );
@@ -286,6 +278,26 @@
287279 }
288280 }
289281
 282+ /**
 283+ * @param $articleObj Article
 284+ * @param $titleObj Title
 285+ * @param $pageId Int
 286+ * @return ParserOutput
 287+ */
 288+ private function getParsedSectionOrText( $articleObj, $titleObj, $pageId = null ) {
 289+ global $wgParser;
 290+
 291+ if ( $this->section !== false ) {
 292+ $text = $this->getSectionText( $text, !is_null ( $pageId )
 293+ ? 'page id ' . $pageId : $titleObj->getText() );
 294+
 295+ return $wgParser->parse( $text, $titleObj, $popts );
 296+ } else {
 297+ // Try the parser cache first
 298+ return $articleObj->getParserOutput();
 299+ }
 300+ }
 301+
290302 private function getSectionText( $text, $what ) {
291303 global $wgParser;
292304 $text = $wgParser->getSection( $text, $this->section, false );

Follow-up revisions

RevisionCommit summaryAuthorDate
r79456Add missing $popts parameter, and pass it from r79455reedy23:06, 1 January 2011
r79727Fix -rakkaus/#mediawiki-i18n- [06-Jan-2011 16:10:59] PHP Notice: Undefined v...reedy16:24, 6 January 2011
r79774More tweaks/comments/fixups per r79455...reedy23:35, 6 January 2011
r814071.17: MFT r79454, r79455, r79456, r79536, r79727, r79733, r79773, r79774, r80...catrope19:18, 2 February 2011

Comments

#Comment by Platonides (talk | contribs)   23:03, 1 January 2011

$popts is undefined there.

#Comment by Duplicatebug (talk | contribs)   22:34, 6 January 2011

The section param always say nosuchsection, except revid != latestrevid, because $text is always empty inside getParsedSectionOrText.

#Comment by Reedy (talk | contribs)   22:36, 6 January 2011

$text is already fixed in r79727

#Comment by Duplicatebug (talk | contribs)   22:38, 6 January 2011

Yes, but is always an empty string.

#Comment by Reedy (talk | contribs)   22:39, 6 January 2011

How do you work that one out?

		$text = $params['text'];

Where it matters...

#Comment by Duplicatebug (talk | contribs)   22:48, 6 January 2011

The parser extract the section from the wikitext.

For revid != latestrevid the $text is set from the revision, but in all other case it is not set (except the declaration from $params). So the parser get a emtpy text and cannot extract anything.

#Comment by Reedy (talk | contribs)   22:51, 6 January 2011

I guess that means it never was before..

#Comment by Reedy (talk | contribs)   22:55, 6 January 2011

Feel free to supply a patch/diff for these. I'm doing other review at the moment, so can't poke at it...

#Comment by Duplicatebug (talk | contribs)   23:31, 6 January 2011

Example: http://translatewiki.net/w/api.php?action=parse&page=Main_Page&section=0

I do not know what is the best.

Maybe call $text = $articleObj->getRawText(); inside getParsedSectionOrText to set $text to the right wikitext. Than you can remove $text from the arguments list.

#Comment by Reedy (talk | contribs)   23:36, 6 January 2011

Cheers

r79774

This module is really a mess

Status & tagging log