function haveCacheVaryCookies() {
$request = $this->getRequest();
foreach ( $this->getCacheVaryCookies() as $cookieName ) {
- if ( $request->getCookie( $cookieName, '' ) ) {
+ if ( $request->getCookie( $cookieName, '', '' ) !== '' ) {
wfDebug( __METHOD__ . ": found $cookieName\n" );
return true;
}
* @return bool
*/
public function userCanPreview() {
- if ( $this->getRequest()->getVal( 'action' ) != 'submit'
- || !$this->getRequest()->wasPosted()
- || !$this->getUser()->matchEditToken(
- $this->getRequest()->getVal( 'wpEditToken' ) )
- ) {
+ $request = $this->getRequest();
+ if ( $request->getVal( 'action' ) !== 'submit' || !$request->wasPosted() ) {
+ return false;
+ }
+
+ $user = $this->getUser();
+ if ( !$user->matchEditToken( $request->getVal( 'wpEditToken' ) ) ) {
return false;
}
- if ( !$this->getTitle()->isJsSubpage() && !$this->getTitle()->isCssSubpage() ) {
+
+ $title = $this->getTitle();
+ if ( !$title->isJsSubpage() && !$title->isCssSubpage() ) {
return false;
}
- if ( !$this->getTitle()->isSubpageOf( $this->getUser()->getUserPage() ) ) {
+ if ( !$title->isSubpageOf( $user->getUserPage() ) ) {
// Don't execute another user's CSS or JS on preview (T85855)
return false;
}
- return !count( $this->getTitle()->getUserPermissionsErrors( 'edit', $this->getUser() ) );
+ $errors = $title->getUserPermissionsErrors( 'edit', $user );
+ if ( count( $errors ) !== 0 ) {
+ return false;
+ }
+
+ return true;
}
/**
* @since 1.19
*/
class DeferredUpdates {
- /** @var array Updates to be deferred until the end of the request */
+ /** @var DeferrableUpdate[] Updates to be deferred until the end of the request */
private static $updates = array();
/** @var bool Defer updates fully even in CLI mode */
private static $forceDeferral = false;
while ( count( $updates ) ) {
self::clearPendingUpdates();
-
- /** @var DeferrableUpdate $update */
+ /** @var DataUpdate[] $dataUpdates */
+ $dataUpdates = array();
+ /** @var DeferrableUpdate[] $otherUpdates */
+ $otherUpdates = array();
foreach ( $updates as $update ) {
+ if ( $update instanceof DataUpdate ) {
+ $dataUpdates[] = $update;
+ } else {
+ $otherUpdates[] = $update;
+ }
+ }
+
+ // Delegate DataUpdate execution to the DataUpdate class
+ DataUpdate::runUpdates( $dataUpdates, 'run' );
+ // Execute the non-DataUpdate tasks
+ foreach ( $otherUpdates as $update ) {
try {
$update->doUpdate();
}
if ( $title instanceof Title ) {
- $output .= "<li>"
- . Linker::link( $title )
- . ' (' . Linker::link( $title->getTalkPage(), $talk )
- . ")</li>\n";
+ $output .= '<li>' .
+ Linker::link( $title ) . ' ' .
+ $this->msg( 'parentheses' )->rawParams(
+ Linker::link( $title->getTalkPage(), $talk )
+ )->escaped() .
+ "</li>\n";
}
}
$link = '<span class="watchlistredir">' . $link . '</span>';
}
- return $link . " (" . $this->getLanguage()->pipeList( $tools ) . ")";
+ return $link . ' ' .
+ $this->msg( 'parentheses' )->rawParams( $this->getLanguage()->pipeList( $tools ) )->escaped();
}
/**
),
);
}
+
+ /**
+ * @covers OutputPage::haveCacheVaryCookies
+ */
+ function testHaveCacheVaryCookies() {
+ $request = new FauxRequest();
+ $context = new RequestContext();
+ $context->setRequest( $request );
+ $outputPage = new OutputPage( $context );
+
+ // No cookies are set.
+ $this->assertFalse( $outputPage->haveCacheVaryCookies() );
+
+ // 'Token' is present but empty, so it shouldn't count.
+ $request->setCookie( 'Token', '' );
+ $this->assertFalse( $outputPage->haveCacheVaryCookies() );
+
+ // 'Token' present and nonempty.
+ $request->setCookie( 'Token', '123' );
+ $this->assertTrue( $outputPage->haveCacheVaryCookies() );
+ }
}
/**