MediaWiki  REL1_24
WebInstaller.php
Go to the documentation of this file.
00001 <?php
00030 class WebInstaller extends Installer {
00031 
00035     public $output;
00036 
00042     public $request;
00043 
00049     protected $session;
00050 
00056     protected $phpErrors;
00057 
00068     public $pageSequence = array(
00069         'Language',
00070         'ExistingWiki',
00071         'Welcome',
00072         'DBConnect',
00073         'Upgrade',
00074         'DBSettings',
00075         'Name',
00076         'Options',
00077         'Install',
00078         'Complete',
00079     );
00080 
00086     protected $otherPages = array(
00087         'Restart',
00088         'Readme',
00089         'ReleaseNotes',
00090         'Copying',
00091         'UpgradeDoc', // Can't use Upgrade due to Upgrade step
00092     );
00093 
00100     protected $happyPages;
00101 
00109     protected $skippedPages;
00110 
00116     public $showSessionWarning = false;
00117 
00123     protected $tabIndex = 1;
00124 
00130     protected $currentPageName;
00131 
00137     public function __construct( WebRequest $request ) {
00138         parent::__construct();
00139         $this->output = new WebInstallerOutput( $this );
00140         $this->request = $request;
00141 
00142         // Add parser hooks
00143         global $wgParser;
00144         $wgParser->setHook( 'downloadlink', array( $this, 'downloadLinkHook' ) );
00145         $wgParser->setHook( 'doclink', array( $this, 'docLink' ) );
00146     }
00147 
00155     public function execute( array $session ) {
00156         $this->session = $session;
00157 
00158         if ( isset( $session['settings'] ) ) {
00159             $this->settings = $session['settings'] + $this->settings;
00160         }
00161 
00162         $this->exportVars();
00163         $this->setupLanguage();
00164 
00165         if ( ( $this->getVar( '_InstallDone' ) || $this->getVar( '_UpgradeDone' ) )
00166             && $this->request->getVal( 'localsettings' )
00167         ) {
00168             $this->request->response()->header( 'Content-type: application/x-httpd-php' );
00169             $this->request->response()->header(
00170                 'Content-Disposition: attachment; filename="LocalSettings.php"'
00171             );
00172 
00173             $ls = InstallerOverrides::getLocalSettingsGenerator( $this );
00174             $rightsProfile = $this->rightsProfiles[$this->getVar( '_RightsProfile' )];
00175             foreach ( $rightsProfile as $group => $rightsArr ) {
00176                 $ls->setGroupRights( $group, $rightsArr );
00177             }
00178             echo $ls->getText();
00179 
00180             return $this->session;
00181         }
00182 
00183         $isCSS = $this->request->getVal( 'css' );
00184         if ( $isCSS ) {
00185             $this->outputCss();
00186             return $this->session;
00187         }
00188 
00189         if ( isset( $session['happyPages'] ) ) {
00190             $this->happyPages = $session['happyPages'];
00191         } else {
00192             $this->happyPages = array();
00193         }
00194 
00195         if ( isset( $session['skippedPages'] ) ) {
00196             $this->skippedPages = $session['skippedPages'];
00197         } else {
00198             $this->skippedPages = array();
00199         }
00200 
00201         $lowestUnhappy = $this->getLowestUnhappy();
00202 
00203         # Special case for Creative Commons partner chooser box.
00204         if ( $this->request->getVal( 'SubmitCC' ) ) {
00205             $page = $this->getPageByName( 'Options' );
00206             $this->output->useShortHeader();
00207             $this->output->allowFrames();
00208             $page->submitCC();
00209 
00210             return $this->finish();
00211         }
00212 
00213         if ( $this->request->getVal( 'ShowCC' ) ) {
00214             $page = $this->getPageByName( 'Options' );
00215             $this->output->useShortHeader();
00216             $this->output->allowFrames();
00217             $this->output->addHTML( $page->getCCDoneBox() );
00218 
00219             return $this->finish();
00220         }
00221 
00222         # Get the page name.
00223         $pageName = $this->request->getVal( 'page' );
00224 
00225         if ( in_array( $pageName, $this->otherPages ) ) {
00226             # Out of sequence
00227             $pageId = false;
00228             $page = $this->getPageByName( $pageName );
00229         } else {
00230             # Main sequence
00231             if ( !$pageName || !in_array( $pageName, $this->pageSequence ) ) {
00232                 $pageId = $lowestUnhappy;
00233             } else {
00234                 $pageId = array_search( $pageName, $this->pageSequence );
00235             }
00236 
00237             # If necessary, move back to the lowest-numbered unhappy page
00238             if ( $pageId > $lowestUnhappy ) {
00239                 $pageId = $lowestUnhappy;
00240                 if ( $lowestUnhappy == 0 ) {
00241                     # Knocked back to start, possible loss of session data.
00242                     $this->showSessionWarning = true;
00243                 }
00244             }
00245 
00246             $pageName = $this->pageSequence[$pageId];
00247             $page = $this->getPageByName( $pageName );
00248         }
00249 
00250         # If a back button was submitted, go back without submitting the form data.
00251         if ( $this->request->wasPosted() && $this->request->getBool( 'submit-back' ) ) {
00252             if ( $this->request->getVal( 'lastPage' ) ) {
00253                 $nextPage = $this->request->getVal( 'lastPage' );
00254             } elseif ( $pageId !== false ) {
00255                 # Main sequence page
00256                 # Skip the skipped pages
00257                 $nextPageId = $pageId;
00258 
00259                 do {
00260                     $nextPageId--;
00261                     $nextPage = $this->pageSequence[$nextPageId];
00262                 } while ( isset( $this->skippedPages[$nextPage] ) );
00263             } else {
00264                 $nextPage = $this->pageSequence[$lowestUnhappy];
00265             }
00266 
00267             $this->output->redirect( $this->getUrl( array( 'page' => $nextPage ) ) );
00268 
00269             return $this->finish();
00270         }
00271 
00272         # Execute the page.
00273         $this->currentPageName = $page->getName();
00274         $this->startPageWrapper( $pageName );
00275 
00276         if ( $page->isSlow() ) {
00277             $this->disableTimeLimit();
00278         }
00279 
00280         $result = $page->execute();
00281 
00282         $this->endPageWrapper();
00283 
00284         if ( $result == 'skip' ) {
00285             # Page skipped without explicit submission.
00286             # Skip it when we click "back" so that we don't just go forward again.
00287             $this->skippedPages[$pageName] = true;
00288             $result = 'continue';
00289         } else {
00290             unset( $this->skippedPages[$pageName] );
00291         }
00292 
00293         # If it was posted, the page can request a continue to the next page.
00294         if ( $result === 'continue' && !$this->output->headerDone() ) {
00295             if ( $pageId !== false ) {
00296                 $this->happyPages[$pageId] = true;
00297             }
00298 
00299             $lowestUnhappy = $this->getLowestUnhappy();
00300 
00301             if ( $this->request->getVal( 'lastPage' ) ) {
00302                 $nextPage = $this->request->getVal( 'lastPage' );
00303             } elseif ( $pageId !== false ) {
00304                 $nextPage = $this->pageSequence[$pageId + 1];
00305             } else {
00306                 $nextPage = $this->pageSequence[$lowestUnhappy];
00307             }
00308 
00309             if ( array_search( $nextPage, $this->pageSequence ) > $lowestUnhappy ) {
00310                 $nextPage = $this->pageSequence[$lowestUnhappy];
00311             }
00312 
00313             $this->output->redirect( $this->getUrl( array( 'page' => $nextPage ) ) );
00314         }
00315 
00316         return $this->finish();
00317     }
00318 
00323     public function getLowestUnhappy() {
00324         if ( count( $this->happyPages ) == 0 ) {
00325             return 0;
00326         } else {
00327             return max( array_keys( $this->happyPages ) ) + 1;
00328         }
00329     }
00330 
00337     public function startSession() {
00338         if ( wfIniGetBool( 'session.auto_start' ) || session_id() ) {
00339             // Done already
00340             return true;
00341         }
00342 
00343         $this->phpErrors = array();
00344         set_error_handler( array( $this, 'errorHandler' ) );
00345         try {
00346             session_start();
00347         } catch ( Exception $e ) {
00348             restore_error_handler();
00349             throw $e;
00350         }
00351         restore_error_handler();
00352 
00353         if ( $this->phpErrors ) {
00354             return false;
00355         }
00356 
00357         return true;
00358     }
00359 
00368     public function getFingerprint() {
00369         // Get the base URL of the installation
00370         $url = $this->request->getFullRequestURL();
00371         if ( preg_match( '!^(.*\?)!', $url, $m ) ) {
00372             // Trim query string
00373             $url = $m[1];
00374         }
00375         if ( preg_match( '!^(.*)/[^/]*/[^/]*$!', $url, $m ) ) {
00376             // This... seems to try to get the base path from
00377             // the /mw-config/index.php. Kinda scary though?
00378             $url = $m[1];
00379         }
00380 
00381         return md5( serialize( array(
00382             'local path' => dirname( __DIR__ ),
00383             'url' => $url,
00384             'version' => $GLOBALS['wgVersion']
00385         ) ) );
00386     }
00387 
00392     public function showError( $msg /*...*/ ) {
00393         $args = func_get_args();
00394         array_shift( $args );
00395         $args = array_map( 'htmlspecialchars', $args );
00396         $msg = wfMessage( $msg, $args )->useDatabase( false )->plain();
00397         $this->output->addHTML( $this->getErrorBox( $msg ) );
00398     }
00399 
00406     public function errorHandler( $errno, $errstr ) {
00407         $this->phpErrors[] = $errstr;
00408     }
00409 
00415     public function finish() {
00416         $this->output->output();
00417 
00418         $this->session['happyPages'] = $this->happyPages;
00419         $this->session['skippedPages'] = $this->skippedPages;
00420         $this->session['settings'] = $this->settings;
00421 
00422         return $this->session;
00423     }
00424 
00428     public function reset() {
00429         $this->session = array();
00430         $this->happyPages = array();
00431         $this->settings = array();
00432     }
00433 
00441     public function getUrl( $query = array() ) {
00442         $url = $this->request->getRequestURL();
00443         # Remove existing query
00444         $url = preg_replace( '/\?.*$/', '', $url );
00445 
00446         if ( $query ) {
00447             $url .= '?' . wfArrayToCgi( $query );
00448         }
00449 
00450         return $url;
00451     }
00452 
00459     public function getPageByName( $pageName ) {
00460         $pageClass = 'WebInstaller' . $pageName;
00461 
00462         return new $pageClass( $this );
00463     }
00464 
00473     public function getSession( $name, $default = null ) {
00474         if ( !isset( $this->session[$name] ) ) {
00475             return $default;
00476         } else {
00477             return $this->session[$name];
00478         }
00479     }
00480 
00487     public function setSession( $name, $value ) {
00488         $this->session[$name] = $value;
00489     }
00490 
00496     public function nextTabIndex() {
00497         return $this->tabIndex++;
00498     }
00499 
00503     public function setupLanguage() {
00504         global $wgLang, $wgContLang, $wgLanguageCode;
00505 
00506         if ( $this->getSession( 'test' ) === null && !$this->request->wasPosted() ) {
00507             $wgLanguageCode = $this->getAcceptLanguage();
00508             $wgLang = $wgContLang = Language::factory( $wgLanguageCode );
00509             $this->setVar( 'wgLanguageCode', $wgLanguageCode );
00510             $this->setVar( '_UserLang', $wgLanguageCode );
00511         } else {
00512             $wgLanguageCode = $this->getVar( 'wgLanguageCode' );
00513             $wgContLang = Language::factory( $wgLanguageCode );
00514         }
00515     }
00516 
00522     public function getAcceptLanguage() {
00523         global $wgLanguageCode, $wgRequest;
00524 
00525         $mwLanguages = Language::fetchLanguageNames();
00526         $headerLanguages = array_keys( $wgRequest->getAcceptLang() );
00527 
00528         foreach ( $headerLanguages as $lang ) {
00529             if ( isset( $mwLanguages[$lang] ) ) {
00530                 return $lang;
00531             }
00532         }
00533 
00534         return $wgLanguageCode;
00535     }
00536 
00542     private function startPageWrapper( $currentPageName ) {
00543         $s = "<div class=\"config-page-wrapper\">\n";
00544         $s .= "<div class=\"config-page\">\n";
00545         $s .= "<div class=\"config-page-list\"><ul>\n";
00546         $lastHappy = -1;
00547 
00548         foreach ( $this->pageSequence as $id => $pageName ) {
00549             $happy = !empty( $this->happyPages[$id] );
00550             $s .= $this->getPageListItem(
00551                 $pageName,
00552                 $happy || $lastHappy == $id - 1,
00553                 $currentPageName
00554             );
00555 
00556             if ( $happy ) {
00557                 $lastHappy = $id;
00558             }
00559         }
00560 
00561         $s .= "</ul><br/><ul>\n";
00562         $s .= $this->getPageListItem( 'Restart', true, $currentPageName );
00563         // End list pane
00564         $s .= "</ul></div>\n";
00565 
00566         // Messages:
00567         // config-page-language, config-page-welcome, config-page-dbconnect, config-page-upgrade,
00568         // config-page-dbsettings, config-page-name, config-page-options, config-page-install,
00569         // config-page-complete, config-page-restart, config-page-readme, config-page-releasenotes,
00570         // config-page-copying, config-page-upgradedoc, config-page-existingwiki
00571         $s .= Html::element( 'h2', array(),
00572             wfMessage( 'config-page-' . strtolower( $currentPageName ) )->text() );
00573 
00574         $this->output->addHTMLNoFlush( $s );
00575     }
00576 
00586     private function getPageListItem( $pageName, $enabled, $currentPageName ) {
00587         $s = "<li class=\"config-page-list-item\">";
00588 
00589         // Messages:
00590         // config-page-language, config-page-welcome, config-page-dbconnect, config-page-upgrade,
00591         // config-page-dbsettings, config-page-name, config-page-options, config-page-install,
00592         // config-page-complete, config-page-restart, config-page-readme, config-page-releasenotes,
00593         // config-page-copying, config-page-upgradedoc, config-page-existingwiki
00594         $name = wfMessage( 'config-page-' . strtolower( $pageName ) )->text();
00595 
00596         if ( $enabled ) {
00597             $query = array( 'page' => $pageName );
00598 
00599             if ( !in_array( $pageName, $this->pageSequence ) ) {
00600                 if ( in_array( $currentPageName, $this->pageSequence ) ) {
00601                     $query['lastPage'] = $currentPageName;
00602                 }
00603 
00604                 $link = Html::element( 'a',
00605                     array(
00606                         'href' => $this->getUrl( $query )
00607                     ),
00608                     $name
00609                 );
00610             } else {
00611                 $link = htmlspecialchars( $name );
00612             }
00613 
00614             if ( $pageName == $currentPageName ) {
00615                 $s .= "<span class=\"config-page-current\">$link</span>";
00616             } else {
00617                 $s .= $link;
00618             }
00619         } else {
00620             $s .= Html::element( 'span',
00621                 array(
00622                     'class' => 'config-page-disabled'
00623                 ),
00624                 $name
00625             );
00626         }
00627 
00628         $s .= "</li>\n";
00629 
00630         return $s;
00631     }
00632 
00636     private function endPageWrapper() {
00637         $this->output->addHTMLNoFlush(
00638             "<div class=\"visualClear\"></div>\n" .
00639             "</div>\n" .
00640             "<div class=\"visualClear\"></div>\n" .
00641             "</div>" );
00642     }
00643 
00651     public function getErrorBox( $text ) {
00652         return $this->getInfoBox( $text, 'critical-32.png', 'config-error-box' );
00653     }
00654 
00662     public function getWarningBox( $text ) {
00663         return $this->getInfoBox( $text, 'warning-32.png', 'config-warning-box' );
00664     }
00665 
00675     public function getInfoBox( $text, $icon = false, $class = false ) {
00676         $text = $this->parse( $text, true );
00677         $icon = ( $icon == false ) ?
00678             'images/info-32.png' :
00679             'images/' . $icon;
00680         $alt = wfMessage( 'config-information' )->text();
00681 
00682         return Html::infoBox( $text, $icon, $alt, $class );
00683     }
00684 
00692     public function getHelpBox( $msg /*, ... */ ) {
00693         $args = func_get_args();
00694         array_shift( $args );
00695         $args = array_map( 'htmlspecialchars', $args );
00696         $text = wfMessage( $msg, $args )->useDatabase( false )->plain();
00697         $html = $this->parse( $text, true );
00698 
00699         return "<div class=\"mw-help-field-container\">\n" .
00700             "<span class=\"mw-help-field-hint\" title=\"" .
00701             wfMessage( 'config-help-tooltip' )->escaped() . "\">" .
00702             wfMessage( 'config-help' )->escaped() . "</span>\n" .
00703             "<span class=\"mw-help-field-data\">" . $html . "</span>\n" .
00704             "</div>\n";
00705     }
00706 
00711     public function showHelpBox( $msg /*, ... */ ) {
00712         $args = func_get_args();
00713         $html = call_user_func_array( array( $this, 'getHelpBox' ), $args );
00714         $this->output->addHTML( $html );
00715     }
00716 
00723     public function showMessage( $msg /*, ... */ ) {
00724         $args = func_get_args();
00725         array_shift( $args );
00726         $html = '<div class="config-message">' .
00727             $this->parse( wfMessage( $msg, $args )->useDatabase( false )->plain() ) .
00728             "</div>\n";
00729         $this->output->addHTML( $html );
00730     }
00731 
00735     public function showStatusMessage( Status $status ) {
00736         $errors = array_merge( $status->getErrorsArray(), $status->getWarningsArray() );
00737         foreach ( $errors as $error ) {
00738             call_user_func_array( array( $this, 'showMessage' ), $error );
00739         }
00740     }
00741 
00752     public function label( $msg, $forId, $contents, $helpData = "" ) {
00753         if ( strval( $msg ) == '' ) {
00754             $labelText = '&#160;';
00755         } else {
00756             $labelText = wfMessage( $msg )->escaped();
00757         }
00758 
00759         $attributes = array( 'class' => 'config-label' );
00760 
00761         if ( $forId ) {
00762             $attributes['for'] = $forId;
00763         }
00764 
00765         return "<div class=\"config-block\">\n" .
00766             "  <div class=\"config-block-label\">\n" .
00767             Xml::tags( 'label',
00768                 $attributes,
00769                 $labelText
00770             ) . "\n" .
00771             $helpData .
00772             "  </div>\n" .
00773             "  <div class=\"config-block-elements\">\n" .
00774             $contents .
00775             "  </div>\n" .
00776             "</div>\n";
00777     }
00778 
00793     public function getTextBox( $params ) {
00794         if ( !isset( $params['controlName'] ) ) {
00795             $params['controlName'] = 'config_' . $params['var'];
00796         }
00797 
00798         if ( !isset( $params['value'] ) ) {
00799             $params['value'] = $this->getVar( $params['var'] );
00800         }
00801 
00802         if ( !isset( $params['attribs'] ) ) {
00803             $params['attribs'] = array();
00804         }
00805         if ( !isset( $params['help'] ) ) {
00806             $params['help'] = "";
00807         }
00808 
00809         return $this->label(
00810             $params['label'],
00811             $params['controlName'],
00812             Xml::input(
00813                 $params['controlName'],
00814                 30, // intended to be overridden by CSS
00815                 $params['value'],
00816                 $params['attribs'] + array(
00817                     'id' => $params['controlName'],
00818                     'class' => 'config-input-text',
00819                     'tabindex' => $this->nextTabIndex()
00820                 )
00821             ),
00822             $params['help']
00823         );
00824     }
00825 
00840     public function getTextArea( $params ) {
00841         if ( !isset( $params['controlName'] ) ) {
00842             $params['controlName'] = 'config_' . $params['var'];
00843         }
00844 
00845         if ( !isset( $params['value'] ) ) {
00846             $params['value'] = $this->getVar( $params['var'] );
00847         }
00848 
00849         if ( !isset( $params['attribs'] ) ) {
00850             $params['attribs'] = array();
00851         }
00852         if ( !isset( $params['help'] ) ) {
00853             $params['help'] = "";
00854         }
00855 
00856         return $this->label(
00857             $params['label'],
00858             $params['controlName'],
00859             Xml::textarea(
00860                 $params['controlName'],
00861                 $params['value'],
00862                 30,
00863                 5,
00864                 $params['attribs'] + array(
00865                     'id' => $params['controlName'],
00866                     'class' => 'config-input-text',
00867                     'tabindex' => $this->nextTabIndex()
00868                 )
00869             ),
00870             $params['help']
00871         );
00872     }
00873 
00889     public function getPasswordBox( $params ) {
00890         if ( !isset( $params['value'] ) ) {
00891             $params['value'] = $this->getVar( $params['var'] );
00892         }
00893 
00894         if ( !isset( $params['attribs'] ) ) {
00895             $params['attribs'] = array();
00896         }
00897 
00898         $params['value'] = $this->getFakePassword( $params['value'] );
00899         $params['attribs']['type'] = 'password';
00900 
00901         return $this->getTextBox( $params );
00902     }
00903 
00918     public function getCheckBox( $params ) {
00919         if ( !isset( $params['controlName'] ) ) {
00920             $params['controlName'] = 'config_' . $params['var'];
00921         }
00922 
00923         if ( !isset( $params['value'] ) ) {
00924             $params['value'] = $this->getVar( $params['var'] );
00925         }
00926 
00927         if ( !isset( $params['attribs'] ) ) {
00928             $params['attribs'] = array();
00929         }
00930         if ( !isset( $params['help'] ) ) {
00931             $params['help'] = "";
00932         }
00933         if ( isset( $params['rawtext'] ) ) {
00934             $labelText = $params['rawtext'];
00935         } else {
00936             $labelText = $this->parse( wfMessage( $params['label'] )->text() );
00937         }
00938 
00939         return "<div class=\"config-input-check\">\n" .
00940             $params['help'] .
00941             "<label>\n" .
00942             Xml::check(
00943                 $params['controlName'],
00944                 $params['value'],
00945                 $params['attribs'] + array(
00946                     'id' => $params['controlName'],
00947                     'tabindex' => $this->nextTabIndex(),
00948                 )
00949             ) .
00950             $labelText . "\n" .
00951             "</label>\n" .
00952             "</div>\n";
00953     }
00954 
00973     public function getRadioSet( $params ) {
00974         $items = $this->getRadioElements( $params );
00975 
00976         if ( !isset( $params['label'] ) ) {
00977             $label = '';
00978         } else {
00979             $label = $params['label'];
00980         }
00981 
00982         if ( !isset( $params['controlName'] ) ) {
00983             $params['controlName'] = 'config_' . $params['var'];
00984         }
00985 
00986         if ( !isset( $params['help'] ) ) {
00987             $params['help'] = "";
00988         }
00989 
00990         $s = "<ul>\n";
00991         foreach ( $items as $value => $item ) {
00992             $s .= "<li>$item</li>\n";
00993         }
00994         $s .= "</ul>\n";
00995 
00996         return $this->label( $label, $params['controlName'], $s, $params['help'] );
00997     }
00998 
01006     public function getRadioElements( $params ) {
01007         if ( !isset( $params['controlName'] ) ) {
01008             $params['controlName'] = 'config_' . $params['var'];
01009         }
01010 
01011         if ( !isset( $params['value'] ) ) {
01012             $params['value'] = $this->getVar( $params['var'] );
01013         }
01014 
01015         $items = array();
01016 
01017         foreach ( $params['values'] as $value ) {
01018             $itemAttribs = array();
01019 
01020             if ( isset( $params['commonAttribs'] ) ) {
01021                 $itemAttribs = $params['commonAttribs'];
01022             }
01023 
01024             if ( isset( $params['itemAttribs'][$value] ) ) {
01025                 $itemAttribs = $params['itemAttribs'][$value] + $itemAttribs;
01026             }
01027 
01028             $checked = $value == $params['value'];
01029             $id = $params['controlName'] . '_' . $value;
01030             $itemAttribs['id'] = $id;
01031             $itemAttribs['tabindex'] = $this->nextTabIndex();
01032 
01033             $items[$value] =
01034                 Xml::radio( $params['controlName'], $value, $checked, $itemAttribs ) .
01035                 '&#160;' .
01036                 Xml::tags( 'label', array( 'for' => $id ), $this->parse(
01037                     isset( $params['itemLabels'] ) ?
01038                         wfMessage( $params['itemLabels'][$value] )->plain() :
01039                         wfMessage( $params['itemLabelPrefix'] . strtolower( $value ) )->plain()
01040                 ) );
01041         }
01042 
01043         return $items;
01044     }
01045 
01051     public function showStatusBox( $status ) {
01052         if ( !$status->isGood() ) {
01053             $text = $status->getWikiText();
01054 
01055             if ( $status->isOk() ) {
01056                 $box = $this->getWarningBox( $text );
01057             } else {
01058                 $box = $this->getErrorBox( $text );
01059             }
01060 
01061             $this->output->addHTML( $box );
01062         }
01063     }
01064 
01075     public function setVarsFromRequest( $varNames, $prefix = 'config_' ) {
01076         $newValues = array();
01077 
01078         foreach ( $varNames as $name ) {
01079             $value = $this->request->getVal( $prefix . $name );
01080             // bug 30524, do not trim passwords
01081             if ( stripos( $name, 'password' ) === false ) {
01082                 $value = trim( $value );
01083             }
01084             $newValues[$name] = $value;
01085 
01086             if ( $value === null ) {
01087                 // Checkbox?
01088                 $this->setVar( $name, false );
01089             } else {
01090                 if ( stripos( $name, 'password' ) !== false ) {
01091                     $this->setPassword( $name, $value );
01092                 } else {
01093                     $this->setVar( $name, $value );
01094                 }
01095             }
01096         }
01097 
01098         return $newValues;
01099     }
01100 
01108     protected function getDocUrl( $page ) {
01109         $url = "{$_SERVER['PHP_SELF']}?page=" . urlencode( $page );
01110 
01111         if ( in_array( $this->currentPageName, $this->pageSequence ) ) {
01112             $url .= '&lastPage=' . urlencode( $this->currentPageName );
01113         }
01114 
01115         return $url;
01116     }
01117 
01127     public function docLink( $linkText, $attribs, $parser ) {
01128         $url = $this->getDocUrl( $attribs['href'] );
01129 
01130         return '<a href="' . htmlspecialchars( $url ) . '">' .
01131             htmlspecialchars( $linkText ) .
01132             '</a>';
01133     }
01134 
01144     public function downloadLinkHook( $text, $attribs, $parser ) {
01145         $anchor = Html::rawElement( 'a',
01146             array( 'href' => $this->getURL( array( 'localsettings' => 1 ) ) ),
01147             wfMessage( 'config-download-localsettings' )->parse()
01148         );
01149 
01150         return Html::rawElement( 'div', array( 'class' => 'config-download-link' ), $anchor );
01151     }
01152 
01156     public function envCheckPath() {
01157         // PHP_SELF isn't available sometimes, such as when PHP is CGI but
01158         // cgi.fix_pathinfo is disabled. In that case, fall back to SCRIPT_NAME
01159         // to get the path to the current script... hopefully it's reliable. SIGH
01160         $path = false;
01161         if ( !empty( $_SERVER['PHP_SELF'] ) ) {
01162             $path = $_SERVER['PHP_SELF'];
01163         } elseif ( !empty( $_SERVER['SCRIPT_NAME'] ) ) {
01164             $path = $_SERVER['SCRIPT_NAME'];
01165         }
01166         if ( $path !== false ) {
01167             $scriptPath = preg_replace( '{^(.*)/(mw-)?config.*$}', '$1', $path );
01168             $scriptExtension = $this->getVar( 'wgScriptExtension' );
01169 
01170             $this->setVar( 'wgScriptPath', "$scriptPath" );
01171             // Update variables set from Setup.php that are derived from wgScriptPath
01172             $this->setVar( 'wgScript', "$scriptPath/index$scriptExtension" );
01173             $this->setVar( 'wgLoadScript', "$scriptPath/load$scriptExtension" );
01174             $this->setVar( 'wgStylePath', "$scriptPath/skins" );
01175             $this->setVar( 'wgLocalStylePath', "$scriptPath/skins" );
01176             $this->setVar( 'wgExtensionAssetsPath', "$scriptPath/extensions" );
01177             $this->setVar( 'wgUploadPath', "$scriptPath/images" );
01178 
01179         } else {
01180             $this->showError( 'config-no-uri' );
01181 
01182             return false;
01183         }
01184 
01185         return parent::envCheckPath();
01186     }
01187 
01191     protected function envGetDefaultServer() {
01192         return WebRequest::detectServer();
01193     }
01194 
01198     public function outputCss() {
01199         $this->request->response()->header( 'Content-type: text/css' );
01200         echo $this->output->getCSS();
01201     }
01202 
01206     public function getPhpErrors() {
01207         return $this->phpErrors;
01208     }
01209 
01210 }