MediaWiki  REL1_21
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 
00055         protected $phpErrors;
00056 
00066         public $pageSequence = array(
00067                 'Language',
00068                 'ExistingWiki',
00069                 'Welcome',
00070                 'DBConnect',
00071                 'Upgrade',
00072                 'DBSettings',
00073                 'Name',
00074                 'Options',
00075                 'Install',
00076                 'Complete',
00077         );
00078 
00083         protected $otherPages = array(
00084                 'Restart',
00085                 'Readme',
00086                 'ReleaseNotes',
00087                 'Copying',
00088                 'UpgradeDoc', // Can't use Upgrade due to Upgrade step
00089         );
00090 
00096         protected $happyPages;
00097 
00104         protected $skippedPages;
00105 
00110         public $showSessionWarning = false;
00111 
00116         protected $tabIndex = 1;
00117 
00122         protected $currentPageName;
00123 
00129         public function __construct( WebRequest $request ) {
00130                 parent::__construct();
00131                 $this->output = new WebInstallerOutput( $this );
00132                 $this->request = $request;
00133 
00134                 // Add parser hooks
00135                 global $wgParser;
00136                 $wgParser->setHook( 'downloadlink', array( $this, 'downloadLinkHook' ) );
00137                 $wgParser->setHook( 'doclink', array( $this, 'docLink' ) );
00138         }
00139 
00147         public function execute( array $session ) {
00148                 $this->session = $session;
00149 
00150                 if ( isset( $session['settings'] ) ) {
00151                         $this->settings = $session['settings'] + $this->settings;
00152                 }
00153 
00154                 $this->exportVars();
00155                 $this->setupLanguage();
00156 
00157                 if( ( $this->getVar( '_InstallDone' ) || $this->getVar( '_UpgradeDone' ) )
00158                         && $this->request->getVal( 'localsettings' ) )
00159                 {
00160                         $this->request->response()->header( 'Content-type: application/x-httpd-php' );
00161                         $this->request->response()->header(
00162                                 'Content-Disposition: attachment; filename="LocalSettings.php"'
00163                         );
00164 
00165                         $ls = InstallerOverrides::getLocalSettingsGenerator( $this );
00166                         $rightsProfile = $this->rightsProfiles[$this->getVar( '_RightsProfile' )];
00167                         foreach( $rightsProfile as $group => $rightsArr ) {
00168                                 $ls->setGroupRights( $group, $rightsArr );
00169                         }
00170                         echo $ls->getText();
00171                         return $this->session;
00172                 }
00173 
00174                 $cssDir = $this->request->getVal( 'css' );
00175                 if( $cssDir ) {
00176                         $cssDir = ( $cssDir == 'rtl' ? 'rtl' : 'ltr' );
00177                         $this->request->response()->header( 'Content-type: text/css' );
00178                         echo $this->output->getCSS( $cssDir );
00179                         return $this->session;
00180                 }
00181 
00182                 if ( isset( $session['happyPages'] ) ) {
00183                         $this->happyPages = $session['happyPages'];
00184                 } else {
00185                         $this->happyPages = array();
00186                 }
00187 
00188                 if ( isset( $session['skippedPages'] ) ) {
00189                         $this->skippedPages = $session['skippedPages'];
00190                 } else {
00191                         $this->skippedPages = array();
00192                 }
00193 
00194                 $lowestUnhappy = $this->getLowestUnhappy();
00195 
00196                 # Special case for Creative Commons partner chooser box.
00197                 if ( $this->request->getVal( 'SubmitCC' ) ) {
00198                         $page = $this->getPageByName( 'Options' );
00199                         $this->output->useShortHeader();
00200                         $this->output->allowFrames();
00201                         $page->submitCC();
00202                         return $this->finish();
00203                 }
00204 
00205                 if ( $this->request->getVal( 'ShowCC' ) ) {
00206                         $page = $this->getPageByName( 'Options' );
00207                         $this->output->useShortHeader();
00208                         $this->output->allowFrames();
00209                         $this->output->addHTML( $page->getCCDoneBox() );
00210                         return $this->finish();
00211                 }
00212 
00213                 # Get the page name.
00214                 $pageName = $this->request->getVal( 'page' );
00215 
00216                 if ( in_array( $pageName, $this->otherPages ) ) {
00217                         # Out of sequence
00218                         $pageId = false;
00219                         $page = $this->getPageByName( $pageName );
00220                 } else {
00221                         # Main sequence
00222                         if ( !$pageName || !in_array( $pageName, $this->pageSequence ) ) {
00223                                 $pageId = $lowestUnhappy;
00224                         } else {
00225                                 $pageId = array_search( $pageName, $this->pageSequence );
00226                         }
00227 
00228                         # If necessary, move back to the lowest-numbered unhappy page
00229                         if ( $pageId > $lowestUnhappy ) {
00230                                 $pageId = $lowestUnhappy;
00231                                 if ( $lowestUnhappy == 0 ) {
00232                                         # Knocked back to start, possible loss of session data.
00233                                         $this->showSessionWarning = true;
00234                                 }
00235                         }
00236 
00237                         $pageName = $this->pageSequence[$pageId];
00238                         $page = $this->getPageByName( $pageName );
00239                 }
00240 
00241                 # If a back button was submitted, go back without submitting the form data.
00242                 if ( $this->request->wasPosted() && $this->request->getBool( 'submit-back' ) ) {
00243                         if ( $this->request->getVal( 'lastPage' ) ) {
00244                                 $nextPage = $this->request->getVal( 'lastPage' );
00245                         } elseif ( $pageId !== false ) {
00246                                 # Main sequence page
00247                                 # Skip the skipped pages
00248                                 $nextPageId = $pageId;
00249 
00250                                 do {
00251                                         $nextPageId--;
00252                                         $nextPage = $this->pageSequence[$nextPageId];
00253                                 } while( isset( $this->skippedPages[$nextPage] ) );
00254                         } else {
00255                                 $nextPage = $this->pageSequence[$lowestUnhappy];
00256                         }
00257 
00258                         $this->output->redirect( $this->getUrl( array( 'page' => $nextPage ) ) );
00259                         return $this->finish();
00260                 }
00261 
00262                 # Execute the page.
00263                 $this->currentPageName = $page->getName();
00264                 $this->startPageWrapper( $pageName );
00265 
00266                 if( $page->isSlow() ) {
00267                         $this->disableTimeLimit();
00268                 }
00269 
00270                 $result = $page->execute();
00271 
00272                 $this->endPageWrapper();
00273 
00274                 if ( $result == 'skip' ) {
00275                         # Page skipped without explicit submission.
00276                         # Skip it when we click "back" so that we don't just go forward again.
00277                         $this->skippedPages[$pageName] = true;
00278                         $result = 'continue';
00279                 } else {
00280                         unset( $this->skippedPages[$pageName] );
00281                 }
00282 
00283                 # If it was posted, the page can request a continue to the next page.
00284                 if ( $result === 'continue' && !$this->output->headerDone() ) {
00285                         if ( $pageId !== false ) {
00286                                 $this->happyPages[$pageId] = true;
00287                         }
00288 
00289                         $lowestUnhappy = $this->getLowestUnhappy();
00290 
00291                         if ( $this->request->getVal( 'lastPage' ) ) {
00292                                 $nextPage = $this->request->getVal( 'lastPage' );
00293                         } elseif ( $pageId !== false ) {
00294                                 $nextPage = $this->pageSequence[$pageId + 1];
00295                         } else {
00296                                 $nextPage = $this->pageSequence[$lowestUnhappy];
00297                         }
00298 
00299                         if ( array_search( $nextPage, $this->pageSequence ) > $lowestUnhappy ) {
00300                                 $nextPage = $this->pageSequence[$lowestUnhappy];
00301                         }
00302 
00303                         $this->output->redirect( $this->getUrl( array( 'page' => $nextPage ) ) );
00304                 }
00305 
00306                 return $this->finish();
00307         }
00308 
00313         public function getLowestUnhappy() {
00314                 if ( count( $this->happyPages ) == 0 ) {
00315                         return 0;
00316                 } else {
00317                         return max( array_keys( $this->happyPages ) ) + 1;
00318                 }
00319         }
00320 
00326         public function startSession() {
00327                 if( wfIniGetBool( 'session.auto_start' ) || session_id() ) {
00328                         // Done already
00329                         return true;
00330                 }
00331 
00332                 $this->phpErrors = array();
00333                 set_error_handler( array( $this, 'errorHandler' ) );
00334                 session_start();
00335                 restore_error_handler();
00336 
00337                 if ( $this->phpErrors ) {
00338                         $this->showError( 'config-session-error', $this->phpErrors[0] );
00339                         return false;
00340                 }
00341 
00342                 return true;
00343         }
00344 
00353         public function getFingerprint() {
00354                 // Get the base URL of the installation
00355                 $url = $this->request->getFullRequestURL();
00356                 if ( preg_match( '!^(.*\?)!', $url, $m) ) {
00357                         // Trim query string
00358                         $url = $m[1];
00359                 }
00360                 if ( preg_match( '!^(.*)/[^/]*/[^/]*$!', $url, $m ) ) {
00361                         // This... seems to try to get the base path from
00362                         // the /mw-config/index.php. Kinda scary though?
00363                         $url = $m[1];
00364                 }
00365                 return md5( serialize( array(
00366                         'local path' => dirname( __DIR__ ),
00367                         'url' => $url,
00368                         'version' => $GLOBALS['wgVersion']
00369                 ) ) );
00370         }
00371 
00376         public function showError( $msg /*...*/ ) {
00377                 $args = func_get_args();
00378                 array_shift( $args );
00379                 $args = array_map( 'htmlspecialchars', $args );
00380                 $msg = wfMessage( $msg, $args )->useDatabase( false )->plain();
00381                 $this->output->addHTML( $this->getErrorBox( $msg ) );
00382         }
00383 
00389         public function errorHandler( $errno, $errstr ) {
00390                 $this->phpErrors[] = $errstr;
00391         }
00392 
00398         public function finish() {
00399                 $this->output->output();
00400 
00401                 $this->session['happyPages'] = $this->happyPages;
00402                 $this->session['skippedPages'] = $this->skippedPages;
00403                 $this->session['settings'] = $this->settings;
00404 
00405                 return $this->session;
00406         }
00407 
00411         public function reset() {
00412                 $this->session = array();
00413                 $this->happyPages = array();
00414                 $this->settings = array();
00415         }
00416 
00423         public function getUrl( $query = array() ) {
00424                 $url = $this->request->getRequestURL();
00425                 # Remove existing query
00426                 $url = preg_replace( '/\?.*$/', '', $url );
00427 
00428                 if ( $query ) {
00429                         $url .= '?' . wfArrayToCgi( $query );
00430                 }
00431 
00432                 return $url;
00433         }
00434 
00441         public function getPageByName( $pageName ) {
00442                 $pageClass = 'WebInstaller_' . $pageName;
00443 
00444                 return new $pageClass( $this );
00445         }
00446 
00454         public function getSession( $name, $default = null ) {
00455                 if ( !isset( $this->session[$name] ) ) {
00456                         return $default;
00457                 } else {
00458                         return $this->session[$name];
00459                 }
00460         }
00461 
00467         public function setSession( $name, $value ) {
00468                 $this->session[$name] = $value;
00469         }
00470 
00475         public function nextTabIndex() {
00476                 return $this->tabIndex++;
00477         }
00478 
00482         public function setupLanguage() {
00483                 global $wgLang, $wgContLang, $wgLanguageCode;
00484 
00485                 if ( $this->getSession( 'test' ) === null && !$this->request->wasPosted() ) {
00486                         $wgLanguageCode = $this->getAcceptLanguage();
00487                         $wgLang = $wgContLang = Language::factory( $wgLanguageCode );
00488                         $this->setVar( 'wgLanguageCode', $wgLanguageCode );
00489                         $this->setVar( '_UserLang', $wgLanguageCode );
00490                 } else {
00491                         $wgLanguageCode = $this->getVar( 'wgLanguageCode' );
00492                         $wgContLang = Language::factory( $wgLanguageCode );
00493                 }
00494         }
00495 
00501         public function getAcceptLanguage() {
00502                 global $wgLanguageCode, $wgRequest;
00503 
00504                 $mwLanguages = Language::fetchLanguageNames();
00505                 $headerLanguages = array_keys( $wgRequest->getAcceptLang() );
00506 
00507                 foreach ( $headerLanguages as $lang ) {
00508                         if ( isset( $mwLanguages[$lang] ) ) {
00509                                 return $lang;
00510                         }
00511                 }
00512 
00513                 return $wgLanguageCode;
00514         }
00515 
00521         private function startPageWrapper( $currentPageName ) {
00522                 $s = "<div class=\"config-page-wrapper\">\n";
00523                 $s .= "<div class=\"config-page\">\n";
00524                 $s .= "<div class=\"config-page-list\"><ul>\n";
00525                 $lastHappy = -1;
00526 
00527                 foreach ( $this->pageSequence as $id => $pageName ) {
00528                         $happy = !empty( $this->happyPages[$id] );
00529                         $s .= $this->getPageListItem(
00530                                 $pageName,
00531                                 $happy || $lastHappy == $id - 1,
00532                                 $currentPageName
00533                         );
00534 
00535                         if ( $happy ) {
00536                                 $lastHappy = $id;
00537                         }
00538                 }
00539 
00540                 $s .= "</ul><br/><ul>\n";
00541                 $s .= $this->getPageListItem( 'Restart', true, $currentPageName );
00542                 $s .= "</ul></div>\n"; // end list pane
00543                 $s .= Html::element( 'h2', array(),
00544                         wfMessage( 'config-page-' . strtolower( $currentPageName ) )->text() );
00545 
00546                 $this->output->addHTMLNoFlush( $s );
00547         }
00548 
00558         private function getPageListItem( $pageName, $enabled, $currentPageName ) {
00559                 $s = "<li class=\"config-page-list-item\">";
00560                 $name = wfMessage( 'config-page-' . strtolower( $pageName ) )->text();
00561 
00562                 if ( $enabled ) {
00563                         $query = array( 'page' => $pageName );
00564 
00565                         if ( !in_array( $pageName, $this->pageSequence ) ) {
00566                                 if ( in_array( $currentPageName, $this->pageSequence ) ) {
00567                                         $query['lastPage'] = $currentPageName;
00568                                 }
00569 
00570                                 $link = Html::element( 'a',
00571                                         array(
00572                                                 'href' => $this->getUrl( $query )
00573                                         ),
00574                                         $name
00575                                 );
00576                         } else {
00577                                 $link = htmlspecialchars( $name );
00578                         }
00579 
00580                         if ( $pageName == $currentPageName ) {
00581                                 $s .= "<span class=\"config-page-current\">$link</span>";
00582                         } else {
00583                                 $s .= $link;
00584                         }
00585                 } else {
00586                         $s .= Html::element( 'span',
00587                                 array(
00588                                         'class' => 'config-page-disabled'
00589                                 ),
00590                                 $name
00591                         );
00592                 }
00593 
00594                 $s .= "</li>\n";
00595 
00596                 return $s;
00597         }
00598 
00602         private function endPageWrapper() {
00603                 $this->output->addHTMLNoFlush(
00604                                         "<div class=\"visualClear\"></div>\n" .
00605                                 "</div>\n" .
00606                                 "<div class=\"visualClear\"></div>\n" .
00607                         "</div>" );
00608         }
00609 
00617         public function getErrorBox( $text ) {
00618                 return $this->getInfoBox( $text, 'critical-32.png', 'config-error-box' );
00619         }
00620 
00628         public function getWarningBox( $text ) {
00629                 return $this->getInfoBox( $text, 'warning-32.png', 'config-warning-box' );
00630         }
00631 
00641         public function getInfoBox( $text, $icon = false, $class = false ) {
00642                 $text = $this->parse( $text, true );
00643                 $icon = ( $icon == false ) ? '../skins/common/images/info-32.png' : '../skins/common/images/'.$icon;
00644                 $alt = wfMessage( 'config-information' )->text();
00645                 return Html::infoBox( $text, $icon, $alt, $class, false );
00646         }
00647 
00655         public function getHelpBox( $msg /*, ... */ ) {
00656                 $args = func_get_args();
00657                 array_shift( $args );
00658                 $args = array_map( 'htmlspecialchars', $args );
00659                 $text = wfMessage( $msg, $args )->useDatabase( false )->plain();
00660                 $html = $this->parse( $text, true );
00661 
00662                 return "<div class=\"mw-help-field-container\">\n" .
00663                         "<span class=\"mw-help-field-hint\">" . wfMessage( 'config-help' )->escaped() .
00664                         "</span>\n" .
00665                         "<span class=\"mw-help-field-data\">" . $html . "</span>\n" .
00666                         "</div>\n";
00667         }
00668 
00673         public function showHelpBox( $msg /*, ... */ ) {
00674                 $args = func_get_args();
00675                 $html = call_user_func_array( array( $this, 'getHelpBox' ), $args );
00676                 $this->output->addHTML( $html );
00677         }
00678 
00685         public function showMessage( $msg /*, ... */ ) {
00686                 $args = func_get_args();
00687                 array_shift( $args );
00688                 $html = '<div class="config-message">' .
00689                 $this->parse( wfMessage( $msg, $args )->useDatabase( false )->plain() ) .
00690                         "</div>\n";
00691                 $this->output->addHTML( $html );
00692         }
00693 
00697         public function showStatusMessage( Status $status ) {
00698                 $errors = array_merge( $status->getErrorsArray(), $status->getWarningsArray() );
00699                 foreach ( $errors as $error ) {
00700                         call_user_func_array( array( $this, 'showMessage' ), $error );
00701                 }
00702         }
00703 
00714         public function label( $msg, $forId, $contents, $helpData = "" ) {
00715                 if ( strval( $msg ) == '' ) {
00716                         $labelText = '&#160;';
00717                 } else {
00718                         $labelText = wfMessage( $msg )->escaped();
00719                 }
00720 
00721                 $attributes = array( 'class' => 'config-label' );
00722 
00723                 if ( $forId ) {
00724                         $attributes['for'] = $forId;
00725                 }
00726 
00727                 return
00728                         "<div class=\"config-block\">\n" .
00729                         "  <div class=\"config-block-label\">\n" .
00730                         Xml::tags( 'label',
00731                                 $attributes,
00732                                 $labelText ) . "\n" .
00733                                 $helpData .
00734                         "  </div>\n" .
00735                         "  <div class=\"config-block-elements\">\n" .
00736                                 $contents .
00737                         "  </div>\n" .
00738                         "</div>\n";
00739         }
00740 
00755         public function getTextBox( $params ) {
00756                 if ( !isset( $params['controlName'] ) ) {
00757                         $params['controlName'] = 'config_' . $params['var'];
00758                 }
00759 
00760                 if ( !isset( $params['value'] ) ) {
00761                         $params['value'] = $this->getVar( $params['var'] );
00762                 }
00763 
00764                 if ( !isset( $params['attribs'] ) ) {
00765                         $params['attribs'] = array();
00766                 }
00767                 if ( !isset( $params['help'] ) ) {
00768                         $params['help'] = "";
00769                 }
00770                 return
00771                         $this->label(
00772                                 $params['label'],
00773                                 $params['controlName'],
00774                                 Xml::input(
00775                                         $params['controlName'],
00776                                         30, // intended to be overridden by CSS
00777                                         $params['value'],
00778                                         $params['attribs'] + array(
00779                                                 'id' => $params['controlName'],
00780                                                 'class' => 'config-input-text',
00781                                                 'tabindex' => $this->nextTabIndex()
00782                                         )
00783                                 ),
00784                                 $params['help']
00785                         );
00786         }
00787 
00802         public function getTextArea( $params ) {
00803                 if ( !isset( $params['controlName'] ) ) {
00804                         $params['controlName'] = 'config_' . $params['var'];
00805                 }
00806 
00807                 if ( !isset( $params['value'] ) ) {
00808                         $params['value'] = $this->getVar( $params['var'] );
00809                 }
00810 
00811                 if ( !isset( $params['attribs'] ) ) {
00812                         $params['attribs'] = array();
00813                 }
00814                 if ( !isset( $params['help'] ) ) {
00815                         $params['help'] = "";
00816                 }
00817                 return
00818                         $this->label(
00819                                 $params['label'],
00820                                 $params['controlName'],
00821                                 Xml::textarea(
00822                                         $params['controlName'],
00823                                         $params['value'],
00824                                         30,
00825                                         5,
00826                                         $params['attribs'] + array(
00827                                                 'id' => $params['controlName'],
00828                                                 'class' => 'config-input-text',
00829                                                 'tabindex' => $this->nextTabIndex()
00830                                         )
00831                                 ),
00832                                 $params['help']
00833                         );
00834         }
00835 
00851         public function getPasswordBox( $params ) {
00852                 if ( !isset( $params['value'] ) ) {
00853                         $params['value'] = $this->getVar( $params['var'] );
00854                 }
00855 
00856                 if ( !isset( $params['attribs'] ) ) {
00857                         $params['attribs'] = array();
00858                 }
00859 
00860                 $params['value'] = $this->getFakePassword( $params['value'] );
00861                 $params['attribs']['type'] = 'password';
00862 
00863                 return $this->getTextBox( $params );
00864         }
00865 
00880         public function getCheckBox( $params ) {
00881                 if ( !isset( $params['controlName'] ) ) {
00882                         $params['controlName'] = 'config_' . $params['var'];
00883                 }
00884 
00885                 if ( !isset( $params['value'] ) ) {
00886                         $params['value'] = $this->getVar( $params['var'] );
00887                 }
00888 
00889                 if ( !isset( $params['attribs'] ) ) {
00890                         $params['attribs'] = array();
00891                 }
00892                 if ( !isset( $params['help'] ) ) {
00893                         $params['help'] = "";
00894                 }
00895                 if( isset( $params['rawtext'] ) ) {
00896                         $labelText = $params['rawtext'];
00897                 } else {
00898                         $labelText = $this->parse( wfMessage( $params['label'] )->text() );
00899                 }
00900 
00901                 return
00902                         "<div class=\"config-input-check\">\n" .
00903                         $params['help'] .
00904                         "<label>\n" .
00905                         Xml::check(
00906                                 $params['controlName'],
00907                                 $params['value'],
00908                                 $params['attribs'] + array(
00909                                         'id' => $params['controlName'],
00910                                         'tabindex' => $this->nextTabIndex(),
00911                                 )
00912                         ) .
00913                         $labelText . "\n" .
00914                         "</label>\n" .
00915                         "</div>\n";
00916         }
00917 
00935         public function getRadioSet( $params ) {
00936                 if ( !isset( $params['controlName'] ) ) {
00937                         $params['controlName'] = 'config_' . $params['var'];
00938                 }
00939 
00940                 if ( !isset( $params['value'] ) ) {
00941                         $params['value'] = $this->getVar( $params['var'] );
00942                 }
00943 
00944                 if ( !isset( $params['label'] ) ) {
00945                         $label = '';
00946                 } else {
00947                         $label = $params['label'];
00948                 }
00949                 if ( !isset( $params['help'] ) ) {
00950                         $params['help'] = "";
00951                 }
00952                 $s = "<ul>\n";
00953                 foreach ( $params['values'] as $value ) {
00954                         $itemAttribs = array();
00955 
00956                         if ( isset( $params['commonAttribs'] ) ) {
00957                                 $itemAttribs = $params['commonAttribs'];
00958                         }
00959 
00960                         if ( isset( $params['itemAttribs'][$value] ) ) {
00961                                 $itemAttribs = $params['itemAttribs'][$value] + $itemAttribs;
00962                         }
00963 
00964                         $checked = $value == $params['value'];
00965                         $id = $params['controlName'] . '_' . $value;
00966                         $itemAttribs['id'] = $id;
00967                         $itemAttribs['tabindex'] = $this->nextTabIndex();
00968 
00969                         $s .=
00970                                 '<li>' .
00971                                 Xml::radio( $params['controlName'], $value, $checked, $itemAttribs ) .
00972                                 '&#160;' .
00973                                 Xml::tags( 'label', array( 'for' => $id ), $this->parse(
00974                                         wfMessage( $params['itemLabelPrefix'] . strtolower( $value ) )->plain()
00975                                 ) ) .
00976                                 "</li>\n";
00977                 }
00978 
00979                 $s .= "</ul>\n";
00980 
00981                 return $this->label( $label, $params['controlName'], $s, $params['help'] );
00982         }
00983 
00989         public function showStatusBox( $status ) {
00990                 if( !$status->isGood() ) {
00991                         $text = $status->getWikiText();
00992 
00993                         if( $status->isOk() ) {
00994                                 $box = $this->getWarningBox( $text );
00995                         } else {
00996                                 $box = $this->getErrorBox( $text );
00997                         }
00998 
00999                         $this->output->addHTML( $box );
01000                 }
01001         }
01002 
01013         public function setVarsFromRequest( $varNames, $prefix = 'config_' ) {
01014                 $newValues = array();
01015 
01016                 foreach ( $varNames as $name ) {
01017                         $value = trim( $this->request->getVal( $prefix . $name ) );
01018                         $newValues[$name] = $value;
01019 
01020                         if ( $value === null ) {
01021                                 // Checkbox?
01022                                 $this->setVar( $name, false );
01023                         } else {
01024                                 if ( stripos( $name, 'password' ) !== false ) {
01025                                         $this->setPassword( $name, $value );
01026                                 } else {
01027                                         $this->setVar( $name, $value );
01028                                 }
01029                         }
01030                 }
01031 
01032                 return $newValues;
01033         }
01034 
01041         protected function getDocUrl( $page ) {
01042                 $url = "{$_SERVER['PHP_SELF']}?page=" . urlencode( $page );
01043 
01044                 if ( in_array( $this->currentPageName, $this->pageSequence ) ) {
01045                         $url .= '&lastPage=' . urlencode( $this->currentPageName );
01046                 }
01047 
01048                 return $url;
01049         }
01050 
01059         public function docLink( $linkText, $attribs, $parser ) {
01060                 $url = $this->getDocUrl( $attribs['href'] );
01061                 return '<a href="' . htmlspecialchars( $url ) . '">' .
01062                         htmlspecialchars( $linkText ) .
01063                         '</a>';
01064         }
01065 
01074         public function downloadLinkHook( $text, $attribs, $parser  ) {
01075                 $img = Html::element( 'img', array(
01076                         'src' => '../skins/common/images/download-32.png',
01077                         'width' => '32',
01078                         'height' => '32',
01079                 ) );
01080                 $anchor = Html::rawElement( 'a',
01081                         array( 'href' => $this->getURL( array( 'localsettings' => 1 ) ) ),
01082                         $img . ' ' . wfMessage( 'config-download-localsettings' )->parse() );
01083                 return Html::rawElement( 'div', array( 'class' => 'config-download-link' ), $anchor );
01084         }
01085 
01089         public function envCheckPath() {
01090                 // PHP_SELF isn't available sometimes, such as when PHP is CGI but
01091                 // cgi.fix_pathinfo is disabled. In that case, fall back to SCRIPT_NAME
01092                 // to get the path to the current script... hopefully it's reliable. SIGH
01093                 $path = false;
01094                 if ( !empty( $_SERVER['PHP_SELF'] ) ) {
01095                         $path = $_SERVER['PHP_SELF'];
01096                 } elseif ( !empty( $_SERVER['SCRIPT_NAME'] ) ) {
01097                         $path = $_SERVER['SCRIPT_NAME'];
01098                 }
01099                 if ( $path !== false ) {
01100                         $uri = preg_replace( '{^(.*)/(mw-)?config.*$}', '$1', $path );
01101                         $this->setVar( 'wgScriptPath', $uri );
01102                 } else {
01103                         $this->showError( 'config-no-uri' );
01104                         return false;
01105                 }
01106                 return parent::envCheckPath();
01107         }
01108 
01109         protected function envGetDefaultServer() {
01110                 return WebRequest::detectServer();
01111         }
01112 }