Merge "Added Parsoid WT escaping tests (several disabled for PHP parser)."
authorGWicke <gwicke@wikimedia.org>
Thu, 1 Nov 2012 18:27:04 +0000 (18:27 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Thu, 1 Nov 2012 18:27:04 +0000 (18:27 +0000)
14 files changed:
includes/ChangesList.php
includes/Import.php
includes/Message.php
includes/Revision.php
includes/Title.php
includes/WikiPage.php
includes/cache/MessageCache.php
includes/specials/SpecialCachedPage.php
includes/specials/SpecialDeletedContributions.php
includes/specials/SpecialMergeHistory.php
skins/CologneBlue.php
skins/cologneblue/screen.css
skins/common/shared.css
tests/phpunit/includes/WikiPageTest.php

index e7395c0..6b7e99c 100644 (file)
@@ -514,12 +514,12 @@ class ChangesList extends ContextSource {
                        if ( $this->getUser()->isAllowed('rollback') && $rc->mAttribs['page_latest'] == $rc->mAttribs['rc_this_oldid'] )
                        {
                                $rev = new Revision( array(
+                                       'title'     => $page,
                                        'id'        => $rc->mAttribs['rc_this_oldid'],
                                        'user'      => $rc->mAttribs['rc_user'],
                                        'user_text' => $rc->mAttribs['rc_user_text'],
                                        'deleted'   => $rc->mAttribs['rc_deleted']
                                ) );
-                               $rev->setTitle( $page );
                                $s .= ' '.Linker::generateRollback( $rev, $this->getContext() );
                        }
                }
index 71498ac..2017466 100644 (file)
@@ -1397,6 +1397,7 @@ class WikiRevision {
                # @todo FIXME: Use original rev_id optionally (better for backups)
                # Insert the row
                $revision = new Revision( array(
+                       'title'      => $this->title,
                        'page'       => $pageId,
                        'content_model'  => $this->getModel(),
                        'content_format' => $this->getFormat(),
index 2feaed2..5a4b810 100644 (file)
@@ -629,7 +629,8 @@ class Message {
         * @return string Wikitext parsed into HTML
         */
        protected function parseText( $string ) {
-               return MessageCache::singleton()->parse( $string, $this->title, /*linestart*/true, $this->interface, $this->language )->getText();
+               $out = MessageCache::singleton()->parse( $string, $this->title, /*linestart*/true, $this->interface, $this->language );
+               return is_object( $out ) ? $out->getText() : $out;
        }
 
        /**
index 1ab44bf..d556edc 100644 (file)
@@ -178,6 +178,13 @@ class Revision implements IDBAccessObject {
                        unset( $attribs['content_format'] );
                }
 
+               if ( !isset( $attribs['title'] )
+                       && isset( $row->ar_namespace )
+                       && isset( $row->ar_title ) ) {
+
+                       $attribs['title'] = Title::makeTitle( $row->ar_namespace, $row->ar_title );
+               }
+
                if ( isset( $row->ar_text ) && !$row->ar_text_id ) {
                        // Pre-1.5 ar_text row
                        $attribs['text'] = self::getRevisionText( $row, 'ar_' );
index 00fdc3a..b484045 100644 (file)
@@ -3816,6 +3816,7 @@ class Title {
                        $newid = $redirectArticle->insertOn( $dbw );
                        if ( $newid ) { // sanity
                                $redirectRevision = new Revision( array(
+                                       'title'   => $this, // for determining the default content model
                                        'page'    => $newid,
                                        'comment' => $comment,
                                        'content'    => $redirectContent ) );
index b525ff1..df3086a 100644 (file)
@@ -2163,6 +2163,7 @@ class WikiPage extends Page implements IDBAccessObject {
 
                $dbw = wfGetDB( DB_MASTER );
                $revision = new Revision( array(
+                       'title'      => $this->getTitle(), // for determining the default content model
                        'page'       => $this->getId(),
                        'text'       => $serialized,
                        'length'     => $content->getSize(),
index 148e26b..9bf7436 100644 (file)
@@ -820,7 +820,7 @@ class MessageCache {
         * @param $linestart bool
         * @param $interface bool
         * @param $language
-        * @return ParserOutput
+        * @return ParserOutput|string
         */
        public function parse( $text, $title = null, $linestart = true, $interface = false, $language = null  ) {
                if ( $this->mInParser ) {
index 949ac35..ddd11ad 100644 (file)
@@ -119,7 +119,7 @@ abstract class SpecialCachedPage extends SpecialPage implements ICacheHelper {
         *
         * @since 1.20
         *
-        * @param function $computeFunction
+        * @param callable $computeFunction
         * @param array|mixed $args
         * @param string|null $key
         *
@@ -137,7 +137,7 @@ abstract class SpecialCachedPage extends SpecialPage implements ICacheHelper {
         *
         * @since 1.20
         *
-        * @param function $computeFunction
+        * @param callable $computeFunction
         * @param array $args
         * @param string|null $key
         */
index 3d39e37..bdeb7fe 100644 (file)
@@ -135,7 +135,10 @@ class DeletedContribsPager extends IndexPager {
        function formatRow( $row ) {
                wfProfileIn( __METHOD__ );
 
+               $page = Title::makeTitle( $row->ar_namespace, $row->ar_title );
+
                $rev = new Revision( array(
+                               'title'      => $page,
                                'id'         => $row->ar_rev_id,
                                'comment'    => $row->ar_comment,
                                'user'       => $row->ar_user,
@@ -145,8 +148,6 @@ class DeletedContribsPager extends IndexPager {
                                'deleted'    => $row->ar_deleted,
                                ) );
 
-               $page = Title::makeTitle( $row->ar_namespace, $row->ar_title );
-
                $undelete = SpecialPage::getTitleFor( 'Undelete' );
 
                $logs = SpecialPage::getTitleFor( 'Log' );
index bc9a3d9..85e1d65 100644 (file)
@@ -380,6 +380,7 @@ class SpecialMergeHistory extends SpecialPage {
                        if ( $redirectContent ) {
                                $redirectPage = WikiPage::factory( $targetTitle );
                                $redirectRevision = new Revision( array(
+                                       'title'   => $targetTitle,
                                        'page'    => $this->mTargetID,
                                        'comment' => $comment,
                                        'content' => $redirectContent ) );
index 8c97a3c..84042c3 100644 (file)
@@ -122,223 +122,79 @@ class CologneBlueTemplate extends BaseTemplate {
                return $this->getSkin()->getLanguage()->pipeList( $s );
        }
 
-       function bottomLinks() {
-               $sep = wfMessage( 'pipe-separator' )->escaped() . "\n";
-
-               $s = '';
-               if ( $this->getSkin()->getOutput()->isArticleRelated() ) {
-                       $element[] = '<strong>' . $this->editThisPage() . '</strong>';
-
-                       if ( $this->getSkin()->getUser()->isLoggedIn() ) {
-                               $element[] = $this->watchThisPage();
-                       }
-
-                       $element[] = $this->talkLink();
-                       $element[] = $this->historyLink();
-                       $element[] = $this->whatLinksHere();
-                       $element[] = $this->watchPageLinksLink();
-
-                       $title = $this->getSkin()->getTitle();
-
-                       if (
-                               $title->getNamespace() == NS_USER ||
-                               $title->getNamespace() == NS_USER_TALK
-                       ) {
-                               $id = User::idFromName( $title->getText() );
-                               $ip = User::isIP( $title->getText() );
-
-                               # Both anons and non-anons have contributions list
-                               if ( $id || $ip ) {
-                                       $element[] = $this->userContribsLink();
-                               }
-
-                               if ( $this->getSkin()->showEmailUser( $id ) ) {
-                                       $element[] = $this->emailUserLink();
-                               }
-                       }
-
-                       $s = implode( $element, $sep );
-
-                       if ( $title->getArticleID() ) {
-                               $s .= "\n<br />";
-
-                               // Delete/protect/move links for privileged users
-                               if ( $this->getSkin()->getUser()->isAllowed( 'delete' ) ) {
-                                       $s .= $this->deleteThisPage();
-                               }
-
-                               if ( $this->getSkin()->getUser()->isAllowed( 'protect' ) ) {
-                                       $s .= $sep . $this->protectThisPage();
-                               }
-
-                               if ( $this->getSkin()->getUser()->isAllowed( 'move' ) ) {
-                                       $s .= $sep . $this->moveThisPage();
-                               }
-                       }
-
-                       $s .= "<br />\n" . $this->otherLanguages();
+       /**
+        * Used in bottomLinks() to eliminate repetitive code.
+        *
+        * @param $key string Key to be passed to makeListItem()
+        * @param $navlink array Navlink suitable for processNavlinkForDocument()
+        * @param $message string Key of the message to use in place of standard text
+        *
+        * @return string
+        * @fixed
+        */
+       function processBottomLink( $key, $navlink, $message=null ) {
+               if ( !$navlink ) {
+                       // Empty navlinks might be passed.
+                       return null;
                }
 
-               return $s;
-       }
-
-       function editThisPage() {
-               if ( !$this->getSkin()->getOutput()->isArticleRelated() ) {
-                       $s = wfMessage( 'protectedpage' )->text();
-               } else {
-                       $title = $this->getSkin()->getTitle();
-                       if ( $title->quickUserCan( 'edit' ) && $title->exists() ) {
-                               $t = wfMessage( 'editthispage' )->text();
-                       } elseif ( $title->quickUserCan( 'create' ) && !$title->exists() ) {
-                               $t = wfMessage( 'create-this-page' )->text();
-                       } else {
-                               $t = wfMessage( 'viewsource' )->text();
-                       }
-
-                       $s = Linker::linkKnown(
-                               $title,
-                               $t,
-                               array(),
-                               $this->getSkin()->editUrlOptions()
-                       );
+               if ( $message ) {
+                       $navlink['text'] = wfMessage( $message )->escaped();
                }
 
-               return $s;
+               return $this->makeListItem( $key, $this->processNavlinkForDocument( $navlink ), array( 'tag' => 'span' ) );
        }
 
-       function deleteThisPage() {
-               $diff = $this->getSkin()->getRequest()->getVal( 'diff' );
-               $title = $this->getSkin()->getTitle();
-
-               if ( $title->getArticleID() && ( !$diff ) && $this->getSkin()->getUser()->isAllowed( 'delete' ) ) {
-                       $t = wfMessage( 'deletethispage' )->text();
+       // @fixed
+       function bottomLinks() {
+               $toolbox = $this->getToolbox();
+               $content_nav = $this->data['content_navigation'];
 
-                       $s = Linker::linkKnown(
-                               $title,
-                               $t,
-                               array(),
-                               array( 'action' => 'delete' )
-                       );
-               } else {
-                       $s = '';
-               }
+               $lines = array();
 
-               return $s;
-       }
+               if ( $this->getSkin()->getOutput()->isArticleRelated() ) {
+                       // First row. Regular actions.
+                       $element = array();
 
-       function protectThisPage() {
-               $diff = $this->getSkin()->getRequest()->getVal( 'diff' );
-               $title = $this->getSkin()->getTitle();
+                       $editLinkMessage = $this->getSkin()->getTitle()->exists() ? 'editthispage' : 'create-this-page';
+                       $element[] = $this->processBottomLink( 'edit', $content_nav['views']['edit'], $editLinkMessage );
+                       $element[] = $this->processBottomLink( 'viewsource', $content_nav['views']['viewsource'], 'viewsource' );
 
-               if ( $title->getArticleID() && ( ! $diff ) && $this->getSkin()->getUser()->isAllowed( 'protect' ) ) {
-                       if ( $title->isProtected() ) {
-                               $text = wfMessage( 'unprotectthispage' )->text();
-                               $query = array( 'action' => 'unprotect' );
-                       } else {
-                               $text = wfMessage( 'protectthispage' )->text();
-                               $query = array( 'action' => 'protect' );
-                       }
+                       $element[] = $this->processBottomLink( 'watch', $content_nav['actions']['watch'], 'watchthispage' );
+                       $element[] = $this->processBottomLink( 'unwatch', $content_nav['actions']['unwatch'], 'unwatchthispage' );
 
-                       $s = Linker::linkKnown(
-                               $title,
-                               $text,
-                               array(),
-                               $query
-                       );
-               } else {
-                       $s = '';
-               }
+                       $element[] = $this->talkLink();
 
-               return $s;
-       }
+                       $element[] = $this->processBottomLink( 'history', $content_nav['views']['history'], 'history' );
+                       $element[] = $this->processBottomLink( 'info', $toolbox['info'] );
+                       $element[] = $this->processBottomLink( 'whatlinkshere', $toolbox['whatlinkshere'] );
+                       $element[] = $this->processBottomLink( 'recentchangeslinked', $toolbox['recentchangeslinked'] );
 
-       function watchThisPage() {
-               // Cache
-               $title = $this->getSkin()->getTitle();
+                       $element[] = $this->processBottomLink( 'contributions', $toolbox['contributions'] );
+                       $element[] = $this->processBottomLink( 'emailuser', $toolbox['emailuser'] );
 
-               if ( $this->getSkin()->getOutput()->isArticleRelated() ) {
-                       if ( $this->getSkin()->getUser()->isWatched( $title ) ) {
-                               $text = wfMessage( 'unwatchthispage' )->text();
-                               $query = array(
-                                       'action' => 'unwatch',
-                                       'token' => UnwatchAction::getUnwatchToken( $title, $this->getSkin()->getUser() ),
-                               );
-                               $id = 'mw-unwatch-link';
-                       } else {
-                               $text = wfMessage( 'watchthispage' )->text();
-                               $query = array(
-                                       'action' => 'watch',
-                                       'token' => WatchAction::getWatchToken( $title, $this->getSkin()->getUser() ),
-                               );
-                               $id = 'mw-watch-link';
-                       }
+                       $lines[] = $this->getSkin()->getLanguage()->pipeList( array_filter( $element ) );
 
-                       $s = Linker::linkKnown(
-                               $title,
-                               $text,
-                               array( 'id' => $id ),
-                               $query
-                       );
-               } else {
-                       $s = wfMessage( 'notanarticle' )->text();
-               }
 
-               return $s;
-       }
+                       // Second row. Privileged actions.
+                       $element = array();
 
-       function moveThisPage() {
-               if ( $this->getSkin()->getTitle()->quickUserCan( 'move' ) ) {
-                       return Linker::linkKnown(
-                               SpecialPage::getTitleFor( 'Movepage' ),
-                               wfMessage( 'movethispage' )->text(),
-                               array(),
-                               array( 'target' => $this->getSkin()->getTitle()->getPrefixedDBkey() )
-                       );
-               } else {
-                       // no message if page is protected - would be redundant
-                       return '';
-               }
-       }
+                       $element[] = $this->processBottomLink( 'delete', $content_nav['actions']['delete'], 'deletethispage' );
+                       $element[] = $this->processBottomLink( 'undelete', $content_nav['actions']['undelete'], 'undeletethispage' );
 
-       function historyLink() {
-               return Linker::link(
-                       $this->getSkin()->getTitle(),
-                       wfMessage( 'history' )->escaped(),
-                       array( 'rel' => 'archives' ),
-                       array( 'action' => 'history' )
-               );
-       }
+                       $element[] = $this->processBottomLink( 'protect', $content_nav['actions']['protect'], 'protectthispage' );
+                       $element[] = $this->processBottomLink( 'unprotect', $content_nav['actions']['unprotect'], 'unprotectthispage' );
 
-       function whatLinksHere() {
-               return Linker::linkKnown(
-                       SpecialPage::getTitleFor( 'Whatlinkshere', $this->getSkin()->getTitle()->getPrefixedDBkey() ),
-                       wfMessage( 'whatlinkshere' )->escaped()
-               );
-       }
+                       $element[] = $this->processBottomLink( 'move', $content_nav['actions']['move'], 'movethispage' );
 
-       function userContribsLink() {
-               return Linker::linkKnown(
-                       SpecialPage::getTitleFor( 'Contributions', $this->getSkin()->getTitle()->getDBkey() ),
-                       wfMessage( 'contributions' )->escaped()
-               );
-       }
+                       $lines[] = $this->getSkin()->getLanguage()->pipeList( array_filter( $element ) );
 
-       function emailUserLink() {
-               return Linker::linkKnown(
-                       SpecialPage::getTitleFor( 'Emailuser', $this->getSkin()->getTitle()->getDBkey() ),
-                       wfMessage( 'emailuser' )->escaped()
-               );
-       }
 
-       function watchPageLinksLink() {
-               if ( !$this->getSkin()->getOutput()->isArticleRelated() ) {
-                       return wfMessage( 'parentheses', wfMessage( 'notanarticle' )->text() )->escaped();
-               } else {
-                       return Linker::linkKnown(
-                               SpecialPage::getTitleFor( 'Recentchangeslinked', $this->getSkin()->getTitle()->getPrefixedDBkey() ),
-                               wfMessage( 'recentchangeslinked-toolbox' )->escaped()
-                       );
+                       // Third row. Language links.
+                       $lines[] = $this->otherLanguages();
                }
+
+               return implode( array_filter( $lines ), "<br />\n" ) . "<br />\n";
        }
 
        // @fixed
@@ -385,10 +241,7 @@ class CologneBlueTemplate extends BaseTemplate {
 
                // Use the regular navigational link, but replace its text. Everything else stays unmodified.
                $namespacesLinks = $this->data['content_navigation']['namespaces'];
-               $link = $this->processNavlinkForDocument( $namespacesLinks[ $key ] );
-               $link['text'] = wfMessage( $message )->text();
-
-               return $this->makeListItem( $message, $link, array( 'tag' => 'span' ) );
+               return $this->processBottomLink( $message,  $namespacesLinks[$key], $message );
        }
 
        /**
index 51186d8..0d9615f 100644 (file)
@@ -70,6 +70,10 @@ textarea {
        display: inline;
 }
 
+#cb-ca-edit {
+       font-weight: bold;
+}
+
 #pagestats {
        font-family: Verdana, Arial, sans-serif;
        color: black;
@@ -164,7 +168,7 @@ a.stub, #quickbar a.stub {
        text-decoration: none;
 }
 
-a.new, #quickbar a.new {
+a.new, #quickbar span.new a, #footer span.new a {
        color: #CC2200;
 }
 
index 8f771e9..ed4e8c5 100644 (file)
@@ -448,6 +448,11 @@ th.mw-revdel-checkbox {
        text-align: center;
 }
 
+/* red links; see bug 36276 */
+a.new {
+       color: #BA0000;
+}
+
 /* feed links */
 a.feedlink {
        /* @embed */
index 6dc1568..d7c4d56 100644 (file)
@@ -60,7 +60,8 @@ class WikiPageTest extends MediaWikiLangTestCase {
         */
        protected function newPage( $title, $model = null ) {
                if ( is_string( $title ) ) {
-                       $title = Title::newFromText( $title );
+                       $ns = $this->getDefaultWikitextNS();
+                       $title = Title::newFromText( $title, $ns );
                }
 
                $p = new WikiPage( $title );
@@ -79,11 +80,7 @@ class WikiPageTest extends MediaWikiLangTestCase {
         * @return WikiPage
         */
        protected function createPage( $page, $text, $model = null ) {
-               if ( is_string( $page ) ) {
-                       $page = Title::newFromText( $page );
-               }
-
-               if ( $page instanceof Title ) {
+               if ( is_string( $page ) || $page instanceof Title ) {
                        $page = $this->newPage( $page, $model );
                }
 
@@ -94,9 +91,8 @@ class WikiPageTest extends MediaWikiLangTestCase {
        }
 
        public function testDoEditContent() {
-               $title = Title::newFromText( "WikiPageTest_testDoEditContent" );
-
-               $page = $this->newPage( $title );
+               $page = $this->newPage( "WikiPageTest_testDoEditContent" );
+               $title = $page->getTitle();
 
                $content = ContentHandler::makeContent( "[[Lorem ipsum]] dolor sit amet, consetetur sadipscing elitr, sed diam "
                                                . " nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat.",
@@ -543,10 +539,16 @@ class WikiPageTest extends MediaWikiLangTestCase {
         * @dataProvider provideIsCountable
         */
        public function testIsCountable( $title, $model, $text, $mode, $expected ) {
-               global $wgArticleCountMethod;
+               global $wgContentHandlerUseDB;
 
-               $oldArticleCountMethod = $wgArticleCountMethod;
-               $wgArticleCountMethod = $mode;
+               $this->setMwGlobals( 'wgArticleCountMethod', $mode );
+
+               $title = Title::newFromText( $title );
+
+               if ( !$wgContentHandlerUseDB && ContentHandler::getDefaultModelFor( $title ) != $model ) {
+                       $this->markTestSkipped( "Can not use non-default content model $model for "
+                               . $title->getPrefixedDBkey() . " with \wgArticleCountMethod disabled." );
+               }
 
                $page = $this->createPage( $title, $text, $model );
                $hasLinks = wfGetDB( DB_SLAVE )->selectField( 'pagelinks', 1,
@@ -557,8 +559,6 @@ class WikiPageTest extends MediaWikiLangTestCase {
                $v = $page->isCountable();
                $w = $page->isCountable( $editInfo );
 
-               $wgArticleCountMethod = $oldArticleCountMethod;
-
                $this->assertEquals( $expected, $v, "isCountable( null ) returned unexpected value " . var_export( $v, true )
                                                                                        . " instead of " . var_export( $expected, true ) . " in mode `$mode` for text \"$text\"" );