X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FTitle.php;h=b0df15f044f5494373032ba928aef2b0bc13eadd;hb=0c86649f4b683598761eaeb01929984adb373b0b;hp=921538b2871ddaaad6d13b83a651f8570504cafd;hpb=65294205a1cda97c5c20f1c1e0495252b54fcdcd;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/Title.php b/includes/Title.php index 921538b287..b0df15f044 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -96,7 +96,7 @@ class Title { /** @var array Array of groups allowed to edit this article */ public $mRestrictions = array(); - /** @var bool */ + /** @var string|bool */ protected $mOldRestrictions = false; /** @var bool Cascade restrictions on this page to included templates and images? */ @@ -256,12 +256,14 @@ class Title { * by a prefix. If you want to force a specific namespace even if * $text might begin with a namespace prefix, use makeTitle() or * makeTitleSafe(). - * @throws MWException + * @throws InvalidArgumentException * @return Title|null Title or null on an error. */ public static function newFromText( $text, $defaultNamespace = NS_MAIN ) { if ( is_object( $text ) ) { - throw new MWException( 'Title::newFromText given an object' ); + throw new InvalidArgumentException( '$text must be a string.' ); + } elseif ( !is_string( $text ) ) { + wfWarn( __METHOD__ . ': $text must be a string. This will throw an InvalidArgumentException in future.', 2 ); } $cache = self::getTitleCache(); @@ -449,6 +451,9 @@ class Title { if ( isset( $row->page_lang ) ) { $this->mDbPageLanguage = (string)$row->page_lang; } + if ( isset( $row->page_restrictions ) ) { + $this->mOldRestrictions = $row->page_restrictions; + } } else { // page not found $this->mArticleID = 0; $this->mLength = 0; @@ -2572,6 +2577,7 @@ class Title { if ( $row['permission'] == 'autoconfirmed' ) { $row['permission'] = 'editsemiprotected'; // B/C } + $row['expiry'] = $dbr->decodeExpiry( $row['expiry'] ); } $this->mTitleProtection = $row; } @@ -2709,7 +2715,6 @@ class Title { * false. */ public function getCascadeProtectionSources( $getPages = true ) { - global $wgContLang; $pagerestrictions = array(); if ( $this->mCascadeSources !== null && $getPages ) { @@ -2752,7 +2757,7 @@ class Title { $now = wfTimestampNow(); foreach ( $res as $row ) { - $expiry = $wgContLang->formatExpiry( $row->pr_expiry, TS_MW ); + $expiry = $dbr->decodeExpiry( $row->pr_expiry ); if ( $expiry > $now ) { if ( $getPages ) { $page_id = $row->pr_page; @@ -2885,28 +2890,29 @@ class Title { * restrictions from page table (pre 1.10) */ public function loadRestrictionsFromRows( $rows, $oldFashionedRestrictions = null ) { - global $wgContLang; $dbr = wfGetDB( DB_SLAVE ); $restrictionTypes = $this->getRestrictionTypes(); foreach ( $restrictionTypes as $type ) { $this->mRestrictions[$type] = array(); - $this->mRestrictionsExpiry[$type] = $wgContLang->formatExpiry( '', TS_MW ); + $this->mRestrictionsExpiry[$type] = 'infinity'; } $this->mCascadeRestriction = false; # Backwards-compatibility: also load the restrictions from the page record (old format). + if ( $oldFashionedRestrictions !== null ) { + $this->mOldRestrictions = $oldFashionedRestrictions; + } - if ( $oldFashionedRestrictions === null ) { - $oldFashionedRestrictions = $dbr->selectField( 'page', 'page_restrictions', + if ( $this->mOldRestrictions === false ) { + $this->mOldRestrictions = $dbr->selectField( 'page', 'page_restrictions', array( 'page_id' => $this->getArticleID() ), __METHOD__ ); } - if ( $oldFashionedRestrictions != '' ) { - - foreach ( explode( ':', trim( $oldFashionedRestrictions ) ) as $restrict ) { + if ( $this->mOldRestrictions != '' ) { + foreach ( explode( ':', trim( $this->mOldRestrictions ) ) as $restrict ) { $temp = explode( '=', trim( $restrict ) ); if ( count( $temp ) == 1 ) { // old old format should be treated as edit/move restriction @@ -2919,9 +2925,6 @@ class Title { } } } - - $this->mOldRestrictions = true; - } if ( count( $rows ) ) { @@ -2938,7 +2941,7 @@ class Title { // This code should be refactored, now that it's being used more generally, // But I don't really see any harm in leaving it in Block for now -werdna - $expiry = $wgContLang->formatExpiry( $row->pr_expiry, TS_MW ); + $expiry = $dbr->decodeExpiry( $row->pr_expiry ); // Only apply the restrictions if they haven't expired! if ( !$expiry || $expiry > $now ) { @@ -2960,11 +2963,9 @@ class Title { * restrictions from page table (pre 1.10) */ public function loadRestrictions( $oldFashionedRestrictions = null ) { - global $wgContLang; if ( !$this->mRestrictionsLoaded ) { + $dbr = wfGetDB( DB_SLAVE ); if ( $this->exists() ) { - $dbr = wfGetDB( DB_SLAVE ); - $res = $dbr->select( 'page_restrictions', array( 'pr_type', 'pr_expiry', 'pr_level', 'pr_cascade' ), @@ -2978,7 +2979,7 @@ class Title { if ( $title_protection ) { $now = wfTimestampNow(); - $expiry = $wgContLang->formatExpiry( $title_protection['expiry'], TS_MW ); + $expiry = $dbr->decodeExpiry( $title_protection['expiry'] ); if ( !$expiry || $expiry > $now ) { // Apply the restrictions @@ -2988,7 +2989,7 @@ class Title { $this->mTitleProtection = false; } } else { - $this->mRestrictionsExpiry['create'] = $wgContLang->formatExpiry( '', TS_MW ); + $this->mRestrictionsExpiry['create'] = 'infinity'; } $this->mRestrictionsLoaded = true; } @@ -3272,6 +3273,7 @@ class Title { } $this->mRestrictionsLoaded = false; $this->mRestrictions = array(); + $this->mOldRestrictions = false; $this->mRedirect = null; $this->mLength = -1; $this->mLatestID = false; @@ -3418,8 +3420,6 @@ class Title { * @return array Array of Title objects linking here */ public function getLinksFrom( $options = array(), $table = 'pagelinks', $prefix = 'pl' ) { - global $wgContentHandlerUseDB; - $id = $this->getArticleID(); # If the page doesn't exist; there can't be any link from this page @@ -3433,49 +3433,36 @@ class Title { $db = wfGetDB( DB_SLAVE ); } - $namespaceFiled = "{$prefix}_namespace"; - $titleField = "{$prefix}_title"; - - $fields = array( - $namespaceFiled, - $titleField, - 'page_id', - 'page_len', - 'page_is_redirect', - 'page_latest' - ); - - if ( $wgContentHandlerUseDB ) { - $fields[] = 'page_content_model'; - } + $blNamespace = "{$prefix}_namespace"; + $blTitle = "{$prefix}_title"; $res = $db->select( array( $table, 'page' ), - $fields, + array_merge( + array( $blNamespace, $blTitle ), + WikiPage::selectFields() + ), array( "{$prefix}_from" => $id ), __METHOD__, $options, array( 'page' => array( 'LEFT JOIN', - array( "page_namespace=$namespaceFiled", "page_title=$titleField" ) + array( "page_namespace=$blNamespace", "page_title=$blTitle" ) ) ) ); $retVal = array(); - if ( $res->numRows() ) { - $linkCache = LinkCache::singleton(); - foreach ( $res as $row ) { - $titleObj = Title::makeTitle( $row->$namespaceFiled, $row->$titleField ); - if ( $titleObj ) { - if ( $row->page_id ) { - $linkCache->addGoodLinkObjFromRow( $titleObj, $row ); - } else { - $linkCache->addBadLinkObj( $titleObj ); - } - $retVal[] = $titleObj; - } + $linkCache = LinkCache::singleton(); + foreach ( $res as $row ) { + if ( $row->page_id ) { + $titleObj = Title::newFromRow( $row ); + } else { + $titleObj = Title::makeTitle( $row->$blNamespace, $row->$blTitle ); + $linkCache->addBadLinkObj( $titleObj ); } + $retVal[] = $titleObj; } + return $retVal; } @@ -4422,35 +4409,29 @@ class Title { * @return string|null */ public function getNotificationTimestamp( $user = null ) { - global $wgUser, $wgShowUpdatedMarker; + global $wgUser; + // Assume current user if none given if ( !$user ) { $user = $wgUser; } // Check cache first $uid = $user->getId(); + if ( !$uid ) { + return false; + } // avoid isset here, as it'll return false for null entries if ( array_key_exists( $uid, $this->mNotificationTimestamp ) ) { return $this->mNotificationTimestamp[$uid]; } - if ( !$uid || !$wgShowUpdatedMarker || !$user->isAllowed( 'viewmywatchlist' ) ) { - $this->mNotificationTimestamp[$uid] = false; - return $this->mNotificationTimestamp[$uid]; - } // Don't cache too much! if ( count( $this->mNotificationTimestamp ) >= self::CACHE_MAX ) { $this->mNotificationTimestamp = array(); } - $dbr = wfGetDB( DB_SLAVE ); - $this->mNotificationTimestamp[$uid] = $dbr->selectField( 'watchlist', - 'wl_notificationtimestamp', - array( - 'wl_user' => $user->getId(), - 'wl_namespace' => $this->getNamespace(), - 'wl_title' => $this->getDBkey(), - ), - __METHOD__ - ); + + $watchedItem = WatchedItem::fromUserTitle( $user, $this ); + $this->mNotificationTimestamp[$uid] = $watchedItem->getNotificationTimestamp(); + return $this->mNotificationTimestamp[$uid]; }