r38158 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r38157‎ | r38158 | r38159 >
Date:23:00, 28 July 2008
Author:brion
Status:old
Tags:
Comment:
Revert r38149 for now, causes regressions in API parsing.
Bug 14965 - https://bugzilla.wikimedia.org/show_bug.cgi?id=14965

PHP Catchable fatal error: Argument 1 passed to Title::equals() must be an instance of Title, null given, called in /usr/local/apache/common-local/php-1.5/includes/Linker.php on line 1323 and defined in /usr/local/apache/common-local/php-1.5/includes/Title.php on line 3003
$wgTitle isn't available in this sort of background rendering.
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/docs/hooks.txt (modified) (history)
  • /trunk/phase3/includes/Linker.php (modified) (history)
  • /trunk/phase3/includes/parser/Parser.php (modified) (history)

Diff [purge]

Index: trunk/phase3/docs/hooks.txt
@@ -533,17 +533,6 @@
534534 $article: article (object) being viewed
535535 $oldid: oldid (int) being viewed
536536
537 -'DoEditSectionLink': Override the HTML generated for section edit links
538 -$skin: Skin object rendering the UI
539 -$title: Title object for the title being linked to (may not be the same as
540 - $wgTitle, if the section is included from a template)
541 -$section: The designation of the section being pointed to, to be included in
542 - the link, like "&section=$section"
543 -$tooltip: The default tooltip. Escape with htmlspecialchars() before using.
544 - By default, this is wrapped in the 'editsectionhint' message.
545 -$result: The HTML to return, prefilled with the default plus whatever other
546 - changes earlier hooks have made
547 -
548537 'EditFilter': Perform checks on an edit
549538 $editor: Edit form (see includes/EditPage.php)
550539 $text: Contents of the edit box
@@ -590,14 +579,14 @@
591580 &$editpage: The current EditPage object
592581 &$buttons: Array of edit buttons "Save", "Preview", "Live", and "Diff"
593582
594 -'EditSectionLink': Do not use, use DoEditSectionLink instead.
 583+'EditSectionLink': Override the return value of Linker::editSectionLink()
595584 $skin: Skin rendering the UI
596585 $title: Title being linked to
597586 $section: Section to link to
598587 $link: Default link
599588 $result: Result (alter this to override the generated links)
600589
601 -'EditSectionLinkForOther': Do not use, use DoEditSectionLink instead.
 590+'EditSectionLinkForOther': Override the return value of Linker::editSectionLinkForOther()
