r96460 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r96459‎ | r96460 | r96461 >
Date:17:55, 7 September 2011
Author:aaron
Status:ok
Tags:
Comment:
For r91123:
* Moved generateReason() to WikiPage. This fixes the PureWikiDeletion ext too.
* Make Checkpoint ext call getRawText() as doEdit() does. Aalso, WikiPage doesn't have fetchContent().
* Call getAutosummary() statically in doEdit().
* Fixed outdated code comment.
* Fixed title used in unit test.
Modified paths:
  • /trunk/extensions/Checkpoint/Checkpoint.php (modified) (history)
  • /trunk/phase3/includes/Article.php (modified) (history)
  • /trunk/phase3/includes/WikiPage.php (modified) (history)
  • /trunk/phase3/tests/phpunit/includes/ArticleTest.php (modified) (history)

Diff [purge]

Index: trunk/phase3/tests/phpunit/includes/ArticleTest.php
@@ -7,7 +7,7 @@
88
99 /** creates a title object and its article object */
1010 function setUp() {
11 - $this->title = Title::makeTitle( NS_MAIN, 'somePage' );
 11+ $this->title = Title::makeTitle( NS_MAIN, 'SomePage' );
1212 $this->article = new Article( $this->title );
1313
1414 }
Index: trunk/phase3/includes/Article.php
@@ -1267,101 +1267,6 @@
12681268 }
12691269
12701270 /**
1271 - * Auto-generates a deletion reason
1272 - *
1273 - * @param &$hasHistory Boolean: whether the page has a history
1274 - * @return mixed String containing deletion reason or empty string, or boolean false
1275 - * if no revision occurred
1276 - */
1277 - public function generateReason( &$hasHistory ) {
1278 - global $wgContLang;
1279 -
1280 - $dbw = wfGetDB( DB_MASTER );
1281 - // Get the last revision
1282 - $rev = Revision::newFromTitle( $this->getTitle() );
1283 -
1284 - if ( is_null( $rev ) ) {
1285 - return false;
1286 - }
1287 -
1288 - // Get the article's contents
1289 - $contents = $rev->getText();
1290 - $blank = false;
1291 -
1292 - // If the page is blank, use the text from the previous revision,
1293 - // which can only be blank if there's a move/import/protect dummy revision involved
1294 - if ( $contents == '' ) {
1295 - $prev = $rev->getPrevious();
1296 -
1297 - if ( $prev ) {
1298 - $contents = $prev->getText();
1299 - $blank = true;
1300 - }
1301 - }
1302 -
1303 - // Find out if there was only one contributor
1304 - // Only scan the last 20 revisions
1305 - $res = $dbw->select( 'revision', 'rev_user_text',
1306 - array( 'rev_page' => $this->mPage->getID(), $dbw->bitAnd( 'rev_deleted', Revision::DELETED_USER ) . ' = 0' ),
1307 - __METHOD__,
1308 - array( 'LIMIT' => 20 )
1309 - );
1310 -
1311 - if ( $res === false ) {
1312 - // This page has no revisions, which is very weird
1313 - return false;
1314 - }
1315 -
1316 - $hasHistory = ( $res->numRows() > 1 );
1317 - $row = $dbw->fetchObject( $res );
1318 -
1319 - if ( $row ) { // $row is false if the only contributor is hidden
1320 - $onlyAuthor = $row->rev_user_text;
1321 - // Try to find a second contributor
1322 - foreach ( $res as $row ) {
1323 - if ( $row->rev_user_text != $onlyAuthor ) { // Bug 22999
1324 - $onlyAuthor = false;
1325 - break;
1326 - }
1327 - }
1328 - } else {
1329 - $onlyAuthor = false;
1330 - }
1331 -
1332 - // Generate the summary with a '$1' placeholder
1333 - if ( $blank ) {
1334 - // The current revision is blank and the one before is also
1335 - // blank. It's just not our lucky day
1336 - $reason = wfMsgForContent( 'exbeforeblank', '$1' );
1337 - } else {
1338 - if ( $onlyAuthor ) {
1339 - $reason = wfMsgForContent( 'excontentauthor', '$1', $onlyAuthor );
1340 - } else {
1341 - $reason = wfMsgForContent( 'excontent', '$1' );
1342 - }
1343 - }
1344 -
1345 - if ( $reason == '-' ) {
1346 - // Allow these UI messages to be blanked out cleanly
1347 - return '';
1348 - }
1349 -
1350 - // Replace newlines with spaces to prevent uglyness
1351 - $contents = preg_replace( "/[\n\r]/", ' ', $contents );
1352 - // Calculate the maximum amount of chars to get
1353 - // Max content length = max comment length - length of the comment (excl. $1)
1354 - $maxLength = 255 - ( strlen( $reason ) - 2 );
1355 - $contents = $wgContLang->truncate( $contents, $maxLength );
1356 - // Remove possible unfinished links
1357 - $contents = preg_replace( '/\[\[([^\]]*)\]?$/', '$1', $contents );
1358 - // Now replace the '$1' placeholder
1359 - $reason = str_replace( '$1', $contents, $reason );
1360 -
1361 - return $reason;
1362 - }
1363 -
1364 -
1365 - /**
13661271 * UI entry point for page deletion
13671272 */
13681273 public function delete() {
@@ -2042,6 +1947,10 @@
20431948 return $this->mPage->commitRollback( $fromP, $summary, $bot, $resultDetails, $guser );
20441949 }
20451950
 1951+ public function generateReason( &$hasHistory ) {
 1952+ return $this->mPage->getAutoDeleteReason( $hasHistory );
 1953+ }
 1954+
