r91162 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r91161‎ | r91162 | r91163 >
Date:07:52, 30 June 2011
Author:aaron
Status:ok
Tags:
Comment:
* Fixes for r91123:
** Avoid calling protected pageDataFromId() from Article class.
** Made pageDataFromTitle()/pageDataFromId() public for anything else doing something like that (loadPageData was already public anyway).
** Moved getParserOutput() back to Article since it needs getOutputFromWikitext().
* Other: cascading protection side-effect moved to outputWikiText().
Modified paths:
  • /trunk/phase3/includes/Article.php (modified) (history)
  • /trunk/phase3/includes/WikiPage.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/Article.php
@@ -284,18 +284,14 @@
285285 wfDebug( __METHOD__ . " failed to retrieve specified revision, id $oldid\n" );
286286 return false;
287287 }
288 -
 288+ // Revision title doesn't match the page title given?
289289 if ( $this->mPage->getID() != $revision->getPage() ) {
290 - $data = $this->mPage->pageDataFromId( wfGetDB( DB_SLAVE ), $revision->getPage() );
291 -
292 - if ( !$data ) {
 290+ $function = array( get_class( $this->mPage ), 'newFromID' );
 291+ $this->mPage = call_user_func( $function, $revision->getPage() );
 292+ if ( !$this->mPage->getId() ) {
293293 wfDebug( __METHOD__ . " failed to get page data linked to revision id $oldid\n" );
294294 return false;
295295 }
296 -
297 - $title = Title::makeTitle( $data->page_namespace, $data->page_title );
298 - $this->mPage = new WikiPage( $title );
299 - $this->mPage->loadPageData( $data );
300296 }
301297 } else {
302298 if ( $this->mPage->getLatest() === false ) {
@@ -1931,10 +1927,61 @@
19321928 global $wgOut;
19331929
19341930 $this->mParserOutput = $this->getOutputFromWikitext( $text, $cache, $parserOptions );
 1931+
 1932+ $this->doCascadeProtectionUpdates( $this->mParserOutput );
 1933+
19351934 $wgOut->addParserOutput( $this->mParserOutput );
19361935 }
19371936
19381937 /**
 1938+ * Lightweight method to get the parser output for a page, checking the parser cache
 1939+ * and so on. Doesn't consider most of the stuff that WikiPage::view is forced to
 1940+ * consider, so it's not appropriate to use there.
 1941+ *
 1942+ * @since 1.16 (r52326) for LiquidThreads
 1943+ *
 1944+ * @param $oldid mixed integer Revision ID or null
 1945+ * @param $user User The relevant user
 1946+ * @return ParserOutput or false if the given revsion ID is not found
 1947+ */
 1948+ public function getParserOutput( $oldid = null, User $user = null ) {
 1949+ global $wgEnableParserCache, $wgUser;
 1950+ $user = is_null( $user ) ? $wgUser : $user;
 1951+
 1952+ // Should the parser cache be used?
 1953+ $useParserCache = $wgEnableParserCache &&
 1954+ $user->getStubThreshold() == 0 &&
 1955+ $this->mPage->exists() &&
 1956+ $oldid === null;
 1957+
 1958+ wfDebug( __METHOD__ . ': using parser cache: ' . ( $useParserCache ? 'yes' : 'no' ) . "\n" );
 1959+
 1960+ if ( $user->getStubThreshold() ) {
 1961+ wfIncrStats( 'pcache_miss_stub' );
 1962+ }
 1963+
 1964+ if ( $useParserCache ) {
 1965+ $parserOutput = ParserCache::singleton()->get( $this, $this->mPage->getParserOptions() );
 1966+ if ( $parserOutput !== false ) {
 1967+ return $parserOutput;
 1968+ }
 1969+ }
 1970+
 1971+ // Cache miss; parse and output it.
 1972+ if ( $oldid === null ) {
 1973+ $text = $this->mPage->getRawText();
 1974+ } else {
 1975+ $rev = Revision::newFromTitle( $this->getTitle(), $oldid );
 1976+ if ( $rev === null ) {
 1977+ return false;
 1978+ }
 1979+ $text = $rev->getText();
 1980+ }
 1981+
 1982+ return $this->getOutputFromWikitext( $text, $useParserCache );
 1983+ }
 1984+
 1985+ /**
19391986 * This does all the heavy lifting for outputWikitext, except it returns the parser
19401987 * output instead of sending it straight to $wgOut. Makes things nice and simple for,
19411988 * say, embedding thread pages within a discussion system (LiquidThreads)
Index: trunk/phase3/includes/WikiPage.php
@@ -277,7 +277,7 @@
278278 * @param $title Title object
279279 * @return mixed Database result resource, or false on failure
280280 */
281 - protected function pageDataFromTitle( $dbr, $title ) {
 281+ public function pageDataFromTitle( $dbr, $title ) {
282282 return $this->pageData( $dbr, array(
283283 'page_namespace' => $title->getNamespace(),
284284 'page_title' => $title->getDBkey() ) );
@@ -290,7 +290,7 @@
291291 * @param $id Integer
292292 * @return mixed Database result resource, or false on failure
293293 */
294 - protected function pageDataFromId( $dbr, $id ) {
 294+ public function pageDataFromId( $dbr, $id ) {
295295 return $this->pageData( $dbr, array( 'page_id' => $id ) );
296296 }
297297
@@ -2408,54 +2408,6 @@
24092409 }
24102410 }
24112411
2412 - /**
2413 - * Lightweight method to get the parser output for a page, checking the parser cache
2414 - * and so on. Doesn't consider most of the stuff that WikiPage::view is forced to
2415 - * consider, so it's not appropriate to use there.
2416 - *
2417 - * @since 1.16 (r52326) for LiquidThreads
2418 - *
2419 - * @param $oldid mixed integer Revision ID or null
2420 - * @param $user User The relevant user
2421 - * @return ParserOutput or false if the given revsion ID is not found
2422 - */
2423 - public function getParserOutput( $oldid = null, User $user = null ) {
2424 - global $wgEnableParserCache, $wgUser;
2425 - $user = is_null( $user ) ? $wgUser : $user;
2426 -
2427 - // Should the parser cache be used?
2428 - $useParserCache = $wgEnableParserCache &&
2429 - $user->getStubThreshold() == 0 &&
2430 - $this->exists() &&
2431 - $oldid === null;
2432 -
2433 - wfDebug( __METHOD__ . ': using parser cache: ' . ( $useParserCache ? 'yes' : 'no' ) . "\n" );
2434 -
2435 - if ( $user->getStubThreshold() ) {
2436 - wfIncrStats( 'pcache_miss_stub' );
2437 - }
2438 -
2439 - if ( $useParserCache ) {
2440 - $parserOutput = ParserCache::singleton()->get( $this, $this->getParserOptions() );
2441 - if ( $parserOutput !== false ) {
2442 - return $parserOutput;
2443 - }
2444 - }
2445 -
2446 - // Cache miss; parse and output it.
2447 - if ( $oldid === null ) {
2448 - $text = $this->getRawText();
2449 - } else {
2450 - $rev = Revision::newFromTitle( $this->getTitle(), $oldid );
2451 - if ( $rev === null ) {
2452 - return false;
2453 - }
2454 - $text = $rev->getText();
2455 - }
2456 -
2457 - return $this->getOutputFromWikitext( $text, $useParserCache );
2458 - }
2459 -
24602412 /*
24612413 * @deprecated since 1.19
24622414 */

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r91123* Split off WikiPage class from Article, WikiFilePage class from ImagePage, a...aaron22:09, 29 June 2011

Status & tagging log