602591 $skin: Skin rendering the UI
603592 $title: Title being linked to
604593 $section: Section to link to
Index: trunk/phase3/includes/parser/Parser.php
@@ -3609,9 +3609,9 @@
36103610 if( $isTemplate ) {
36113611 # Put a T flag in the section identifier, to indicate to extractSections()
36123612 # that sections inside <includeonly> should be counted.
3613 - $editlink = $sk->doEditSectionLink(Title::newFromText( $titleText ), "T-$sectionIndex");
 3613+ $editlink = $sk->editSectionLinkForOther($titleText, "T-$sectionIndex");
36143614 } else {
3615 - $editlink = $sk->doEditSectionLink($this->mTitle, $sectionIndex, $headlineHint);
 3615+ $editlink = $sk->editSectionLink($this->mTitle, $sectionIndex, $headlineHint);
36163616 }
36173617 } else {
36183618 $editlink = '';
Index: trunk/phase3/includes/Linker.php
@@ -1276,7 +1276,6 @@
12771277 * @param $section Integer: section number.
12781278 */
12791279 public function editSectionLinkForOther( $title, $section ) {
1280 - wfDeprecated( __METHOD__ );
12811280 $title = Title::newFromText( $title );
12821281 return $this->doEditSectionLink( $title, $section, '', 'EditSectionLinkForOther' );
12831282 }
@@ -1287,61 +1286,48 @@
12881287 * @param $hint Link String: title, or default if omitted or empty
12891288 */
12901289 public function editSectionLink( Title $nt, $section, $hint='' ) {
1291 - wfDeprecated( __METHOD__ );
 1290+ if( $hint != '' ) {
 1291+ $hint = wfMsgHtml( 'editsectionhint', htmlspecialchars( $hint ) );
 1292+ $hint = " title=\"$hint\"";
 1293+ }
12921294 return $this->doEditSectionLink( $nt, $section, $hint, 'EditSectionLink' );
12931295 }
12941296
12951297 /**
1296 - * Create a section edit link. This supersedes editSectionLink() and
1297 - * editSectionLinkForOther().
 1298+ * Implement editSectionLink and editSectionLinkForOther.
12981299 *
1299 - * @param $nt Title The title being linked to (may not be the same as
1300 - * $wgTitle, if the section is included from a template)
1301 - * @param $section string The designation of the section being pointed to,
1302 - * to be included in the link, like "&section=$section"
1303 - * @param $tooltip string The tooltip to use for the link: will be escaped
1304 - * and wrapped in the 'editsectionhint' message
1305 - * @return string HTML to use for edit link
 1300+ * @param $nt Title object
 1301+ * @param $section Integer, section number
 1302+ * @param $hint String, for HTML title attribute
 1303+ * @param $hook String, name of hook to run
 1304+ * @return String, HTML to use for edit link
13061305 */
1307 - public function doEditSectionLink( Title $nt, $section, $tooltip='' ) {
1308 - global $wgTitle;
1309 - $attribs = '';
1310 - if( $tooltip ) {
1311 - $attribs = wfMsgHtml( 'editsectionhint', htmlspecialchars( $tooltip ) );
1312 - $attribs = " title=\"$attribs\"";
1313 - }
1314 -
 1306+ protected function doEditSectionLink( Title $nt, $section, $hint, $hook ) {
 1307+ global $wgContLang;
 1308+ $editurl = '&section='.$section;
13151309 $url = $this->makeKnownLinkObj(
13161310 $nt,
13171311 htmlspecialchars(wfMsg('editsection')),
1318 - "action=edit&section=$section",
1319 - '', '', '', $attribs
 1312+ 'action=edit'.$editurl,
 1313+ '', '', '', $hint
13201314 );
1321 -
1322 - # Run the old hooks
13231315 $result = null;
1324 - if( $nt->equals( $wgTitle ) ) {
1325 - wfRunHooks( 'EditSectionLink', array( &$this, $nt, $section, $attribs, $url, &$result ) );
1326 - } else {
 1316+
 1317+ // The two hooks have slightly different interfaces . . .
 1318+ if( $hook == 'EditSectionLink' ) {
 1319+ wfRunHooks( 'EditSectionLink', array( &$this, $nt, $section, $hint, $url, &$result ) );
 1320+ } elseif( $hook == 'EditSectionLinkForOther' ) {
13271321 wfRunHooks( 'EditSectionLinkForOther', array( &$this, $nt, $section, $url, &$result ) );
13281322 }
13291323
1330 - if( !is_null( $result ) ) {
1331 - # For reverse compatibility, add the brackets *after* the hook is
1332 - # run, and even add them to hook-provided text. These hooks have
1333 - # inconsistent and redundant interfaces, which is why they should
1334 - # no longer be used. Use DoEditSectionLink instead.
 1324+ // For reverse compatibility, add the brackets *after* the hook is run,
 1325+ // and even add them to hook-provided text.
 1326+ if( is_null( $result ) ) {
13351327 $result = wfMsgHtml( 'editsection-brackets', $url );
1336 - return "<span class=\"editsection\">$result</span>";
 1328+ } else {
 1329+ $result = wfMsgHtml( 'editsection-brackets', $result );
13371330 }
1338 -
1339 - # Add the brackets and the span, and *then* run the nice new hook, with
1340 - # consistent and non-redundant arguments.
1341 - $result = wfMsgHtml( 'editsection-brackets', $url );
1342 - $result = "<span class=\"editsection\">$result</span>";
1343 -
1344 - wfRunHooks( 'DoEditSectionLink', array( $this, $nt, $section, $tooltip, &$result ) );
1345 - return $result;
 1331+ return "<span class=\"editsection\">$result</span>";
13461332 }
13471333
13481334 /**
Index: trunk/phase3/RELEASE-NOTES
@@ -29,8 +29,6 @@
3030 * (bug 8068) New __INDEX__ and __NOINDEX__ magic words allow user control of
3131 search engine indexing on a per-article basis.
3232 * Handheld stylesheet options
33 -* Added 'DoEditSectionLink' hook as a cleaner unified version of the old
34 - 'EditSectionLink' and 'EditSectionLinkForOther' hooks
3533
3634 === Bug fixes in 1.14 ===
3735

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r38149Linker::doEditSectionLink() and Linker::doEditSectionLinkForOther() and their...simetrical20:33, 28 July 2008
r38157Add type hint to Title::equals(); this lets the error log give us something u...brion22:52, 28 July 2008

Status & tagging log