20461955 // ****** B/C functions for static methods ( __callStatic is PHP>=5.3 ) ****** //
20471956 public static function selectFields() {
20481957 return WikiPage::selectFields();
Index: trunk/phase3/includes/WikiPage.php
@@ -574,7 +574,7 @@
575575 * @return string MW timestamp of last article revision
576576 */
577577 public function getTimestamp() {
578 - // Check if the field has been filled by ParserCache::get()
 578+ // Check if the field has been filled by WikiPage::setTimestamp()
579579 if ( !$this->mTimestamp ) {
580580 $this->loadLastEdit();
581581 }
@@ -1094,7 +1094,7 @@
10951095
10961096 # Provide autosummaries if one is not provided and autosummaries are enabled.
10971097 if ( $wgUseAutomaticEditSummaries && $flags & EDIT_AUTOSUMMARY && $summary == '' ) {
1098 - $summary = $this->getAutosummary( $oldtext, $text, $flags );
 1098+ $summary = self::getAutosummary( $oldtext, $text, $flags );
10991099 }
11001100
11011101 $editInfo = $this->prepareTextForEdit( $text, null, $user );
@@ -2465,6 +2465,100 @@
24662466 }
24672467
24682468 /**
 2469+ * Auto-generates a deletion reason
 2470+ *
 2471+ * @param &$hasHistory Boolean: whether the page has a history
 2472+ * @return mixed String containing deletion reason or empty string, or boolean false
 2473+ * if no revision occurred
 2474+ */
 2475+ public function getAutoDeleteReason( &$hasHistory ) {
 2476+ global $wgContLang;
 2477+
 2478+ $dbw = wfGetDB( DB_MASTER );
 2479+ // Get the last revision
 2480+ $rev = Revision::newFromTitle( $this->getTitle() );
 2481+
 2482+ if ( is_null( $rev ) ) {
 2483+ return false;
 2484+ }
 2485+
 2486+ // Get the article's contents
 2487+ $contents = $rev->getText();
 2488+ $blank = false;
 2489+
 2490+ // If the page is blank, use the text from the previous revision,
 2491+ // which can only be blank if there's a move/import/protect dummy revision involved
 2492+ if ( $contents == '' ) {
 2493+ $prev = $rev->getPrevious();
 2494+
 2495+ if ( $prev ) {
 2496+ $contents = $prev->getText();
 2497+ $blank = true;
 2498+ }
 2499+ }
 2500+
 2501+ // Find out if there was only one contributor
 2502+ // Only scan the last 20 revisions
 2503+ $res = $dbw->select( 'revision', 'rev_user_text',
 2504+ array( 'rev_page' => $this->getID(), $dbw->bitAnd( 'rev_deleted', Revision::DELETED_USER ) . ' = 0' ),
 2505+ __METHOD__,
 2506+ array( 'LIMIT' => 20 )
 2507+ );
 2508+
 2509+ if ( $res === false ) {
 2510+ // This page has no revisions, which is very weird
 2511+ return false;
 2512+ }
 2513+
 2514+ $hasHistory = ( $res->numRows() > 1 );
 2515+ $row = $dbw->fetchObject( $res );
 2516+
 2517+ if ( $row ) { // $row is false if the only contributor is hidden
 2518+ $onlyAuthor = $row->rev_user_text;
 2519+ // Try to find a second contributor
 2520+ foreach ( $res as $row ) {
 2521+ if ( $row->rev_user_text != $onlyAuthor ) { // Bug 22999
 2522+ $onlyAuthor = false;
 2523+ break;
 2524+ }
 2525+ }
 2526+ } else {
 2527+ $onlyAuthor = false;
 2528+ }
 2529+
 2530+ // Generate the summary with a '$1' placeholder
 2531+ if ( $blank ) {
 2532+ // The current revision is blank and the one before is also
 2533+ // blank. It's just not our lucky day
 2534+ $reason = wfMsgForContent( 'exbeforeblank', '$1' );
 2535+ } else {
 2536+ if ( $onlyAuthor ) {
 2537+ $reason = wfMsgForContent( 'excontentauthor', '$1', $onlyAuthor );
 2538+ } else {
 2539+ $reason = wfMsgForContent( 'excontent', '$1' );
 2540+ }
 2541+ }
 2542+
 2543+ if ( $reason == '-' ) {
 2544+ // Allow these UI messages to be blanked out cleanly
 2545+ return '';
 2546+ }
 2547+
 2548+ // Replace newlines with spaces to prevent uglyness
 2549+ $contents = preg_replace( "/[\n\r]/", ' ', $contents );
 2550+ // Calculate the maximum amount of chars to get
 2551+ // Max content length = max comment length - length of the comment (excl. $1)
 2552+ $maxLength = 255 - ( strlen( $reason ) - 2 );
 2553+ $contents = $wgContLang->truncate( $contents, $maxLength );
 2554+ // Remove possible unfinished links
 2555+ $contents = preg_replace( '/\[\[([^\]]*)\]?$/', '$1', $contents );
 2556+ // Now replace the '$1' placeholder
 2557+ $reason = str_replace( '$1', $contents, $reason );
 2558+
 2559+ return $reason;
 2560+ }
 2561+
 2562+ /**
24692563 * Get parser options suitable for rendering the primary article wikitext
24702564 * @param $canonical boolean Determines that the generated options must not depend on user preferences (see bug 14404)
24712565 * @return mixed ParserOptions object or boolean false
Index: trunk/extensions/Checkpoint/Checkpoint.php
@@ -45,7 +45,7 @@
4646 // blank summary, so let's get an automatic one if
4747 // applicable (the appending bit prevents autosummaries
4848 // from appearing otherwise).
49 - $oldtext = $article->fetchContent();
 49+ $oldtext = $article->getRawText(); // current revision
5050 $summary = $article->getAutosummary( $oldtext, $text, $flags );
5151 }
5252 $summary .= wfMsg( 'word-separator' ) . wfMsg( 'checkpoint-notice' );

Follow-up revisions

RevisionCommit summaryAuthorDate
r965121.18: MFT r95655, r96227, r96386, r96393, r96405, r96427, r96460, r96472. And...catrope22:18, 7 September 2011

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