r91361 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r91360‎ | r91361 | r91362 >
Date:17:45, 2 July 2011
Author:aaron
Status:ok
Tags:
Comment:
Moved doCascadeProtectionUpdates() to WikiPage.php
Modified paths:
  • /trunk/phase3/includes/Article.php (modified) (history)
  • /trunk/phase3/includes/WikiPage.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/Article.php
@@ -1897,7 +1897,7 @@
18981898 * @param $text string
18991899 * @param $cache boolean
19001900 * @param $parserOptions parsing options, defaults to false
1901 - * @return string containing parsed output
 1901+ * @return ParserOutput
19021902 */
19031903 public function getOutputFromWikitext( $text, $cache = true, $parserOptions = false ) {
19041904 global $wgParser, $wgEnableParserCache, $wgUseFileCache;
@@ -1929,63 +1929,14 @@
19301930 $wgUseFileCache = false;
19311931 }
19321932
1933 - $this->doCascadeProtectionUpdates( $this->mParserOutput );
 1933+ if ( $this->isCurrent() ) {
 1934+ $this->mPage->doCascadeProtectionUpdates( $this->mParserOutput );
 1935+ }
19341936
19351937 return $this->mParserOutput;
19361938 }
19371939
19381940 /**
1939 - * Updates cascading protections
1940 - *
1941 - * @param $parserOutput ParserOutput object, or boolean false
1942 - **/
1943 - protected function doCascadeProtectionUpdates( $parserOutput ) {
1944 - if ( !$this->isCurrent() || wfReadOnly() || !$this->getTitle()->areRestrictionsCascading() ) {
1945 - return;
1946 - }
1947 -
1948 - // templatelinks table may have become out of sync,
1949 - // especially if using variable-based transclusions.
1950 - // For paranoia, check if things have changed and if
1951 - // so apply updates to the database. This will ensure
1952 - // that cascaded protections apply as soon as the changes
1953 - // are visible.
1954 -
1955 - # Get templates from templatelinks
1956 - $id = $this->getTitle()->getArticleID();
1957 -
1958 - $tlTemplates = array();
1959 -
1960 - $dbr = wfGetDB( DB_SLAVE );
1961 - $res = $dbr->select( array( 'templatelinks' ),
1962 - array( 'tl_namespace', 'tl_title' ),
1963 - array( 'tl_from' => $id ),
1964 - __METHOD__
1965 - );
1966 -
1967 - foreach ( $res as $row ) {
1968 - $tlTemplates["{$row->tl_namespace}:{$row->tl_title}"] = true;
1969 - }
1970 -
1971 - # Get templates from parser output.
1972 - $poTemplates = array();
1973 - foreach ( $parserOutput->getTemplates() as $ns => $templates ) {
1974 - foreach ( $templates as $dbk => $id ) {
1975 - $poTemplates["$ns:$dbk"] = true;
1976 - }
1977 - }
1978 -
1979 - # Get the diff
1980 - $templates_diff = array_diff_key( $poTemplates, $tlTemplates );
1981 -
1982 - if ( count( $templates_diff ) > 0 ) {
1983 - # Whee, link updates time.
1984 - $u = new LinksUpdate( $this->getTitle(), $parserOutput, false );
1985 - $u->doUpdate();
1986 - }
1987 - }
1988 -
1989 - /**
19901941 * Sets the context this Article is executed in
19911942 *
19921943 * @param $context RequestContext
Index: trunk/phase3/includes/WikiPage.php
@@ -2428,6 +2428,57 @@
24292429 }
24302430 }
24312431
 2432+ /**
 2433+ * Updates cascading protections
 2434+ *
 2435+ * @param $parserOutput ParserOutput object for the current version
 2436+ **/
 2437+ public function doCascadeProtectionUpdates( ParserOutput $parserOutput ) {
 2438+ if ( wfReadOnly() || !$this->mTitle->areRestrictionsCascading() ) {
 2439+ return;
 2440+ }
 2441+
 2442+ // templatelinks table may have become out of sync,
 2443+ // especially if using variable-based transclusions.
 2444+ // For paranoia, check if things have changed and if
 2445+ // so apply updates to the database. This will ensure
 2446+ // that cascaded protections apply as soon as the changes
 2447+ // are visible.
 2448+
 2449+ # Get templates from templatelinks
 2450+ $id = $this->mTitle->getArticleID();
 2451+
 2452+ $tlTemplates = array();
 2453+
 2454+ $dbr = wfGetDB( DB_SLAVE );
 2455+ $res = $dbr->select( array( 'templatelinks' ),
 2456+ array( 'tl_namespace', 'tl_title' ),
 2457+ array( 'tl_from' => $id ),
 2458+ __METHOD__
 2459+ );
 2460+
 2461+ foreach ( $res as $row ) {
 2462+ $tlTemplates["{$row->tl_namespace}:{$row->tl_title}"] = true;
 2463+ }
 2464+
 2465+ # Get templates from parser output.
 2466+ $poTemplates = array();
 2467+ foreach ( $parserOutput->getTemplates() as $ns => $templates ) {
 2468+ foreach ( $templates as $dbk => $id ) {
 2469+ $poTemplates["$ns:$dbk"] = true;
 2470+ }
 2471+ }
 2472+
 2473+ # Get the diff
 2474+ $templates_diff = array_diff_key( $poTemplates, $tlTemplates );
 2475+
 2476+ if ( count( $templates_diff ) > 0 ) {
 2477+ # Whee, link updates time.
 2478+ $u = new LinksUpdate( $this->mTitle, $parserOutput, false );
 2479+ $u->doUpdate();
 2480+ }
 2481+ }
 2482+
24322483 /*
24332484 * @deprecated since 1.19
24342485 */

Status & tagging log